Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.2 Final
-
None
Description
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"))
}
mapper.writeValue(System.out, json);
} finally
} catch (Exception ex)
{ throw new RuntimeException(ex); } }
}
}
Attachments
Issue Links
- duplicates
-
HTTPCLIENT-1200 DecompressingHttpClient fails to request on https host
- Closed