【问题标题】:Set up proxy for Java app deployed in tomcat 8为部署在 tomcat 8 中的 Java 应用程序设置代理
【发布时间】:2019-07-03 09:58:50
【问题描述】:

我在 Tomcat 8.5 中部署应用程序。这个 tomcat 在代理后面运行。如果我使用 eclipse,应用程序可以正常运行,但不能在 Tomcat 中运行。我已经看到,如果我使用 Web 浏览器进行身份验证,应用程序运行正常,而身份验证仍然存在。一旦过期,我需要再次提供凭据。

我已尝试通过代码提供此信息,并将这些行添加到 catalina.bat:

http.proxyHost=proxy.myproxy.es

http.proxyPort=8080

http.proxyUser=用户名

http.proxyPassword=密码

System.setProperty("http.proxyHost", PROXY_SERVER);
System.setProperty("http.proxyPort", PROXY_PORT.toString());
System.setProperty("https.proxyHost", PROXY_SERVER);
System.setProperty("https.proxyPort", PROXY_PORT.toString());
System.setProperty("http.proxyUser", PROXY_USER);
System.setProperty("http.proxyPassword", PROXY_PASSWORD);
System.setProperty("http.proxySet", "true");
// AUTENTICAMOS EL PROXY
Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        if (getRequestorType() == RequestorType.PROXY) {
            String prot = getRequestingProtocol().toLowerCase();
            String host = System.getProperty(prot + ".proxyHost", PROXY_SERVER);
            String port = System.getProperty(prot + ".proxyPort",PROXY_PORT.toString());
            String user = System.getProperty(prot + ".proxyUser", PROXY_USER);
            String password = System.getProperty(prot + ".proxyPassword", PROXY_PASSWORD);
            if (getRequestingHost().equalsIgnoreCase(host)) {
                if (Integer.parseInt(port) == getRequestingPort()) {
                    return new PasswordAuthentication(user, password.toCharArray());
                }
            }
        }
        return null;
    }
});

我需要此身份验证自动运行。

编辑:此代理应由第 3 方类使用。如果我创建一个到 google.com 之类的随机 URL 的新连接,然后向 3rd 方类发出请求,它可以正常工作,所以我假设它没有使用 Authenticator.setDefault。对正在发生的事情有任何想法吗?

【问题讨论】:

  • 你有什么问题?
  • 如何在不通过浏览器提供凭据的情况下使其工作。为什么 tomcat 不使用 setProperty 值?

标签: java tomcat proxy


【解决方案1】:

最后,第 3 方课程有一个错误。 关闭

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多