views:

44

answers:

1

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:

  1. Each requester uses an active http listener, so this is not scalable,
  2. 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.

A: 

Consider using JAX-WS 2.0 asynchronous programming model (and most likely a callback client in your case). Here are some resources:

Pascal Thivent
Pascal - thank you for your reply. I have the client side working well, I think. The problem is seemingly in the server side only. I edited my question to add information about the client side calls I am making to the web service.
John K