use of org.apache.http.entity.ByteArrayEntity in project sling by apache.
the class DistributionUtils method assertPostResource.
private static String assertPostResource(SlingInstance slingInstance, int status, String path, byte[] bytes) throws IOException {
Request request = slingInstance.getRequestBuilder().buildPostRequest(path);
if (bytes != null) {
ByteArrayEntity entity = new ByteArrayEntity(bytes);
request.withEntity(entity);
}
return slingInstance.getRequestExecutor().execute(request.withCredentials(slingInstance.getServerUsername(), slingInstance.getServerPassword())).assertStatus(status).getContent();
}
use of org.apache.http.entity.ByteArrayEntity in project dubbo by alibaba.
the class HttpClientConnection method sendRequest.
public void sendRequest() throws IOException {
request.setEntity(new ByteArrayEntity(output.toByteArray()));
this.response = httpClient.execute(request);
}
use of org.apache.http.entity.ByteArrayEntity in project 360-Engine-for-Android by 360.
the class HttpConnectionThread method postHTTPRequest.
/**
* Posts the serialized data to the RPG and synchronously grabs the
* response.
*
* @param postData The post data to send to the RPG.
* @param uri The URL to send the request to.
* @param contentType The content type to send as, usually
* "application/binary)
* @return The response data as a byte array.
* @throws An exception if the request went wrong after HTTP_MAX_RETRY_COUNT
* retries.
*/
public HttpResponse postHTTPRequest(byte[] postData, URI uri, String contentType) throws Exception {
HttpResponse response = null;
if (null == postData) {
return response;
}
mRetryCount++;
if (uri != null) {
logI("RpgHttpConnectionThread.postHTTPRequest()", "HTTP Requesting URI " + uri.toString() + " " + contentType);
HttpPost httpPost = new HttpPost(uri);
httpPost.addHeader("Content-Type", contentType);
httpPost.addHeader("User-Agent", "PeopleAndroidClient/1.0");
httpPost.addHeader("Cache-Control", "no-cache");
httpPost.setEntity(new ByteArrayEntity(postData));
try {
response = mHttpClient.execute(httpPost);
} catch (Exception e) {
e.printStackTrace();
// repeat the request N times
if (mRetryCount < Settings.HTTP_MAX_RETRY_COUNT) {
return postHTTPRequest(postData, uri, contentType);
} else {
throw new Exception("Could not post request " + e);
}
}
}
return response;
}
use of org.apache.http.entity.ByteArrayEntity in project 360-Engine-for-Android by 360.
the class PollThread method postHTTPRequest.
/**
* Posts an HTTP request with data to a URL under a certain content type.
* The method will retry HTTP_MAX_RETRY_COUNT number of times until it
* throws an exception.
*
* @param postData A byte array representing the data to be posted.
* @param uri The URI to post the data to.
* @param contentType The content type to post under.
* @return The response of the server.
* @throws Exception Thrown if the request failed for HTTP_MAX_RETRY_COUNT
* number of times.
*/
private HttpResponse postHTTPRequest(byte[] postData, URI uri, String contentType) throws Exception {
HttpResponse response = null;
if (null == postData) {
return response;
}
mRetryCount++;
if (uri != null) {
Log.d("POLLTIMETEST", "POLL Requesting URI " + uri.toString());
HttpPost httpPost = new HttpPost(uri);
httpPost.addHeader("Content-Type", contentType);
httpPost.setEntity(new ByteArrayEntity(postData));
Log.d("POLLTIMETEST", "POLL Requesting URI " + httpPost.getRequestLine());
try {
response = mHttpClient.execute(httpPost);
} catch (Exception e) {
e.printStackTrace();
if (mRetryCount < Settings.HTTP_MAX_RETRY_COUNT) {
postHTTPRequest(postData, uri, contentType);
} else {
throw e;
}
}
}
return response;
}
use of org.apache.http.entity.ByteArrayEntity in project gocd by gocd.
the class GoHttpClientHttpInvokerRequestExecutor method doExecuteRequest.
@Override
protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws Exception {
HttpPost postMethod = new HttpPost(config.getServiceUrl());
ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray());
entity.setContentType(getContentType());
postMethod.setEntity(entity);
BasicHttpContext context = null;
if (environment.useSslContext()) {
context = new BasicHttpContext();
context.setAttribute(HttpClientContext.USER_TOKEN, goAgentServerHttpClient.principal());
}
try (CloseableHttpResponse response = goAgentServerHttpClient.execute(postMethod, context)) {
validateResponse(response);
InputStream responseBody = getResponseBody(response);
return readRemoteInvocationResult(responseBody, config.getCodebaseUrl());
}
}
Aggregations