Author: remy.maucherat(a)jboss.com
Date: 2009-04-07 23:30:04 -0400 (Tue, 07 Apr 2009)
New Revision: 994
Modified:
trunk/.project
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/core/ApplicationContext.java
trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
trunk/java/org/apache/catalina/core/StandardWrapperValve.java
Log:
- Work on the async impl. ApplicationDispatcher.async is missing (but it does not do much,
so not too hard),
and the path handling is not that great.
Modified: trunk/.project
===================================================================
--- trunk/.project 2009-04-08 03:28:20 UTC (rev 993)
+++ trunk/.project 2009-04-08 03:30:04 UTC (rev 994)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jbossweb-2.1.x</name>
+ <name>jbossweb-3.0.x</name>
<comment></comment>
<projects>
</projects>
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-04-08 03:28:20 UTC (rev
993)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-04-08 03:30:04 UTC (rev
994)
@@ -2994,6 +2994,7 @@
protected ServletContext servletContext = null;
protected String path = null;
protected Runnable runnable = null;
+ protected boolean useAttributes = false;
public AsyncContextImpl(ServletRequest request, ServletResponse response) {
this.request = request;
@@ -3006,11 +3007,24 @@
}
public void dispatch() {
+ if (request == getRequestFacade()) {
+ // Get the path directly
+ path = getRequestPathMB().toString();
+ } else if (request instanceof HttpServletRequest) {
+ // Rebuild the path
+ path = ((HttpServletRequest) request).getRequestURI();
+ if (servletContext != null) {
+ path = path.substring(servletContext.getContextPath().length());
+ } else {
+ path = path.substring(context.getName().length());
+ }
+ }
resume();
}
public void dispatch(String path) {
this.path = path;
+ useAttributes = true;
resume();
}
@@ -3045,6 +3059,10 @@
return path;
}
+ public boolean getUseAttributes() {
+ return useAttributes;
+ }
+
public Runnable getRunnable() {
return runnable;
}
Modified: trunk/java/org/apache/catalina/core/ApplicationContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-04-08 03:28:20 UTC
(rev 993)
+++ trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-04-08 03:30:04 UTC
(rev 994)
@@ -24,7 +24,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.EnumSet;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
@@ -52,7 +51,6 @@
import org.apache.catalina.Wrapper;
import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.deploy.FilterDef;
-import org.apache.catalina.deploy.SessionCookie;
import org.apache.catalina.util.Enumerator;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.util.ResourceSet;
Modified: trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-04-08 03:28:20 UTC
(rev 993)
+++ trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-04-08 03:30:04 UTC
(rev 994)
@@ -186,10 +186,7 @@
this.pathInfo = pathInfo;
this.queryString = queryString;
this.name = name;
- if (wrapper instanceof StandardWrapper)
- this.support = ((StandardWrapper) wrapper).getInstanceSupport();
- else
- this.support = new InstanceSupport(wrapper);
+ this.support = wrapper.getInstanceSupport();
}
@@ -824,8 +821,6 @@
break;
if (current instanceof ApplicationRequest)
break;
- if (current instanceof Request)
- break;
previous = current;
current = ((ServletRequestWrapper) current).getRequest();
}
@@ -887,8 +882,6 @@
break;
if (current instanceof ApplicationResponse)
break;
- if (current instanceof Response)
- break;
previous = current;
current = ((ServletResponseWrapper) current).getResponse();
}
Modified: trunk/java/org/apache/catalina/core/StandardWrapperValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-04-08 03:28:20 UTC
(rev 993)
+++ trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-04-08 03:30:04 UTC
(rev 994)
@@ -48,10 +48,14 @@
import java.io.IOException;
+import java.util.Iterator;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.servlet.AsyncEvent;
+import javax.servlet.AsyncListener;
import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletResponse;
@@ -63,7 +67,6 @@
import org.apache.catalina.connector.Response;
import org.apache.catalina.util.StringManager;
import org.apache.catalina.valves.ValveBase;
-import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.log.SystemLogHandler;
import org.jboss.servlet.http.HttpEvent;
import org.jboss.servlet.http.HttpEventServlet;
@@ -221,16 +224,12 @@
exception(request, response, e);
servlet = null;
}
- MessageBytes requestPathMB = null;
- if (request != null) {
- requestPathMB = request.getRequestPathMB();
- }
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
ApplicationFilterFactory.REQUEST_INTEGER);
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
- requestPathMB);
+ request.getRequestPathMB());
// Create the filter chain for this request
ApplicationFilterFactory factory =
ApplicationFilterFactory.getInstance();
@@ -397,6 +396,58 @@
public void event(Request request, Response response, HttpEvent event)
throws IOException, ServletException {
+ // Async processing
+ Request.AsyncContextImpl asyncContext = (Request.AsyncContextImpl)
request.getAsyncContext();
+ if (asyncContext != null) {
+ if (event.getType() == EventType.END || event.getType() == EventType.ERROR
+ || event.getType() == EventType.TIMEOUT) {
+ // Invoke the listeners with onComplete or onTimeout
+ boolean timeout = (event.getType() == EventType.TIMEOUT) ? true : false;
+ Iterator<AsyncEvent> asyncEvents =
asyncContext.getAsyncListeners().keySet().iterator();
+ while (asyncEvents.hasNext()) {
+ AsyncEvent asyncEvent = asyncEvents.next();
+ AsyncListener asyncListener =
asyncContext.getAsyncListeners().get(asyncEvent);
+ try {
+ if (timeout) {
+ asyncListener.onTimeout(asyncEvent);
+ } else {
+ asyncListener.onComplete(asyncEvent);
+ }
+ } catch (Throwable e) {
+
container.getLogger().error(sm.getString("standardWrapper.async.listenerError",
+ getContainer().getName()), e);
+ exception(request, response, e);
+ }
+ }
+ } else if (asyncContext.getRunnable() != null) {
+ // Execute the runnable
+ try {
+ asyncContext.getRunnable().run();
+ } catch (Throwable e) {
+
container.getLogger().error(sm.getString("standardWrapper.async.runnableError",
+ getContainer().getName()), e);
+ exception(request, response, e);
+ }
+ } else if (asyncContext.getPath() != null) {
+ // Remap the request, set the dispatch attributes, create the filter
chain
+ // and invoke the Servlet
+ Context context = (Context) getContainer().getParent();
+ ServletContext servletContext = context.getServletContext();
+ if (asyncContext.getServletContext() != null) {
+ // Cross context
+ servletContext = asyncContext.getServletContext();
+ }
+ ApplicationDispatcher dispatcher =
+ (ApplicationDispatcher)
servletContext.getRequestDispatcher(asyncContext.getPath());
+ // FIXME: Add an async method to Application dispatcher
+ // Invoke the dispatcher
+ asyncContext.getUseAttributes();
+ } else {
+ // FIXME: should not happen
+ }
+ return;
+ }
+
// Initialize local variables we may need
Throwable throwable = null;
// This should be a Request attribute...
@@ -433,45 +484,13 @@
servlet = null;
}
- MessageBytes requestPathMB = null;
- if (request != null) {
- requestPathMB = request.getRequestPathMB();
- }
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_TYPE_ATTR,
ApplicationFilterFactory.ASYNC_INTEGER);
request.setAttribute
(ApplicationFilterFactory.DISPATCHER_REQUEST_PATH_ATTR,
- requestPathMB);
+ request.getRequestPathMB());
- // FIXME: Implement async mode, which means invoking listeners or the Servlet,
etc
- Request.AsyncContextImpl asyncContext = (Request.AsyncContextImpl)
request.getAsyncContext();
- if (asyncContext != null) {
- if (event.getType() == EventType.END || event.getType() == EventType.ERROR)
{
- // Invoke the listeners with onComplete
- // FIXME
- } else if (event.getType() == EventType.TIMEOUT) {
- // Invoke the listeners with onTimeout
- // FIXME
- } else if (asyncContext.getRunnable() != null) {
- // Execute the runnable
- // FIXME
- } else if (asyncContext.getPath() != null) {
- // Remap the request, set the dispatch attributes, create the filter
chain
- // and invoke the Servlet
- // FIXME: Also check how cross context works, but it is be ok to do from
here
- // (or do another distpatcher object similar to the current request
dispatcher)
- if (asyncContext.getServletContext() != null) {
- // Cross context
- // FIXME
- }
- } else {
- // Create the filter chain and reinvoke the same Servlet
- // FIXME
- }
- return; // FIXME
- }
-
// Get the current (unchanged) filter chain for this request
ApplicationFilterChain filterChain =
(ApplicationFilterChain) request.getFilterChain();