You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Marc Logemann <ml...@logemann.org> on 2008/09/09 18:03:16 UTC
accessing ServletContext from within @WebMethod
Hi,
in a webservice i need to get hold of an ServletContext because i need
to load some resources for BIRT eclipse reporting.
Is this possible somehow?
--
Marc Logemann
blog http://logemannreloaded.blogspot.com
privat http://www.logemann.org
Re: accessing ServletContext from within @WebMethod
Posted by Marc Logemann <ml...@logemann.org>.
Hi,
thanks folks, i just discovered it too and wanted to post this and ask
if this is correct (which is of course)
@Resource
private WebServiceContext context;
public void submitOrder(Order order) {
MessageContext messageContext = context.getMessageContext();
ServletContext servletContext =
(ServletContext
)messageContext.get(AbstractHTTPDestination.HTTP_CONTEXT);
:)
But of course i am using Spring and i was not aware that i can use
ServletContextAware, which makes it even easier.
Thanks again for quick response and yeah, i could have seen this
myself in the docs but i have my very own problems with the CXF docs,
because they are quite ... ahmmmm..... fragmented :)
--
Marc Logemann
blog http://logemannreloaded.blogspot.com
privat http://www.logemann.org
Am 09.09.2008 um 18:16 schrieb Ian Roberts:
> Marc Logemann wrote:
>> Hi,
>>
>> in a webservice i need to get hold of an ServletContext because i
>> need
>> to load some resources for BIRT eclipse reporting.
>> Is this possible somehow?
>
> If you're creating your implementation object using Spring then the
> easiest way is to implement the ServletContextAware interface and
> Spring
> will inject it for you by calling setServletContext. Alternatively,
> you
> can get a reference to the servlet context via the WebServiceContext
> (this may only work during calls to your web service operations, if
> you
> need access to the context before any of your WS methods have been
> called, use ServletContextAware).
>
> @Resource
> private WebServiceContext ctx;
>
> public String webServiceOperation(....) {
> ServletContext sctx =
> ctx.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
> ...
> }
>
> Ian
>
> --
> Ian Roberts | Department of Computer Science
> i.roberts@dcs.shef.ac.uk | University of Sheffield, UK
>
Re: accessing ServletContext from within @WebMethod
Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Marc Logemann wrote:
> Hi,
>
> in a webservice i need to get hold of an ServletContext because i need
> to load some resources for BIRT eclipse reporting.
> Is this possible somehow?
If you're creating your implementation object using Spring then the
easiest way is to implement the ServletContextAware interface and Spring
will inject it for you by calling setServletContext. Alternatively, you
can get a reference to the servlet context via the WebServiceContext
(this may only work during calls to your web service operations, if you
need access to the context before any of your WS methods have been
called, use ServletContextAware).
@Resource
private WebServiceContext ctx;
public String webServiceOperation(....) {
ServletContext sctx =
ctx.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
...
}
Ian
--
Ian Roberts | Department of Computer Science
i.roberts@dcs.shef.ac.uk | University of Sheffield, UK