List of usage examples for org.apache.http.client.methods HttpEntityEnclosingRequestBase setEntity
public void setEntity(final HttpEntity entity)
From source file:com.groupon.odo.bmp.http.BrowserMobHttpRequest.java
public BrowserMobHttpResponse execute() { // deal with PUT/POST requests if (method instanceof HttpEntityEnclosingRequestBase) { HttpEntityEnclosingRequestBase enclodingRequest = (HttpEntityEnclosingRequestBase) method; if (!nvps.isEmpty()) { try { if (!multiPart) { enclodingRequest.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); } else { for (NameValuePair nvp : nvps) { multipartEntity.addPart(nvp.getName(), new StringBody(nvp.getValue())); }/* w w w . j a v a 2s. co m*/ enclodingRequest.setEntity(multipartEntity); } } catch (UnsupportedEncodingException e) { LOG.severe("Could not find UTF-8 encoding, something is really wrong", e); } } else if (multipartEntity != null) { enclodingRequest.setEntity(multipartEntity); } else if (byteArrayEntity != null) { enclodingRequest.setEntity(byteArrayEntity); } else if (stringEntity != null) { enclodingRequest.setEntity(stringEntity); } else if (inputStreamEntity != null) { enclodingRequest.setEntity(inputStreamEntity); } } return client.execute(this); }
From source file:org.cloudsmith.stackhammer.api.client.StackHammerClient.java
private void assignJSONContent(HttpEntityEnclosingRequestBase request, Object params) { if (params != null) { request.addHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE_JSON + "; charset=" + UTF_8.name()); //$NON-NLS-1$ byte[] data = toJson(params).getBytes(UTF_8); request.setEntity(new ByteArrayEntity(data)); }/*from ww w .j av a2s . co m*/ }
From source file:net.sf.jaceko.mock.it.helper.request.HttpRequestSender.java
private void constructPlainRequest(HttpEntityEnclosingRequestBase httpRequest, String requestBody, String mediaType) throws UnsupportedEncodingException { StringBuilder contentType = new StringBuilder(); contentType.append(mediaType);//ww w . j av a2 s . c o m contentType.append(";charset=UTF-8"); httpRequest.setHeader("Content-Type", contentType.toString()); if (requestBody != null) { HttpEntity requestEntity = new StringEntity(requestBody); httpRequest.setEntity(requestEntity); } }
From source file:com.cloudant.client.org.lightcouch.CouchDbClientBase.java
/** * Sets a JSON String as a request entity. * * @param httpRequest The request to set entity. * @param json The JSON String to set. *///from w w w . ja v a 2 s . c o m private void setEntity(HttpEntityEnclosingRequestBase httpRequest, String json) { StringEntity entity = new StringEntity(json, "UTF-8"); entity.setContentType("application/json"); httpRequest.setEntity(entity); }
From source file:com.partnet.automation.http.ApacheHttpAdapter.java
private void setEntity(HttpEntityEnclosingRequestBase httpBase, String contentType, String body) { //TODO make charset configurable? if (body != null) { StringEntity entity = new StringEntity(body, Consts.UTF_8); if (contentType == null && body != null) { LOG.warn("Content type is not setup for request {} {}", httpBase.getMethod(), httpBase.getURI()); }// w w w . j av a2 s .c o m entity.setContentType(contentType); httpBase.setEntity(entity); } }
From source file:de.betterform.connector.http.AbstractHTTPConnector.java
private void configureRequest(HttpEntityEnclosingRequestBase httpMethod, String body, String type, String encoding) throws UnsupportedEncodingException { HttpEntity entity = new StringEntity(body, type, encoding); httpMethod.setEntity(entity);//from ww w . j a va 2s.c om //httpMethod.setHeader(new BasicHeader("Content-Length", String.valueOf(body.getBytes(encoding).length))); }
From source file:com.am.rest.RestServiceClient.java
protected void setFormParams(HttpEntityEnclosingRequestBase request, List<NameValuePair> formParams) throws UnsupportedEncodingException { if (request == null || formParams == null) return;//from ww w . j a v a 2s . co m // Set HTTP request entity. UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formParams, HTTP.UTF_8); request.addHeader(formEntity.getContentType()); request.addHeader(formEntity.getContentEncoding()); request.setEntity(formEntity); }
From source file:com.mirth.connect.client.core.ServerConnection.java
private HttpRequestBase setupRequestBase(ClientRequest request, ExecuteType executeType) { HttpRequestBase requestBase = getRequestBase(executeType, request.getMethod()); requestBase.setURI(request.getUri()); for (Entry<String, List<String>> entry : request.getStringHeaders().entrySet()) { for (String value : entry.getValue()) { requestBase.addHeader(entry.getKey(), value); }//from ww w .j a v a 2 s.com } if (request.hasEntity() && requestBase instanceof HttpEntityEnclosingRequestBase) { final HttpEntityEnclosingRequestBase entityRequestBase = (HttpEntityEnclosingRequestBase) requestBase; entityRequestBase.setEntity(new ClientRequestEntity(request)); } return requestBase; }
From source file:com.uwindsor.elgg.project.http.AsyncHttpClient.java
private HttpEntityEnclosingRequestBase addEntityToRequestBase(HttpEntityEnclosingRequestBase requestBase, HttpEntity entity) {/*from www.jav a 2s. c o m*/ if (entity != null) { requestBase.setEntity(entity); } return requestBase; }
From source file:org.aicer.hibiscus.http.workers.HttpEntityEnclosingRequestWorker.java
/** * {@inheritDoc}//from w ww .j av a 2 s.c o m */ @Override public void prepare() throws HibiscusException { HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) this.httpRequest; try { request.setURI(getURI()); for (BasicNameValuePair header : httpClient.getRequestHeaders()) { request.addHeader(header.getName(), header.getValue()); } } catch (URISyntaxException e1) { throw new HibiscusException(e1); } final String requestBody = httpClient.getRequestBody(); final int contentLength = (null != requestBody) ? requestBody.length() : 0; if (contentLength > 0) { try { request.setEntity(new StringEntity(requestBody, httpClient.getEncoding())); } catch (UnsupportedEncodingException e2) { throw new HibiscusException("The encoding " + httpClient.getEncoding() + " is not supported", e2); } } }