Fixed merge (take 2) of development / 12.8.1-5 versions of HttpClient.java
Former-commit-id:c72218985b
[formerlye2267aa186
] [formerly926ff5dc5a
] [formerlyc72218985b
[formerlye2267aa186
] [formerly926ff5dc5a
] [formerly9e2e0fa166
[formerly926ff5dc5a
[formerly 5717f9bf344b6d78ca30f1387679e535bac5a13c]]]] Former-commit-id:9e2e0fa166
Former-commit-id:9688e06a3a
[formerlyd42beafc73
] [formerly 447b1173369877f42f724fff7bac204016c3883e [formerly15753699bd
]] Former-commit-id: d7ed4a42f3312d5ff6c151f837117009fbb2640a [formerly3eefb26e94
] Former-commit-id:05ef298baf
This commit is contained in:
parent
aa7a35f8c3
commit
0e71c58d17
1 changed files with 25 additions and 18 deletions
|
@ -255,12 +255,7 @@ public class HttpClient {
|
|||
private HttpResponse postRequest(HttpUriRequest put) throws IOException,
|
||||
CommunicationException {
|
||||
HttpResponse resp = client.execute(put);
|
||||
int code = resp.getStatusLine().getStatusCode();
|
||||
if (code != SUCCESS_CODE) {
|
||||
throw new CommunicationException(
|
||||
"Error reading server response. Got error message: "
|
||||
+ EntityUtils.toString(resp.getEntity()));
|
||||
} else if (previousConnectionFailed) {
|
||||
if (previousConnectionFailed) {
|
||||
previousConnectionFailed = false;
|
||||
statusHandler.handle(Priority.INFO,
|
||||
"Connection with server reestablished.");
|
||||
|
@ -280,8 +275,8 @@ public class HttpClient {
|
|||
* @return the http status code
|
||||
* @throws CommunicationException
|
||||
*/
|
||||
private int process(HttpUriRequest put, IStreamHandler handlerCallback)
|
||||
throws CommunicationException {
|
||||
private HttpClientResponse process(HttpUriRequest put,
|
||||
IStreamHandler handlerCallback) throws CommunicationException {
|
||||
int tries = 0;
|
||||
boolean retry = true;
|
||||
HttpResponse resp = null;
|
||||
|
@ -340,7 +335,12 @@ public class HttpClient {
|
|||
// should only be able to get here if we didn't encounter the
|
||||
// exceptions above on the most recent try
|
||||
processResponse(resp, handlerCallback);
|
||||
return resp.getStatusLine().getStatusCode();
|
||||
byte[] byteResult = null;
|
||||
if (handlerCallback instanceof DefaultInternalStreamHandler) {
|
||||
byteResult = ((DefaultInternalStreamHandler) handlerCallback).byteResult;
|
||||
}
|
||||
return new HttpClientResponse(resp.getStatusLine().getStatusCode(),
|
||||
byteResult);
|
||||
} finally {
|
||||
if (ongoing != null) {
|
||||
ongoing.decrementAndGet();
|
||||
|
@ -387,10 +387,6 @@ public class HttpClient {
|
|||
"Error reading InputStream, assuming closed", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// this should be impossible to reach
|
||||
throw new CommunicationException(
|
||||
"Error ocurred while contacting server, did not get a reponse or an exception");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,8 +402,9 @@ public class HttpClient {
|
|||
private byte[] executePostMethod(HttpPost put)
|
||||
throws CommunicationException {
|
||||
DefaultInternalStreamHandler handlerCallback = new DefaultInternalStreamHandler();
|
||||
this.process(put, handlerCallback);
|
||||
return handlerCallback.byteResult;
|
||||
HttpClientResponse resp = this.process(put, handlerCallback);
|
||||
checkStatusCode(resp);
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -475,8 +472,7 @@ public class HttpClient {
|
|||
public HttpClientResponse executeRequest(HttpUriRequest request)
|
||||
throws CommunicationException {
|
||||
DefaultInternalStreamHandler streamHandler = new DefaultInternalStreamHandler();
|
||||
int statusCode = process(request, streamHandler);
|
||||
return new HttpClientResponse(statusCode, streamHandler.byteResult);
|
||||
return process(request, streamHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,6 +496,16 @@ public class HttpClient {
|
|||
postStreamingEntity(address, new StringEntity(message), handlerCallback);
|
||||
}
|
||||
|
||||
private void checkStatusCode(HttpClientResponse response)
|
||||
throws CommunicationException {
|
||||
if (response.code != SUCCESS_CODE) {
|
||||
throw new CommunicationException(
|
||||
"Error reading server response. Got error message: "
|
||||
+ response.data != null ? new String(response.data)
|
||||
: null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts an entity to the address and stream the result back.
|
||||
*
|
||||
|
@ -514,7 +520,8 @@ public class HttpClient {
|
|||
private void postStreamingEntity(String address, AbstractHttpEntity entity,
|
||||
IStreamHandler handlerCallback) throws CommunicationException {
|
||||
HttpPost put = new HttpPost(address);
|
||||
process(put, handlerCallback);
|
||||
HttpClientResponse resp = process(put, handlerCallback);
|
||||
checkStatusCode(resp);
|
||||
}
|
||||
|
||||
public void setMaxConnectionsPerHost(int maxConnections) {
|
||||
|
|
Loading…
Add table
Reference in a new issue