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) 

Source Link

Usage

From source file:com.braffdev.server.core.module.filehandler.handler.DefaultFileHandler.java

/**
 *
 *///www  . j  a va  2 s.com
@Override
public HttpEntity handle(RequestEnvironment environment, Container container, File file, InputStream in,
        Model model) {
    return new InputStreamEntity(in);
}

From source file:com.redhat.red.build.koji.it.AbstractWithSetupIT.java

protected void executeSetup(String importsDirPath, String scriptName, CloseableHttpClient client)
        throws Exception {
    InputStream is = getResourceStream(importsDirPath, scriptName);

    String scriptResource = Paths.get(importsDirPath, scriptName).toString();
    String url = formatUrl(SETUP_CGI);
    System.out.println(//from www .j  a va 2  s  . c om
            "\n\n ##### START: " + name.getMethodName() + " :: Setup script: " + scriptResource + " #####\n\n");

    CloseableHttpResponse response = null;
    try {
        HttpPost post = new HttpPost(url);
        post.setEntity(new InputStreamEntity(is));
        response = client.execute(post);
    } catch (IOException e) {
        e.printStackTrace();
        fail(String.format("Failed to execute GET request: %s. Reason: %s", url, e.getMessage()));
    }

    String result = IOUtils.toString(response.getEntity().getContent());

    System.out.println(result);

    int code = response.getStatusLine().getStatusCode();
    if (code != 201 || code != 200) {
        fail("Failed to execute script: " + scriptResource + "\nSERVER RESPONSE STATUS: "
                + response.getStatusLine());
    } else {
        System.out.println("\n\n ##### END: " + name.getMethodName() + " :: Setup script: " + scriptResource
                + " #####\n\n");
    }
}

From source file:org.nuxeo.docusign.core.test.TestDocuSignCallback.java

@Test
public void testReceiveCallbackWithURLParam() throws IOException {
    String url = "http://localhost:18090/docusign/javascript.workflow";
    HttpClient client = HttpClientBuilder.create().build();
    HttpPost post = new HttpPost(url);
    post.setEntity(new InputStreamEntity(getClass().getResourceAsStream("/files/callback.xml")));
    HttpResponse response = client.execute(post);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}

From source file:org.fcrepo.client.BodyRequestBuilder.java

/**
 * Add a body to this request as a stream with the given content type
 * //  w w w .  j  a v a  2 s . c o m
 * @param stream InputStream of the content to be sent to the server
 * @param contentType the Content-Type of the body
 * @return this builder
 */
protected BodyRequestBuilder body(final InputStream stream, final String contentType) {
    if (stream != null) {
        String type = contentType;
        if (type == null) {
            type = "application/octet-stream";
        }

        ((HttpEntityEnclosingRequestBase) request).setEntity(new InputStreamEntity(stream));
        request.addHeader(CONTENT_TYPE, type);
    }

    return this;
}

From source file:com.microsoft.windowsazure.core.pipeline.apache.HttpServiceResponseContext.java

@Override
public void setEntityInputStream(InputStream entity) {
    clientResponse.setEntity(new InputStreamEntity(entity));
}

From source file:org.talend.dataprep.api.service.command.dataset.CreateDataSet.java

