camel-http4 无法忽略 https 证书调用

发布于 2022-08-16 21:25:22 字数 2771 浏览 21 评论 4

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



请问,camel里面哪里配置有问题?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╄→承喏 2022-08-19 23:05:28

我也遇到一样的情况,请问有解决方法吗?

终难愈 2022-08-19 21:13:52

我都是2.14.1版本,加和不加是一样的。而且configureHttpClient方法已经执行了。最后结果不知道为啥不行

蓝眼睛不忧郁 2022-08-19 18:29:18

引用来自“滄海一夢”的评论

加个#号试下:

<touri="http4://invoke?httpClientConfigurer=#sslConfig"/>

野侃 2022-08-19 02:25:59

加个#号试下:

<touri="http4://invoke?httpClientConfigurer=#sslConfig"/>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文