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

ServletContext uninitialized when doing asynch request

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.2.RC1
    • 1.1.GA
    • jaxrs
    • None

      I'm having trouble injecting ServletContext in my RESTeasy service class when I invoke it as asynchronous i.e with an asynch=true parameter. I've tried this with GET and POST. The call gets to the service but since ServletContext is needed by my app it just prints for me the error and errors out. Also, when I invoke the service without the asynch=true it seems to processes as I expect.

      Here is what I have:

      import
      javax.servlet.ServletContext;

      @Context

      private ServletContext servletCtx;

      protected void setServletContext(ServletContext servletCtx)

      { this.servletCtx = servletCtx; }

      protected ServletContext getServletContext()

      { return servletCtx; }

      @GET

      @Path("result/

      
      

      ")

      @Produces("application/xml")

      public ResultBean getResult(@PathParam("code") ErrorCodeType errorCode,

      @QueryParam("msg") String errorMsg,

      @QueryParam("incidentId") @DefaultValue("1") Integer incidentId)

      throws ModuleException, HandlerException {

      debug(
      "getResult");

      ResultBean result =
      new ResultBean();

      result.setErrorCode(errorCode);

      result.setErrorMsg(errorMsg);

      debug(
      "checking servlet context");

      if (getServletContext() != null)

      { debug( "servletcontext.getserverinfo"); debug( "serverinfo:" + getServletContext().getServerInfo()); }

      else

      { debug( "ServletContext is null"); }

      return result;

      }

      web.xml:

      <!-- set this if you map the Resteasy servlet to something other than -->

      <context-param>

      <param-name>resteasy.servlet.mapping.prefix</param-name>

      <param-value>/handsetservice</param-value>

      </context-param>

      <context-param>

      <param-name>resteasy.resources</param-name>

      <param-value>com.xxx.xxx.IncidentResourceManager</param-value>

      </context-param>

      <!-- enable the Asynchronous Job Service -->

      <context-param>

      <param-name>resteasy.async.job.service.enabled</param-name>

      <param-value>true</param-value>

      </context-param>

      <!-- The next context parameters are all optional.

      Their default values are shown as example param-values -->

      <!-- How many jobs results can be held in memory at once? -->

      <context-param>

      <param-name>resteasy.async.job.service.max.job.results</param-name>

      <param-value>100</param-value>

      </context-param>

      <!-- Maximum wait time on a job when a client is querying for it -->

      <context-param>

      <param-name>resteasy.async.job.service.max.wait</param-name>

      <param-value>300000</param-value>

      </context-param>

      <!-- Thread pool size of background threads that run the job -->

      <context-param>

      <param-name>resteasy.async.job.service.thread.pool.size</param-name>

      <param-value>100</param-value>

      </context-param>

      <!-- Set the base path for the Job uris -->

      <context-param>

      <param-name>resteasy.async.job.service.base.path</param-name>

      <param-value>/handsetservice/asynch/jobs</param-value>

      </context-param>

      <listener>

      <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>

      </listener>

      <servlet>

      <servlet-name>Resteasy</servlet-name>

      <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>

      </servlet>

      <servlet-mapping>

      <servlet-name>Resteasy</servlet-name>

      <url-pattern>/handsetservice/*</url-pattern>

      </servlet-mapping>

              patriot1burke@gmail.com Bill Burke (Inactive)
              samirshaikh_jira Samir Shaikh (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: