簡體   English   中英

為部署在 tomcat 8 中的 Java 應用程序設置代理

[英]Set up proxy for Java app deployed in tomcat 8

我正在 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。 關於發生了什么的任何想法?

最后,第 3 方課程有一個錯誤。 關閉

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM