Example usage for com.google.common.net HttpHeaders TRANSFER_ENCODING

List of usage examples for com.google.common.net HttpHeaders TRANSFER_ENCODING

Introduction

In this page you can find the example usage for com.google.common.net HttpHeaders TRANSFER_ENCODING.

Prototype

String TRANSFER_ENCODING

To view the source code for com.google.common.net HttpHeaders TRANSFER_ENCODING.

Click Source Link

Document

The HTTP Transfer-Encoding header field name.

Usage

From source file:org.apache.hadoop.hdfs.ByteRangeInputStream.java

private static boolean isChunkedTransferEncoding(final Map<String, List<String>> headers) {
    return contains(headers, HttpHeaders.TRANSFER_ENCODING, "chunked")
            || contains(headers, HttpHeaders.TE, "chunked");
}

From source file:org.dswarm.tools.apiclients.DswarmGraphExtensionAPIClient.java

private Observable<Tuple2<String, String>> importDataModelContent(
        final Tuple3<String, String, InputStream> writeDataModelContentRequestTriple) {

    final String dataModelId = writeDataModelContentRequestTriple._1;
    final String writeDataModelContentRequestJSONString = writeDataModelContentRequestTriple._2;
    final InputStream dataModelContentJSONIS = writeDataModelContentRequestTriple._3;

    LOG.debug("metadata for write data model content request = '{}'", writeDataModelContentRequestJSONString);

    final RxWebTarget<RxObservableInvoker> rxWebTarget = rxWebTarget(WRITE_DATA_MODEL_CONTENT_ENDPOINT);

    final RxObservableInvoker rx = rxWebTarget.request(MULTIPART_MIXED)
            .header(HttpHeaders.TRANSFER_ENCODING, CHUNKED_TRANSFER_ENCODING).rx();

    final MultiPart multiPart = new MultiPart();
    final BufferedInputStream entity1 = new BufferedInputStream(dataModelContentJSONIS, CHUNK_SIZE);

    multiPart.bodyPart(writeDataModelContentRequestJSONString, MediaType.APPLICATION_JSON_TYPE)
            .bodyPart(entity1, MediaType.APPLICATION_OCTET_STREAM_TYPE);

    // POST the request
    final Entity<MultiPart> entity = Entity.entity(multiPart, MULTIPART_MIXED);

    final Observable<Response> post = rx.post(entity).observeOn(IMPORT_SCHEDULER);

    return post.map(response -> {

        int status = response.getStatus();

        try {/*from  ww  w .  ja  v a 2s  .c o m*/

            closeResource(multiPart, WRITE_GDM);
            closeResource(entity1, WRITE_GDM);
            closeResource(dataModelContentJSONIS, WRITE_GDM);

        } catch (final DswarmToolsException e) {

            throw DswarmToolsError.wrap(e);
        }

        if (status == 200) {

            LOG.debug("wrote GDM data for data model '{}' into data hub", dataModelId);
        } else {

            throw DswarmToolsError.wrap(new DswarmToolsException(String.format(
                    "Couldn't store GDM data into database. Received status code '%s' from database endpoint (response body = '%s').",
                    status, response.readEntity(String.class))));
        }

        return Tuple.of(dataModelId, String.valueOf(status));
    }).doOnError(throwable -> {

        throw DswarmToolsError.wrap(new DswarmToolsException(
                String.format("Couldn't store GDM data into database (err0r = '%s')", throwable.getMessage())));
    }).doOnCompleted(
            () -> LOG.debug("completely wrote GDM data for data model '{}' into data hub", dataModelId));
}