简体   繁体   English

如何使用Jersey客户端为每个POST请求建立新连接

[英]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. 我的程序应该向一个https站点发出多个POST请求,并且每次执行新请求时都需要它进行SSL握手。 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. 我确定它不会在以后进行握手,因为第一次执行请求和接收响应大约需要700毫秒,但是以后仅花费大约30毫秒。

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.) (服务变量是Builder类,该类创建ClientRequest。在该URL中指定URL。)

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. HTTP具有持久性连接,而SSL具有可恢复的会话,这两个会话都是专门用来防止您尝试完成的。

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. 你可能把他们都关在某种程度上为你的测试目的,如果你深入到你的服务器的内部结构,但我真的没有看到测试你会疯部署在生产环境配置的点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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