Hi,
I have 2 different code bases that are using httpclient 4.0.1 to do secure,
https traffic over different ports. e.g. call1:443 call2:8443. The problem I am
having is that the connections are swapping out their ports when in a
multi-threaded run.
The application is using Jersey and runs in Jetty. A client makes a jersey,
rest based service call that uses httpclient to do an HTTPS call to our payment
processor. On success, the same thread makes a call to another Jersey based
REST call to store information using httpclient; https over port 8443. This
application is being hit by a threaded application do do a big import. What I
am seeing is that the calls are swapping ports e.g. call1:443 call1:8443 and
call2:8443 call2:443 - when in the code call1 should ALWAYS use 443 and call2
should ALWAYS use 8443 AND NEVER swap ports.
I first discovered that neither code base was following the instructions for
threading and was using the 3.1 version of http client. So, I upgraded to 4.01.
and made sure I was following the recommended way to run in a mult-threaded
environment. However, when hit with a load, I was still swapping out ports such
that call1 may be using 443 or 8443, it was random. Then, as I was looking at
some of the code I noticed that the code was registering a protocol:
Protocol https = new Protocol("https", socketFactory,
port);Protocol.registerProtocol("https", https);
This got me to thinking, maybe, just maybe, the code was overwriting the https
protocol definition. So, I left that code alone, but modified the other line of
code that also uses httpclient as such:
// **************************************************ProtocolSocketFactory
socketFactory = new SSLProtocolSocketFactory();Protocol https = new
Protocol("cttps", socketFactory, port);Protocol.registerProtocol("cttps",
https);PostMethod httpMethod = new
PostMethod(getCallUrl(serviceRequest));RequestEntity re = new
StringRequestEntity(requestJSON.toString(), CONTENT_TYPE,
CHARSET);((PostMethod) httpMethod).setRequestEntity(re);
try { final MultiThreadedHttpConnectionManager
connectionManager = new MultiThreadedHttpConnectionManager(); final HttpClient
client = new HttpClient(connectionManager); client.executeMethod(httpMethod);}
finally { httpMethod.releaseConnection();}
// **************************************************
I am still testing to verify that each call is calling the correct host:port by
doing a mad dump of netstat.
I am using the following script to catch the bad behavior during a run:
while [ 1 == 1 ]; do netstat -na|grep tcp|grep :8443|awk '{print $5 " "
$6}'|sed 's|.*127.0.0.1.*||'|awk 'NF>0 {print $0}'|sort -u >> tracking; done
The box doesn't have iptables installed, so I can't log each outbound TCP
request - maybe someone has a better idea how to verify that I've fixed the
issue.
Thanks,
Russ