init not being called in my @WebService annotated webservice
Ok, this is really getting frustrating.
I'm developing a web service using JAX-WS and have created my service using a @WebService annotated class. Everything works fine, so now I'm trying to incorporate some session management in my service.
According to the examples I've read, all I need to do is implement the javax.xml.rpc.server.ServiceLifecycle interface and use init(context) to get the ServletEndpointContext. Seems simple enough, but it simply does not work for me - the init(Object context) method is NEVER called.
I've tried using the @PostConstruct annotation and indeed a method so annotated is called when the service is first created. The @Resource annotation also allows properly injects a ServiceContext resource into the class - but I NEED a ServletEndpointContext to get the HttpSession!
HELP!
[847 byte] By [
derek_ka] at [2007-10-2 16:59:53]

You are mixing up JAXRPC and JAXWS. JAXWS doesn't have ServletEndpointContext. Whatever you are doing with @Resource is fine and you can get ServletContext from MessageContext. MessageContext can be got from WebServiceContext
For e.g.
public class HelloServiceImpl {
@Resource
private WebServiceContext wsc;
private Set<String> clients;
public HelloServiceImpl() {
clients = new HashSet<String>();
}
@WebMethod
public void introduce() {
String id = getClientId();
System.out.println("** storing session id: " + id);
clients.add(id);
}
@WebMethod
public boolean rememberMe() {
String id = getClientId();
System.out.println("** looking up id: " + id);
return clients.contains(id);
}
private String getClientId() {
HttpServletRequest req = (HttpServletRequest)
wsc.getMessageContext().get(MessageContext.SERVLET_REQUEST);
HttpSession session = req.getSession();
return session.getId();
}
}
jitua at 2007-7-13 18:13:18 >
