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

Provide error page support #1973

Closed
cwellekoetter opened this issue May 7, 2015 · 8 comments
Closed

Provide error page support #1973

cwellekoetter opened this issue May 7, 2015 · 8 comments

Comments

@cwellekoetter
Copy link

I am using atmosphere-runtime:2.1.4 along with a current Apache-Tomcat:7.0.59+ and Wicket integration (Apache-Wicket:6.18.0, org.apache.wicket.experimental.wicket6:wicket-atmosphere:0.19). All pages and resources (including the error pages) are served by Wicket, which is integrated in the AtmosphereServlet.

After updating the wicket-atmosphere artifact to a newer version (0.20-0.22), which use a newer atmosphere-runtime ( 2.1.4+) we get empty error pages with HTTP-Status-Code 501. Also we get the following log message: "Invalid request state. AsyncContext#startAsync not supported. Make sure async-supported is set to true in web.xml".
After some investigation I found out which code change is responsible for this behavior, I found the following commit (line 125ff):
83ec6b8

Following web.xml configuration:

...


<error-page>
    <error-code>403</error-code>
    <location>/forbidden.html</location> <!-- forbidden.html is a mount to the Wicket page: AccessDeniedPage.java -->
</error-page>

<error-page>
    <error-code>404</error-code>
    <location>/notFound.html</location> <!-- forbidden.html is a mount to the Wicket page: PageNotFoundPage.java -->
</error-page>
<!-- servlet -->
<!-- =================================================================================-->
<!-- atmosphere -->

<servlet>
    <servlet-name>atmosphere</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <init-param>
        <param-name>org.atmosphere.cpr.sessionSupport</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.removeSessionTimeout</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.websocket.WebSocketProtocol</param-name>
        <param-value>org.atmosphere.websocket.protocol.EchoProtocol</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
        <param-value>org.atmosphere.client.TrackMessageSizeInterceptor</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.client.TrackMessageSizeInterceptor.delimiter</param-name>
        <param-value><![CDATA[<|msg|>]]></param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
        <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    <async-supported>true</async-supported>
</servlet>

<servlet-mapping>
    <servlet-name>atmosphere</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Following atmosphere.xml configuration:

<atmosphere-handlers>
    <atmosphere-handler context-root="/*" class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="filterClassName" value="org.apache.wicket.protocol.http.WicketFilter" />
        <applicationConfig>
            <param-name>applicationFactoryClassName</param-name>
            <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
        </applicationConfig>
        <applicationConfig>
            <param-name>applicationBean</param-name>
            <param-value>wicketApplication</param-value>
        </applicationConfig>
        <applicationConfig>
            <param-name>configuration</param-name>
            <param-value>development</param-value>
        </applicationConfig>
        <applicationConfig>
            <param-name>filterMappingUrlPattern</param-name>
            <param-value>/*</param-value>
        </applicationConfig>
    </atmosphere-handler>
</atmosphere-handlers>

PS: Error pages, that are directly forwarded in Wicket (like InternalServerError) work smoothly. Error Pages that are defined in the web.xml, do not work with with the AtmosphereServlet

@jfarcand
Copy link
Member

jfarcand commented May 7, 2015

I don't think it's a bug in Atmosphere. This message is from the Servlet Spec:

"Invalid request state. AsyncContext#startAsync not supported. Make sure async-supported is set to true in web.xml". 

Also please try at least with 2.1.10 and let's follow up on the mailing list https://groups.google.com/group/atmosphere-framework?pli=1

@jfarcand jfarcand closed this as completed May 7, 2015
@cwellekoetter
Copy link
Author

The log message is produced in the AsynchronousProcessor of the atmosphere framework:

if (isServlet30 && !req.isAsyncSupported()) {
    logger.error("Invalid request state. AsyncContext#startAsync not supported. Make sure async-supported is set to true in web.xml");
    res.setStatus(501);
    res.addHeader(X_ATMOSPHERE_ERROR, "AsyncContext not enabled");
    res.flushBuffer();
    return new Action();
}

This conditional block was added from version 2.1.4 to 2.1.5. (See your commit 83ec6b8)

If it is not a bug of atmosphere, can you please give me an advice/workaround for generating error pages that should be rendered by Wicket (defined in the atmosphere.xml)?

@cwellekoetter
Copy link
Author

With version 2.1.10 I get the same error, if i would like to access http://localhost:8080/abcdefgh (which does not exist):

…
ERROR 16:10:44 org.atmosphere.cpr.AsynchronousProcessor: Invalid request state. AsyncContext#startAsync not supported. Make sure async-supported is set to true in web.xml
…

@jfarcand
Copy link
Member

jfarcand commented May 7, 2015

Yes, this is a bug in your application. Like I said, this is a Servlet Spec mandatory deployment descriptor. If Atmosphere gets called without it, then it fail as expected. Take a look at the definition of 'HttpServletRequest#isAsyncSupported()' for more information. But for sure nothing can be done here. Make sure async-supported is defined for all Wicket's Filters and Servlets.

@cwellekoetter
Copy link
Author

async-supported is defined for every filter and servlet in my web.xml. The only problem are the error pages, that also should be generated by wicket:

<error-page>
    <error-code>403</error-code>
    <location>/forbidden.html</location> <!-- forbidden.html is a mount to the Wicket page: AccessDeniedPage.java -->
</error-page>

<error-page>
    <error-code>404</error-code>
    <location>/notFound.html</location> <!-- forbidden.html is a mount to the Wicket page: PageNotFoundPage.java -->
</error-page>

I think it is a general problem: If error pages should be generated by a framework like Wicket, Vaadin, GWT, or etc. that is used with the AtmosphereServlet, then you will not get it but only a blank page with the error code 501.

As a workaround i will have to generate the error pages with simple jsp files.

@jfarcand
Copy link
Member

jfarcand commented May 7, 2015

@cwellekoetter I still fail to understand why the error page ends up within Atmosphere? But I'm open to suggestion about helping the issue. Can you share a test case? Also if you remove the code that generate the 501, does it work?

@cwellekoetter
Copy link
Author

With atmosphere-runtime:2.1.4 the error pages are generated and returned. With any atmosphere-runtime > 2.1.4 I get a blank error page with state code 501.

As you can see in the web.xml snippet, that i posted for this task, every request loops through the AtmosphereServlet. I have only one atmosphere handler configured, that dispatches all requests to the Wicket Filter, as you can see in the atmosphere.xml snippet above.

If I request a resource, that does not exist / that Wicket cannot handle, then the default error configuration of tomcat will act:

<error-page>
    <error-code>404</error-code>
    <location>/notFound.html</location> <!-- notFound.html is a mount to the Wicket page: PageNotFoundPage.java -->
</error-page>

The location "/notFound.html" is not a resource in the webroot, but should be handled by Wicket.
But anyway the check of request.isAsyncSupported returns false.

@jfarcand jfarcand reopened this May 7, 2015
@jfarcand
Copy link
Member

jfarcand commented May 7, 2015

Rollback #1637 to allow framework that runs on top of Atmosphere via the 'ReflectorServletProcessor' to handler error pages.

@jfarcand jfarcand closed this as completed May 7, 2015
jfarcand added a commit that referenced this issue May 7, 2015
jfarcand added a commit that referenced this issue May 7, 2015
jfarcand added a commit that referenced this issue May 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants