Asynchronous Servlet Not Supported #43

peterwkc opened this Issue Apr 17, 2013 · 23 comments


None yet
7 participants

Hello, I'm implemented asynchronous servlet using spring which return Callable but the view is not decorated by sitemesh.

Does sitemesh 3 support decorate the view with asynchronous servlet ?



musketyr commented Aug 8, 2013

could you please attach some code snippet?


musketyr commented Aug 8, 2013

could this issue be related?

can you try check it again with the latest version of spring?

mdeimel commented Jul 15, 2014

I'm also trying to include Sitemesh 3 into an async filter chain, but it does not appear to be supported. Are there any plans to make Sitemesh 3 async (with true)? Thanks.


codeconsole commented Jul 31, 2014

If an example can be provided, it will be addressed.

mdeimel commented Aug 7, 2014

I've created a test project to show the behavior:

Here's the situation and rundown:

  1. Once the project is built ("mvn package") and deployed to Tomcat, there are two URLs that can be reached, one for a standard servlet (SyncServlet), and one for an asynchronous servlet (AsyncServlet).
  2. Navigate to http://localhost:8080/sitemesh-asynch-attempt-1.0-SNAPSHOT/sync and notice there is text from SyncServlet, and that content has been added from SiteMesh.
  3. Navigate to http://localhost:8080/sitemesh-asynch-attempt-1.0-SNAPSHOT/async and notice an IllegalStateException: Not supported. It doesn't like the fact that a synchronous request is being made from a non-async filter. If you remove the sitemesh filter in web.xml, the url will display content from the AsyncServlet.

I have tried making some customizations to sitemesh (overriding different classes) to actually start the process in an AsyncContext, but I was not able to get that to work, when SiteMesh tries to get out of the filter chain and into the servlet it fails with a NullPointerException in the ApplicationFilterChain (Tomcat class).

So - if SiteMesh was configured to also have an asynchronous filter, so that I could use <async-supported>true</async-supported> in web.xml, that would be ideal.

Thanks for the help, and let me know if there are any questions with what I'm doing or the code.

mdeimel commented Aug 21, 2014

Hi @codeconsole I just wanted to check to see if you had a chance to look at the test project I created, thanks.

pluppens commented Sep 3, 2014

Hi @mdeimel, could you have a look at my sitemesh fork and see if it solves your problem? I've had a similar issue, and I think I fixed it, but it might be a bit of a hack that causes problems for others (plus I had to bump some dependencies ...). Comments welcome.

mdeimel commented Sep 3, 2014

@pluppens thanks for providing this - I had previously tried to customize SiteMesh to support asynchronous calls, but I did it through extending classes to leave the core intact, which might have contributed to me not getting it working. I'm going to test out what you have to see if it works for my use case. Thanks!

mdeimel commented Sep 4, 2014

@pluppens I'm not able to build the project - would you mind sharing with me how you built it? I'm trying to use "mvn", but still build errors and complaints about the jetty version. It looks like you modified the gradle build script to include the new version of jetty. Could you share what command you used to build, and if it was in the sitemesh3-master directory or in sitemesh3-master/sitemesh directory? Thanks.

pluppens commented Sep 4, 2014

Apologies - I assumed the Maven build was no longer used, and hence changed only the Gradle build. I built both modules, but you can just build just the sitemesh module with 'gradle jar' - or 'gradle install', and then refer to the sitemesh 3.0.1-SNAPSHOT version in your project.

pluppens commented Sep 5, 2014

@mdeimel if you don't succeed at building it, drop me a message at my {name}.{lastname} at gmail, and I'll send you the jar file to try it out.

mdeimel commented Sep 30, 2014

@musketyr and @codeconsole would you two be able to take a look at the changes made by @pluppens to make SiteMesh work with async support? Here are the commits he has made on his forked version:

These changes would be instrumental in allowing SiteMesh to work for an upcoming project.

Thanks for your time.


musketyr commented Oct 1, 2014

any pull requests are certainly welcome. have you tested that it solves your problem? I'll take a look.

pluppens commented Oct 1, 2014

Just a quick clarification; the changes include some major dependency bumps & is only tested on Tomcat 8 & Java 7 - since that's the environment for my hobby project in which I needed it. It might have been a lot cleaner to use a Filter subclass or even an extension.

Also, I've had to bump the Jetty version to get tests working again, and even then there are some failures. So, use it at your own risk ;)


musketyr commented Oct 1, 2014

ok, thanks for the clarification. much appreciated.

mdeimel commented Oct 1, 2014

Thanks for the quick response guys. Given what @pluppens has said, I'll take another look through the changes and see if I can pull things together for a clean pull request, and then send it over for review.


musketyr commented Oct 2, 2014

that would be fantastic

2014-10-01 22:48 GMT+02:00 mdeimel

Thanks for the quick response guys. Given what @pluppens has said, I'll take another look through
the changes and see if I can pull things together for a clean pull request,
and then send it over for review.

Reply to this email directly or view it on GitHub
#43 (comment).

mdeimel commented Oct 8, 2014

@musketyr or @codeconsole can either of you explain (or point me to an explanation) of the ContentBufferingFilter.postProcess(), and how it decorates the content? It seems to me that it is making some type of request to get decorator information, to decorate the content that has already been retrieved. I'm running into an issue when using a Jetty proxy, which then requires SiteMesh to decorate the response. The issue is that a request is being made after the Jetty has already closed out the request. I believe this is related to how postProcess() is retrieving information about the decorator, but I haven't been able to verify that yet. The stack trace is below to show the path it takes through the code. If you have any suggestions, or want me to upload a full test project to GitHub, let me know.


P.S. If this is a question better suited for a mailing list, I can do that too.

    at org.eclipse.jetty.server.Dispatcher.forward(
    at org.eclipse.jetty.server.Dispatcher.forward(
    at org.sitemesh.webapp.WebAppContext.dispatch(
    at org.sitemesh.webapp.WebAppContext.decorate(
    at org.sitemesh.BaseSiteMeshContext.decorate(
    at org.sitemesh.webapp.SiteMeshFilter.postProcess(

musketyr commented Oct 13, 2014

@mdeimel I'm afraid I don't have that deep knowledge. maybe @joewalnes could be the one who knows better


joewalnes commented Oct 14, 2014

I'm afraid I don't know. May have more luck on the Jetty list.

@joewalnes joewalnes closed this Oct 14, 2014

@joewalnes joewalnes reopened this Oct 14, 2014


joewalnes commented Oct 14, 2014

(Sorry didn't mean to hit "close". Fat fingered it. Reopened)

tommyxu commented Oct 17, 2014

I have a fix which is similiar to pluppens. (I should have read this post first :-) ) It failed on jetty 9, but works on tomcat 8.
@mdeimel the issue is after getting the real page content, when sitemesh want to request decoration template before merging, it failed as there is bug in Jetty for async support that prevent get the template page.

mdeimel commented Oct 17, 2014

@tommyxu - I worked with the Jetty mailing list for the issue I was facing using an async SiteMesh3 with Jetty 9, they ended up creating a bug because of an edge case not properly defined by the servlet spec. You can see the bug here:
I've heard that they'll try to take a look at the bug by the end of this month, but because it might require a discussion with the spec community, it might take a while to fix.
If you happen to find any workaround or solution for it, please let me know. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment