java 使用 URLEndpoint 通过代理的 SOAP 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4928272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SOAP connections through a proxy using URLEndpoint
提问by Rudiger
I've had to update a previous java application that requests a SOAP response from an external web service. This service is outside our firewall which now requires us to go through a proxy instead of hitting the URL directly.
我不得不更新以前的 Java 应用程序,该应用程序从外部 Web 服务请求 SOAP 响应。该服务在我们的防火墙之外,现在需要我们通过代理而不是直接访问 URL。
Currently the Java App uses URLEndpoint that takes a string for the URL. Usually when I am getting to a URL through a proxy I create a URL like so:
目前,Java 应用程序使用 URLEndpoint,它采用 URL 字符串。通常,当我通过代理访问 URL 时,我会创建一个如下所示的 URL:
URL url = new URL("http", "theproxy.com", 5555, finalUrl);
The problem is URLEndpoint only takes a string for the url, I tried to convert URL to string using toExternalForm() but it malformed the URL.
问题是 URLEndpoint 只需要一个字符串作为 url,我尝试使用 toExternalForm() 将 URL 转换为字符串,但它的 URL 格式错误。
Any ideas as to a way around this?
关于解决这个问题的任何想法?
EDIT: I can't use System.setProperty as this runs with a whole heap of other Java applications in tomcat.
编辑:我不能使用 System.setProperty,因为它在 tomcat 中与一大堆其他 Java 应用程序一起运行。
second edit: I can't set a system properties as it will override all other applications running on the server, I can't use jsocks as the proxy we run through squid proxy which does not support socks4/5
第二次编辑:我无法设置系统属性,因为它会覆盖服务器上运行的所有其他应用程序,我不能使用 jsocks 作为我们通过不支持 socks4/5 的鱿鱼代理运行的代理
Any help appreciated.
任何帮助表示赞赏。
回答by Will Hartung
That's not how proxy's work. The way a proxy works is that you take your normal URL:
这不是代理的工作方式。代理的工作方式是使用普通 URL:
http://example.com/service
and instead of looking up "example.com" and port 80, the message is sent to your proxy host instead (http://theproxy.com:5555).
而不是查找“example.com”和端口 80,而是将消息发送到您的代理主机(http://theproxy.com:5555)。
Java has built in proxy handling using http.proxyHost and http.proxyPort System properties.
Java 使用 http.proxyHost 和 http.proxyPort 系统属性内置了代理处理。
So in your case you would need to do:
因此,在您的情况下,您需要执行以下操作:
System.setProperty("http.proxyHost", "theproxy.com");
System.setProperty("http.proxyPort", "5555");
Then your code should, ideally, "Just Work".
那么理想情况下,您的代码应该“正常工作”。
Hereis a page documenting the proxy properties.
这是一个记录代理属性的页面。
回答by ThomasRS
Use Apache HttpClientand do as show in thisexample.
使用Apache HttpClient并按照本示例中的说明进行操作。
回答by Christ
About the URL constructor with individual proxy setting:
关于具有单独代理设置的 URL 构造函数:
http://edn.embarcadero.com/article/29783
http://edn.embarcadero.com/article/29783
(sorry don't have privileges to comment)
(抱歉没有评论权限)