It's not a secret anymore!*
The moose likes Web Services and the fly likes stop synchronous web service call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "stop synchronous web service call" Watch "stop synchronous web service call" New topic
Author

stop synchronous web service call

ankur Gautam
Greenhorn

Joined: Aug 18, 2009
Posts: 6
Hi All

I am making synchronous web service calls in my application, there are scenario where user requires to stop the execution of web service call in between i.e before response is returned .
Does any one has an idea how to stop a web service call in middle.

Thnaks in advance
Ankur Gautam


SCJP 1.4 , SCWCD -5
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
On the service side, you could have the service throw a SOAP exception and hope that the toolkit unwinds all the resources properly.

Your biggest problem will be matching the HTTP request (SOAP also?) to stop with the SOAP request that is running since SOAP does not normally maintain any sort of session ID for you.

On the client side you could close the connection and hope for the best.

Exactly what do you have on the client side? You should certainly be running the SOAP request in its own Thread if you want the client to be able to respond at all.

Bill
ankur Gautam
Greenhorn

Joined: Aug 18, 2009
Posts: 6
i am making a web service call from a java class. then what is returned from web service as a response is passed back to UI(adobe flex) .
I am using SOAp for web service call.

Now the requirement is if web service call is taking a long time , then i need to give user a facility to stop the webservice call.
So how can i cut a call , before response is returned.


Is there a way to implemnt this scenario
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
How about making the client asynchronous and, if the user cancels the operation or if there is a timeout, cancel the client waiting for the response and ignore (the response)?
Best wishes!
Waswani Naresh
Ranch Hand

Joined: May 01, 2008
Posts: 66
Asynchronous call generally denotes background processing and letting the foreground flow continue. Is that the intention here ? Not very sure if this would be the solution.

Make WS call in a separate thread and along with that start a parallel timer thread. Mention the time in the timer thread (using sleep or join methods). If you do not get the response in time, then stop the WS invoker thread and pop a message to the user.

Note : If user still says I am OK to wait for the response, above solution has to be tweaked. This solution will stop the WS invoker thread alltogether and the response would always be ignored.


Naresh Waswani
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Waswani Naresh wrote:Asynchronous call generally denotes background processing and letting the foreground flow continue. Is that the intention here ? Not very sure if this would be the solution.

Asynchronous client, not server.
Make WS call in a separate thread and along with that start a parallel timer thread.

This is exactly what I meant when suggesting an asynchronous client. The advantage is that you do not have to start a thread yourself. When generating client artifacts using wsimport, you need to supply a binding file in which you set <enableAsyncMapping>true</enableAsyncMapping>, in order to get asynchronous client methods.
Best wishes!
ankur Gautam
Greenhorn

Joined: Aug 18, 2009
Posts: 6
for changing synchronous WS to asynchronous WS i would be changing my complete application(around 100 web services) ...........

so suggest something in context with sysnchronous WS,

i have thought , when we make a wS call a thread is created between java and server(where services lie) , if i can get hold of that thread then i can truncate it .
I checked on response object in eclipse ide , i was getting prompted for only to 2 threading methods notify and wait (sort of confirming my doubt that we dont have the access to truncate ws call once started)
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Not sure if the following would help - ASP Net - How do I stop the Webservice execution after certain amount of time?

Regards,
Dan

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
William Brogden wrote:On the service side, you could have the service throw a SOAP exception and hope that the toolkit unwinds all the resources properly.



With the Restlet framework the Resource class has the allowPost method, which can return false. At that point, no new HTTP post requests will not be processed until allowPost returns true.

Regards,
Dan
ankur Gautam
Greenhorn

Joined: Aug 18, 2009
Posts: 6
Hi Dan thanks for your inputs ... i have seen that link i,ts for .net , solution in java is not over there
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: stop synchronous web service call