1 17 18 19 package org.apache.catalina.core; 20 21 22 import java.io.IOException ; 23 24 import javax.servlet.ServletException ; 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.ServletRequestEvent ; 27 import javax.servlet.ServletRequestListener ; 28 import javax.servlet.http.HttpServletResponse ; 29 30 import org.apache.catalina.CometEvent; 31 import org.apache.catalina.Container; 32 import org.apache.catalina.Globals; 33 import org.apache.catalina.Wrapper; 34 import org.apache.catalina.connector.Request; 35 import org.apache.catalina.connector.Response; 36 import org.apache.catalina.util.StringManager; 37 import org.apache.catalina.valves.ValveBase; 38 import org.apache.tomcat.util.buf.MessageBytes; 39 40 50 51 final class StandardContextValve 52 extends ValveBase { 53 54 55 57 58 61 private static final String info = 62 "org.apache.catalina.core.StandardContextValve/1.0"; 63 64 65 68 private static final StringManager sm = 69 StringManager.getManager(Constants.Package); 70 71 72 private StandardContext context = null; 73 74 75 77 78 81 public String getInfo() { 82 83 return (info); 84 85 } 86 87 88 90 91 96 public void setContainer(Container container) { 97 super.setContainer(container); 98 context = (StandardContext) container; 99 } 100 101 102 114 public final void invoke(Request request, Response response) 115 throws IOException , ServletException { 116 117 MessageBytes requestPathMB = request.getRequestPathMB(); 119 if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) 120 || (requestPathMB.equalsIgnoreCase("/META-INF")) 121 || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) 122 || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { 123 String requestURI = request.getDecodedRequestURI(); 124 notFound(requestURI, response); 125 return; 126 } 127 128 while (context.getPaused()) { 130 try { 131 Thread.sleep(1000); 132 } catch (InterruptedException e) { 133 ; 134 } 135 } 136 137 Wrapper wrapper = request.getWrapper(); 139 if (wrapper == null) { 140 String requestURI = request.getDecodedRequestURI(); 141 notFound(requestURI, response); 142 return; 143 } 144 145 Object instances[] = context.getApplicationEventListeners(); 147 148 ServletRequestEvent event = null; 149 150 if ((instances != null) 151 && (instances.length > 0)) { 152 event = new ServletRequestEvent 153 (((StandardContext) container).getServletContext(), 154 request.getRequest()); 155 for (int i = 0; i < instances.length; i++) { 157 if (instances[i] == null) 158 continue; 159 if (!(instances[i] instanceof ServletRequestListener )) 160 continue; 161 ServletRequestListener listener = 162 (ServletRequestListener ) instances[i]; 163 try { 164 listener.requestInitialized(event); 165 } catch (Throwable t) { 166 container.getLogger().error(sm.getString("standardContext.requestListener.requestInit", 167 instances[i].getClass().getName()), t); 168 ServletRequest sreq = request.getRequest(); 169 sreq.setAttribute(Globals.EXCEPTION_ATTR,t); 170 return; 171 } 172 } 173 } 174 175 wrapper.getPipeline().getFirst().invoke(request, response); 176 177 if ((instances !=null ) && 178 (instances.length > 0)) { 179 for (int i = 0; i < instances.length; i++) { 181 if (instances[i] == null) 182 continue; 183 if (!(instances[i] instanceof ServletRequestListener )) 184 continue; 185 ServletRequestListener listener = 186 (ServletRequestListener ) instances[i]; 187 try { 188 listener.requestDestroyed(event); 189 } catch (Throwable t) { 190 container.getLogger().error(sm.getString("standardContext.requestListener.requestDestroy", 191 instances[i].getClass().getName()), t); 192 ServletRequest sreq = request.getRequest(); 193 sreq.setAttribute(Globals.EXCEPTION_ATTR,t); 194 } 195 } 196 } 197 198 } 199 200 201 213 public final void event(Request request, Response response, CometEvent event) 214 throws IOException , ServletException { 215 216 Wrapper wrapper = request.getWrapper(); 218 219 251 252 wrapper.getPipeline().getFirst().event(request, response, event); 253 254 276 277 } 278 279 280 282 283 292 private void notFound(String requestURI, HttpServletResponse response) { 293 294 try { 295 response.sendError(HttpServletResponse.SC_NOT_FOUND, requestURI); 296 } catch (IllegalStateException e) { 297 ; 298 } catch (IOException e) { 299 ; 300 } 301 302 } 303 304 305 } 306 | Popular Tags |