Two Laptop Bag*
The moose likes Web Services and the fly likes simple session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "simple session" Watch "simple session" New topic
Author

simple session

Koen Van Eetvelde
Greenhorn

Joined: Apr 12, 2005
Posts: 3
Hi,

For a few days now im searching on how to implement a session in a java webservice (even though a webservice is by nature stateless, it should be possible).

My serverimplementation just returns the sessionID, which should be the same on every click of the refresh button, but different if i close and open a new windows to the service.
the service is called NewsWS

public class NewsWSImpl implements NewsWSSEI, ServiceLifecycle {
private ServletEndpointContext jaxrpcContext;

public void init(Object context) throws ServiceException {
jaxrpcContext = (ServletEndpointContext) context;
}

public String getGlobal() {
return jaxrpcContext.getHttpSession().getId();
}
//destroy() and other methods also present
}

and this is my client, a servlet

public class NewsLoginServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
javax.xml.rpc.Stub jaxRpcStub=(javax.xml.rpc.Stub) getNewsWSSEIPort();
jaxRpcStub._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewsServlet</title>");
out.println("</head>");
out.println("<body>");
String result="test";
try {result=getNewsWSSEIPort().getGlobal();}
catch(java.rmi.RemoteException ex) {}
out.println(result);
out.println("</body>");
out.println("</html>");
out.close();
}
//getNewsWS() and getNewsWSSEIPort() also implemented
}

my environment: netbeans4.1 and sun application server.
as you see, im trying to do this with the jax-rpc method, but any method would be okay.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi Wibra,
Welcome to Javaranch.
We have a simple policy here that all posters should comply with regarding their name. Would you please take a minute and read the JavaRanch naming policy (which requires you to have a proper display name), and then change your display name to comply with that policy. You can change it by following this link.

Thank you.
Regards
Balaji
Koen Van Eetvelde
Greenhorn

Joined: Apr 12, 2005
Posts: 3
alright, i changed my name (excuse me for not reading the naming policy, i figured the displayed name would be my login as I was used to)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple session
 
Similar Threads
Servlet HelloWorld problem
sequence of form information is not the same WHY???
Trying to test my first servlet.
Session maintenance with j2ee generated stub
Pls help : I get error when i try to access servlet directly