当前位置: 首页>>代码示例>>Java>>正文


Java GzipDecompressingEntity类代码示例

本文整理汇总了Java中org.apache.http.client.entity.GzipDecompressingEntity的典型用法代码示例。如果您正苦于以下问题:Java GzipDecompressingEntity类的具体用法?Java GzipDecompressingEntity怎么用?Java GzipDecompressingEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GzipDecompressingEntity类属于org.apache.http.client.entity包,在下文中一共展示了GzipDecompressingEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildHttpClient

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public static CloseableHttpClient buildHttpClient() {
    CloseableHttpClient httpClient = HttpClients.custom()
            .addInterceptorFirst((HttpRequestInterceptor) (request, context) -> {
                if (!request.containsHeader("Accept-Encoding")) {
                    request.addHeader("Accept-Encoding", "gzip");
                }
            }).addInterceptorFirst((HttpResponseInterceptor) (response1, context) -> {
                HttpEntity entity = response1.getEntity();
                if (entity != null) {
                    Header ceHeader = entity.getContentEncoding();
                    if (ceHeader != null) {
                        HeaderElement[] codecs = ceHeader.getElements();
                        for (HeaderElement codec : codecs) {
                            if (codec.getName().equalsIgnoreCase("gzip")) {
                                response1.setEntity(
                                        new GzipDecompressingEntity(response1.getEntity()));
                                return;
                            }
                        }
                    }
                }
            }).build();

    return httpClient;
}
 
开发者ID:jwboardman,项目名称:whirlpool,代码行数:26,代码来源:HttpClientHelper.java

示例2: testContentEncodingRequestParameter

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
@Test
public void testContentEncodingRequestParameter() throws Exception {
    final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
    final StringEntity original = new StringEntity("encoded stuff");
    original.setContentEncoding("GZip");
    response.setEntity(original);

    final RequestConfig config = RequestConfig.custom()
            .setDecompressionEnabled(false)
            .build();

    final HttpContext context = new BasicHttpContext();
    context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);

    final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
    interceptor.process(response, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertNotNull(entity);
    Assert.assertFalse(entity instanceof GzipDecompressingEntity);
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:21,代码来源:TestResponseContentEncoding.java

示例3: initClient

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
private HttpClient initClient() {
    DefaultHttpClient client = new DefaultHttpClient();
    client.addRequestInterceptor((request, context) -> {
        if (!request.containsHeader(ACCEPT_ENCODING)) {
            request.addHeader(ACCEPT_ENCODING, GZIP);
        }
    });

    client.addResponseInterceptor((response, context) -> {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            Header header = entity.getContentEncoding();
            if (header != null) {
                HeaderElement[] elements = header.getElements();
                for (int i = 0; i < elements.length; i++) {
                    if (elements[i].getName().equalsIgnoreCase(GZIP)) {
                        response.setEntity(
                                new GzipDecompressingEntity(response.getEntity()));
                        return;
                    }
                }
            }
        }
    });
    return client;
}
 
开发者ID:staliang,项目名称:ymaps4j,代码行数:27,代码来源:GZipHttpClient.java

示例4: process

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
@Override
public void process(HttpResponse response, HttpContext context)
		throws HttpException, IOException {
	HttpEntity entity = response.getEntity();
	if (entity != null) {
		Header ceheader = entity.getContentEncoding();
		if (ceheader != null) {
			HeaderElement[] codecs = ceheader.getElements();
			for (int i = 0; i < codecs.length; i++) {
				if (codecs[i].getName().equalsIgnoreCase("gzip")) {
					response.setEntity(new GzipDecompressingEntity(
							response.getEntity()));
					return;
				}
			}
		}
	}
}
 
开发者ID:mondo-project,项目名称:mondo-integration,代码行数:19,代码来源:GZipResponseInterceptor.java

