List of usage examples for org.apache.http.client.methods HttpEntityEnclosingRequestBase setEntity
public void setEntity(final HttpEntity entity)
From source file:v2.service.generic.library.utils.HttpClientUtil.java
private static HttpEntityEnclosingRequestBase formSubmit(HttpEntityEnclosingRequestBase request, Map<String, String> params, Map<String, String> headers) { List<BasicNameValuePair> nvps = new ArrayList<>(); if (params != null) { Set<String> keySet = params.keySet(); for (String key : keySet) { nvps.add(new BasicNameValuePair(key, params.get(key))); }// w w w . j av a2s.c o m request.setEntity(new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); } if (headers != null) { Set<String> keySet_header = headers.keySet(); for (String key : keySet_header) { request.setHeader(key, headers.get(key)); } } return request; }
From source file:com.arangodb.http.HttpManager.java
public static void configureBodyParams(HttpRequestEntity requestEntity, HttpEntityEnclosingRequestBase request) { if (requestEntity.entity != null) { request.setEntity(requestEntity.entity); } else if (requestEntity.bodyText != null) { request.setEntity(new StringEntity(requestEntity.bodyText, APPLICATION_JSON_UTF8)); }// w w w . j a va2 s . co m }
From source file:com.kubeiwu.commontool.khttp.toolbox.HttpClientStack.java
/** * ??/*from ww w .j a va2 s.c o m*/ * * @param httpRequest * @param request * @throws AuthFailureError */ private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request) throws AuthFailureError { byte[] body = request.getBody(); if (body != null) { // ? // List<NameValuePair> params = new ArrayList<NameValuePair>(); // params.add(new BasicNameValuePair("city", "xxx")); // HttpParams httpParams = httpClient.getParams(); // HttpEntity httpEntity = new UrlEncodedFormEntity(params, HTTP.UTF_8); HttpEntity entity = new ByteArrayEntity(body); httpRequest.setEntity(entity); } }
From source file:org.jboss.pnc.auth.keycloakutil.util.HttpUtil.java
private static InputStream doPostOrPut(String contentType, String acceptType, String content, String authorization, HttpEntityEnclosingRequestBase request) throws IOException { request.setHeader(HttpHeaders.CONTENT_TYPE, contentType); request.setHeader(HttpHeaders.ACCEPT, acceptType); if (content != null) { request.setEntity(new StringEntity(content)); }//from w w w. j av a 2s . com return doRequest(authorization, request); }
From source file:fi.helsinki.cs.iot.hub.jsengine.DuktapeJavascriptEngineWrapper.java
private static void addRequestBody(HttpEntityEnclosingRequestBase message, String data) throws UnsupportedEncodingException { if (data != null) { StringEntity se = new StringEntity(data); message.addHeader("content-type", HttpRequestHandler.JSON_MIME_TYPE); message.setEntity(se); }//from www .jav a 2 s. c om }
From source file:com.sugarcrm.candybean.webservices.WS.java
/** * Private helper method to abstract creating a POST/PUT request. * Side Effect: Adds the body to the request * * @param request A PUT or POST request * @param body Map of Key Value pairs * @param contentType The intended content type of the body *///from www. ja v a 2 s . c om protected static void addBodyToRequest(HttpEntityEnclosingRequestBase request, Map<String, Object> body, ContentType contentType) { if (body != null) { if (contentType == ContentType.MULTIPART_FORM_DATA) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); for (Map.Entry<String, Object> entry : body.entrySet()) { builder.addTextBody(entry.getKey(), (String) entry.getValue()); } request.setEntity(builder.build()); } else { JSONObject jsonBody = new JSONObject(body); StringEntity strBody = new StringEntity(jsonBody.toJSONString(), ContentType.APPLICATION_JSON); request.setEntity(strBody); } } }
From source file:it.restrung.rest.client.DefaultRestClientImpl.java
/** * Private helper to setup a simple request body *///w w w .j av a 2s. c om private static void setupSimpleRequestBody(HttpEntityEnclosingRequestBase httpEntityEnclosingRequestBase, String body) throws UnsupportedEncodingException { if (body != null) { httpEntityEnclosingRequestBase.setHeader("Content-Type", "application/json; charset=utf-8"); httpEntityEnclosingRequestBase.setEntity(new StringEntity(body, "UTF-8")); } }
From source file:azkaban.utils.RestfulApiClient.java
/** helper function to fill the request with header entries and posting body . * *//*from w w w.j av a 2 s. co m*/ private static HttpEntityEnclosingRequestBase completeRequest(HttpEntityEnclosingRequestBase request, List<NameValuePair> headerEntries, String postingBody) throws UnsupportedEncodingException { if (null != completeRequest(request, headerEntries)) { // dump the post body UTF-8 will be used as the default encoding type. if (null != postingBody && postingBody.length() > 0) { HttpEntity entity = new ByteArrayEntity(postingBody.getBytes("UTF-8")); request.setHeader("Content-Length", Long.toString(entity.getContentLength())); request.setEntity(entity); } } return request; }
From source file:org.hl7.fhir.client.ClientUtils.java
/** * Method posts request payload//from w w w .j ava 2s.co m * * @param request * @param payload * @return */ protected static HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload) { HttpResponse response = null; try { HttpClient httpclient = new DefaultHttpClient(); request.setEntity(new ByteArrayEntity(payload)); response = httpclient.execute(request); } catch (IOException ioe) { throw new EFhirClientException("Error sending HTTP Post/Put Payload", ioe); } return response; }
From source file:com.navercorp.volleyextensions.volleyer.multipart.stack.MultipartHttpClientStack.java
/** * <pre>//from w ww .ja v a 2 s . co m * Set a multipart entity if it exists. * * NOTE : {@code MultipartEntityWrapper} is a chunked transfer encoding mode, * the server should supports it. * </pre> */ private static void setEntityIfNonEmptyMultipart(HttpEntityEnclosingRequestBase httpRequest, Request<?> request) throws AuthFailureError { if (!(request instanceof MultipartContainer)) { return; } MultipartContainer container = (MultipartContainer) request; if (!container.hasMultipart()) { return; } Multipart multipart = container.getMultipart(); if (multipart == null) { return; } httpRequest.addHeader("Content-Type", multipart.getContentType()); HttpEntity entity = createMultipartHttpEntity(multipart); httpRequest.setEntity(entity); }