camel-http4 无法忽略 https 证书调用
camel的配置如下:
<bean id="sslConfig" class="com.pp.bean.SSLHttpClientConfigurer" /> <route> <from uri="direct://start-http" /> <setHeader headerName="CamelHttpMethod"> <constant>POST</constant> </setHeader> <setHeader headerName="CamelHttpUri"> <constant>https://www.xxxxx.com/api/v1/rest.do</constant> </setHeader> <setProperty propertyName="CamelCharsetName"> <constant>UTF-8</constant> </setProperty> <to uri="http4://invoke?httpClientConfigurer=sslConfig" /> <to uri="bean:showBody" /> </route>
package com.pp.bean; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.SSLContext; import org.apache.camel.component.http4.HttpClientConfigurer; import org.apache.http.conn.ssl.SSLContextBuilder; import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.impl.client.HttpClientBuilder; public class SSLHttpClientConfigurer implements HttpClientConfigurer { public void configureHttpClient(HttpClientBuilder clientBuilder) { try { SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() { // 信任所有 public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); clientBuilder.setSslcontext(sslContext); }catch(Exception e) { } } }
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(Unknown Source) at sun.security.validator.PKIXValidator.engineValidate(Unknown Source) at sun.security.validator.Validator.validate(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) ... 40 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source) at java.security.cert.CertPathBuilder.build(Unknown Source) ... 46 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我也遇到一样的情况,请问有解决方法吗?
我都是2.14.1版本,加和不加是一样的。而且configureHttpClient方法已经执行了。最后结果不知道为啥不行
引用来自“滄海一夢”的评论
加个#号试下:
<touri="http4://invoke?httpClientConfigurer=#sslConfig"/>
加个#号试下:
<touri="http4://invoke?httpClientConfigurer=#sslConfig"/>