  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Subject: - How can we manage session using JAX-WS? | Subject: - How can we manage session using JAX-WS? 2007-10-01 - By contactnag
Back Hi,
We are currently using the Jboss 4.0.5 GA, JAX-WS webservices. I am trying to implement session management. I am getting WebServiceContext injection is null . Please find the code below which I have implemented Server and client side for session management. Can anyone help me why I am getting WebServiceContext null. If you have any code works on Jboss4.0.5 it is really helpful for me
Server Side code -- ---- ---- ---- -- /* * Hello.java * * Created on September 24, 2007, 10:42 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
package cisco;
import javax.jws.*; import javax.xml.ws.WebServiceContext; import javax.annotation.Resource; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.xml.ws.WebServiceException; import javax.xml.ws.handler.MessageContext; import javax.servlet.http.HttpSession;
@(protected) public class Hello { /** * WebServiceContext is injected by the JAX-WS Runtime */ @(protected) private WebServiceContext wsContext;
/** * another way to inject WebServiceContext * make sure this is not a WebMethod * */ /* @(protected)(exclude = true) @(protected) public void initializeContext(WebServiceContext wsContext) { System.out.println("Setting WebServiceContext"); this.wsContext = wsContext; } */ @(protected) public int getCounter() { MessageContext mc = wsContext.getMessageContext(); HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get (MessageContext.SERVLET_REQUEST)).getSession(); // Get a session property "counter" from context if (session == null) throw new WebServiceException("No session in WebServiceContext"); Integer counter = (Integer) session.getAttribute("counter"); if (counter == null) { counter = new Integer(0); System.out.println("Starting the Session"); } counter = new Integer(counter.intValue() + 1); session.setAttribute("counter", counter); return counter;
}
/** * Lifecycle method called before servicing any requests */ @(protected) @(protected)(exclude = true) public void onBeginService() { System.out.println("Called onBeginService: Session test"); // Initialize resources need by the Service // .... }
/** * Lifecycle method called before destroying the service instance */ @(protected) @(protected)(exclude = true) public void onEndService() { System.out.println("Called onEndService: Session test"); // Clean up resources need by the Service // .... } }
Client Clode: try { cisco.HelloService service = new cisco.HelloService(); cisco.Hello port = service.getHelloPort(); ((BindingProvider)port).getRequestContext().put(BindingProvider.SESSION _MAINTAIN_PROPERTY,new Boolean(true)); // TODO process result here //int result = port.getCounter(); //out.println("Result = "+result); //Hello proxy = new HelloService().getHelloPort(); //((BindingProvider)proxy).getRequestContext().put(BindingProvider .SESSION_MAINTAIN_PROPERTY,true); int result = port.getCounter(); System.out.println(result); result = port.getCounter(); System.out.println(result); } catch (Exception ex) { ex.printStackTrace(); }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic &p=4090201#4090201
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode =reply&p=4090201 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ jboss-user mailing list jboss-user@(protected) https://lists.jboss.org/mailman/listinfo/jboss-user
|
|
 |