Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

407 Proxy Authentication required

Avatar

Level 3

Am trying to consume a web service which is running on different sub-domain but on the same domain. I am getting 407 - Proxy Authentication Required. Not really sure this was firewall issue or my coding issue. Below is code which I am using to call the webservice from OSGI Component class.


       String  url = "https://banking.pnc.com";
        PostMethod post = null;
        BufferedReader br = null;
        try {
            HttpClient httpClient = new HttpClient();
            post = new PostMethod(url);
            post.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));

            String json_Params = "{\"token\":\"" + token + "\",\"usrName\":\"" + userName + "\",\"password\":\"" + password + "\"}";
            StringRequestEntity requestEntity = new StringRequestEntity(json_Params, "application/json", "UTF-8");
            post.setRequestEntity(requestEntity);

            int statusCode = httpClient.executeMethod(post);
            logger.debug("statusCode :::"+statusCode);
            logger.debug("response body :::"+post.getResponseBodyAsString());
            response.setStatus(statusCode);
           

        } catch (Exception e) {
            logger.error("Error while ", e);
        } finally {
            if (post != null)
                post.releaseConnection();
            if (br != null)
                br.close();
        }

Have done the proxy settings in OSGI Config "Day Commons HTTP Client 3.1", 

Is my code is correct ? if I initiate  HttpClient httpClient = new HttpClient(); will it will pass through the Proxy,as am i configured proxy in OSGI config "Day Commons HTTP Client 3.1" ? 

Please do let me know if you need any more detials?

Thanks,

Chandra

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

The proxy configuration which you have done in OSGI configuration isn't going to work in your code because you are instantiating the client object using the new operator. 

Make the following changes in your code- (I assume you are consuming this service in an OSGI Java component in AEM)

//Add the HTTP Client Builder Factory reference like below in your OSGI component. @Reference private HttpClientBuilderFactory httpFactory; //in your method then you can get the HTTP Client object. HTTPClient client =  httpFactory.newBuilder().build();

View solution in original post

3 Replies

Avatar

Level 10

try getting this code to work outside of AEM - in an Eclipse project - that will inform you if its a network issue as opposed to an OSGi config issue. 

Avatar

Correct answer by
Employee Advisor

The proxy configuration which you have done in OSGI configuration isn't going to work in your code because you are instantiating the client object using the new operator. 

Make the following changes in your code- (I assume you are consuming this service in an OSGI Java component in AEM)

//Add the HTTP Client Builder Factory reference like below in your OSGI component. @Reference private HttpClientBuilderFactory httpFactory; //in your method then you can get the HTTP Client object. HTTPClient client =  httpFactory.newBuilder().build();

Avatar

Employee Advisor

Also, add your proxy settings in Apache HTTP Components Proxy Configuration  instead of Day Commons HTTP Client 3.1.