407 Proxy Authentication required | Community
Skip to main content
New Participant
February 16, 2016
Solved

407 Proxy Authentication required

  • February 16, 2016
  • 3 replies
  • 3376 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kunal_Gaba_

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();

3 replies

Kunal_Gaba_
New Participant
February 17, 2016

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

Kunal_Gaba_
Kunal_Gaba_Accepted solution
New Participant
February 17, 2016

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();
smacdonald2008
New Participant
February 17, 2016

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.