use of org.apache.http.entity.ByteArrayEntity in project jackrabbit by apache.
the class XmlEntity method create.
public static HttpEntity create(Document doc) throws IOException {
try {
ByteArrayOutputStream xml = new ByteArrayOutputStream();
DomUtil.transformDocument(doc, xml);
return new ByteArrayEntity(xml.toByteArray(), CT);
} catch (TransformerException ex) {
LOG.error(ex.getMessage());
throw new IOException(ex);
} catch (SAXException ex) {
LOG.error(ex.getMessage());
throw new IOException(ex);
}
}
use of org.apache.http.entity.ByteArrayEntity in project spring-framework by spring-projects.
the class HttpComponentsHttpInvokerRequestExecutor method setRequestBody.
/**
* Set the given serialized remote invocation as request body.
* <p>The default implementation simply sets the serialized invocation as the
* HttpPost's request body. This can be overridden, for example, to write a
* specific encoding and to potentially set appropriate HTTP request headers.
* @param config the HTTP invoker configuration that specifies the target service
* @param httpPost the HttpPost to set the request body on
* @param baos the ByteArrayOutputStream that contains the serialized
* RemoteInvocation object
* @throws java.io.IOException if thrown by I/O methods
*/
protected void setRequestBody(HttpInvokerClientConfiguration config, HttpPost httpPost, ByteArrayOutputStream baos) throws IOException {
ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray());
entity.setContentType(getContentType());
httpPost.setEntity(entity);
}
use of org.apache.http.entity.ByteArrayEntity in project spring-framework by spring-projects.
the class HttpComponentsClientHttpRequest method executeInternal.
@Override
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
addHeaders(this.httpRequest, headers);
if (this.httpRequest instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest;
HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput);
entityEnclosingRequest.setEntity(requestEntity);
}
HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext);
return new HttpComponentsClientHttpResponse(httpResponse);
}
use of org.apache.http.entity.ByteArrayEntity in project cdap by caskdata.
the class AppFabricTestBase method addArtifactProperties.
// add artifact properties and return the response code
protected HttpResponse addArtifactProperties(Id.Artifact artifactId, Map<String, String> properties) throws Exception {
String nonNamespacePath = String.format("artifacts/%s/versions/%s/properties", artifactId.getName(), artifactId.getVersion());
String path = getVersionedAPIPath(nonNamespacePath, artifactId.getNamespace().getId());
HttpEntityEnclosingRequestBase request = getPut(path);
request.setEntity(new ByteArrayEntity(properties.toString().getBytes()));
return execute(request);
}
use of org.apache.http.entity.ByteArrayEntity in project TaEmCasa by Dionen.
the class HttpClientStack method setEntityIfNonEmptyBody.
private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request) throws AuthFailureError {
byte[] body = request.getBody();
if (body != null) {
HttpEntity entity = new ByteArrayEntity(body);
httpRequest.setEntity(entity);
}
}
Aggregations