From: fhanik Date: Thu, 16 Jul 2009 17:44:46 +0000 (+0000) Subject: Refactor the dispatcher types from int and Integer to the one supplied by the Servlet... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=695c1f0ead364b6fe4171114465f09e6a21472cc;p=tomcat7.0 Refactor the dispatcher types from int and Integer to the one supplied by the Servlet specification. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@794766 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/connector/AsyncContextImpl.java b/java/org/apache/catalina/connector/AsyncContextImpl.java index 06f843a0a..39788044c 100644 --- a/java/org/apache/catalina/connector/AsyncContextImpl.java +++ b/java/org/apache/catalina/connector/AsyncContextImpl.java @@ -41,9 +41,13 @@ public class AsyncContextImpl implements AsyncContext { private ServletResponse servletResponse = null; private List listeners = new ArrayList(); private boolean hasOriginalRequestAndResponse = true; + private boolean completed = false; - public AsyncContextImpl() { + private Request request; + + public AsyncContextImpl(Request request) { //TODO SERVLET3 - async + this.request = request; } @Override @@ -59,6 +63,7 @@ public class AsyncContextImpl implements AsyncContext { log.error("",x); } } + this.completed = true; } @@ -119,6 +124,7 @@ public class AsyncContextImpl implements AsyncContext { servletResponse = null; listeners.clear(); hasOriginalRequestAndResponse = true; + completed = false; } public boolean isStarted() { @@ -153,8 +159,14 @@ public class AsyncContextImpl implements AsyncContext { public void setHasOriginalRequestAndResponse(boolean hasOriginalRequestAndResponse) { this.hasOriginalRequestAndResponse = hasOriginalRequestAndResponse; } - - + + public boolean isCompleted() { + return completed; + } + + public void setCompleted(boolean completed) { + this.completed = completed; + } diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java index f667b649c..dda9e1546 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -19,11 +19,10 @@ package org.apache.catalina.connector; -import java.io.InputStream; -import java.io.IOException; import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; -import java.nio.channels.IllegalSelectorException; import java.security.Principal; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -56,18 +55,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import javax.servlet.http.Part; -import org.apache.tomcat.util.buf.B2CConverter; -import org.apache.tomcat.util.buf.ByteChunk; -import org.apache.tomcat.util.buf.MessageBytes; -import org.apache.tomcat.util.buf.StringCache; -import org.apache.tomcat.util.http.Cookies; -import org.apache.tomcat.util.http.FastHttpDateFormat; -import org.apache.tomcat.util.http.Parameters; -import org.apache.tomcat.util.http.ServerCookie; -import org.apache.tomcat.util.http.mapper.MappingData; - -import org.apache.coyote.ActionCode; - import org.apache.catalina.Context; import org.apache.catalina.Globals; import org.apache.catalina.Host; @@ -79,8 +66,18 @@ import org.apache.catalina.core.ApplicationFilterFactory; import org.apache.catalina.realm.GenericPrincipal; import org.apache.catalina.util.Enumerator; import org.apache.catalina.util.ParameterMap; -import org.apache.tomcat.util.res.StringManager; import org.apache.catalina.util.StringParser; +import org.apache.coyote.ActionCode; +import org.apache.tomcat.util.buf.B2CConverter; +import org.apache.tomcat.util.buf.ByteChunk; +import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.buf.StringCache; +import org.apache.tomcat.util.http.Cookies; +import org.apache.tomcat.util.http.FastHttpDateFormat; +import org.apache.tomcat.util.http.Parameters; +import org.apache.tomcat.util.http.ServerCookie; +import org.apache.tomcat.util.http.mapper.MappingData; +import org.apache.tomcat.util.res.StringManager; /** @@ -225,7 +222,7 @@ public class Request /** * The current dispatcher type. */ - protected Object dispatcherType = null; + protected DispatcherType internalDispatcherType = null; /** @@ -403,6 +400,8 @@ public class Request * async timeout */ protected long asyncTimeout = 0; + + // --------------------------------------------------------- Public Methods @@ -421,7 +420,7 @@ public class Request context = null; wrapper = null; - dispatcherType = null; + internalDispatcherType = null; requestDispatcherPath = null; comet = false; @@ -490,7 +489,9 @@ public class Request } - + protected boolean isProcessing() { + return coyoteRequest.isProcessing(); + } /** * Clear cached encoders (to save memory for Comet requests). */ @@ -842,9 +843,9 @@ public class Request public Object getAttribute(String name) { if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { - return (dispatcherType == null) - ? ApplicationFilterFactory.REQUEST_INTEGER - : dispatcherType; + return (internalDispatcherType == null) + ? DispatcherType.REQUEST + : internalDispatcherType; } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { return (requestDispatcherPath == null) ? getRequestPathMB().toString() @@ -1364,7 +1365,7 @@ public class Request } if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { - dispatcherType = value; + internalDispatcherType = (DispatcherType)value; return; } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { requestDispatcherPath = value; @@ -1461,7 +1462,7 @@ public class Request public AsyncContext startAsync() { // TODO SERVLET3 - async if (!isAsyncSupported()) throw new IllegalStateException("Not supported."); - if (asyncContext==null) asyncContext = new AsyncContextImpl(); + if (asyncContext==null) asyncContext = new AsyncContextImpl(this); else if (asyncContext.isStarted()) throw new IllegalStateException("Already started."); asyncContext.setServletRequest(getRequest()); asyncContext.setServletResponse(response.getResponse()); @@ -1512,7 +1513,10 @@ public class Request public void setAsyncTimeout(long timeout) { // TODO SERVLET3 - async - this.asyncTimeout = timeout; + if (this.asyncTimeout!=timeout) { + this.asyncTimeout = timeout; + coyoteRequest.action(ActionCode.ACTION_ASYNC_SETTIMEOUT,new Long(timeout)); + } } public long getAsyncTimeout() { @@ -1522,7 +1526,11 @@ public class Request public DispatcherType getDispatcherType() { // TODO SERVLET3 - dispatcher - return null; + if (internalDispatcherType==null) { + return DispatcherType.REQUEST; + } else { + return this.internalDispatcherType; + } } // ---------------------------------------------------- HttpRequest Methods diff --git a/java/org/apache/catalina/core/ApplicationDispatcher.java b/java/org/apache/catalina/core/ApplicationDispatcher.java index 9b18058d5..4fd833214 100644 --- a/java/org/apache/catalina/core/ApplicationDispatcher.java +++ b/java/org/apache/catalina/core/ApplicationDispatcher.java @@ -24,6 +24,7 @@ import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; import javax.servlet.ServletException; @@ -425,16 +426,15 @@ final class ApplicationDispatcher State state) throws IOException, ServletException { - Integer disInt = (Integer) request.getAttribute - (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR); + DispatcherType disInt = (DispatcherType) request.getAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR); if (disInt != null) { - if (disInt.intValue() != ApplicationFilterFactory.ERROR) { + if (disInt != DispatcherType.ERROR) { state.outerRequest.setAttribute (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath()); state.outerRequest.setAttribute (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - Integer.valueOf(ApplicationFilterFactory.FORWARD)); + DispatcherType.FORWARD); invoke(state.outerRequest, response, state); } else { invoke(state.outerRequest, response, state); @@ -514,7 +514,7 @@ final class ApplicationDispatcher if (servletPath != null) wrequest.setServletPath(servletPath); wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - Integer.valueOf(ApplicationFilterFactory.INCLUDE)); + DispatcherType.INCLUDE); wrequest.setAttribute( ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath()); @@ -546,7 +546,7 @@ final class ApplicationDispatcher } wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - Integer.valueOf(ApplicationFilterFactory.INCLUDE)); + DispatcherType.INCLUDE); wrequest.setAttribute( ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, getCombinedPath()); diff --git a/java/org/apache/catalina/core/ApplicationFilterFactory.java b/java/org/apache/catalina/core/ApplicationFilterFactory.java index ea3e1ecb2..05c588eab 100644 --- a/java/org/apache/catalina/core/ApplicationFilterFactory.java +++ b/java/org/apache/catalina/core/ApplicationFilterFactory.java @@ -19,6 +19,7 @@ package org.apache.catalina.core; +import javax.servlet.DispatcherType; import javax.servlet.Servlet; import javax.servlet.ServletRequest; @@ -43,15 +44,6 @@ public final class ApplicationFilterFactory { // -------------------------------------------------------------- Constants - public static final int ERROR = 1; - public static final Integer ERROR_INTEGER = new Integer(ERROR); - public static final int FORWARD = 2; - public static final Integer FORWARD_INTEGER = new Integer(FORWARD); - public static final int INCLUDE = 4; - public static final Integer INCLUDE_INTEGER = new Integer(INCLUDE); - public static final int REQUEST = 8; - public static final Integer REQUEST_INTEGER = new Integer(REQUEST); - public static final String DISPATCHER_TYPE_ATTR = Globals.DISPATCHER_TYPE_ATTR; public static final String DISPATCHER_REQUEST_PATH_ATTR = @@ -96,11 +88,9 @@ public final class ApplicationFilterFactory { (ServletRequest request, Wrapper wrapper, Servlet servlet) { // get the dispatcher type - int dispatcher = -1; + DispatcherType dispatcher = null; if (request.getAttribute(DISPATCHER_TYPE_ATTR) != null) { - Integer dispatcherInt = - (Integer) request.getAttribute(DISPATCHER_TYPE_ATTR); - dispatcher = dispatcherInt.intValue(); + dispatcher = (DispatcherType) request.getAttribute(DISPATCHER_TYPE_ATTR); } String requestPath = null; Object attribute = request.getAttribute(DISPATCHER_REQUEST_PATH_ATTR); @@ -341,8 +331,8 @@ public final class ApplicationFilterFactory { * Convienience method which returns true if the dispatcher type * matches the dispatcher types specified in the FilterMap */ - private boolean matchDispatcher(FilterMap filterMap, int dispatcher) { - switch (dispatcher) { + private boolean matchDispatcher(FilterMap filterMap, DispatcherType type) { + switch (type) { case FORWARD : { if (filterMap.getDispatcherMapping() == FilterMap.FORWARD || filterMap.getDispatcherMapping() == FilterMap.FORWARD_ERROR || diff --git a/java/org/apache/catalina/core/ApplicationHttpRequest.java b/java/org/apache/catalina/core/ApplicationHttpRequest.java index 99d69bfc0..7cceae68c 100644 --- a/java/org/apache/catalina/core/ApplicationHttpRequest.java +++ b/java/org/apache/catalina/core/ApplicationHttpRequest.java @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; @@ -126,7 +127,7 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { /** * The current dispatcher type. */ - protected Object dispatcherType = null; + protected DispatcherType dispatcherType = null; /** @@ -268,7 +269,7 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { public void setAttribute(String name, Object value) { if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { - dispatcherType = value; + dispatcherType = (DispatcherType)value; return; } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { requestDispatcherPath = value; @@ -673,7 +674,7 @@ class ApplicationHttpRequest extends HttpServletRequestWrapper { super.setRequest(request); // Initialize the attributes for this request - dispatcherType = request.getAttribute(Globals.DISPATCHER_TYPE_ATTR); + dispatcherType = (DispatcherType)request.getAttribute(Globals.DISPATCHER_TYPE_ATTR); requestDispatcherPath = request.getAttribute(Globals.DISPATCHER_REQUEST_PATH_ATTR); diff --git a/java/org/apache/catalina/core/StandardHostValve.java b/java/org/apache/catalina/core/StandardHostValve.java index 699bf382a..b4ac6eda3 100644 --- a/java/org/apache/catalina/core/StandardHostValve.java +++ b/java/org/apache/catalina/core/StandardHostValve.java @@ -21,6 +21,7 @@ package org.apache.catalina.core; import java.io.IOException; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -251,7 +252,7 @@ final class StandardHostValve (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, errorPage.getLocation()); request.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - new Integer(ApplicationFilterFactory.ERROR)); + DispatcherType.ERROR); request.setAttribute (Globals.STATUS_CODE_ATTR, new Integer(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)); @@ -330,7 +331,7 @@ final class StandardHostValve (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, errorPage.getLocation()); request.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - new Integer(ApplicationFilterFactory.ERROR)); + DispatcherType.ERROR); Wrapper wrapper = request.getWrapper(); diff --git a/java/org/apache/catalina/core/StandardWrapperValve.java b/java/org/apache/catalina/core/StandardWrapperValve.java index 14eb0705f..514ed848e 100644 --- a/java/org/apache/catalina/core/StandardWrapperValve.java +++ b/java/org/apache/catalina/core/StandardWrapperValve.java @@ -23,6 +23,7 @@ import java.io.IOException; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.servlet.DispatcherType; import javax.servlet.Servlet; import javax.servlet.ServletException; import javax.servlet.UnavailableException; @@ -183,7 +184,7 @@ final class StandardWrapperValve MessageBytes requestPathMB = request.getRequestPathMB(); request.setAttribute (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - ApplicationFilterFactory.REQUEST_INTEGER); + DispatcherType.REQUEST); request.setAttribute (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, requestPathMB); @@ -381,7 +382,7 @@ final class StandardWrapperValve MessageBytes requestPathMB = request.getRequestPathMB(); request.setAttribute (ApplicationFilterFactory.DISPATCHER_TYPE_ATTR, - ApplicationFilterFactory.REQUEST_INTEGER); + DispatcherType.REQUEST); request.setAttribute (ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR, requestPathMB); diff --git a/java/org/apache/coyote/Request.java b/java/org/apache/coyote/Request.java index fb3547e4f..46be43538 100644 --- a/java/org/apache/coyote/Request.java +++ b/java/org/apache/coyote/Request.java @@ -528,4 +528,8 @@ public final class Request { public void setBytesRead(int bytesRead) { this.bytesRead = bytesRead; } + + public boolean isProcessing() { + return reqProcessorMX.getStage()==org.apache.coyote.Constants.STAGE_SERVICE; + } }