Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async actions do not work with tomcat #47

Open
vankeisb opened this issue Mar 11, 2016 · 7 comments
Open

Async actions do not work with tomcat #47

vankeisb opened this issue Mar 11, 2016 · 7 comments
Assignees
Labels

Comments

@vankeisb
Copy link
Member

Async actions don't work in tomcat because tomcat complains that "a servlet or filter in the chain is not async".

Stack (tomcat 8) :

java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
    org.apache.catalina.connector.Request.startAsync(Request.java:1612)
    org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1037)
    javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:392)
    net.sourceforge.stripes.controller.AsyncResponseServlet3.<init>(AsyncResponseServlet3.java:31)
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    net.sourceforge.stripes.controller.AsyncResponse.newInstance(AsyncResponse.java:215)
    net.sourceforge.stripes.controller.DispatcherHelper$6.intercept(DispatcherHelper.java:651)
    net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:180)
    net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
    net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:177)
    net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:86)
    net.sourceforge.stripes.controller.DispatcherHelper.invokeEventHandler(DispatcherHelper.java:577)
    net.sourceforge.stripes.controller.DispatcherServlet.invokeEventHandler(DispatcherServlet.java:303)
    net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:162)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    net.sourceforge.stripes.controller.DynamicMappingFilter$2.doFilter(DynamicMappingFilter.java:467)
    net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:208)
    net.sourceforge.stripes.controller.DynamicMappingFilter.doFilter(DynamicMappingFilter.java:453)
@vankeisb vankeisb added the bug label Mar 11, 2016
@vankeisb vankeisb self-assigned this Mar 11, 2016
@dshurt
Copy link

dshurt commented Apr 16, 2016

I ran into the same issue with Tomcat 7 when trying to use Atmosphere library long pull support. I wasn't able to resolve it but, I think you mentioned that DynamicMapperFilter may be the cause in a another issue. I think that may be the case. I didn't have any luck marking the dispatch servlet and the stripe filter with async support.

I would be interested in a fix for this. Although, it not a big issue for me at the moment.

@vankeisb
Copy link
Member Author

Problem is that DMF wraps a DispatcherServlet directly and delegates to it, bypassing the servlet's lifecycle management (the dispatcher is not managed by the container). Tomcat somehow detects the servlet anyway, and as it's not declared as async, it throws an exception.
You should not have the problem if you don't use DMF though, since you will declare the filter and servlet in web.xml, and mark them as async.

@ppantera
Copy link

I'm having the same problem. I'm writing a simple Ginger service that I want to make async. I set async-supported to true in web.xml for both the servlet (GingerServlet) and the filter (RequestContextFilter). My AH post is here:

https://answerhub.corp.ebay.com/questions/262377/asynchronous-servlets-in-raptor-255.html

I don't see DynamicMapperFilter anywhere in scope so I don't think I'm using that.

@vankeisb
Copy link
Member Author

Could you please post the stack trace ? Or even better, provide a SSCCE ? There is a (failing) test for async actions in the build, but it's using DMF.

@prai14
Copy link

prai14 commented May 7, 2018

I have the same issue -
See the stack trace:

2018-05-07 07:48:57 SEVERE org.apache.catalina.core.StandardWrapperValve invoke Servlet.service() for servlet [functional] in context with path [] threw exception
java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
at org.apache.catalina.connector.Request.startAsync(Request.java:1630)
at org.apache.catalina.connector.Request.startAsync(Request.java:1623)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1030)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at org.springframework.http.server.reactive.ServletHttpHandlerAdapter.service(ServletHttpHandlerAdapter.java:165)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.venarc.printer.filter.JsessionidRemovalFilter.doFilter(JsessionidRemovalFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.venarc.printer.filter.RequestSchemeFilter.doFilter(RequestSchemeFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:877)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

@rgrashel
Copy link
Member

rgrashel commented May 9, 2018

@prai-git Have you tried not using the DynamicMappingFilter? The way it is designed causes other issues also.

@swarvanumedda
Copy link

swarvanumedda commented Jul 29, 2018

You have to mention async option as true. By default it's not true.
A sample code snippet in Spring 5 to start embedded tomcat with router functions and async as true:

    public RouterFunction<ServerResponse> routingFunction() {
         return route(GET("/ .... );
    }

    WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
    HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler)
        .filter(new IndexRewriteFilter())
        .build();

    Tomcat tomcat = new Tomcat();
    tomcat.setHostname("localhost");
    tomcat.setPort(9090);
    Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
    ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
    Wrapper servletWrapper = Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
    servletWrapper.setAsyncSupported(true);
    rootContext.addServletMappingDecoded("/", "httpHandlerServlet");

    TomcatWebServer server = new TomcatWebServer(tomcat);
    server.start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants