This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple session

 
Koen Van Eetvelde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic