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:io.tourniquet.junit.http.rules.examples.HttpClientHelper.java

public static HttpPost post(String url, InputStream data) throws UnsupportedEncodingException {

    HttpPost post = new HttpPost(url);
    post.setEntity(new InputStreamEntity(data));
    return post;//  w  w w  . java2s.co  m
}

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

private UpdateDataSet(String id, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {//www . ja  va  2 s .  c  o  m
        final HttpPut put = new HttpPut(datasetServiceUrl + "/datasets/" + id); //$NON-NLS-1$ //$NON-NLS-2$
        put.setHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        put.setEntity(new InputStreamEntity(dataSetContent));
        return put;
    });
    on(HttpStatus.NO_CONTENT).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:org.talend.dataprep.api.service.command.transformation.SuggestActionParams.java

private SuggestActionParams(final HystrixCommand<InputStream> content, final String action,
        final String columnId) {
    super(content);
    execute(() -> {/*ww w.j  ava  2 s . c  om*/
        final String uri = transformationServiceUrl + "/transform/suggest/" + action + "/params?columnId="
                + columnId;
        final HttpPost getParametersCall = new HttpPost(uri);
        final InputStreamEntity entity = new InputStreamEntity(getInput());
        getParametersCall.setEntity(entity);
        return getParametersCall;
    });
    on(HttpStatus.OK).then(pipeStream());
}

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

private UpdateColumn(final String dataSetId, final String columnId, final InputStream body) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {/* www.  j  a v  a  2  s.  co  m*/
        final HttpPost post = new HttpPost(
                datasetServiceUrl + "/datasets/" + dataSetId + "/column/" + columnId); //$NON-NLS-1$ //$NON-NLS-2$
        post.setHeader("Content-Type", APPLICATION_JSON_VALUE);
        post.setEntity(new InputStreamEntity(body));
        return post;
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET, e,
            ExceptionContext.build().put("id", dataSetId)));
    on(HttpStatus.OK).then(asNull());
}

From source file:org.talend.dataprep.api.service.command.transformation.ColumnActions.java

/**
 * Constructor./*from  w  ww .  j  a  v  a 2s . co m*/
 *
 * @param input the column metadata to get the actions for (in json).
 */
private ColumnActions(InputStream input) {
    super(GenericCommand.TRANSFORM_GROUP);
    execute(() -> {
        HttpPost post = new HttpPost(transformationServiceUrl + "/actions/column");
        post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
        post.setEntity(new InputStreamEntity(input));
        return post;
    });
    onError((e) -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_SUGGESTED_ACTIONS, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(asNull());
    on(HttpStatus.OK).then(pipeStream());
}

From source file:org.talend.dataprep.api.service.command.transformation.SuggestColumnActions.java

/**
 * Constructor.//w w  w .  ja  va  2 s.  c  o  m
 *
 * @param input the column metadata to get the actions for (in json).
 */
private SuggestColumnActions(InputStream input) {
    super(GenericCommand.TRANSFORM_GROUP);
    execute(() -> {
        HttpPost post = new HttpPost(transformationServiceUrl + "/suggest/column");
        post.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
        post.setEntity(new InputStreamEntity(input));
        return post;
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_SUGGESTED_ACTIONS, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(asNull());
    on(HttpStatus.OK).then(pipeStream());
}

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

@Test
public void testReceiveCallback() throws IOException {
    String url = "http://localhost:18090/docusign";
    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.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet.java

/**
 * Private constructor./* w  w  w . j a v a2 s .  c  om*/
 *
 * @param id the dataset id.
 * @param name the dataset name.
 * @param dataSetContent the new dataset content.
 */
private CreateOrUpdateDataSet(String id, String name, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + id + "/raw/");
            if (!StringUtils.isEmpty(name)) {
                uriBuilder.addParameter("name", name);
            }
            final HttpPut put = new HttpPut(uriBuilder.build()); // $NON-NLS-1$ //$NON-NLS-2$
            put.setEntity(new InputStreamEntity(dataSetContent));
            return put;
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:com.meplato.store2.MockResponse.java

/**
 * Parse a response from String contents.
 *
 * @param contents/*from   w  w w  .  java 2s  .  c  om*/
 * @return String contents
 * @throws IOException
 * @throws HttpException
 * @throws ServiceException
 */
public static Response fromContents(String contents) throws IOException, HttpException, ServiceException {
    // If this code works, it was written by Georg Wall.
    SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535);
    sib.bind(new ByteArrayInputStream(contents.getBytes(Consts.UTF_8)));
    DefaultHttpResponseParser parser = new DefaultHttpResponseParser(sib);
    HttpResponse httpResponse = parser.parse();
    int endOfHeader = contents.indexOf("\r\n\r\n");
    if (endOfHeader >= 0) {
        endOfHeader += 4; // for \r\n\r\n
        byte[] bytes = contents.getBytes(Consts.UTF_8);
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes, endOfHeader, bytes.length - endOfHeader);
        InputStreamEntity entity = new InputStreamEntity(bais);
        entity.setContentType(httpResponse.getFirstHeader("Content-Type"));
        entity.setContentEncoding(httpResponse.getFirstHeader("Content-Encoding"));
        httpResponse.setEntity(entity);
    }
    return new ApacheHttpResponse(httpResponse);
}