Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-828

Issue with injected ServletContext in Resteasy/SpringMVC setup

XMLWordPrintable

      I'm having an issue retrieving servlet parameters with a springmvc resteasy setup using 2.3.5.Final. A class that I have no control over uses the @Context to inject the ServletConfig so that it can look up an init-param. When this class asks the injected context for the param an exception is thrown saying

      org.jboss.resteasy.spi.LoggableFailure: Unable to find contextual data of type: javax.servlet.ServletContext

      Digging in a little further showed that its a proxy for the ServletContext gets injected into the class; a ContextParameterInjector$GenericDelegatingProxy specifically. When the 'getInitParameter' method is called on the proxy, it calls to the to the ResteasyProviderFactory to retrieve the ServletContext. This context is missing and so the above exception gets thrown.

      From what I can tell, it seems that the deploment gets configured differently using springmvc-resteasy.xml than it otherwise might with the plain ResteasyBootstrap. I'm thinking it boils down the the init method in the ServletContainerDispatcher, if the app is bootstrapped outside of spring it causes the following code to be run

      lines 86...89

                     dispatcher.getDefaultContextObjects().put(Application.class, app);
                     // push context data so we can inject it
                     Map contextDataMap = ResteasyProviderFactory.getContextDataMap();
                     contextDataMap.putAll(dispatcher.getDefaultContextObjects());
      

      And this makes the ServletContext available via the provider factory and subsequently for injection. When spring initializes the deployment the other path is taken and this is not called.

      I've condensed down my config into a simple maven based example to illustrate. I'll happily provide any extra info that might be required to help troubleshoot.

      Thanks kindly,

      Regards

      Steve.

              weli@redhat.com Weinan Li
              sgargan_jira Steve Gargan (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: