[英]Reverse Proxy: Accessing .Net Web Application from Java Web Application
[英]Play java application accessing a Web Service through an Authenticating Proxy
我正在开发Play Java应用程序,它需要通过身份验证代理使用Play WS API(JavaWS)连接到另一个REST服务(即,代理需要用户名/密码)。
首先,我在启动Play应用时尝试使用下面提供的JVM选项。
-Dhttp.proxyHost=<proxy_server_hostname> -Dhttp.proxyPort=<proxy_server_port> -Dhttp.proxyUser=<username> -Dhttp.proxyPassword=<password>
上面的没有完全工作。 应用程序能够毫无问题地连接到代理服务器,但是代理服务器返回PROXY_AUTH_REQUIRED错误,该错误表明-Dhttp.proxyUser和-Dhttp.proxyPassword JVM选项不起作用。
我搜索并找到以下两个链接,这些链接显示了如何在典型的Java应用程序中执行此操作。
http://memorynotfound.com/configure-http-proxy-settings-java/ http://rolandtapken.de/blog/2012-04/java-process-httpproxyuser-and-httpproxypassword
就像这两个链接中所建议的那样,我如下修改了Global.java中Play应用程序的onStart方法,
@Override
public void onStart(Application application) {
//Proxy authentication begin
System.setProperty("http.proxyHost", "<proxy_server_hostname>");
System.setProperty("http.proxyPort", "<proxy_server_port>");
System.setProperty("http.proxyUser", "<username>");
System.setProperty("http.proxyPassword", "<password>");
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY) {
String prot = getRequestingProtocol().toLowerCase();
String host = System.getProperty(prot + ".proxyHost", "");
String port = System.getProperty(prot + ".proxyPort", "");
String user = System.getProperty(prot + ".proxyUser", "");
String password = System.getProperty(prot + ".proxyPassword", "");
if (getRequestingHost().equalsIgnoreCase(host)) {
if (Integer.parseInt(port) == getRequestingPort()) {
return new PasswordAuthentication(user, password.toCharArray());
}
}
}
return null;
}
});
//Proxy authentication end
}
通过上面的修改,我启动了Play应用程序,而没有指定前面提到的JVM选项(因为我现在在代码中提供了相同的选项)。 但是结果保持不变。 代理服务器仍然向应用程序返回PROXY_AUTH_REQUIRED错误消息。 再次,应用程序通过上述代码修改连接到代理服务器,但是Java Authenticator似乎没有将代理用户名和密码提交给代理服务器。
还是在Play Java应用程序中有其他方法可以做到这一点?
谢谢
网络身份验证:类身份验证器
- The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually, it will do this by prompting
the user for information.
- Can be used when credential need to be sent over network.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.