java - retrieve jsf bean in axis2 web service as server request -


i using eclipse axis2 create web service client wsdl.

my impl method is:

public output[] startprocess(message[] messages){    myapplicationbean managementbean = (myapplicationbean) facescontext.getcurrentinstance().getexternalcontext().getapplicationmap().get("myapp"); ... } 

however when execute:

http://localhost:8080/myproject/services/portstartprocessservice method startprocess

i see in tomcat debug reaches method, facescontext.getcurrentinstance() returns null.

my web.xml (part of it)

<servlet-mapping>     <servlet-name>faces servlet</servlet-name>     <url-pattern>*.jsf</url-pattern>      <url-pattern>/services/*</url-pattern>   </servlet-mapping> <servlet-mapping>     <servlet-name>axisservlet</servlet-name>     <url-pattern>/servlet/axisservlet</url-pattern>   </servlet-mapping> 

how can use jsf beans (like application scope) in web services call?

i know not want hear yet, got architecture wrong. jsf application context useless web service calls, because whole idea of jsf gui built of stateful components stored:

  • in user session, or:
  • in hidden form field.

since neither session nor forms available web service calls, jsf not apply here. might ask how make web service presses jbutton or inserts cd cd-rom.

i understand not need jsf components, rather need application logic resides inside 1 of managed beans, right?

well, easiest solution time machine, go in time when project planned , tell architect never put application logic managed beans. 1 of reason unavailable web service calls. application logic should reside in service layer, provided spring or ejb.

both spring beans , ejbs easy reach axis services , managed beans, , never need access jsf managed beans place else jsf front-end. if not spring , can't use ejb reason, build service layer pojos, set in applicationcontextlistener , register in application scope.

if such clean solution unavailable , refactoring impossible, have 2 choices:

  • if managed beans try reach application scoped , eager, can accessed in jsp way, application context, using venerable getattribute method (you can access application context through servlet context, afaik access through message context, in turn access static messagecontext.getcurrentmessagecontext method in axis).

  • if managed beans want use request scoped , require jsf plumbing (so can not instantiate them yourself) can pretend facesservlet , create faces context yourself; tricky doable, , quite famous description here: http://www.thoughtsabout.net/blog/archives/000033.html. need need servletrequest , servletresponse (from messagecontext). can skip parts required pass facescontext on, because not require process views.

disclaimer: never tried last solution - seems work, although pretty dirty (and causes web services depend on jsf, bizzare).


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -