简体   繁体   中英

How to make a new connection for each POST request with Jersey Client

My program is supposed to make multiple POST requests to a https site and I need it to do a SSL-handshake each time it does a new request. However it seems to only do the handshake the first time and then use the existing connection to do the other requests without a new handshake. I'm sure it doesn't do the handshake later times, because the first time it takes about 700 ms to do the request and receive a response, but later ones only take about 30 ms.

Here's how I initialize the client: (Am I missing some property here?)

    SSLContext context = SSLContext.getInstance("SSL");
    context.init(kms, trustAllCerts, null);
    SSLContext.setDefault(context);

    ClientConfig config = new DefaultClientConfig();
    config.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, timeout * 1000);
    config.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, false);
    config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true);
    client = Client.create(config);

And here's how I make the actual request:

    ClientResponse cr = service.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(ClientResponse.class, batch);

(The service variable is the Builder class, which creates the ClientRequest. It's where the URL is specified.)

Any ideas, please?

HTTP has persistent connections, and SSL has resumable sessions, both of which are specifically intended to prevent what you are trying to accomplish.

You probably turn them both off somehow for your testing purposes, if you delve into the innards of your servers, but I really don't see the point of testing a configuration you would be mad to deploy in production.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM