Example usage for org.apache.http.protocol HTTP CONTENT_ENCODING

List of usage examples for org.apache.http.protocol HTTP CONTENT_ENCODING

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP CONTENT_ENCODING.

Prototype

String CONTENT_ENCODING

To view the source code for org.apache.http.protocol HTTP CONTENT_ENCODING.

Click Source Link

Usage

From source file:org.apache.synapse.transport.nhttp.util.MessageFormatterDecoratorFactory.java

public static MessageFormatter createMessageFormatterDecorator(MessageContext msgContext) {

    if (msgContext == null) {
        throw new IllegalArgumentException("Message Context cannot be null");
    }//from w w w .j  a v  a2 s . c om

    try {
        // Get message formatter based on the content type
        MessageFormatter formatter = MessageProcessorSelector.getMessageFormatter(msgContext);

        Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (o != null && o instanceof Map) {
            Map headers = (Map) o;

            String encode = (String) headers.get(HTTP.CONTENT_ENCODING);
            if (encode != null) {

                //If message  contains 'Accept-Encoding' header and  if it's value is 'qzip'
                if (GZIP_CODEC.equals(encode)) {
                    formatter = new GzipMessageFormatterDecorator(formatter);
                }
                //if there are any type for 'Accept-Encoding' , those should go here

            }
        }
        return formatter;

    } catch (AxisFault axisFault) {
        String msg = "Cannot find a suitable MessageFormatter : " + axisFault.getMessage();
        log.error(msg, axisFault);
    }

    return null;

}

From source file:net.yacy.cora.protocol.http.GzipCompressingEntity.java

@Override
public Header getContentEncoding() {
    return new BasicHeader(HTTP.CONTENT_ENCODING, HeaderFramework.CONTENT_ENCODING_GZIP);
}

From source file:de.undercouch.gradle.tasks.download.internal.ContentEncodingNoneInterceptor.java

@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
    //replace invalid 'Content-Encoding' header
    Header[] hs = response.getHeaders(HTTP.CONTENT_ENCODING);
    if (hs != null) {
        for (Header h : hs) {
            if (isNone(h)) {
                response.removeHeaders(HTTP.CONTENT_ENCODING);
                response.addHeader(IDENTITY);
                break;
            }//from   w  w  w.  j a v a  2  s  .  c o m
        }
    }

    //replace (cached) Content-Encoding in HttpEntity
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header ce = entity.getContentEncoding();
        if (isNone(ce)) {
            response.setEntity(new CustomContentEncodingEntity(entity, IDENTITY));
        }
    }
}

From source file:com.autonomy.nonaci.indexing.impl.PostDataHttpEntity.java

@Override
public Header getContentEncoding() {
    Header header = null;// www .  j  a  va  2  s .co m

    final String ceString = postData.getContentEncoding();
    if (ceString != null) {
        header = new BasicHeader(HTTP.CONTENT_ENCODING, ceString);
    }

    return header;
}

From source file:z.hol.net.http.entity.compress.GzipCompressingEntity.java

@Override
public Header getContentEncoding() {
    return new BasicHeader(HTTP.CONTENT_ENCODING, GZIP_CODEC);
}

From source file:com.apigee.sdk.apm.http.impl.client.cache.CacheEntity.java

public Header getContentEncoding() {
    return this.cacheEntry.getFirstHeader(HTTP.CONTENT_ENCODING);
}

From source file:NGzipCompressingEntity.java

public Header getContentEncoding() {
    return new BasicHeader(HTTP.CONTENT_ENCODING, GZIP_CODEC);
}

From source file:com.subgraph.vega.internal.http.requests.RequestTask.java

@Override
public IHttpResponse call() throws Exception {
    if (config.getForceIdentityEncoding())
        request.setHeader(HTTP.CONTENT_ENCODING, HTTP.IDENTITY_CODING);

    if (rateLimit != null)
        rateLimit.maybeDelayRequest();/*from   www  .j  a  v  a  2s .  c o  m*/

    final long start = System.currentTimeMillis();
    final HttpResponse httpResponse = client.execute(request, context);
    final long elapsed = System.currentTimeMillis() - start;

    final HttpEntity entity = httpResponse.getEntity();

    if (entity != null) {
        if (config.getMaximumResponseKilobytes() > 0
                && entity.getContentLength() > (config.getMaximumResponseKilobytes() * 1024)) {
            logger.warning("Aborting request " + request.getURI().toString() + " because response length "
                    + entity.getContentLength() + " exceeds maximum length of "
                    + config.getMaximumResponseKilobytes() + " kb.");
            request.abort();
            httpResponse.setEntity(createEmptyEntity());
        }

        final HttpEntity newEntity = processEntity(httpResponse, entity);
        httpResponse.setEntity(newEntity);
    }
    final HttpHost host = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
    final HttpRequest sentRequest = (HttpRequest) context.getAttribute(HttpRequestEngine.VEGA_SENT_REQUEST);

    final IHttpResponse response = new EngineHttpResponse(request.getURI(), host,
            (sentRequest == null) ? (request) : (sentRequest), httpResponse, elapsed, htmlParser);

    for (IHttpResponseProcessor p : config.getResponseProcessors()) {
        p.processResponse(response.getOriginalRequest(), response, context);
    }

    return response;
}

From source file:com.subgraph.vega.internal.http.proxy.ResponseContentCustom.java

public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }/*ww w  . j  a  v  a  2 s.  c  om*/

    ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
    HttpEntity entity = response.getEntity();

    if (entity != null) {
        long len = entity.getContentLength();

        if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) {
            response.removeHeaders(HTTP.CONTENT_LEN);
            response.setHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        } else if (len >= 0) {
            response.removeHeaders(HTTP.TRANSFER_ENCODING);
            response.setHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength()));
        }

        // Specify a content type if known
        if (entity.getContentType() != null && !response.containsHeader(HTTP.CONTENT_TYPE)) {
            response.addHeader(entity.getContentType());
        }

        // Specify a content encoding if known
        if (entity.getContentEncoding() != null && !response.containsHeader(HTTP.CONTENT_ENCODING)) {
            response.addHeader(entity.getContentEncoding());
        }
    } else {
        int status = response.getStatusLine().getStatusCode();
        if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED
                && status != HttpStatus.SC_RESET_CONTENT) {
            response.setHeader(HTTP.CONTENT_LEN, "0");
        }
    }
}

From source file:com.nexmo.sdk.core.client.Client.java

/**
 * Prepare a new connection with necessary custom header fields.
 * @param request The request object./*from   ww w. j  a va2 s  . c  o  m*/
 *
 * @return A new url connection.
 * @throws IOException if an error occurs while opening the connection.
 */
public HttpURLConnection initConnection(Request request) throws IOException {
    // Generate signature using pre-shared key.
    RequestSigning.constructSignatureForRequestParameters(request.getParams(), request.getSecretKey());

    // Construct connection with necessary custom headers.
    URL url = constructUrlGetConnection(request.getParams(), request.getMethod(), request.getUrl());
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setReadTimeout(Defaults.CONNECTION_READ_TIMEOUT);
    connection.setConnectTimeout(Defaults.CONNECTION_TIMEOUT);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.addRequestProperty(HTTP.CONTENT_ENCODING, Config.PARAMS_ENCODING);
    connection.addRequestProperty(BaseService.OS_FAMILY, Config.OS_ANDROID);
    connection.addRequestProperty(BaseService.OS_REVISION, DeviceProperties.getApiLevel());
    connection.addRequestProperty(BaseService.SDK_REVISION, Config.SDK_REVISION_CODE);

    return connection;
}