ServiceLifeCycle Question
burrsutter May 26, 2006 2:36 AMI was experimenting with the ServiceLifeCycle in my 181 WS and it would appear that the session is recreated with every invocation/operation. Perhaps there is something in a config file that I need to setup. If so then the doc doesn't mention that fact:
http://labs.jboss.com/portal/jbossws/user-guide/en/html/endpoints.html#service-lifecycle
Here is my code, perhaps I simply built it incorrectly:
package org.jboss.samples; import javax.jws.WebMethod; import javax.jws.WebService; import javax.xml.rpc.server.ServiceLifecycle; import javax.xml.rpc.server.ServletEndpointContext; import javax.xml.rpc.ServiceException; import javax.xml.rpc.handler.MessageContext; import java.util.Iterator; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Use; @WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public class ExamineContext implements ServiceLifecycle { private ServletEndpointContext context; @WebMethod (operationName="GetUserPrincipalName") public String getUserPrincipalName() { return context.getUserPrincipal().getName(); } @WebMethod public String getAttribute(String key) { return (String) context.getHttpSession().getAttribute(key); } @WebMethod public void setAttribute(String key, String value) { context.getHttpSession().setAttribute(key,value); } @WebMethod public void removeAttribute(String key) { context.getHttpSession().removeAttribute(key); } @WebMethod public String getSessionId() { return context.getHttpSession().getId(); } @WebMethod public String getMessageContext() { MessageContext msgContext = context.getMessageContext(); StringBuffer sb = new StringBuffer(); String key = null; for(Iterator i = msgContext.getPropertyNames(); i.hasNext(); ) { key = (String) i.next(); sb.append(";" + key + "=" + msgContext.getProperty(key)); } return sb.toString(); } public void init(Object context) throws ServiceException { System.out.println("ExamineContext Init\n"); this.context = (ServletEndpointContext)context; } public void destroy() { System.out.println("ExamineContext Destroy\n"); } }
Burr