views:

853

answers:

1

I have an axis web service running in Tomcat. Clients are making connections without sending a Connection: close header in HTTP 1.1 which means that the default is Keep-Alive. Unfortunately the client seems to be having a problem and when it gets an exception the client is not closing the connection. Since these clients are sending lots of traffic in batch jobs this quickly eats up all my connections. I want to force my web service to close each connection as soon as a particular Handler (extends BasicHandler) completes.

How do I do this? I.e. how do I force the server to close a connection after calling BasicHandler#invoke()?

+1  A: 

In your tomcat's server.xml file, find the HTTP Connector definition (it's the element with protocol="HTTP/1.1"), and add the keepAliveTimeout attribute, as detailed here:

http://tomcat.apache.org/tomcat-6.0-doc/config/http.html

You'll have to experiment with different values to see which gives you the behaviour you want. Check out the other settings also, some might be useful to you.

Note that that's the Tomcat 6 docs, so not all options might work on tomcat 5, so check the same part of the tomcat 5 docs.

skaffman
I knew about this option. The problem is that it is server wide. I don't want to mess with my JSP and servlet keep alive timeout. Just this one webservice.
quadelirus
HTTP handling is not expose to the application, though. I suggest you define another HTTP Connector in server.xml, on a different port, and make the web service clients use that.
skaffman
How about an upvote too? :)
skaffman
:) Sorry. Yesterday I had <5 score so I couldn't do that yet. (new user) PS. You don't happen to know how to accomplish the same thing with websphere do you? My app is deployed in both Tomcat and WebSphere.
quadelirus
I'm afraid not, no. You may want to consider putting Apache webserver in front of your app servers. This will give you common control over the connections, with apache doing the http config instead of the appserver, and would also let you use mod_rewrite to automatically direct webservice requests at the new tomcat connector, so the client wouldn't have to change their URL.
skaffman