views:

105

answers:

1

I'm developing a Web Service which will be called by clients which are written by me. In the web service I need to use application-wide objects which eases the load of application on the system. I have implemented my application-wide objects as shown in this question.

I can use my object in a jsf page with no problem as follows.

MyObject mo = (MyObject) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("MyObjectsName");

But when it comes to use it in a Web Service Request FacesContext.getCurrentInstance() returns null. Is there any way to use the FacesContext in a web service.

+2  A: 

It is null, because web services don't come through the Faces Servlet. And this is the way it should be, because web services have nothing to do with JSF.

In case you are using a jax-ws implementation, you can use:

@Resource
WebServiceContext context;

This will inject the WebServiceContext, by which you can:

ServletContext servletContext = (ServletContext) 
     context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);

And having the ServletContext, you can access your application-scope objects.

Bozho
I'will give it a try as soon as possible. Thanks.
scriptmonster