From: <sa...@sl...> - 2009-08-29 00:37:46
|
Sorry I missed this part from code: * import* javax.servlet.ServletContext; @Context *private* ServletContext servletCtx; *protected* *void* setServletContext(ServletContext servletCtx) { *this*.servletCtx = servletCtx; } *protected* ServletContext getServletContext() { *return* servletCtx; } On Fri, Aug 28, 2009 at 5:35 PM, sa...@sl... <sa...@sl...>wrote: > Hi, > > 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: > > @GET > > @Path("result/{code}") > > @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.cisco.ipics.handsetserviceapi.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> > > > > Please let me know if there is a problem with a config or if this is a bug > in the implementation. > > Regards, > > Samir > |