簡體   English   中英

使用 CXF 通過代理進行 https 調用時出錯

[英]Error during https call through proxy using CXF

在 camel-cxf 中,我必須通過代理調用 SOAP web 服務(在 https 中公開):配置 http 管道如下

public void configureClient(Client client) {

        String proxySrv = Util.getProperty(Constants.Config.PROXY_SRV);
        int proxyPort = new Integer(Util.getProperty(Constants.Config.PROXY_PORT));
        log.info("Configurazione del server proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setProxyServer(proxySrv); // set proxy host
        policy.setProxyServerPort(proxyPort); // set proxy port
        policy.setProxyServerType(ProxyServerType.SOCKS);
        conduit.setClient(policy);
        conduit.setAuthSupplier(new DefaultBasicAuthSupplier());
        boolean proxyAuthEnabled = new Boolean(Util.getProperty(Constants.Config.PROXY_AUTH_EN));
        String user = Util.getProperty(Constants.Config.PROXY_USER);
        String pass = Util.getProperty(Constants.Config.PROXY_PASS);
        log.info("Recuperati username:'+"+user+"' e password per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");
        if (proxyAuthEnabled) {
            ProxyAuthorizationPolicy ap =  new ProxyAuthorizationPolicy();
            ap.setUserName(user);
            ap.setPassword(pass);
            conduit.setProxyAuthorization(ap);
//          conduit.getAuthorization().setUserName(user);
//          conduit.getAuthorization().setPassword(pass);
            log.info("Autenticazione abilitata per userName ='"+user+"' per il proxy:'"+proxySrv+"' port:'"+proxyPort+"'");

        }

它適用於 http 調用(未設置代理服務器類型)但不適用於 https 調用。 此代理需要基本身份驗證。

閱讀各種文章后,我發現 CXF 中存在一個錯誤,它不會在 CONNECT 調用中發送標頭授權(事實上,我得到了 407 Authorization required -> 即使使用與 http 調用相同的憑據,它也能正常工作)。

有辦法解決嗎? 我讀到了 Olivier Billard 解決方案

https://www.mail-archive.com/users@cxf.apache.org/msg06422.html

但我並沒有理解該解決方案(而且我無法在代碼中導入任何密鑰庫)。

謝謝

你好,我剛剛遇到了 apache cxf 客戶端的這個問題,郵件列表中建議的解決方法是使用java.net.Authenticator類的以下靜態方法:

Authenticator.setDefault(new Authenticator() {
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("youruser", "yourpassword".toCharArray());
          }
        });

這樣,將在所有使用代理的HttpUrlConnection上自動設置 basic,因為 java 8 您還必須為 HTTPS 隧道啟用基本身份驗證,您可以使用以下屬性執行此操作:

-Djdk.http.auth.tunneling.disabledSchemes=""

我希望這有幫助

暫無
暫無

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

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