[英]Error during https call through proxy using CXF
In camel-cxf I have to call a SOAP webservice (exposed in https) through a proxy: configuring the http conduit as follows在 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+"'");
}
it works for http call (without the proxy server type set) but it doesn't work for https call.它适用于 http 调用(未设置代理服务器类型)但不适用于 https 调用。 This proxy requires basic auth.
此代理需要基本身份验证。
Reading various articles I saw that there is a bug in CXF that doesn't send the header authorization in the CONNECT call (and infact I'm getting 407 Authorization required -> even if with the same credentials with http calls it works).阅读各种文章后,我发现 CXF 中存在一个错误,它不会在 CONNECT 调用中发送标头授权(事实上,我得到了 407 Authorization required -> 即使使用与 http 调用相同的凭据,它也能正常工作)。
Is there a way to fix it?有办法解决吗? I read about Olivier Billard solution
我读到了 Olivier Billard 解决方案
https://www.mail-archive.com/users@cxf.apache.org/msg06422.html https://www.mail-archive.com/users@cxf.apache.org/msg06422.html
but I didn't undestand that solution (and I can't import at code any keystore).但我并没有理解该解决方案(而且我无法在代码中导入任何密钥库)。
Thanks谢谢
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:你好,我刚刚遇到了 apache cxf 客户端的这个问题,邮件列表中建议的解决方法是使用
java.net.Authenticator
类的以下静态方法:
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:这样,将在所有使用代理的
HttpUrlConnection
上自动设置 basic,因为 java 8 您还必须为 HTTPS 隧道启用基本身份验证,您可以使用以下属性执行此操作:
-Djdk.http.auth.tunneling.disabledSchemes=""
I hope this helps我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.