-
1. Re: How can I use session sope in jbossws?
froden Jan 25, 2008 10:16 AM (in response to chicochen)I would be very interested in some pointers on this as well, as I have the exact same problem. Have you figured it out, chicochen?
-
2. Re: How can I use session sope in jbossws?
mjhammel Jan 25, 2008 12:15 PM (in response to chicochen)I don't know if this helps, but see my thread on a similar subject:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=128375
I tried to get the session context via the MessageContext, but that doesn't appear to work. At least not the way I tried. There is a helpful explanation on how to get the request context here:
https://jax-ws.dev.java.net/articles/MessageContext.html
and that's what I've used to get as far as I have. But I'm still not able to retrieve the property I'm after (the PASSWORD_PROPERTY). -
3. Re: How can I use session sope in jbossws?
froden Jan 30, 2008 8:51 AM (in response to chicochen)Thanks for your reply, mjhammel, Using the approach described in your links, I managed to get the session object. I can now set and retrieve variables from session as long as the client has the JSESSIONID http header field set correctly.
However, I still have some unresolved issues with this.
In my application, I have a JSF page where users can log in. The page uses a seam component, in which I have the following code (somewhat simplified):@Stateless @Name("authenticator") public class AuthenticatorAction { @EJB ProfileDAO profileDAO; @RequestParameter String username; @RequestParameter String password; @In(required=false) @Out(required=false, scope=SESSION) private Profile authenticatedProfile; public String login() { Profile p = profileDAO.getUser(username, password); authenticatedProfile = profile; } }
This works fine, and the Profile object is put into the session scope (ie can be fetched in other seam components over different page loads etc).
The question is, how can I retreive the profile object in my web service? Doing asession.getAttribute("authenticatedProfile")
does not work. In fact,System.out.println((session.getValueNames()).length);
reveals that there are no variables stored in the session!
Any ideas? -
4. Re: How can I use session sope in jbossws?
chicochen Jan 31, 2008 5:27 AM (in response to chicochen)To froden:
Would mind parse you code here pls? -
5. Re: How can I use session sope in jbossws?
froden Jan 31, 2008 6:37 AM (in response to chicochen)You mean for the webservice? This is the interface:
package services; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; @WebService( name = "EndpointInterface", targetNamespace = "http://mynamespace/xml" ) @SOAPBinding(style = SOAPBinding.Style.RPC) public interface UserService { @WebMethod(operationName = "registerUser", action = "urn:registerUser") public String registerUser( @WebParam(name = "nickname") String nickname, @WebParam(name = "password") String password, @WebParam(name = "email") String email ); }
And the implementation:package services; import javax.annotation.Resource; import javax.ejb.EJB; import javax.ejb.EJBContext; import javax.ejb.Stateless; import javax.jws.WebService; import javax.naming.InitialContext; import javax.servlet.http.HttpSession; import javax.xml.ws.WebServiceContext; import javax.xml.ws.WebServiceException; import javax.xml.ws.handler.MessageContext; import org.jboss.ws.annotation.WebContext; import org.jboss.ws.core.CommonMessageContext; import org.jboss.ws.core.jaxws.WebServiceContextEJB; import org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS; import org.jboss.ws.core.soap.MessageContextAssociation; @WebService( endpointInterface = services.UserService", serviceName = "UserService" ) @WebContext(contextRoot="/ws", urlPattern="/UserService") @Stateless public class UserServiceImpl implements UserService { WebServiceContext wsContext; @Resource EJBContext ejbCtx; public String registerUser(String nickname, String password, String email) { CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext(); wsContext = new WebServiceContextEJB((SOAPMessageContextJAXWS)msgContext, ejbCtx); MessageContext mc = wsContext.getMessageContext(); HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession(); if (session == null) throw new WebServiceException("No session in WebServiceContext"); String[] names = session.getValueNames(); System.out.println("There are " + names.length + " variables in the session."); for(int i = 0; i < names.length; i++) { System.out.println("We have a session variable called " + names[ i ] + " holding the value " + session.getAttribute(names[ i ])); } // Get a session property "counter" from context Integer counter = (Integer)session.getAttribute("counter"); if (counter == null) { counter = new Integer(0); System.out.println("Starting the Session"); } System.out.println("Session id is: " + session.getId()); counter = new Integer(counter.intValue() + 1); session.setAttribute("counter", counter); System.out.println("Counter is: " + counter); return "blabla"; } }
Sorry about the mess hehe