List of usage examples for org.apache.http.client.methods HttpEntityEnclosingRequestBase setEntity
public void setEntity(final HttpEntity entity)
From source file:com.github.yongchristophertang.engine.web.request.HttpMultipartRequestBuilders.java
/** * {@inheritDoc}/*w ww . j a v a 2s . co m*/ */ @Override public HttpRequestBase buildRequest() throws Exception { HttpEntityEnclosingRequestBase requestBase = (HttpEntityEnclosingRequestBase) super.buildRequest(); requestBase.setEntity(this.bodyBuilder.buildBody().getHttpEntity()); return requestBase; }
From source file:uk.co.visalia.brightpearl.apiclient.http.httpclient4.HttpClient4Client.java
private void addBody(HttpEntityEnclosingRequestBase requestBase, String body) { if (body != null) { requestBase.setEntity(new StringEntity(body, Charset.forName("UTF-8"))); }//from ww w . jav a2 s . co m }
From source file:playn.http.HttpAndroid.java
@Override protected void doSend(final HttpRequest request, final Callback<HttpResponse> callback) { platform.invokeAsync(new Runnable() { public void run() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setHttpElementCharset(params, HTTP.UTF_8); HttpClient httpclient = new DefaultHttpClient(params); HttpRequestBase req;/* w ww. ja v a2s. c om*/ HttpMethod method = request.getMethod(); String url = request.getUrl(); switch (method) { case GET: req = new HttpGet(url); break; case POST: req = new HttpPost(url); break; case PUT: req = new HttpPut(url); break; default: throw new UnsupportedOperationException(method.toString()); } String requestBody = request.getBody(); if (requestBody != null && req instanceof HttpEntityEnclosingRequestBase) { try { HttpEntityEnclosingRequestBase op = (HttpEntityEnclosingRequestBase) req; op.setEntity(new StringEntity(requestBody)); } catch (UnsupportedEncodingException e) { platform.notifyFailure(callback, e); } } for (Map.Entry<String, String> header : request.getHeaders()) { req.setHeader(header.getKey(), header.getValue()); } int statusCode = -1; String statusLineMessage = null; Map<String, String> responseHeaders = new HashMap<String, String>(); String responseBody = null; try { org.apache.http.HttpResponse response = httpclient.execute(req); StatusLine statusLine = response.getStatusLine(); statusCode = statusLine.getStatusCode(); statusLineMessage = statusLine.getReasonPhrase(); for (Header header : response.getAllHeaders()) { responseHeaders.put(header.getName(), header.getValue()); } responseBody = EntityUtils.toString(response.getEntity()); HttpResponse httpResponse = new HttpResponse(statusCode, statusLineMessage, responseHeaders, responseBody); platform.notifySuccess(callback, httpResponse); } catch (Throwable cause) { HttpErrorType errorType = cause instanceof ConnectTimeoutException || cause instanceof HttpHostConnectException || cause instanceof ConnectionPoolTimeoutException || cause instanceof UnknownHostException ? HttpErrorType.NETWORK_FAILURE : HttpErrorType.SERVER_ERROR; HttpException reason = new HttpException(statusCode, statusLineMessage, responseBody, cause, errorType); platform.notifyFailure(callback, reason); } } }); }
From source file:org.elasticsearch.test.rest.client.http.HttpRequestBuilder.java
private HttpEntityEnclosingRequestBase addOptionalBody(HttpEntityEnclosingRequestBase requestBase) { if (Strings.hasText(body)) { requestBase.setEntity(new StringEntity(body, DEFAULT_CHARSET)); }// w ww .j av a 2 s . c o m return requestBase; }
From source file:com.epam.wilma.browsermob.transformer.BrowserMobRequestUpdater.java
/** * Updates BrowserMob specific HTTP request. Adds wilma logger id to headers and updates URI. * * @param browserMobHttpRequest what will be updated * @param wilmaRequest contains refresher data *///from w ww .java2 s.c om public void updateRequest(final BrowserMobHttpRequest browserMobHttpRequest, final WilmaHttpRequest wilmaRequest) { // Update the headers of the original request with extra headers added/removed by Req interceptors // Note, that when we redirect the request to the stub, we always add the message id to the extra headers part Map<String, HttpHeaderChange> headerChangeMap = wilmaRequest.getHeaderChanges(); if (headerChangeMap != null && !headerChangeMap.isEmpty()) { //we have header change requests for (Map.Entry<String, HttpHeaderChange> headerChangeEntry : headerChangeMap.entrySet()) { String headerKey = headerChangeEntry.getKey(); HttpHeaderChange headerChange = headerChangeEntry.getValue(); Header header = browserMobHttpRequest.getMethod().getFirstHeader(headerKey); if (headerChange instanceof HttpHeaderToBeUpdated) { // it is HttpHeaderToBeChanged, so added, or updated if (header != null) { ((HttpHeaderToBeUpdated) headerChange).setOriginalValue(header.getValue()); } browserMobHttpRequest.getMethod().addHeader(headerKey, ((HttpHeaderToBeUpdated) headerChange).getNewValue()); headerChange.setApplied(); } else { // it is HttpHeaderToBeRemoved if (header != null) { browserMobHttpRequest.getMethod().removeHeader(header); headerChange.setApplied(); } } } } //update the body byte[] newBody = wilmaRequest.getNewBody(); if (newBody != null) { if (browserMobHttpRequest.getMethod() instanceof HttpEntityEnclosingRequestBase) { HttpEntityEnclosingRequestBase enclosingRequest = (HttpEntityEnclosingRequestBase) browserMobHttpRequest .getMethod(); enclosingRequest.setEntity(new ByteArrayEntity(wilmaRequest.getNewBody())); } } //set response volatility approach browserMobHttpRequest.setResponseVolatile(wilmaRequest.isResponseVolatile()); //switch between original uri (proxy mode selected) or wilma internal uri (stub mode selected) browserMobHttpRequest.getMethod().setURI(wilmaRequest.getUri()); }
From source file:com.woonoz.proxy.servlet.HttpEntityEnclosingRequestHandler.java
private void copyData(HttpServletRequest request, HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase) throws FileUploadException, IOException { HttpEntity entity = createHttpEntity(request); httpEntityEnclosingRequestBase.setEntity(entity); }
From source file:com.microsoft.services.odata.unittests.testsupport.WireMockTestClient.java
private WireMockResponse requestWithBody(HttpEntityEnclosingRequestBase request, String body, String contentType, TestHttpHeader... headers) { request.setEntity(new StringEntity(body, ContentType.create(contentType, "utf-8"))); return executeMethodAndCovertExceptions(request, headers); }
From source file:org.stem.api.BaseHttpClient.java
public <T extends StemResponse> T send(HttpEntityEnclosingRequestBase request, ClusterManagerRequest msg, Class<T> clazz) {//from w w w . j a va 2s. c o m try { setHeaders(request); StringEntity body = prepareJsonBody(msg); request.setEntity(body); return (T) client.execute(request, getResponseHandler(clazz)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:eionet.webq.xforms.XFormsHTTPSubmissionHandler.java
/** * Create encoded HttpEntity with request body. * * @param httpMethod Http request/*from w ww.j a v a 2 s . c om*/ * @param body String to be written into request body * @param type request body type * @param encoding Request encoding * @throws UnsupportedEncodingException when encoding is not supported */ private void configureRequest(HttpEntityEnclosingRequestBase httpMethod, String body, String type, String encoding) throws UnsupportedEncodingException { HttpEntity entity = new StringEntity(body, type, encoding); httpMethod.setEntity(entity); }
From source file:com.logsniffer.event.publisher.http.HttpPublisher.java
protected void addBody(final HttpEntityEnclosingRequestBase request, final VelocityContext vCtx) { request.setEntity(new StringEntity(body != null ? velocityRenderer.render(body, vCtx) : "", ContentType.create(bodyMimeType, "UTF-8"))); }