hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendy Irawan (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1206) DecompressingHttpClient doesn't work with HTTPS
Date Tue, 19 Jun 2012 09:34:43 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1206?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13396623#comment-13396623
] 

Hendy Irawan commented on HTTPCLIENT-1206:
------------------------------------------

I apologize for the lack of clarity.

DecompressingHttpClient doesn't throw any exception, it simply treats the request as a plain
HTTP request. As if the URI magically string-replaced from "https://" to "http://"

Simpler code to reproduce the bug: (no access token needed)

HttpClient httpClient = new DecompressingHttpClient(new DefaultHttpClient());
HttpGet getReq = new HttpGet( URI.create("https://graph.facebook.com/ceefour") );
HttpResponse resp = httpClient.execute(getReq); 

The above code should succeed, however when you inspect the logs you will notice that it doesn't
connect to https://graph.facebook.com but rather to http://graph.facebook.com

                
> 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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message