Hendy Irawan created HTTPCLIENT-1206:
----------------------------------------

             Summary: DecompressingHttpClient doesn't work with HTTPS
                 Key: HTTPCLIENT-1206
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1206
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 4.2 Final
            Reporter: Hendy Irawan


DecompressingHttpClient is the successor of ContentEncodingHttpClient. However 
ContentEncodingHttpClient works well with HTTPS, while DecompressingHttpClient 
always uses plain HTTP.

Sample code (from https://github.com/soluvas/fb-tools ):

package org.soluvas.fbcli;

import java.net.URI;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.ContentEncodingHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.BasicHttpParams;
import org.jboss.weld.environment.se.bindings.Parameters;
import org.jboss.weld.environment.se.events.ContainerInitialized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import akka.actor.ActorSystem;
import akka.dispatch.Future;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * @author ceefour
 */
public class FbCli {
        private transient Logger log = LoggerFactory.getLogger(FbCli.class);
        @Inject @Parameters String[] args;
        @Inject @Named("facebook_accessToken") String accessToken;

        public void run(@Observes ContainerInitialized e) {
                log.info("fbcli starting");
                if (args.length < 1)
                        throw new RuntimeException("Requires command line 
arguments.");
                
                if ("friends".equals(args[0])) {
                        try {
                                // this works: 
                                HttpClient httpClient = new 
ContentEncodingHttpClient(new PoolingClientConnectionManager(), new 
BasicHttpParams());
                                // this doesn't work:
//                               HttpClient httpClient = new 
DecompressingHttpClient(new DefaultHttpClient(new 
PoolingClientConnectionManager(), new BasicHttpParams()));
                                try {
                                        URI friendsUri = new 
URIBuilder("https://graph.facebook.com/me/friends";).addParameter("access_token",
 accessToken).build();
                                        HttpGet getReq = new 
HttpGet(friendsUri);
                                        HttpResponse friendsResp = 
httpClient.execute(getReq);
                                        
                                        ObjectMapper mapper = new 
ObjectMapper();
                                        
mapper.enable(SerializationFeature.INDENT_OUTPUT);
                                        JsonNode json = 
mapper.readTree(friendsResp.getEntity().getContent());
                                        
                                        if (json.has("paging")) {
                                                JsonNode pagingNode = 
json.get("paging");
                                                if (pagingNode.has("next")) {
                                                        String nextUri = 
pagingNode.get("next").asText();
                                                }
                                        }
                                        
                                        mapper.writeValue(System.out, json);
                                } finally {
                                        
httpClient.getConnectionManager().shutdown();
                                }
                        } catch (Exception ex) {
                                throw new RuntimeException(ex);
                        }
                }
        }
}


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to