use of org.apache.http.entity.AbstractHttpEntity 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.AbstractHttpEntity in project scout.rt by eclipse.
the class ApacheHttpRequest method execute.
@Override
public LowLevelHttpResponse execute() throws IOException {
final StreamingContent streamingContent = getStreamingContent();
if (streamingContent != null) {
if (!(m_request instanceof HttpEntityEnclosingRequest)) {
throw new ProcessingException("This request {} does not support content.", m_request);
}
AbstractHttpEntity entity = new AbstractHttpEntity() {
@Override
public void writeTo(OutputStream outstream) throws IOException {
streamingContent.writeTo(outstream);
}
@Override
public boolean isStreaming() {
return true;
}
@Override
public boolean isRepeatable() {
if (streamingContent instanceof HttpContent) {
return ((HttpContent) streamingContent).retrySupported();
}
return false;
}
@Override
public long getContentLength() {
return ApacheHttpRequest.this.getContentLength();
}
@Override
public InputStream getContent() throws IOException {
throw new UnsupportedOperationException("Streaming entity cannot be represented as an input stream.");
}
};
((HttpEntityEnclosingRequest) m_request).setEntity(entity);
entity.setContentEncoding(getContentEncoding());
entity.setContentType(getContentType());
}
return createResponseInternal();
}
use of org.apache.http.entity.AbstractHttpEntity in project coastal-hazards by USGS-CIDA.
the class GeoserverUtil method postToWPS.
private static String postToWPS(String url, String username, String password, File wpsRequestFile) throws IOException {
HttpPost post;
HttpClient httpClient = HttpClientBuilder.create().build();
post = new HttpPost(url);
FileInputStream wpsRequestInputStream = null;
try {
log.info("About to perform wps post request at URL: " + url);
wpsRequestInputStream = new FileInputStream(wpsRequestFile);
AbstractHttpEntity entity = new InputStreamEntity(wpsRequestInputStream, wpsRequestFile.length());
post.setEntity(entity);
String userPass = username + ":" + password;
post.addHeader(new BasicHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(userPass.getBytes())));
HttpResponse response = httpClient.execute(post);
String responseString = EntityUtils.toString(response.getEntity());
log.info("WPS Response Recieved: " + responseString);
return responseString;
} finally {
IOUtils.closeQuietly(wpsRequestInputStream);
FileUtils.deleteQuietly(wpsRequestFile);
}
}
use of org.apache.http.entity.AbstractHttpEntity in project rdf4j by eclipse.
the class RDF4JProtocolSession method upload.
protected void upload(final Reader contents, String baseURI, final RDFFormat dataFormat, boolean overwrite, boolean preserveNodeIds, Action action, Resource... contexts) throws IOException, RDFParseException, RepositoryException, UnauthorizedException {
final Charset charset = dataFormat.hasCharset() ? dataFormat.getCharset() : Charset.forName("UTF-8");
HttpEntity entity = new AbstractHttpEntity() {
private InputStream content;
public long getContentLength() {
// don't know
return -1;
}
public Header getContentType() {
return new BasicHeader("Content-Type", dataFormat.getDefaultMIMEType() + "; charset=" + charset.name());
}
public boolean isRepeatable() {
return false;
}
public boolean isStreaming() {
return true;
}
public synchronized InputStream getContent() throws IOException, IllegalStateException {
if (content == null) {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
writeTo(buf);
content = new ByteArrayInputStream(buf.toByteArray());
}
return content;
}
public void writeTo(OutputStream out) throws IOException {
try {
OutputStreamWriter writer = new OutputStreamWriter(out, charset);
IOUtil.transfer(contents, writer);
writer.flush();
} finally {
contents.close();
}
}
};
upload(entity, baseURI, overwrite, preserveNodeIds, action, contexts);
}
use of org.apache.http.entity.AbstractHttpEntity in project rdf4j by eclipse.
the class RDF4JProtocolSession method sendTransaction.
/**
* Sends a transaction list as serialized XML to the server.
*
* @deprecated since 2.8.0
* @param txn
* @throws IOException
* @throws RepositoryException
* @throws UnauthorizedException
*/
@Deprecated
public void sendTransaction(final Iterable<? extends TransactionOperation> txn) throws IOException, RepositoryException, UnauthorizedException {
checkRepositoryURL();
HttpPost method = new HttpPost(Protocol.getStatementsLocation(getQueryURL()));
try {
// Create a RequestEntity for the transaction data
method.setEntity(new AbstractHttpEntity() {
public long getContentLength() {
// don't know
return -1;
}
public Header getContentType() {
return new BasicHeader("Content-Type", Protocol.TXN_MIME_TYPE);
}
public boolean isRepeatable() {
return true;
}
public boolean isStreaming() {
return true;
}
public InputStream getContent() throws IOException, IllegalStateException {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
writeTo(buf);
return new ByteArrayInputStream(buf.toByteArray());
}
public void writeTo(OutputStream out) throws IOException {
TransactionWriter txnWriter = new TransactionWriter();
txnWriter.serialize(txn, out);
}
});
try {
executeNoContent(method);
} catch (RepositoryException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
}
} finally {
method.reset();
}
}
Aggregations