Retrieve jsf bean in axis2 web service as server request?

I know you do not want to hear this just yet, but you got the architecture wrong. JSF application context is useless with web service calls, because the whole idea of JSF is that GUI is built of stateful components stored.

I know you do not want to hear this just yet, but you got the architecture wrong. JSF application context is useless with web service calls, because the whole idea of JSF is that GUI is built of stateful components stored: in user session, or: in a hidden form field. Since neither session nor forms are available to web service calls, JSF does not apply here.

You might as well ask how to make a web service that presses a JButton or inserts a CD into your CD-ROM. I understand that you do not need the JSF components, but rather need some application logic that resides inside one of the managed beans, right? Well, The easiest solution is to get a time machine, go back in time to when the project was planned and tell the architect that YOU NEVER PUT APPLICATION LOGIC INTO MANAGED BEANS.

One of the reason is that they are unavailable to web service calls. Your application logic should reside in the service layer, provided by Spring or EJB. Both Spring beans and EJBs are easy to reach from Axis services and from managed beans, and so you never need to access JSF managed beans from any place else than JSF front-end.

If you do not like Spring and can't use EJB for some reason, build your service layer from POJOs, set it up in ApplicationContextListener and register in the application scope. If such clean solution is unavailable and refactoring is impossible, you have two choices: if the managed beans you try to reach are application scoped and eager, then they can be accessed in a JSP way, from the application context, using the venerable getAttribute method (you can access application context through the servlet context, which afaik you access through the message context, which in turn you access by the static MessageContext. GetCurrentMessageContext method in Axis).

If the managed beans you want to use are request scoped and require some JSF plumbing (so you can not instantiate them by yourself) then you can pretend to be a FacesServlet and create the faces context by yourself; it is tricky but doable, a good and quite famous description is here: http://www.thoughtsabout.net/blog/archives/000033.html. You need will need servletrequest and servletresponse (from MessageContext). You can probably skip the parts required to pass the FacesContext on, because you will not require it to process any views.

Disclaimer: I never tried the last solution - it seems to work, although it is pretty dirty (and actually causes your web services to depend on JSF, which is bizzare).

Very nice answer. In fact - if you want to replace JSF application scope bean how do you define one like this in spring that once the server is starting it will call a method? – Odelya Feb 9 at 18:39 1 @Odelya: In a web application an instance of WebApplicationContext is created and registered with a custom ApplicationContextListener.

This is also when all the singleton beans are created, and so any methods marked as initialization (or annotated with @PostContruct) are executed before the application starts. – fdreger Feb 9 at 20:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions