Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Apache HTTP Components Proxy Configuration

Avatar

Level 2

Hi,

I'm having an issue using Apache HTTP Components Proxy Configuration to connect to our proxy using AEM 6.3.  Using HTTPClient 3.x code I am able to access the proxy without issue using Day Commons HTTP Client 3.1.  However switching the code to org.apache.httpcomponents 4.x I am not hitting the proxy using Apache HTTP Components Proxy config using the same proxy parameters. Are there any other settings that may need to be updated to make this connection work? Is there a specific version of httpcomponents that I need to use?

1 Accepted Solution

Avatar

Correct answer by
Employee

Hi Michael,

Two things to check:

1) Make sure that you've configured your proxy settings in the Apache HTTP Components Proxy Configuration factory and not the plain PID

2) Use the HttpClientBuilderFactory (org.apache.http.osgi.services.HttpClientBuilderFactory) service to get a HttpClientBuilder

View solution in original post

7 Replies

Avatar

Correct answer by
Employee

Hi Michael,

Two things to check:

1) Make sure that you've configured your proxy settings in the Apache HTTP Components Proxy Configuration factory and not the plain PID

2) Use the HttpClientBuilderFactory (org.apache.http.osgi.services.HttpClientBuilderFactory) service to get a HttpClientBuilder

Avatar

Level 2

Hi Joseph,

Thanks for the response. Unfortunately I believe I've tried those with no luck. Just double-checking though on the Proxy Configuration. For factory, do you mean create a new factory configuration (+ next to configuration in italics) rather than update the primary factory?

Thanks,

Mike

Avatar

Employee

Can you share a screenshot of your configuration (scrub the sensitive details) and a code snippet?

Avatar

Level 2

Sure just running a simple HTTP GET to google:  AEM log shows the GET itself is successful.  I have a apache proxy running on localhost (screenshot attached). Viewing the apache access log I can see there is no connection through the proxy.

public class CustomStep implements WorkflowProcess

{

    

    

/** Default log. */

protected final Logger log = LoggerFactory.getLogger(this.getClass());

//Inject a HTTP Factory Service

@Reference

private HttpClientBuilderFactory httpFactory;

    

public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {

        

try

{

    log.info("Here in execute method");    //ensure that the execute method is invoked  

  

  

    String url = "https://www.google.com";

    HttpClient client = httpFactory.newBuilder().build();

    HttpGet request = new HttpGet(url);

  

    HttpResponse response = client.execute(request);

  

    log.info("Response Code GET GOOGLE : "

            + response.getStatusLine().getStatusCode());

Screen Shot 2017-10-09 at 9.19.17 PM.png

Screen Shot 2017-10-09 at 9.23.18 PM.png

Avatar

Level 2

Hi Joseph,

Actually you're configuration settings did work! For some reason the apache logs with this configuration showed a 5 min delay. Thanks again for your help!