I'm trying to make a GET request in JAVA from an HttpServlet running on AppEngine. The request should be executed via a proxy server which has to be authorized (user and pass).
I tried using UrlFetch API, both high level (httpRequest) and low level (UrlConnection) but both didn't solve my problem.
When authorizing the proxy with
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication("User", "Pass".toCharArray()));
}
};
Authenticator.setDefault(authenticator);
I'm getting this exception when running on AppEngine:
java.security.AccessControlException: access denied ("java.net.NetPermission" "setDefaultAuthenticator") at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382) at java.security.AccessController.checkPermission(AccessController.java:572) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at
com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:55) at java.net.Authenticator.setDefault(Authenticator.java:127) at com.bionic.ig_dump.FetchUrlServlet.testProxy(FetchUrlServlet.java:92) at com.bionic.ig_dump.FetchUrlServlet.doGet(FetchUrlServlet.java:47) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
What is the best way to implement it correctly?
Thanks!