java 如何设置 Glassfish 以通过代理服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7274041/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:23:18  来源:igfitidea点击:

How do I set up Glassfish to go via a proxy server?

javaproxyconnectionglassfish

提问by Rónán ó Braonáin

I have been having issues with running a Glassfish v2.1.1 instance on my local machine from within the office, where we have a proxy server for outgoing connections. My initial workaround has been to work from home.

我在办公室内在本地机器上运行 Glassfish v2.1.1 实例时遇到问题,我们有一个用于传出连接的代理服务器。我最初的解决方法是在家工作。

I am calling a SOAP service on a HTTPS server outside of the company. As Glassfish is not going via the company's proxy server, I get the following error when trying to initialise my SOAP clients:

我正在公司外部的 HTTPS 服务器上调用 SOAP 服务。由于 Glassfish 不通过公司的代理服务器,因此在尝试初始化 SOAP 客户端时出现以下错误:

javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://www.hostname.com...

and

Caused by: java.net.UnknownHostException: www.hostname.com

I have proxy environment variables set on my command line, as well as my system proxy settings all working correctly so that I can get to the WSDL with the browser. How should I configure Glassfish?

我在命令行上设置了代理环境变量,以及我的系统代理设置都正常工作,以便我可以使用浏览器访问 WSDL。我应该如何配置 Glassfish?

回答by Rónán ó Braonáin

I had a lot of trouble finding an answer to this, as the topic isn't covered in a lot of detail on the web. One link told me how to configure the HTTP proxy, but mentioned nothing about HTTPS, so it took me a while to figure it out.

我很难找到答案,因为网络上没有详细介绍该主题。一个链接告诉我如何配置HTTP代理,但没有提到HTTPS,所以我花了一段时间才弄清楚。

Open up the admin console on your Glassfish server and go to: Application Server -> JVM Settings -> JVM Options. Click "Add JVM Option" 4 times and enter the following 4 options

打开 Glassfish 服务器上的管理控制台并转到:应用程序服务器 -> JVM 设置 -> JVM 选项。点击“Add JVM Option”4次,输入以下4个选项

-Dhttp.proxyHost=proxyhostname
-Dhttp.proxyPort=8080
-Dhttps.proxyHost=proxyhostname
-Dhttps.proxyPort=8080

Where proxyhostname and the port number are correct for your setup. Then you need to restart the server.

其中 proxyhostname 和端口号对于您的设置是正确的。然后你需要重新启动服务器。

Note that I couldn't find any options for setting up the proxy from a PAC file, nor for proxies which require auth. In this case, you may need to install a local auth proxy handler like Authoxy for Mac OS X, which turns your localhost into a non-auth proxy and masks the authentication request from the central auth proxy.

请注意,我找不到用于从 PAC 文件设置代理的任何选项,也找不到需要身份验证的代理。在这种情况下,您可能需要为 Mac OS X 安装一个像 Authoxy 这样的本地身份验证代理处理程序,它将您的本地主机变成一个非身份验证代理并屏蔽来自中央身份验证代理的身份验证请求。

Also, this link was good for various proxy options to the JVM: http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

此外,此链接适用于 JVM 的各种代理选项:http: //download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html

回答by home

You have to explicitly set the proxy server. Several options are available depending on the Glassfish version. In general you can set the proxy by either using JVM arguments or the Glassfish Admin console. An intro for GF3 is available here(sorry for only providing a link, but I do not want to repeat all the details here).

您必须明确设置代理服务器。根据 Glassfish 版本的不同,有几个选项可用。通常,您可以使用 JVM 参数或 Glassfish 管理控制台设置代理。GF3 的介绍可以在这里找到(抱歉只提供了一个链接,但我不想在这里重复所有的细节)。

回答by birraa

Just to make the answer complete, if the proxy requires user name and password, set the following in Glassfish:

为了使答案完整,如果代理需要用户名和密码,请在 Glassfish 中设置以下内容:

-Dhttp.proxyUser=someUserName
-Dhttp.proxyPassword=somePassword

回答by Marius Burz

The host cannot be resolved, are you sure you use a hostname resolvable by an internet DNS server or are you using something that can only be resolved from within your network or even worse, a hosts entry local to your machine?
Aside from that, the proxy server might be denying you access to some ports, but this is probably not your problem right now. If the proxy allows access to port 80, try running your Glassfish on port 80 as well if you get any connection timeout errors.

主机无法解析,您确定使用可由 Internet DNS 服务器解析的主机名,还是使用只能从您的网络内解析的内容,或者更糟的是,您的机器本地的主机条目?
除此之外,代理服务器可能会拒绝您访问某些端口,但这可能不是您现在的问题。如果代理允许访问端口 80,如果您遇到任何连接超时错误,请尝试在端口 80 上运行您的 Glassfish。