Hey,

I have a use-case where a user action in a GUI results in a web service
invocation. A web-service invocation being a remote operation can take
arbitrary amount of time to complete. For this reason, the GUI provides an
option to the user to cancel the operation.

My question is what is the right way to cancel a web service invocation.

I tried interrupting the thread that invoked the web service but the web
service does not get interrupted. The isInterrupted() status of the thread
remains set and the stack of that thread looks like the following

thread...@4220, priority=5, in group 'main', status: 'RUNNING'
      at java.net.SocketInputStream.socketRead0(SocketInputStream.java:-1)
      at java.net.SocketInputStream.read(SocketInputStream.java:129)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
      at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
      at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
      at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
      at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1,064)
      at
java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
      at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1,937)
      at
org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1,865)
      at
org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
      at
org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
      at
org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
      at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
      at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
      at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
      at
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)

There seems to be a bigger issue around interruptibility of I/O streams and
its platform dependence in the JDK. (bug
4385444<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4385444>).


It appears that there isn't much that can be done to interrupt a web service
invocation implementation-wise if we are using streams instead of nio
classes..

I'm guessing that to deal with this use-case we'll just have to let the
thread invoking the backend API run until the invocation returns or until it
hits the ReceiveTimeout. In the worst case, if the user is invoking and
canceling operations frequently, we run out of threads...

Are there any other means that can be used to cancel a web service
invocation?

Cheers,
Anshul

Reply via email to