use of org.apache.http.entity.InputStreamEntity in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testUploadInputStream.
@Test
public void testUploadInputStream() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_inputstream");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
HttpResponse response = httpclient.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.entity.InputStreamEntity in project camel by apache.
the class CxfRsConsumerSimpleBindingTest method testUploadDataHandler.
@Test
public void testUploadDataHandler() throws Exception {
HttpPost post = new HttpPost("http://localhost:" + PORT_PATH + "/rest/customerservice/customers/123/image_datahandler");
post.addHeader("Content-Type", "image/jpeg");
post.addHeader("Accept", "text/xml");
post.setEntity(new InputStreamEntity(this.getClass().getClassLoader().getResourceAsStream("java.jpg"), 100));
HttpResponse response = httpclient.execute(post);
assertEquals(200, response.getStatusLine().getStatusCode());
}
use of org.apache.http.entity.InputStreamEntity in project camel by apache.
the class HttpEntityConverter method asHttpEntity.
private static HttpEntity asHttpEntity(InputStream in, Exchange exchange) throws IOException {
InputStreamEntity entity;
if (!exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
InputStream stream = GZIPHelper.compressGzip(contentEncoding, in);
entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream ? stream.available() != 0 ? stream.available() : -1 : -1);
} else {
Message inMessage = exchange.getIn();
String length = inMessage.getHeader(Exchange.CONTENT_LENGTH, String.class);
if (ObjectHelper.isEmpty(length)) {
entity = new InputStreamEntity(in, -1);
} else {
entity = new InputStreamEntity(in, Long.parseLong(length));
}
}
if (exchange != null) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
String contentType = ExchangeHelper.getContentType(exchange);
entity.setContentEncoding(contentEncoding);
entity.setContentType(contentType);
}
return entity;
}
use of org.apache.http.entity.InputStreamEntity in project camel by apache.
the class HttpEntityConverter method asHttpEntity.
private static HttpEntity asHttpEntity(byte[] data, Exchange exchange) throws Exception {
AbstractHttpEntity entity;
if (exchange != null && !exchange.getProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.FALSE, Boolean.class)) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
InputStream stream = GZIPHelper.compressGzip(contentEncoding, data);
entity = new InputStreamEntity(stream, stream instanceof ByteArrayInputStream ? stream.available() != 0 ? stream.available() : -1 : -1);
} else {
// create the Repeatable HttpEntity
entity = new ByteArrayEntity(data);
}
if (exchange != null) {
String contentEncoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class);
String contentType = ExchangeHelper.getContentType(exchange);
entity.setContentEncoding(contentEncoding);
entity.setContentType(contentType);
}
return entity;
}
use of org.apache.http.entity.InputStreamEntity in project hbase by apache.
the class Client method put.
/**
* Send a PUT request
* @param cluster the cluster definition
* @param path the path or URI
* @param headers the HTTP headers to include, <tt>Content-Type</tt> must be
* supplied
* @param content the content bytes
* @return a Response object with response detail
* @throws IOException
*/
public Response put(Cluster cluster, String path, Header[] headers, byte[] content) throws IOException {
HttpPut method = new HttpPut(path);
try {
method.setEntity(new InputStreamEntity(new ByteArrayInputStream(content), content.length));
HttpResponse resp = execute(cluster, method, headers, path);
headers = resp.getAllHeaders();
content = getResponseBody(resp);
return new Response(resp.getStatusLine().getStatusCode(), headers, content);
} finally {
method.releaseConnection();
}
}
Aggregations