private ServletResponse servletResponse = null;
private List<AsyncListenerWrapper> listeners = new ArrayList<AsyncListenerWrapper>();
private boolean hasOriginalRequestAndResponse = true;
+ private boolean completed = false;
- public AsyncContextImpl() {
+ private Request request;
+
+ public AsyncContextImpl(Request request) {
//TODO SERVLET3 - async
+ this.request = request;
}
@Override
log.error("",x);
}
}
+ this.completed = true;
}
servletResponse = null;
listeners.clear();
hasOriginalRequestAndResponse = true;
+ completed = false;
}
public boolean isStarted() {
public void setHasOriginalRequestAndResponse(boolean hasOriginalRequestAndResponse) {
this.hasOriginalRequestAndResponse = hasOriginalRequestAndResponse;
}
-
-
+
+ public boolean isCompleted() {
+ return completed;
+ }
+
+ public void setCompleted(boolean completed) {
+ this.completed = completed;
+ }
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;
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;
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;
/**
/**
* The current dispatcher type.
*/
- protected Object dispatcherType = null;
+ protected DispatcherType internalDispatcherType = null;
/**
* async timeout
*/
protected long asyncTimeout = 0;
+
+
// --------------------------------------------------------- Public Methods
context = null;
wrapper = null;
- dispatcherType = null;
+ internalDispatcherType = null;
requestDispatcherPath = null;
comet = false;
}
-
+ protected boolean isProcessing() {
+ return coyoteRequest.isProcessing();
+ }
/**
* Clear cached encoders (to save memory for Comet requests).
*/
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()
}
if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) {
- dispatcherType = value;
+ internalDispatcherType = (DispatcherType)value;
return;
} else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) {
requestDispatcherPath = value;
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());
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() {
public DispatcherType getDispatcherType() {
// TODO SERVLET3 - dispatcher
- return null;
+ if (internalDispatcherType==null) {
+ return DispatcherType.REQUEST;
+ } else {
+ return this.internalDispatcherType;
+ }
}
// ---------------------------------------------------- HttpRequest Methods
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
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);
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());
}
wrequest.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- Integer.valueOf(ApplicationFilterFactory.INCLUDE));
+ DispatcherType.INCLUDE);
wrequest.setAttribute(
ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
getCombinedPath());
package org.apache.catalina.core;
+import javax.servlet.DispatcherType;
import javax.servlet.Servlet;
import javax.servlet.ServletRequest;
// -------------------------------------------------------------- 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 =
(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);
* 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 ||
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;
/**
* The current dispatcher type.
*/
- protected Object dispatcherType = null;
+ protected DispatcherType dispatcherType = null;
/**
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;
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);
import java.io.IOException;
+import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
(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));
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
errorPage.getLocation());
request.setAttribute(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- new Integer(ApplicationFilterFactory.ERROR));
+ DispatcherType.ERROR);
Wrapper wrapper = request.getWrapper();
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.servlet.DispatcherType;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
MessageBytes requestPathMB = request.getRequestPathMB();
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- ApplicationFilterFactory.REQUEST_INTEGER);
+ DispatcherType.REQUEST);
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
requestPathMB);
MessageBytes requestPathMB = request.getRequestPathMB();
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
- ApplicationFilterFactory.REQUEST_INTEGER);
+ DispatcherType.REQUEST);
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
requestPathMB);
public void setBytesRead(int bytesRead) {
this.bytesRead = bytesRead;
}
+
+ public boolean isProcessing() {
+ return reqProcessorMX.getStage()==org.apache.coyote.Constants.STAGE_SERVICE;
+ }
}