示例5: getResponseString

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public static String getResponseString(HttpResponse response) {
	if (response == null) {
		return null;
	}

	try {
		HttpEntity entity = response.getEntity();
		Header contentEncoding = entity.getContentEncoding();
		if (contentEncoding != null) {
			if (contentEncoding.getValue().toLowerCase(Locale.getDefault())
					.contains("gzip")) {
				GzipDecompressingEntity gzipEntity = new GzipDecompressingEntity(
						entity);
				return EntityUtils.toString(gzipEntity);
			}
		}
		return EntityUtils.toString(entity);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:coodoing,项目名称:dataasync,代码行数:23,代码来源:HttpHandler.java

示例6: process

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
  HttpEntity entity = response.getEntity();
  if (entity != null) {
    Header ceheader = entity.getContentEncoding();
    if (ceheader != null) {
      HeaderElement[] codecs = ceheader.getElements();
      for (int i = 0; i < codecs.length; i++) {
        if (codecs[i].getName().equalsIgnoreCase("gzip")) {
          response.setEntity(
              new GzipDecompressingEntity(response.getEntity()));
          return;
        }
      }
    }
  }
}
 
开发者ID:Idilia,项目名称:idilia-java-sdk,代码行数:18,代码来源:GzipInterceptors.java

示例7: process

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
@Override
public void process(HttpResponse httpResponse, HttpContext httpContext)
		throws HttpException, IOException
{
	HttpEntity entity = httpResponse.getEntity();
	if (entity != null)
	{
		Header ceheader = entity.getContentEncoding();
		if (ceheader != null)
		{
			HeaderElement[] codecs = ceheader.getElements();
			for (int i = 0; i < codecs.length; i++)
			{
				if (codecs[i].getName().equalsIgnoreCase("gzip"))
				{
					httpResponse.setEntity(new GzipDecompressingEntity(
							httpResponse.getEntity()));
					return;
				}
			}
		}
	}
}
 
开发者ID:Esquive,项目名称:iticrawler,代码行数:24,代码来源:GzipEncodedResponseInterceptor.java

示例8: postJSON

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public JSONObject postJSON() throws JSONException, NForumException, IOException{
       HttpResponse response = httpClient.execute(httpPost);
	int statusCode = response.getStatusLine().getStatusCode();
	if (statusCode != 200)
		throw new NForumException(NForumException.EXCEPTION_NETWORK + ":" + statusCode);
	Header header = response.getEntity().getContentEncoding();
	if (header != null) {
		for (HeaderElement element : header.getElements()) {
			if (element.getName().equalsIgnoreCase("gzip")) {
				response.setEntity(new GzipDecompressingEntity(response.getEntity()));
				break;
			}
		}
	}
	String result = ResponseProcessor.getStringFromResponse(response);
	httpPost.abort();
	
	JSONObject json = new JSONObject(result);
	if(json.has("msg")){
		throw new NForumException(json.getString("msg"));
	}
	return json;
}
 
开发者ID:dss886,项目名称:nForumSDK,代码行数:24,代码来源:PostMethod.java

示例9: getJSON

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public JSONObject getJSON() throws JSONException, NForumException, IOException{
       HttpResponse response = httpClient.execute(httpGet);
	
	int statusCode = response.getStatusLine().getStatusCode();
	if (statusCode != 200)
		throw new NForumException(NForumException.EXCEPTION_NETWORK + ":" + statusCode);
	Header header = response.getEntity().getContentEncoding();
	if (header != null) {
		for (HeaderElement element : header.getElements()) {
			if (element.getName().equalsIgnoreCase("gzip")) {
				response.setEntity(new GzipDecompressingEntity(response.getEntity()));
				break;
			}
		}
	}
	String result = ResponseProcessor.getStringFromResponse(response);
	httpGet.abort();
	
	JSONObject json = new JSONObject(result);
	if(json.has("msg")){
		throw new NForumException(json.getString("msg"));
	}
	return json;
}
 
开发者ID:dss886,项目名称:nForumSDK,代码行数:25,代码来源:GetMethod.java

示例10: process

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
@Override
public void process(HttpResponse response, HttpContext context) throws HttpException, IOException {
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        Header contentEncoding = entity.getContentEncoding();
        if (contentEncoding != null) {
            HeaderElement[] codecs = contentEncoding.getElements();
            for (HeaderElement codec : codecs) {
                if (codec.getName().equalsIgnoreCase(GZIP)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    return;
                }
                if (codec.getName().equalsIgnoreCase(DEFLATE)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    return;
                }
            }
        }
    }
}
 
开发者ID:polyglot-mark,项目名称:salesforce-plugin,代码行数:21,代码来源:HttpCompressionResponseInterceptor.java

示例11: handleContentEncoding

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
private void handleContentEncoding(HttpResponse response) throws ServletException {
	HttpEntity entity = response.getEntity();
	if (entity != null) {
		Header contentEncodingHeader = entity.getContentEncoding();
		if (contentEncodingHeader != null) {
			HeaderElement[] codecs = contentEncodingHeader.getElements();
			LOGGER.debug("Content-Encoding in response:");
			for (HeaderElement codec : codecs) {
				String codecname = codec.getName().toLowerCase();
				LOGGER.debug("    => codec: " + codecname);
				if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
					response.setEntity(new GzipDecompressingEntity(response.getEntity()));
					return;
				} else if ("deflate".equals(codecname)) {
					response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
					return;
				} else if ("identity".equals(codecname)) {
					return;
				} else {
					throw new ServletException("Unsupported Content-Encoding: " + codecname);
				}
			}
		}
	}
}
 
