Example usage for org.apache.http.entity InputStreamEntity InputStreamEntity

List of usage examples for org.apache.http.entity InputStreamEntity InputStreamEntity

Introduction

In this page you can find the example usage for org.apache.http.entity InputStreamEntity InputStreamEntity.

Prototype

public InputStreamEntity(InputStream inputStream, long j, ContentType contentType) 

Source Link

Usage

From source file:de.drv.dsrv.spoc.web.service.impl.FachverfahrenRequestServiceImpl.java

@Override
public StreamSource executeFachverfahrenRequest(final URI fachverfahrenUrl,
        final InputStream payloadInputStream) throws IOException {

    final HttpPost httpPost = new HttpPost(fachverfahrenUrl);
    httpPost.setEntity(new InputStreamEntity(payloadInputStream, -1L, CONTENT_TYPE));

    StreamSource response;//from   ww  w .  java 2  s.c o  m
    try {
        response = this.httpClient.execute(httpPost, this.responseHandler);
    } finally {
        httpPost.releaseConnection();
    }

    return response;
}

From source file:com.google.devtools.build.lib.remote.blobstore.RestBlobStore.java

@Override
public void put(String key, long length, InputStream in) throws IOException {
    put(CAS_PREFIX, key, new InputStreamEntity(in, length, ContentType.APPLICATION_OCTET_STREAM));
}

From source file:org.opens.urlmanager.it.CreateITCase.java

private HttpResponse doRequest(String url, File file, String mime) throws Exception {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://localhost:8080/urlmanager/" + url);

    httpPost.addHeader("Accept", mime);
    httpPost.setEntity(//w  w w.ja v  a2  s .c  o m
            new InputStreamEntity(new FileInputStream(file), file.length(), ContentType.create(mime)));
    return httpClient.execute(httpPost);
}

From source file:com.github.tomakehurst.wiremock.http.ProxyResponseRenderer.java

private static HttpEntity buildEntityFrom(Request originalRequest) {
    ContentTypeHeader contentTypeHeader = originalRequest.contentTypeHeader().or("text/plain");
    ContentType contentType = ContentType.create(contentTypeHeader.mimeTypePart(),
            contentTypeHeader.encodingPart().or("utf-8"));

    if (originalRequest.containsHeader(TRANSFER_ENCODING)
            && originalRequest.header(TRANSFER_ENCODING).firstValue().equals("chunked")) {
        return new InputStreamEntity(new ByteArrayInputStream(originalRequest.getBody()), -1, contentType);
    }//  w ww . j a v a 2 s  . c o m

    return new ByteArrayEntity(originalRequest.getBody());
}

From source file:integration.report.ReportIT.java

protected void createEntity(IntellectualEntity ie) throws IOException {
    HttpPost post = new HttpPost(serverAddress + "/scape/entity");
    ByteArrayOutputStream sink = new ByteArrayOutputStream();
    try {//from ww w.  j a va 2 s  .com
        this.scapeMarshaller.serialize(ie, sink);
    } catch (JAXBException e) {
        throw new IOException(e);
    }
    post.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(),
            ContentType.TEXT_XML));
    HttpResponse resp = this.client.execute(post);
    assertEquals(201, resp.getStatusLine().getStatusCode());
    String id = EntityUtils.toString(resp.getEntity());
    assertTrue(id.length() > 0);
    post.releaseConnection();
}

From source file:org.eclipse.jgit.lfs.server.fs.LfsServerTest.java

protected LongObjectId putContent(Path f) throws FileNotFoundException, IOException {
    try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
        LongObjectId id1, id2;/*from www .j  a  va  2s  . c o m*/
        String hexId1, hexId2;
        try (DigestInputStream in = new DigestInputStream(new BufferedInputStream(Files.newInputStream(f)),
                Constants.newMessageDigest())) {
            InputStreamEntity entity = new InputStreamEntity(in, Files.size(f),
                    ContentType.APPLICATION_OCTET_STREAM);
            id1 = LongObjectIdTestUtils.hash(f);
            hexId1 = id1.name();
            HttpPut request = new HttpPut(server.getURI() + "/lfs/objects/" + hexId1);
            request.setEntity(entity);
            HttpResponse response = client.execute(request);
            checkResponseStatus(response);
            id2 = LongObjectId.fromRaw(in.getMessageDigest().digest());
            hexId2 = id2.name();
            assertEquals(hexId1, hexId2);
        }
        return id1;
    }
}

From source file:org.craftercms.engine.http.impl.HttpProxyImpl.java

protected void copyOriginalRequestBody(HttpPost httpRequest, HttpServletRequest request) throws IOException {
    int contentLength = request.getContentLength();
    if (contentLength > 0) {
        String contentType = request.getContentType();
        InputStream content = request.getInputStream();

        httpRequest.setEntity(new InputStreamEntity(content, contentLength, ContentType.create(contentType)));
    }//from  w w  w.j a  v a  2s. com
}

From source file:de.drv.dsrv.spoc.web.service.impl.FachverfahrenRequestServiceImpl.java

private HttpResponse processRequest(final URI fachverfahrenUri, final TransportRequestType transportRequestType)
        throws IOException, JAXBException {

    final HttpPost httpPost = new HttpPost(fachverfahrenUri);

    try {/* w w w .ja  v  a 2 s . c  o  m*/
        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        this.extraJaxbMarshaller.marshalTransportRequest(transportRequestType, outputStream);
        httpPost.setEntity(
                new InputStreamEntity(new ByteArrayInputStream(outputStream.toByteArray()), -1L, CONTENT_TYPE));
        // Schicke Request an Fachverfahren
        return this.httpClient.execute(httpPost);
    } finally {
        httpPost.releaseConnection();
    }
}

From source file:com.sap.core.odata.testutil.tool.core.AbstractTestClient.java

private HttpRequestBase createRequest(final URI baseUri, final TestRequest testRequest) {
    RequestHttpMethod method = testRequest.getHttpMethod();
    if (method == null) {
        throw new TestUtilRuntimeException("No HttpMethod set.");
    }//from   w w w .  j  a va 2s  .c om

    switch (method) {
    case GET:
        return new HttpGet(baseUri.getPath() + testRequest.getPath());
    case POST:
        TestPostRequest postRequest = (TestPostRequest) testRequest;
        HttpPost post = new HttpPost(baseUri.getPath() + testRequest.getPath());
        post.setEntity(new InputStreamEntity(postRequest.getContentAsStream(), -1,
                ContentType.create(postRequest.getContentType())));
        return post;
    default:
        throw new TestUtilRuntimeException("Unknown HttpMethod '" + method + "' set.");
    }
}