【问题标题】:Error during https call through proxy using CXF使用 CXF 通过代理进行 https 调用时出错
【发布时间】:2019-04-11 16:02:14
【问题描述】:

在 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

但我没有理解该解决方案(而且我无法在代码中导入任何密钥库)。

谢谢

【问题讨论】:

    标签: proxy cxf http-conduit


    【解决方案1】:

    您好,我刚刚在 apache cxf 客户端上遇到了这个问题,邮件列表中建议的解决方法是使用 java.net.Authenticator 类的以下静态方法:

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

    这样,所有使用代理的HttpUrlConnection 都会自动设置基本信息,因为java 8 你还必须为HTTPS 隧道启用基本身份验证,你可以使用以下属性来做到这一点:

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

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-12
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      • 2012-05-18
      • 1970-01-01
      相关资源
      最近更新 更多