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
JavaRanch » Java Forums » Java » Web Services
Bookmark "simple session" Watch "simple session" New topic

simple session

Koen Van Eetvelde

Joined: Apr 12, 2005
Posts: 3

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("<title>Servlet NewsServlet</title>");
String result="test";
try {result=getNewsWSSEIPort().getGlobal();}
catch(java.rmi.RemoteException ex) {}
//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

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.
Koen Van Eetvelde

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:
subject: simple session
It's not a secret anymore!