I have a pre-existing SOAP-based web service with which I'd like to provide a long-polling based notification system. How can I implement this? The client is currently a Java desktop rich client which must receive updates from other connected clients. The server is GlassFish 3.01. I had a basic, blocking @WebMethod but I had problems resulting from its use. Here's some pseudo-code showing the idea of the web method:
@WebService(serviceName="mywebservice")
@Stateless
public class MyWebService {
@WebMethod
public String longPoll() {
short ct = 0;
while(someCondition == false && ct < 60) {
sleep(1000); // 1 sec
ct++;
}
if (someCondition)
return "got value";
else
return "";
}
}
And on the client-side, I am calling this asynchronously, using the Future object:
public Future<?> requestLongPollAsync(Date lastUpdate,
AsyncHandler<LongPollResponse> handler) {
try {
return mywebservice.longPollAsync(getXMLGregorianCalendar(lastUpdate),
handler);
}
// ...
}
The client side seems to work okay. However, I have 2 problems that arose from this, seemingly due to the long lasting nature of the web service call:
- Each requester uses an active http listener, so this is not scalable,
- When the client disconnects, GlassFish throws an exception (SSL exception, as all calls must go through the secure SSL listener (by default, http-listener-2)).
Do I need to use com.sun.grizzly.comet.CometEngine? Does the EJB 3.1 @Asynchronous annotation do anything here? All examples I've found rely on the Servlet API, AJAX, and other technologies which are not applicable. Thank you.