组件http4的使用"/>
Apache Came组件http4的使用
http : For calling out to external HTTP servers using Apache HTTP Client 3.x
http4 : For calling out to external HTTP servers using Apache HTTP Client 4.x
其实是一样的,只是底层用的http client版本不一样
现在以http4为例子
示例一:http调用
<route><from uri="direct://start-http" /><!-- 指定提交方式 --><setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader><!-- 指定请求参数 --><setHeader headerName="CamelHttpQuery"><constant>account=hongshu&client_id=111111&response_type=code</constant></setHeader><!-- 指定请求地址 --><setHeader headerName="CamelHttpUri"><constant>;/constant></setHeader><!-- 指定请求的编码方式 --><setProperty propertyName="CamelCharsetName"><constant>UTF-8</constant></setProperty><!-- 执行(调用完成后,body是inputStream,转换成string即可) --><to uri="http4://http" /><!-- 转换成string --><convertBodyTo type="java.lang.String" charset="UTF-8" /><to uri="log:show?showAll=true&multiline=true" />
</route>
示例二:https调用
<!-- 配置ssl证书 -->
<camel:sslContextParameters id="sslContextParameters"><camel:trustManagers><camel:keyStore resource="/opt/ssl/key/cacerts.jks" password="changeit" /></camel:trustManagers>
</camel:sslContextParameters><route><from uri="direct://start-http" /><!-- 指定提交方式 --><setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader><!-- 指定请求参数 --><setHeader headerName="CamelHttpQuery"><constant>account=hongshu&client_id=111111&response_type=code</constant></setHeader><!-- 指定请求地址 --><setHeader headerName="CamelHttpUri"><constant>;/constant></setHeader><!-- 指定请求的编码方式 --><setProperty propertyName="CamelCharsetName"><constant>UTF-8</constant></setProperty><!-- 执行,并且指定ssl的证书路径 (调用完成后,body是inputStream,转换成string即可)--><to uri="http4://http?sslContextParametersRef=sslContextParameters" /><to uri="log:show?showAll=true&multiline=true" />
</route>
更多推荐
Apache Came组件http4的使用
发布评论