Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Separates host and URI, to facilitate connection reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
solsson committed May 26, 2019
1 parent 98ea58a commit 08222d6
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
Expand All @@ -26,16 +25,12 @@ public class UpdatesDispatcherHttp implements UpdatesDispatcher {
ResponseHandlerAck responseHandler = new ResponseHandlerAck();
UpdateTarget target;
CloseableHttpClient client;
HttpClientContext context;

public UpdatesDispatcherHttp(String configuredTarget) {
target = new UpdateTarget(configuredTarget);
HttpHost host = target.getHttpclientContextHost(); // If we want to manage contexts
logger.info("Creating http client for host {} target {}", host, target);

context = HttpClientContext.create();
context.setTargetHost(host);

BasicHttpClientConnectionManager connectionManager = new BasicHttpClientConnectionManager();
client = HttpClients.createMinimal(connectionManager);
}
Expand All @@ -47,7 +42,7 @@ public void dispatch(String topicName, UpdatesBodyPerTopic body) throws TargetAc
post.setEntity(getEntity(body));
ResponseResult result;
try {
result = client.execute(post, responseHandler, context);
result = client.execute(target.getHttpclientContextHost(), post, responseHandler);
} catch (ClientProtocolException e) {
throw new TargetAckFailedException(e);
} catch (IOException e) {
Expand Down

0 comments on commit 08222d6

Please sign in to comment.