private HttpRequestBase onExecute(String name, String tag, String contentType, InputStream dataSetContent) {
    try {/*ww w. ja  v  a2  s.c o  m*/
        URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets");
        uriBuilder.addParameter("name", name);
        uriBuilder.addParameter("tag", tag);
        final HttpPost post = new HttpPost(uriBuilder.build());
        post.addHeader("Content-Type", contentType); //$NON-NLS-1$
        post.setEntity(new InputStreamEntity(dataSetContent));
        return post;
    } catch (URISyntaxException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:hu.dolphio.tprttapi.service.RttServiceImpl.java

@Override
public Collection<ReportElementTO> loadRttTrackingsFromReport()
        throws URISyntaxException, IOException, ClientException {

    if ((projectId == null && reportId == null) || (projectId != null && reportId != null)) {
        throw new ClientException("Project ID or Report ID must be set!");
    }/*from  w w w  .ja v  a 2 s .c o  m*/

    BasicCookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore)
            .setDefaultRequestConfig(config).build();

    HttpEntity httpEntity = new InputStreamEntity(new ByteArrayInputStream(
            new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(new Object() {
                public String username = propertyReader.getRttUserName();
                public String password = propertyReader.getRttPassword();
            }).getBytes("UTF-8")));

    HttpUriRequest login = RequestBuilder.post().setUri(new URI(propertyReader.getRttHost() + "/login"))
            .setEntity(httpEntity).setHeader("Accept-Language", "sk,en-US;q=0.8,en;q=0.6,hu;q=0.4")
            .setHeader("Content-Type", "application/json;charset=utf-8").build();
    CloseableHttpResponse loginResponse = httpclient.execute(login);
    LOG.debug("RTT login response: " + loginResponse);

    if (HttpResponseStatus
            .getStatusByCode(loginResponse.getStatusLine().getStatusCode()) != HttpResponseStatus.SUCCESS) {
        throw new ClientException(
                "[" + loginResponse.getStatusLine().getStatusCode() + "] Login to RTT failed!");
    }

    EntityUtils.consume(loginResponse.getEntity());

    StringBuilder postUriBuilder = new StringBuilder().append(propertyReader.getRttHost())
            .append(reportId == null ? propertyReader.getRttReportByProjectUrl()
                    : propertyReader.getRttReportByReportUrl())
            .append(reportId == null ? projectId : reportId).append("/json?startDate=").append(dateFrom)
            .append("&endDate=").append(dateTo);

    LOG.trace("RTT report query: " + postUriBuilder.toString());

    HttpGet get = new HttpGet(postUriBuilder.toString());
    CloseableHttpResponse rttResponse = httpclient.execute(get);

    if (HttpResponseStatus
            .getStatusByCode(rttResponse.getStatusLine().getStatusCode()) != HttpResponseStatus.SUCCESS) {
        throw new ClientException("[" + rttResponse.getStatusLine().getStatusCode()
                + "] Downloading tracking information from RTT failed!");
    }
    String trackingsJson = IOUtils.toString(rttResponse.getEntity().getContent(), "utf-8");

    Collection<ReportElementTO> fromJson = new ObjectMapper().readValue(trackingsJson,
            new TypeReference<Collection<ReportElementTO>>() {
            });

    return fromJson;
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationUpdateAction.java

private HttpRequestBase onExecute(String preparationId, String stepId, AppendStep updatedStep) {
    try {/*from  ww  w .j  a  v  a 2 s . c om*/
        final String url = preparationServiceUrl + "/preparations/" + preparationId + "/actions/" + stepId;

        final List<StepDiff> diff = objectMapper.readValue(getInput(), new TypeReference<List<StepDiff>>() {
        });
        updatedStep.setDiff(diff.get(0));
        final String stepAsString = objectMapper.writeValueAsString(updatedStep);

        final HttpPut actionAppend = new HttpPut(url);
        final InputStream stepInputStream = new ByteArrayInputStream(stepAsString.getBytes());

        actionAppend.setHeader(new BasicHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE));
        actionAppend.setEntity(new InputStreamEntity(stepInputStream));
        return actionAppend;
    } catch (IOException e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

private void copyRequestBody(HttpServletRequest request, HttpUriRequest proxyRequest) throws IOException {
    if (!(proxyRequest instanceof HttpEntityEnclosingRequest)) {
        return;//from w  w w.j a  v a2 s  .c o m
    }

    HttpEntityEnclosingRequest httpEntityEnclosingRequest = (HttpEntityEnclosingRequest) proxyRequest;
    httpEntityEnclosingRequest.setEntity(new InputStreamEntity(request.getInputStream()));
}

From source file:com.joyent.manta.client.multipart.EncryptingPartEntityTest.java

public void doesNotCloseSuppliedOutputStreamWhenWrittenSuccessfully() throws Exception {
    final EncryptingPartEntity encryptingPartEntity = new EncryptingPartEntity(state.getCipherStream(),
            state.getMultipartStream(),//from ww  w  . ja v a 2 s .  c  o  m
            new InputStreamEntity(new BrokenInputStream(new IOException("bad input"))), CALLBACK_NOOP);

    final OutputStream output = Mockito.mock(OutputStream.class);
    Assert.assertThrows(IOException.class, () -> encryptingPartEntity.writeTo(output));
    Mockito.verify(output, Mockito.never()).close();
}