List of usage examples for org.apache.http.entity ByteArrayEntity ByteArrayEntity
public ByteArrayEntity(byte[] bArr)
From source file:fi.csc.kapaVirtaAS.VirtaClient.java
public HttpResponse getVirtaWS(String virtaRequestMessage, String authString) throws Exception { HttpPost post = new HttpPost(conf.getVirtaSOAPURL()); post.setHeader("Content-Type", "text/xml;charset=utf-8"); post.setHeader("X-Forwarded-For", authString); HttpEntity entity = new ByteArrayEntity(virtaRequestMessage.getBytes()); post.setEntity(entity);/*from ww w . j av a2 s .co m*/ return client.execute(post); }
From source file:org.camunda.bpm.ext.sdk.impl.ClientCommandContext.java
public HttpEntity writeObject(Object value) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/*from w w w . j av a 2 s. c o m*/ objectMapper.writeValue(out, value); return new ByteArrayEntity(out.toByteArray()); } catch (Exception e) { throw new CamundaClientException("Exception while serializing object as json", e); } }
From source file:net.javacrumbs.restfire.httpcomponents.HttpComponentsRequestBuilder.java
public RequestBuilder withBody(byte[] body) { setBody(new ByteArrayEntity(body)); return this; }
From source file:co.cask.cdap.client.rest.RestStreamWriter.java
@Override public ListenableFuture<Void> write(String str, Charset charset, Map<String, String> headers) throws IllegalArgumentException { Preconditions.checkArgument(str != null, "Input string parameter is null."); return write(new ByteArrayEntity(charset != null ? str.getBytes(charset) : str.getBytes()), headers); }
From source file:org.cryptable.pki.communication.http.PKIHTTPCommunication.java
public byte[] sendReceiveMsg(byte[] msg) throws IOException { httpPost.addHeader(URLEncodedUtils.CONTENT_TYPE, "application/pkixcmp"); httpPost.setEntity(new ByteArrayEntity(msg)); HttpResponse httpResponse = httpClient.execute(httpPost); InputStream inputStream = httpResponse.getEntity().getContent(); byte[] byteResponse = new byte[(int) httpResponse.getEntity().getContentLength()]; inputStream.read(byteResponse);//from ww w . j a v a 2s .co m return byteResponse; }
From source file:co.freeside.betamax.handler.TargetConnector.java
private HttpRequest createOutboundRequest(Request request) { final HttpRequest outboundRequest; try {/*from w w w . ja v a2 s .co m*/ outboundRequest = httpRequestFactory.newHttpRequest(request.getMethod(), request.getUri().toString()); for (Map.Entry<String, String> header : request.getHeaders().entrySet()) { outboundRequest.addHeader(header.getKey(), header.getValue()); } outboundRequest.addHeader(VIA, VIA_HEADER); if (outboundRequest instanceof HttpEntityEnclosingRequest && request.hasBody()) { ((HttpEntityEnclosingRequest) outboundRequest) .setEntity(new ByteArrayEntity(ByteStreams.toByteArray(request.getBodyAsBinary()))); } return outboundRequest; } catch (MethodNotSupportedException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationCreate.java
private HttpRequestBase onExecute(Preparation preparation, String folderId) { String uri = preparationServiceUrl + "/preparations"; if (StringUtils.isNotBlank(folderId)) { uri += "?folderId=" + folderId; }// w w w . j a va2s . c o m HttpPost preparationCreation = new HttpPost(uri); // Serialize preparation using configured serialization preparationCreation.setHeader("Content-Type", APPLICATION_JSON_VALUE); try { byte[] preparationJSONValue = objectMapper.writeValueAsBytes(preparation); preparationCreation.setEntity(new ByteArrayEntity(preparationJSONValue)); } catch (IOException e) { throw new TDPException(UNABLE_TO_CREATE_PREPARATION, e); } return preparationCreation; }
From source file:org.dataconservancy.ui.it.support.CreateProjectApiAddRequest.java
public HttpPost asHttpPost() { HttpPost post = null;/*ww w. java 2 s.co m*/ try { post = new HttpPost(uiUrlConfig.getProjectApiUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } ByteArrayOutputStream sink = new ByteArrayOutputStream(); builder.buildProject(project, sink); ByteArrayEntity projectEntity = new ByteArrayEntity(sink.toByteArray()); projectEntity.setContentEncoding("UTF-8"); post.addHeader("Content-Type", "text/xml"); post.setEntity(projectEntity); return post; }
From source file:net.oneandone.sushi.fs.webdav.methods.Method.java
public void setRequestEntity(Document body) throws IOException { Serializer serializer;//from w w w . j a va 2 s .c o m ByteArrayOutputStream serialized; serialized = new ByteArrayOutputStream(); serializer = getXml().getSerializer(); synchronized (serializer) { serializer.serialize(new DOMSource(body), new StreamResult(serialized), true); } request.setEntity(new ByteArrayEntity(serialized.toByteArray())); }