ApplicationFilterChain filterChain = factory.createFilterChain(request,
wrapper,servlet);
- Object origAsyncSupported = request.getAttribute(Globals.ASYNC_SUPPORTED_ATTR);
- //we have a new filter chain, setup isAsyncSupported here
- boolean filterAsyncSupported = filterChain.isAsyncSupported();
- if (!filterAsyncSupported && request.isAsyncSupported()) {
- //the request says we support it, but the filters don't
- //TODO SERVLET3 - async
- request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, Boolean.FALSE);
- }
-
// Call the service() method for the allocated servlet instance
try {
String jspFile = wrapper.getJspFile();
wrapper.getLogger().error(sm.getString("applicationDispatcher.serviceException",
wrapper.getName()), e);
runtimeException = e;
- } finally {
- request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, origAsyncSupported);
}
// Release the filter chain (if any) for this request
} catch (Throwable e) {
wrapper.getLogger().error(sm.getString("standardWrapper.releaseFilters",
wrapper.getName()), e);
- // FIXME: Exception handling needs to be simpiler to what is in the StandardWrapperValue
+ // FIXME: Exception handling needs to be simpler to what is in the StandardWrapperValue
}
// Deallocate the allocated servlet instance
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
-import javax.servlet.ServletRequestWrapper;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.Globals;
support.fireInstanceEvent(InstanceEvent.BEFORE_FILTER_EVENT,
filter, request, response);
+ if (request.isAsyncSupported() && "false".equalsIgnoreCase(
+ filterConfig.getFilterDef().getAsyncSupported())) {
+ request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR,
+ Boolean.FALSE);
+ }
if( Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
support.fireInstanceEvent(InstanceEvent.BEFORE_SERVICE_EVENT,
servlet, request, response);
- ServletRequest wRequest;
if (request.isAsyncSupported()
&& !support.getWrapper().isAsyncSupported()) {
- if (request instanceof HttpServletRequest) {
- wRequest = new HttpServletRequestNoAsyc(
- (HttpServletRequest) request);
- } else {
- // Must be a ServletRequest
- wRequest = new ServletRequestNoAsyc(request);
- }
- } else {
- wRequest = request;
+ request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR,
+ Boolean.FALSE);
}
// Use potentially wrapped request from this point
- if ((wRequest instanceof HttpServletRequest) &&
+ if ((request instanceof HttpServletRequest) &&
(response instanceof HttpServletResponse)) {
if( Globals.IS_SECURITY_ENABLED ) {
- final ServletRequest req = wRequest;
+ final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
principal);
args = null;
} else {
- servlet.service(wRequest, response);
+ servlet.service(request, response);
}
} else {
- servlet.service(wRequest, response);
+ servlet.service(request, response);
}
- // Stop using wrapped request now Servlet has been processed
support.fireInstanceEvent(InstanceEvent.AFTER_SERVICE_EVENT,
servlet, request, response);
} catch (IOException e) {
this.support = support;
}
-
- public boolean isAsyncSupported() {
- boolean supported = true;
- for (ApplicationFilterConfig config : filters) {
- if (config!=null && config.getFilterDef()!=null) {
- supported = supported & config.getFilterDef().isAsyncSupported();
- }
- }
- return supported;
- }
-
-
- // --------------------------------- Wrapper classes for isAsyncSupported()
-
- private class HttpServletRequestNoAsyc extends HttpServletRequestWrapper {
-
- public HttpServletRequestNoAsyc(HttpServletRequest request) {
- super(request);
- }
-
- @Override
- public boolean isAsyncSupported() {
- return false;
- }
- }
-
- private class ServletRequestNoAsyc extends ServletRequestWrapper {
-
- public ServletRequestNoAsyc(ServletRequest request) {
- super(request);
- }
-
- @Override
- public boolean isAsyncSupported() {
- return false;
- }
- }
-
}
// Reset comet flag value after creating the filter chain
request.setComet(false);
- //check filters to see if we support async or not.
- if (filterChain != null && request.isAsyncSupported()) {
- request.setAsyncSupported(filterChain.isAsyncSupported());
- }
// Call the filter chain for this request
// NOTE: This also calls the servlet's service() method
this.smallIcon = smallIcon;
}
- private boolean asyncSupported = false;
+ private String asyncSupported = null;
- public boolean isAsyncSupported() {
+ public String getAsyncSupported() {
return asyncSupported;
}
-
- public void setAsyncSupported(boolean asyncSupported) {
+
+ public void setAsyncSupported(String asyncSupported) {
this.asyncSupported = asyncSupported;
}
String type = ae.getAnnotationType();
if ("Ljavax/servlet/annotation/WebServlet;".equals(type)) {
processAnnotationWebServlet(className, ae, fragment);
+ }else if ("Ljavax/servlet/annotation/WebFilter;".equals(type)) {
+ processAnnotationWebFilter(className, ae, fragment);
}else if ("Ljavax/servlet/annotation/WebListener;".equals(type)) {
fragment.addListener(className);
} else {
- // TODO SERVLET 3 - Other annotations
// Unknown annotation - ignore
}
}
// Skip this annotation. Entry in web.xml takes priority
return;
}
- boolean mappingSet = false;
+ boolean urlPatternsSet = false;
ServletDef servletDef = new ServletDef();
servletDef.setServletName(className);
servletDef.setServletClass(className);
- String[] mappings = null;
+ String[] urlPatterns = null;
ElementValuePair[] evps = ae.getElementValuePairs();
for (ElementValuePair evp : evps) {
String name = evp.getNameString();
if ("value".equals(name) || "urlPatterns".equals(name)) {
- if (mappingSet) {
+ if (urlPatternsSet) {
throw new IllegalArgumentException(sm.getString(
"contextConfig.urlPatternValue", className));
}
- mappingSet = true;
- mappings = processAnnotationsUrlPatterns(evp.getValue());
+ urlPatternsSet = true;
+ urlPatterns = processAnnotationsStringArray(evp.getValue());
} else if ("name".equals(name)) {
servletDef.setServletName(evp.getValue().stringifyValue());
} else if ("description".equals(name)) {
// Ignore
}
}
- if (mappings != null) {
+ if (urlPatterns != null) {
fragment.addServlet(servletDef);
- for (String mapping : mappings) {
- fragment.addServletMapping(mapping,
+ for (String urlPattern : urlPatterns) {
+ fragment.addServletMapping(urlPattern,
servletDef.getServletName());
}
}
}
- protected String[] processAnnotationsUrlPatterns(ElementValue ev) {
+ protected void processAnnotationWebFilter(String className,
+ AnnotationEntry ae, WebXml fragment) {
+ if (fragment.getFilters().containsKey(className)) {
+ // Skip this annotation. Entry in web.xml takes priority
+ return;
+ }
+ boolean urlPatternsSet = false;
+ FilterDef filterDef = new FilterDef();
+ FilterMap filterMap = new FilterMap();
+ filterDef.setFilterName(className);
+ filterDef.setFilterClass(className);
+ String[] urlPatterns = null;
+
+ ElementValuePair[] evps = ae.getElementValuePairs();
+ for (ElementValuePair evp : evps) {
+ String name = evp.getNameString();
+ if ("value".equals(name) || "urlPatterns".equals(name)) {
+ if (urlPatternsSet) {
+ throw new IllegalArgumentException(sm.getString(
+ "contextConfig.urlPatternValue", className));
+ }
+ urlPatternsSet = true;
+ urlPatterns = processAnnotationsStringArray(evp.getValue());
+ for (String urlPattern : urlPatterns) {
+ filterMap.addURLPattern(urlPattern);
+ }
+ } else if ("filterName".equals(name)) {
+ filterDef.setFilterName(evp.getValue().stringifyValue());
+ } else if ("servletNames".equals(name)) {
+ String[] servletNames =
+ processAnnotationsStringArray(evp.getValue());
+ for (String servletName : servletNames) {
+ filterMap.addServletName(servletName);
+ }
+ } else if ("dispatcherTypes".equals(name)) {
+ String[] dispatcherTypes =
+ processAnnotationsStringArray(evp.getValue());
+ for (String dispatcherType : dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType);
+ }
+ } else if ("description".equals(name)) {
+ filterDef.setDescription(evp.getValue().stringifyValue());
+ } else if ("displayName".equals(name)) {
+ filterDef.setDisplayName(evp.getValue().stringifyValue());
+ } else if ("largeIcon".equals(name)) {
+ filterDef.setLargeIcon(evp.getValue().stringifyValue());
+ } else if ("smallIcon".equals(name)) {
+ filterDef.setSmallIcon(evp.getValue().stringifyValue());
+ } else if ("asyncSupported".equals(name)) {
+ filterDef.setAsyncSupported(evp.getValue().stringifyValue());
+ } else if ("initParams".equals(name)) {
+ Map<String,String> initParams =
+ processAnnotationWebInitParams(evp.getValue());
+ for (String paramName : initParams.keySet()) {
+ filterDef.addInitParameter(paramName,
+ initParams.get(paramName));
+ }
+ } else {
+ // Ignore
+ }
+ }
+ fragment.addFilter(filterDef);
+ filterMap.setFilterName(filterDef.getFilterName());
+ fragment.addFilterMapping(filterMap);
+ }
+
+ protected String[] processAnnotationsStringArray(ElementValue ev) {
ArrayList<String> values = new ArrayList<String>();
if (ev instanceof ArrayElementValue) {
ElementValue[] arrayValues =
}
private boolean mergeFilter(FilterDef src, FilterDef dest, boolean failOnConflict) {
- if (src.isAsyncSupported() != dest.isAsyncSupported()) {
- // Always fail
- return false;
+ if (dest.getAsyncSupported() == null) {
+ dest.setAsyncSupported(src.getAsyncSupported());
+ } else if (src.getAsyncSupported() != null) {
+ if (failOnConflict &&
+ !src.getAsyncSupported().equals(dest.getAsyncSupported())) {
+ return false;
+ }
}
-
+
if (dest.getFilterClass() == null) {
dest.setFilterClass(src.getFilterClass());
} else if (src.getFilterClass() != null) {