use of org.apache.http.entity.InputStreamEntity in project platform_external_apache-http by android.
the class Request method setBodyProvider.
/**
* Supply an InputStream that provides the body of a request. It's
* not great that the caller must also provide the length of the data
* returned by that InputStream, but the client needs to know up
* front, and I'm not sure how to get this out of the InputStream
* itself without a costly readthrough. I'm not sure skip() would
* do what we want. If you know a better way, please let me know.
*/
private void setBodyProvider(InputStream bodyProvider, int bodyLength) {
if (!bodyProvider.markSupported()) {
throw new IllegalArgumentException("bodyProvider must support mark()");
}
// Mark beginning of stream
bodyProvider.mark(Integer.MAX_VALUE);
((BasicHttpEntityEnclosingRequest) mHttpRequest).setEntity(new InputStreamEntity(bodyProvider, bodyLength));
}
use of org.apache.http.entity.InputStreamEntity in project jackrabbit by apache.
the class RepositoryServiceImpl method importXml.
@Override
public void importXml(SessionInfo sessionInfo, NodeId parentId, InputStream xmlStream, int uuidBehaviour) throws RepositoryException {
// TODO: improve. currently random name is built instead of retrieving name of new resource from top-level xml element within stream
Name nodeName = getNameFactory().create(Name.NS_DEFAULT_URI, UUID.randomUUID().toString());
String uri = getItemUri(parentId, nodeName, sessionInfo);
HttpMkcol mkcolRequest = new HttpMkcol(uri);
mkcolRequest.addHeader(JcrRemotingConstants.IMPORT_UUID_BEHAVIOR, Integer.toString(uuidBehaviour));
mkcolRequest.setEntity(new InputStreamEntity(xmlStream, ContentType.create("text/xml")));
execute(mkcolRequest, sessionInfo);
}
use of org.apache.http.entity.InputStreamEntity in project lucene-solr by apache.
the class SolrExampleJettyTest method testArbitraryJsonIndexing.
@Test
public void testArbitraryJsonIndexing() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.deleteByQuery("*:*");
client.commit();
// make sure it got in
assertNumFound("*:*", 0);
// two docs, one with uniqueKey, another without it
String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}";
HttpClient httpClient = client.getHttpClient();
HttpPost post = new HttpPost(getUri(client));
post.setHeader("Content-Type", "application/json");
post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1));
HttpResponse response = httpClient.execute(post, HttpClientUtil.createNewHttpClientRequestContext());
assertEquals(200, response.getStatusLine().getStatusCode());
client.commit();
QueryResponse rsp = getSolrClient().query(new SolrQuery("*:*"));
assertEquals(2, rsp.getResults().getNumFound());
SolrDocument doc = rsp.getResults().get(0);
String src = (String) doc.getFieldValue("_src_");
Map m = (Map) ObjectBuilder.fromJSON(src);
assertEquals("abc1", m.get("id"));
assertEquals("name1", m.get("name"));
doc = rsp.getResults().get(1);
src = (String) doc.getFieldValue("_src_");
m = (Map) ObjectBuilder.fromJSON(src);
assertEquals("name2", m.get("name"));
}
use of org.apache.http.entity.InputStreamEntity in project indy by Commonjava.
the class IndyClientHttp method putWithStream.
public void putWithStream(final String path, final InputStream stream, final int... responseCodes) throws IndyClientException {
connect();
final HttpPut put = newRawPut(buildUrl(baseUrl, path));
final CloseableHttpClient client = newClient();
CloseableHttpResponse response = null;
try {
put.setEntity(new InputStreamEntity(stream));
response = client.execute(put, newContext());
final StatusLine sl = response.getStatusLine();
if (!validResponseCode(sl.getStatusCode(), responseCodes)) {
throw new ClientProtocolException(new IndyClientException(sl.getStatusCode(), "Error in response from: %s.\n%s", path, new IndyResponseErrorDetails(response)));
}
} catch (final ClientProtocolException e) {
final Throwable cause = e.getCause();
if (cause != null && (cause instanceof IndyClientException)) {
throw (IndyClientException) cause;
}
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} catch (final IOException e) {
throw new IndyClientException("Indy request failed: %s", e, e.getMessage());
} finally {
cleanupResources(put, response, client);
}
}
use of org.apache.http.entity.InputStreamEntity in project gerrit by GerritCodeReview.
the class RestSession method putRaw.
public RestResponse putRaw(String endPoint, RawInput stream) throws IOException {
Preconditions.checkNotNull(stream);
Request put = Request.Put(getUrl(endPoint));
put.addHeader(new BasicHeader("Content-Type", stream.getContentType()));
put.body(new BufferedHttpEntity(new InputStreamEntity(stream.getInputStream(), stream.getContentLength())));
return execute(put);
}
Aggregations