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

孤好梦中X人 发布于 2015/09/17 13:30
阅读 1K+
收藏 0

开源之夏第三届火热来袭,高校学生参与赢万元奖金!>>>

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里面哪里配置有问题?

加载中
0
vidy_tu
vidy_tu

加个#号试下:

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

0
孤好梦中X人
孤好梦中X人

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

加个#号试下:

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

不行。 顺便问一下 #代表什么

孤好梦中X人
孤好梦中X人
我都是2.14.1版本,加和不加是一样的。而且configureHttpClient方法已经执行了。最后结果不知道为啥不行
vidy_tu
vidy_tu
该评论暂时无法显示,详情咨询 QQ 群:点此入群
0
z
zb171681

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

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部