0

在 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

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

谢谢

4

1 回答 1

0

Hello I just faced this issue with the apache cxf client, the workaround suggested in the mailing list is to use the following static method of the java.net.Authenticator class :

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

This way the basic will be set automatically on all your HttpUrlConnection that uses the proxy, since java 8 you also have to enable basic authentication for HTTPS tunneling, you can do this with the following property:

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

I hope this helps

于 2019-12-31T14:35:42.027 回答