use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project openkit-android by OpenKit.
the class AsyncHttpClient method put.
/**
* Perform a HTTP PUT request and track the Android Context which initiated the request.
* And set one-time headers for the request
* @param context the Android Context which initiated the request.
* @param url the URL to send the request to.
* @param headers set one-time headers for this request
* @param entity a raw {@link HttpEntity} to send with the request, for example, use this to send string/json/xml payloads to a server by passing a {@link org.apache.http.entity.StringEntity}.
* @param contentType the content type of the payload you are sending, for example application/json if sending a json payload.
* @param responseHandler the response handler instance that should handle the response.
*/
public void put(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPut(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project platformlayer by platformlayer.
the class ApacheCommonsHttpRequest method setRequestContent.
@Override
public void setRequestContent(final ByteSource data) throws IOException {
HttpEntityEnclosingRequestBase post = (HttpEntityEnclosingRequestBase) request;
post.setEntity(new AbstractHttpEntity() {
@Override
public boolean isRepeatable() {
return true;
}
@Override
public long getContentLength() {
try {
return data.getContentLength();
} catch (IOException e) {
throw new IllegalStateException("Error getting content length", e);
}
}
@Override
public InputStream getContent() throws IOException, IllegalStateException {
return data.open();
}
@Override
public void writeTo(OutputStream os) throws IOException {
InputStream is = data.open();
try {
IoUtils.copyToOutputStream(is, os);
} finally {
is.close();
}
}
@Override
public boolean isStreaming() {
return false;
}
});
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project opennms by OpenNMS.
the class NCSNorthbounder method postAlarms.
private void postAlarms(HttpEntity entity) {
//Need a configuration bean for these
int connectionTimeout = 3000;
int socketTimeout = 3000;
Integer retryCount = 3;
HttpVersion httpVersion = determineHttpVersion(m_config.getHttpVersion());
URI uri = m_config.getURI();
System.err.println("uri = " + uri);
final HttpClientWrapper clientWrapper = HttpClientWrapper.create().setSocketTimeout(socketTimeout).setConnectionTimeout(connectionTimeout).setRetries(retryCount).useBrowserCompatibleCookies().dontReuseConnections();
if ("https".equals(uri.getScheme())) {
try {
clientWrapper.useRelaxedSSL("https");
} catch (final GeneralSecurityException e) {
throw new NorthbounderException("Failed to configure Relaxed SSL handling.", e);
}
}
final HttpEntityEnclosingRequestBase method = m_config.getMethod().getRequestMethod(uri);
if (m_config.getVirtualHost() != null && !m_config.getVirtualHost().trim().isEmpty()) {
method.setHeader(HTTP.TARGET_HOST, m_config.getVirtualHost());
}
if (m_config.getUserAgent() != null && !m_config.getUserAgent().trim().isEmpty()) {
method.setHeader(HTTP.USER_AGENT, m_config.getUserAgent());
}
method.setProtocolVersion(httpVersion);
method.setEntity(entity);
CloseableHttpResponse response = null;
try {
System.err.println("execute: " + method);
response = clientWrapper.execute(method);
} catch (ClientProtocolException e) {
throw new NorthbounderException(e);
} catch (IOException e) {
throw new NorthbounderException(e);
} finally {
IOUtils.closeQuietly(clientWrapper);
}
if (response != null) {
try {
int code = response.getStatusLine().getStatusCode();
final HttpResponseRange range = new HttpResponseRange("200-399");
if (!range.contains(code)) {
LOG.warn("response code out of range for uri: {}. Expected {} but received {}", uri, range, code);
throw new NorthbounderException("response code out of range for uri:" + uri + ". Expected " + range + " but received " + code);
}
} finally {
IOUtils.closeQuietly(clientWrapper);
}
}
LOG.debug(response != null ? response.getStatusLine().getReasonPhrase() : "Response was null");
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project ThinkAndroid by white-cat.
the class AsyncHttpClient method post.
/**
* Perform a HTTP POST request and track the Android Context which initiated
* the request. Set headers only for this request
*
* @param context
* the Android Context which initiated the request.
* @param url
* the URL to send the request to.
* @param headers
* set headers only for this request
* @param entity
* a raw {@link HttpEntity} to send with the request, for
* example, use this to send string/json/xml payloads to a server
* by passing a {@link org.apache.http.entity.StringEntity}.
* @param contentType
* the content type of the payload you are sending, for example
* application/json if sending a json payload.
* @param responseHandler
* the response handler instance that should handle the response.
*/
public void post(Context context, String url, Header[] headers, HttpEntity entity, String contentType, AsyncHttpResponseHandler responseHandler) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPost(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, responseHandler, context);
}
use of org.apache.http.client.methods.HttpEntityEnclosingRequestBase in project afinal by yangfuhai.
the class FinalHttp method post.
public void post(String url, Header[] headers, HttpEntity entity, String contentType, AjaxCallBack<? extends Object> callBack) {
HttpEntityEnclosingRequestBase request = addEntityToRequestBase(new HttpPost(url), entity);
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, contentType, callBack);
}
Aggregations