• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

closing web services connection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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);
 
Ranch Hand
Posts: 2198
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Madhurya Ranjan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic