weblogic.net.http.HttpUnauthorizedException: Proxy or Server Authentication Required at weblogic.net.http.HttpURLConnection.getAuthInfo(HttpURLConnection.java:284) at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:455) at weblogic.net.http.SOAPHttpURLConnection.getInputStream(SOAPHttpURLConnection.java:36) at com.google.api.GoogleAPI.retrieveJSON(GoogleAPI.java:112) ... 45 moreI encountered the above error while attempting to test my Oracle ADF sample application that integrates with the Google Translate behind a proxy. I believe this error applies when your application tries to access the internet while behind a firewall that requires proxy authentication.
Below are the steps that resolved the issue above:
- Extend java.net.Authenticator class and override the getPasswordAuthentication() method.
- Set System properties for the http:proxyHost, http:proxyPort
- Set your custom authenticator above as the default authenticator.
- Modify the instantiation of the URL
package soadev.blogspot.googletranslateapi.common;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class MyAuthenticator extends Authenticator {
private String username;
private String password;
public MyAuthenticator(String username, String password){
this.username = username;
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication () {
return new PasswordAuthentication (username, password.toCharArray());
}
}
Below are the code snippets (as it applies to my case) that illustrates the steps above:
System.setProperty("http.proxyHost", "myproxy");
System.setProperty("http.proxyPort", "8080");
Authenticator.setDefault (new MyAuthenticator("XXXXXX\\username","password"));
Below is how I instantiate the external URL to be accessed:
... final URL url = new URL(null, "http://your_external_URL", new sun.net.www.protocol.http.Handler());notes for readers of my blogpost on leveraging the google translate api: To run your test behind proxy, you need to modify the execute() method of the Translate class to reflect the proper way of instantiating the URL.
Cheers!
pino
