Camel——http4组件https使用

Camel——http4组件https使用

camel配置pom文件

<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-http4</artifactId>
	<version>2.17.1</version>
</dependency>

使用springcamel的DSL实现https配置,配置xml如下:

<!-- 配置ssl证书 -->
	<camel:sslContextParameters id="sslContextParameters">
		<camel:trustManagers>
			<camel:keyStore resource="ca.jks"
				password="123456" type="JKS" />
		</camel:trustManagers>
		<camel:keyManagers keyPassword="IoM@1234">
			<camel:keyStore resource="CertwithKey.pkcs12"
				password="123456" type="PKCS12" />
		</camel:keyManagers>
	</camel:sslContextParameters>
	
	<bean id="https4" class="org.apache.camel.component.http4.HttpComponent">
		<property name="sslContextParameters" ref="sslContextParameters" />
	</bean>

配置route,做一个登陆认证的流程,route配置如下:

<route id="login">
	<from id="1" uri="timer://foo5?fixedRate=true&amp;period=60000&amp;repeatCount=1" />
	<to id="2" uri="bean:com.process.login.LoginRequestProcess" />
	<to id="3" uri="https4://{{platform.url}}/?x509HostnameVerifier=#allowAllHostnameVerifier" />
	<convertBodyTo charset="UTF-8" id="4" type="String" />
	<to id="5" uri="bean:com.process.login.LoginResponseProcess" />
	<log id="_log12" logName="login" message="登录${body} " />
</route>

上图中https4配置参数x509HostnameVerifier=#allowAllHostnameVerifier,其作用是不验证证书的域名。

配置allowAllHostnameVerifier参数需在camel的xml中添加bean配置:

<bean id="allowAllHostnameVerifier" class="org.apache.http.conn.ssl.AllowAllHostnameVerifier"/>

如果配置值参数:运行错误如下:

2018-09-05 18:00:15.433 [Camel (camelContext-2dbf370a-2c54-4112-bda1-6939520839db) thread #0 - timer://foo5] WARN  o.a.c.component.timer.TimerConsumer	-Error processing exchange. Exchange[ID-DESKTOP-1666376-56398-1536141613101-0-2]. Caused by: [javax.net.ssl.SSLPeerUnverifiedException - Host name '10.10.20.11' does not match the certificate subject provided by the peer (CN=demo.com, OU=CN, O=Huawei, L=SZ, ST=GD, C=CN)]
javax.net.ssl.SSLPeerUnverifiedException: Host name '10.10.20.11' does not match the certificate subject provided by the peer (CN=demo.com, OU=CN, O=Huawei, L=SZ, ST=GD, C=CN)
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.verifyHostname(SSLConnectionSocketFactory.java:465) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:395) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:141) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[httpclient-4.5.2.jar:4.5.2]
	at org.apache.camel.component.http4.HttpProducer.executeMethod(HttpProducer.java:301) ~[camel-http4-2.17.1.jar:2.17.1]
	at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:173) ~[camel-http4-2.17.1.jar:2.17.1]
	at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) [camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:121) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83) ~[camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:190) [camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:192) [camel-core-2.17.1.jar:2.17.1]
	at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:76) [camel-core-2.17.1.jar:2.17.1]
	at java.util.TimerThread.mainLoop(Unknown Source) [na:1.8.0_91]
	at java.util.TimerThread.run(Unknown Source) [na:1.8.0_91]

当Content-type为application/x-www-form-urlencoded

需设置body数据格式:a=xxx&bb=XXX

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值