[undertow-dev] Undertow servlet context

Stuart Douglas sdouglas at redhat.com
Thu Feb 16 15:09:05 EST 2017


If you add it via a ServletExtension you can control where it is
executed. io.undertow.servlet.api.DeploymentInfo#addOuterHandlerChainWrapper
will allow you to add it so that it is run after the servlet initial
handler, but before any other handlers.

Stuart

On Thu, Feb 16, 2017 at 5:04 PM, Rohan Emmanuel
<rohan.emmanuel07 at gmail.com> wrote:
> Thanks for your reply Stuart,
> i have the handler "HAHandler" configured as filter in the undertow
> subsystem of wildfly.
> I also have eager filter initialization on filter enabled.And the Filter
> init() method is getting called while application deployment and it had set
> the servletContext.
>
>
>   <filters>
>                     <response-header name="server-header"
> header-name="Server" header-value="WildFly/10"/>
>                     <response-header name="x-powered-by-header"
> header-name="X-Powered-By" header-value="Undertow/1"/>
>                     <error-page name="500Handler"
> path="${jboss.home.dir}/welcome-content/ErrorPage.html" code="506"/>
>                     <error-page name="404Handler"
> path="${jboss.home.dir}/welcome-content/ErrorPage.html" code="404"/>
>                     <filter name="HAHandler" module="com.haHandler"
> class-name="com.HAHandler"/>
>                 </filters>
>
>
> You were correct, by adding some logs,  the sevletInitalHandler hadn't added
> the attachment when my handler was called.
> any suggestions how to move my handler in the chain after a specific handler
> (ServletInitailHandler)?
>
> On Thu, Feb 16, 2017 at 4:48 AM, Stuart Douglas <sdouglas at redhat.com> wrote:
>>
>> Where is your handler running? It sounds like it is running outside
>> the ServletInitialHandler, which is what sets the attachment key.
>>
>> If that is the case you can either move the handler to be run after
>> the ServletInitialHandler, or save the ServletContext somewhere
>> static.
>>
>> Stuart
>>
>> On Wed, Feb 15, 2017 at 9:34 PM, Rohan Emmanuel
>> <rohan.emmanuel07 at gmail.com> wrote:
>> > I am using wildfly 10 and have a filter in my web application which will
>> > set
>> > a attribute in the servlet context.
>> >
>> >
>> >
>> > public void init(FilterConfig arg0)
>> >
>> >     throws ServletException
>> >
>> >   {
>> >
>> >    ServletContext sc = arg0.getServletContext();
>> >
>> >    System.out.println("setting the servlet context");
>> >
>> >    sc.setAttribute("ha","ha is enabled for this application");
>> >
>> >   }
>> >
>> >
>> >
>> > I want to get this attribute in one of my httphandler.
>> >
>> >
>> >
>> > ServletRequestContext servletreqcontext =
>> > exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
>> >
>> >     System.out.println("servletreqcontext-="+servletreqcontext);
>> >
>> >
>> >
>> > the above code is returing NULL.
>> >
>> > Any idea how can i get a handle on the  servletContext in httphandler to
>> > get
>> > this attribute?
>> >
>> >
>> > --
>> > Regards,
>> > Rohan Emmanuel
>> >
>> > _______________________________________________
>> > undertow-dev mailing list
>> > undertow-dev at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/undertow-dev
>
>
>
>
> --
> Regards,
> Rohan Emmanuel


More information about the undertow-dev mailing list