开发者ID:SAP,项目名称:cloud-connectivityproxy,代码行数:26,代码来源:ProxyServlet.java

示例12: getHttpResponse

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public HttpResponse getHttpResponse(String url) throws ClientProtocolException, IOException
{
    HttpResponse response = null;
    HttpGet get = new HttpGet(url);
    get.addHeader("Accept", "text/html");
    get.addHeader("Accept-Charset", "utf-8");
    get.addHeader("Accept-Encoding", "gzip");
    get.addHeader("Accept-Language", "en-US,en");
    int uai = rand.nextInt() % userAgents.size();
    if (uai < 0)
    {
        uai = -uai;
    }
    get.addHeader("User-Agent", userAgents.get(uai));
    response = getHttpClient().execute(get);
    HttpEntity entity = response.getEntity();
    Header header = entity.getContentEncoding();
    if (header != null)
    {
        HeaderElement[] codecs = header.getElements();
        for (int i = 0; i < codecs.length; i++)
        {
            if (codecs[i].getName().equalsIgnoreCase("gzip"))
            {
                response.setEntity(new GzipDecompressingEntity(entity));
            }
        }
    }
    return response;

}
 
开发者ID:dbiir,项目名称:rainbow,代码行数:32,代码来源:HttpFactory.java

示例13: process

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
/**
 * Handles the following {@code Content-Encoding}s by
 * using the appropriate decompressor to wrap the response Entity:
 * <ul>
 * <li>gzip - see {@link GzipDecompressingEntity}</li>
 * <li>deflate - see {@link DeflateDecompressingEntity}</li>
 * <li>identity - no action needed</li>
 * </ul>
 *
 * @param response the response which contains the entity
 * @param  context not currently used
 *
 * @throws HttpException if the {@code Content-Encoding} is none of the above
 */
public void process(
        final HttpResponse response,
        final HttpContext context) throws HttpException, IOException {
    HttpEntity entity = response.getEntity();

    // It wasn't a 304 Not Modified response, 204 No Content or similar
    if (entity != null) {
        Header ceheader = entity.getContentEncoding();
        if (ceheader != null) {
            HeaderElement[] codecs = ceheader.getElements();
            for (HeaderElement codec : codecs) {
                String codecname = codec.getName().toLowerCase(Locale.US);
                if ("gzip".equals(codecname) || "x-gzip".equals(codecname)) {
                    response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);  
                    return;
                } else if ("deflate".equals(codecname)) {
                    response.setEntity(new DeflateDecompressingEntity(response.getEntity()));
                    if (context != null) context.setAttribute(UNCOMPRESSED, true);
                    return;
                } else if ("identity".equals(codecname)) {

                    /* Don't need to transform the content - no-op */
                    return;
                } else {
                    throw new HttpException("Unsupported Content-Coding: " + codec.getName());
                }
            }
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:ResponseContentEncoding.java

示例14: handleCompressedEntity

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
public static HttpEntity handleCompressedEntity(HttpEntity entity) {
    org.apache.http.Header contentEncoding = entity.getContentEncoding();
    if (contentEncoding != null)
        for (HeaderElement e : contentEncoding.getElements()) {
            if (CONTENT_ENCODING_GZIP.equalsIgnoreCase(e.getName())) {
                return new GzipDecompressingEntity(entity);
            }

            if (CONTENT_ENCODING_DEFLATE.equalsIgnoreCase(e.getName())) {
                return new DeflateDecompressingEntity(entity);
            }
        }

    return entity;
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:16,代码来源:HTTPCUtil.java

示例15: createGzipResponseInterceptor

import org.apache.http.client.entity.GzipDecompressingEntity; //导入依赖的package包/类
/**
 * If gzip is enabled, this will decode things.
 * @return 
 */
private HttpResponseInterceptor createGzipResponseInterceptor()
{
  return new HttpResponseInterceptor() 
  {
    @Override
    public void process( HttpResponse response, HttpContext context ) 
      throws HttpException, IOException 
    {
      //..get the entity
      final HttpEntity entity = response.getEntity();
      if ( entity == null )
        return;

      //..Get any content encoding headers
      final Header ceHeader = entity.getContentEncoding();
      if ( ceHeader == null )
        return;

      //..Get any entries
      HeaderElement[] codecs = ceHeader.getElements();

      //..See if one is marked as gzip 
      for ( final HeaderElement codec : codecs ) 
      {
        if ( codec.getName().equalsIgnoreCase( "gzip" )) 
        {
          //..Hey, it's gzip! decompress the entity 
          response.setEntity( new GzipDecompressingEntity( response.getEntity()));

          //..Done with this ish.
          return;
        }
      }
    }
  };
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:41,代码来源:APIHttpClient.java


注:本文中的org.apache.http.client.entity.GzipDecompressingEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。