Search in sources :

Example 31 with ByteArrayEntity

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);
    }
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 32 with ByteArrayEntity

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);
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity)

Example 33 with ByteArrayEntity

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);
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) HttpResponse(org.apache.http.HttpResponse)

Example 34 with ByteArrayEntity

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);
}
Also used : HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity)

Example 35 with ByteArrayEntity

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);
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity)

Aggregations

ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)78 HttpEntity (org.apache.http.HttpEntity)28 HttpPost (org.apache.http.client.methods.HttpPost)24 HttpResponse (org.apache.http.HttpResponse)20 IOException (java.io.IOException)17 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 JSONObject (org.json.JSONObject)11 Test (org.junit.Test)10 HttpClient (org.apache.http.client.HttpClient)9 InputStream (java.io.InputStream)7 JSONArray (org.json.JSONArray)7 URISyntaxException (java.net.URISyntaxException)5 Header (org.apache.http.Header)5 AbstractHttpEntity (org.apache.http.entity.AbstractHttpEntity)5 ContentType (org.apache.http.entity.ContentType)5 BytesRef (org.apache.lucene.util.BytesRef)5 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)5 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)5 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)5 GetRequest (org.elasticsearch.action.get.GetRequest)5