Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/handler/ContextHandler.java @ 1000:32d4b569567c
simplify handle()
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Wed, 19 Oct 2016 04:22:51 -0600 |
| parents | 7d28be82ab75 |
| children | 6939226e0ac4 |
comparison
equal
deleted
inserted
replaced
| 999:74b9daf2826c | 1000:32d4b569567c |
|---|---|
| 55 import javax.servlet.SessionTrackingMode; | 55 import javax.servlet.SessionTrackingMode; |
| 56 import javax.servlet.Filter; | 56 import javax.servlet.Filter; |
| 57 import javax.servlet.FilterRegistration; | 57 import javax.servlet.FilterRegistration; |
| 58 import javax.servlet.FilterRegistration.Dynamic; | 58 import javax.servlet.FilterRegistration.Dynamic; |
| 59 import javax.servlet.descriptor.JspConfigDescriptor; | 59 import javax.servlet.descriptor.JspConfigDescriptor; |
| 60 import javax.servlet.http.HttpServletRequest; | |
| 61 import javax.servlet.http.HttpServletResponse; | 60 import javax.servlet.http.HttpServletResponse; |
| 62 | 61 |
| 63 import org.eclipse.jetty.http.HttpException; | 62 import org.eclipse.jetty.http.HttpException; |
| 64 import org.eclipse.jetty.http.MimeTypes; | 63 import org.eclipse.jetty.http.MimeTypes; |
| 65 import org.eclipse.jetty.io.Buffer; | 64 import org.eclipse.jetty.io.Buffer; |
| 149 { | 148 { |
| 150 super.doStop(); | 149 super.doStop(); |
| 151 LOG.info("stopped {}",this); | 150 LOG.info("stopped {}",this); |
| 152 } | 151 } |
| 153 | 152 |
| 154 private boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response) throws IOException, ServletException | 153 private boolean checkContext(final String target, final Request request, final HttpServletResponse response) throws IOException, ServletException |
| 155 { | 154 { |
| 156 if (baseRequest.isHandled()) | 155 if (request.isHandled()) |
| 157 return false; | 156 return false; |
| 158 | 157 |
| 159 // Are we not the root context? | 158 // Are we not the root context? |
| 160 if (_contextPath.length() > 1) | 159 if (_contextPath.length() > 1) |
| 161 { | 160 { |
| 167 | 166 |
| 168 // redirect null path infos | 167 // redirect null path infos |
| 169 if (_contextPath.length() == target.length()) | 168 if (_contextPath.length() == target.length()) |
| 170 { | 169 { |
| 171 // context request must end with / | 170 // context request must end with / |
| 172 baseRequest.setHandled(true); | 171 request.setHandled(true); |
| 173 if (baseRequest.getQueryString() != null) | 172 if (request.getQueryString() != null) |
| 174 response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH) + "?" + baseRequest.getQueryString()); | 173 response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH) + "?" + request.getQueryString()); |
| 175 else | 174 else |
| 176 response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(),URIUtil.SLASH)); | 175 response.sendRedirect(URIUtil.addPaths(request.getRequestURI(),URIUtil.SLASH)); |
| 177 return false; | 176 return false; |
| 178 } | 177 } |
| 179 } | 178 } |
| 180 | 179 |
| 181 return true; | 180 return true; |
| 182 } | 181 } |
| 183 | 182 |
| 184 @Override | 183 @Override |
| 185 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException | 184 public void handle(String target, Request request, HttpServletResponse response) throws IOException, ServletException |
| 186 { | 185 { |
| 187 String old_context_path = null; | 186 String old_context_path = null; |
| 188 String old_path_info = null; | 187 String old_path_info = null; |
| 189 String pathInfo = target; | 188 String pathInfo = target; |
| 190 | 189 |
| 191 ContextHandler oldContextHandler = baseRequest._contextHandler; | 190 ContextHandler oldContextHandler = request._contextHandler; |
| 192 | 191 |
| 193 // Are we already in this context? | 192 // Are we already in this context? |
| 194 if (oldContextHandler != this) | 193 if (oldContextHandler != this) |
| 195 { | 194 { |
| 196 if (!checkContext(target,baseRequest,response)) | 195 if (!checkContext(target,request,response)) |
| 197 return; | 196 return; |
| 198 | 197 |
| 199 if (target.length() > _contextPath.length()) | 198 if (target.length() > _contextPath.length()) |
| 200 { | 199 { |
| 201 if (_contextPath.length() > 1) | 200 if (_contextPath.length() > 1) |
| 214 } | 213 } |
| 215 } | 214 } |
| 216 | 215 |
| 217 try | 216 try |
| 218 { | 217 { |
| 219 old_context_path = baseRequest.getContextPath(); | 218 old_context_path = request.getContextPath(); |
| 220 old_path_info = baseRequest.getPathInfo(); | 219 old_path_info = request.getPathInfo(); |
| 221 | 220 |
| 222 // Update the paths | 221 // Update the paths |
| 223 baseRequest._contextHandler = this; | 222 request._contextHandler = this; |
| 224 if (target.startsWith("/")) | 223 if (target.startsWith("/")) |
| 225 { | 224 { |
| 226 if (_contextPath.length() == 1) | 225 if (_contextPath.length() == 1) |
| 227 baseRequest.setContextPath(""); | 226 request.setContextPath(""); |
| 228 else | 227 else |
| 229 baseRequest.setContextPath(_contextPath); | 228 request.setContextPath(_contextPath); |
| 230 baseRequest.setPathInfo(pathInfo); | 229 request.setPathInfo(pathInfo); |
| 231 } | 230 } |
| 232 | 231 |
| 233 try | 232 try |
| 234 { | 233 { |
| 235 super.handle(target,baseRequest,request,response); | 234 super.handle(target,request,response); |
| 236 } | 235 } |
| 237 catch (HttpException e) | 236 catch (HttpException e) |
| 238 { | 237 { |
| 239 LOG.debug("",e); | 238 LOG.debug("",e); |
| 240 baseRequest.setHandled(true); | 239 request.setHandled(true); |
| 241 response.sendError(e.getStatus(),e.getReason()); | 240 response.sendError(e.getStatus(),e.getReason()); |
| 242 } | 241 } |
| 243 } | 242 } |
| 244 finally | 243 finally |
| 245 { | 244 { |
| 246 if (oldContextHandler != this) | 245 if (oldContextHandler != this) |
| 247 { | 246 { |
| 248 // reset the context and servlet path. | 247 // reset the context and servlet path. |
| 249 baseRequest._contextHandler = oldContextHandler; | 248 request._contextHandler = oldContextHandler; |
| 250 baseRequest.setContextPath(old_context_path); | 249 request.setContextPath(old_context_path); |
| 251 baseRequest.setPathInfo(old_path_info); | 250 request.setPathInfo(old_path_info); |
| 252 } | 251 } |
| 253 } | 252 } |
| 254 } | 253 } |
| 255 | 254 |
| 256 public void setContextPath(String contextPath) | 255 public void setContextPath(String contextPath) |
