Two Laptop Bag*
The moose likes Web Services and the fly likes closing web services connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "closing web services connection" Watch "closing web services connection" New topic
Author

closing web services connection

Madhurya Ranjan
Greenhorn

Joined: Dec 19, 2010
Posts: 2
I have created client code generated by Apache CXF. The problem is how can I close the connection after calling the web services methods.I just want to make sure that after calling the webservices , it should be closed.Please help me out if there is any method to do so.
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
Madhurya Ranjan wrote:I have created client code generated by Apache CXF. The problem is how can I close the connection after calling the web services methods.I just want to make sure that after calling the webservices , it should be closed.Please help me out if there is any method to do so.



You need not to close anything, just use System.exit(0);


Brainbench Java 2.0 Fundamentals, J2EE 1.4
http://www.brainbench.com/transcript.jsp?pid=8192792
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Bhagat Singh Rawat is correct in that you do not have to explicitly close any connection after having used web service stubs.
The connection used is, most likely, a HTTP connection over which the request is sent and a response received. This HTTP connection is automatically closed when the request-response message exchange is completed.
What you do not need to do, unless you want to terminate the JVM your web service client is running in, is to call System.exit(0).
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Madhurya Ranjan
Greenhorn

Joined: Dec 19, 2010
Posts: 2
Thanks Bhagat/Ivan for your response. My only doubt is after calling system.exit(0), code written after web services will not be reachable.Please correct me .
I am calling the webservices running on webserver and caling it from a web application running on JBoss through a JSP and I have seen lots of open connection after finishing the transaction.This is increasing overhead and web services calling time.
Jim Akmer
Ranch Hand

Joined: Jul 06, 2010
Posts: 104
CXF uses HTTP1.1 to send requests to web service. This means that persistent connections are being used, so connection will remain open (at least for a period).
If you need connections to be closed you should explicitely configure it with something like the following:
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Madhurya Ranjan wrote:My only doubt is after calling system.exit(0), code written after web services will not be reachable.

Try the following program and see what output it generates:


If you do a System.exit(0) in an application server, you will shut down the entire server. That is definitely not good.

I am calling the webservices running on webserver and caling it from a web application running on JBoss through a JSP and I have seen lots of open connection after finishing the transaction.

This sounds a little strange to me, could you show an example?
JSP is presentation technology, meaning that it is to be used to render a webpage (in this case) that the user sees. It is not a good practice to perform business logic or, for instance, call web services, from a JSP.
What kind of connections are left open after having finished the transaction?
Best wishes!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: closing web services connection
 
Similar Threads
Problem with connection to remote access database
Clear SCWCD 1.5 Exam with 92%
Implementing Business Object Web Services using Eclipse
TCP/IP Connection lost
How to access Secure web method