Tapestry 5
  1. Tapestry 5
  2. TAP5-257

NPE in RequestFilter if ApplicationStateManager is used

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.0.16
    • Component/s: None
    • Labels:
      None

      Description

      If one builds a request filter that use ApplicationStateManager, a call to any intersting method of the ASM throws an NPE.

      The problem is that the ApplicationStateManager use the session as default storage strategy, and that he tries to take it trough the RequesGlobals#getRequest that returns null in the request handler.

      It's an expected behavior since the RequestGlobals#storeRequestResponse method is called in the terminator of the RequestFilter pipeline. Perhpas there is a good reason to do it so, and not in the head of the pipeline, but I don't see it.

      Notice: it's exactly the same thing for HttpRequest/HttpResponse and HttpServletRequestHandler and storeServletRequestResponse

      Workaround : contribute a RequestFilter before any other whose sole action is to set Request/Response:

      public static RequestFilter buildSetRequestResponse(final RequestGlobals requestGlobals) {
      return new RequestFilter(){
      public boolean service(Request request, Response response, RequestHandler handler) throws IOException

      { requestGlobals.storeRequestResponse(request, response); return handler.service(request, response); }

      };
      }

      public static void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
      @InjectService("setRequestResponse") RequestFilter setRequestResponse,
      ...other filters...) {
      configuration.add("setRequestResponse", setRequestResponse, "before:*");
      ...other configurations...
      }

        Issue Links

          Activity

          Hide
          Howard M. Lewis Ship added a comment -

          What we can do is put the initial request/response into RequestGlobals at the start of the pipeline, then update it again at the end of the pipeline.

          Show
          Howard M. Lewis Ship added a comment - What we can do is put the initial request/response into RequestGlobals at the start of the pipeline, then update it again at the end of the pipeline.
          Hide
          Ulrich Stärk added a comment -

          I think my problem described here http://markmail.org/message/4d7lycjg3cbaxkfw is related to this, it would be great if this got solved.

          Show
          Ulrich Stärk added a comment - I think my problem described here http://markmail.org/message/4d7lycjg3cbaxkfw is related to this, it would be great if this got solved.
          Hide
          Ulrich Stärk added a comment -

          I am still getting an exception. I am contributing a HttpServletRequestFilter to the HttpServletRequestFilterHandler service. This filter processes OpenID authentication and delegates to another service to look up the user. I am decorating this lookup service in order to store the return value as an ASO. In my decorator I inject the applicationStateManager and call applicationStateManager.set(...), but all I get is the following exception:

          java.lang.NullPointerException
          at $Request_11d24c24553.getSession($Request_11d24c24553.java)
          at $Request_11d24c24518.getSession($Request_11d24c24518.java)
          at org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy.getSession(SessionApplicationStatePersistenceStrategy.java:47)
          at org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy.set(SessionApplicationStatePersistenceStrategy.java:88)
          at $ApplicationStatePersistenceStrategy_11d24c2460b.set($ApplicationStatePersistenceStrategy_11d24c2460b.java)
          at org.apache.tapestry5.internal.services.ApplicationStateManagerImpl$ApplicationStateAdapter.set(ApplicationStateManagerImpl.java:50)
          at org.apache.tapestry5.internal.services.ApplicationStateManagerImpl.set(ApplicationStateManagerImpl.java:138)
          at $ApplicationStateManager_11d24c24569.set($ApplicationStateManager_11d24c24569.java)
          at de.spielviel.mailadmin.services.impl.UserDetailsDecoratorImpl$1.advise(UserDetailsDecoratorImpl.java:43)
          at org.apache.tapestry5.ioc.internal.services.AbstractInvocation.proceed(AbstractInvocation.java:121)
          at $UserDetailsService_11d24c24608.loadUserByUsername($UserDetailsService_11d24c24608.java)
          at $UserDetailsService_11d24c24534.loadUserByUsername($UserDetailsService_11d24c24534.java)
          at org.springframework.security.providers.openid.OpenIDAuthenticationProvider.authenticate(OpenIDAuthenticationProvider.java:70)
          at org.springframework.security.providers.ProviderManager.doAuthentication(ProviderManager.java:195)
          at org.springframework.security.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:46)
          at $AuthenticationManager_11d24c24509.authenticate($AuthenticationManager_11d24c24509.java)
          at org.springframework.security.ui.openid.OpenIDAuthenticationProcessingFilter.attemptAuthentication(OpenIDAuthenticationProcessingFilter.java:84)
          at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:252)
          at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
          at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
          at $HttpServletRequestFilter_11d24c24531.service($HttpServletRequestFilter_11d24c24531.java)
          at $HttpServletRequestHandler_11d24c24533.service($HttpServletRequestHandler_11d24c24533.java)
          at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
          at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
          at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
          at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
          at $HttpServletRequestFilter_11d24c24529.service($HttpServletRequestFilter_11d24c24529.java)
          at $HttpServletRequestHandler_11d24c24533.service($HttpServletRequestHandler_11d24c24533.java)
          at $HttpServletRequestHandler_11d24c24528.service($HttpServletRequestHandler_11d24c24528.java)
          at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:179)
          at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
          at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
          at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
          at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
          at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
          at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
          at org.mortbay.http.HttpServer.service(HttpServer.java:909)
          at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
          at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
          at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
          at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
          at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
          at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

          Show
          Ulrich Stärk added a comment - I am still getting an exception. I am contributing a HttpServletRequestFilter to the HttpServletRequestFilterHandler service. This filter processes OpenID authentication and delegates to another service to look up the user. I am decorating this lookup service in order to store the return value as an ASO. In my decorator I inject the applicationStateManager and call applicationStateManager.set(...), but all I get is the following exception: java.lang.NullPointerException at $Request_11d24c24553.getSession($Request_11d24c24553.java) at $Request_11d24c24518.getSession($Request_11d24c24518.java) at org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy.getSession(SessionApplicationStatePersistenceStrategy.java:47) at org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy.set(SessionApplicationStatePersistenceStrategy.java:88) at $ApplicationStatePersistenceStrategy_11d24c2460b.set($ApplicationStatePersistenceStrategy_11d24c2460b.java) at org.apache.tapestry5.internal.services.ApplicationStateManagerImpl$ApplicationStateAdapter.set(ApplicationStateManagerImpl.java:50) at org.apache.tapestry5.internal.services.ApplicationStateManagerImpl.set(ApplicationStateManagerImpl.java:138) at $ApplicationStateManager_11d24c24569.set($ApplicationStateManager_11d24c24569.java) at de.spielviel.mailadmin.services.impl.UserDetailsDecoratorImpl$1.advise(UserDetailsDecoratorImpl.java:43) at org.apache.tapestry5.ioc.internal.services.AbstractInvocation.proceed(AbstractInvocation.java:121) at $UserDetailsService_11d24c24608.loadUserByUsername($UserDetailsService_11d24c24608.java) at $UserDetailsService_11d24c24534.loadUserByUsername($UserDetailsService_11d24c24534.java) at org.springframework.security.providers.openid.OpenIDAuthenticationProvider.authenticate(OpenIDAuthenticationProvider.java:70) at org.springframework.security.providers.ProviderManager.doAuthentication(ProviderManager.java:195) at org.springframework.security.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:46) at $AuthenticationManager_11d24c24509.authenticate($AuthenticationManager_11d24c24509.java) at org.springframework.security.ui.openid.OpenIDAuthenticationProcessingFilter.attemptAuthentication(OpenIDAuthenticationProcessingFilter.java:84) at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:252) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52) at $HttpServletRequestFilter_11d24c24531.service($HttpServletRequestFilter_11d24c24531.java) at $HttpServletRequestHandler_11d24c24533.service($HttpServletRequestHandler_11d24c24533.java) at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56) at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235) at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52) at $HttpServletRequestFilter_11d24c24529.service($HttpServletRequestFilter_11d24c24529.java) at $HttpServletRequestHandler_11d24c24533.service($HttpServletRequestHandler_11d24c24533.java) at $HttpServletRequestHandler_11d24c24528.service($HttpServletRequestHandler_11d24c24528.java) at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:179) at org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821) at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568) at org.mortbay.http.HttpContext.handle(HttpContext.java:1530) at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633) at org.mortbay.http.HttpContext.handle(HttpContext.java:1482) at org.mortbay.http.HttpServer.service(HttpServer.java:909) at org.mortbay.http.HttpConnection.service(HttpConnection.java:820) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245) at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357) at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

            People

            • Assignee:
              Howard M. Lewis Ship
              Reporter:
              Francois Armand
            • Votes:
              3 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development