Apache Camel http4 blueprint

1.HTTP

<route>  
    <from uri="direct://start-http" />  
    <!-- 指定提交方式 -->  
    <setHeader headerName="CamelHttpMethod">  
        <constant>POST</constant>  
    </setHeader>  
    <!-- 指定请求参数 -->  
    <setHeader headerName="CamelHttpQuery">  
        <constant>account=xxx&client_id=xxx&response_type=code</constant>  
    </setHeader>  
    <!-- 指定请求地址 -->  
    <setHeader headerName="CamelHttpUri">  
        <constant>http://www.oschina.net/cnblog</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>

2.HTTPS

<!-- 配置ssl证书 -->  
<camel:sslContextParameters id="sslContextParameters">  
    <camel:trustManagers>  
        <camel:keyStore resource="D:/opt/ssl/key/certs.jks" password="123456" />  
    </camel:trustManagers>  
</camel:sslContextParameters>  
  
<route>  
    <from uri="direct://start-http" />  
    <!-- 指定提交方式 -->  
    <setHeader headerName="CamelHttpMethod">  
        <constant>POST</constant>  
    </setHeader>  
    <!-- 指定请求参数 -->  
    <setHeader headerName="CamelHttpQuery">  
        <constant>account=xxx&client_id=xxx&response_type=code</constant>  
    </setHeader>  
    <!-- 指定请求地址 -->  
    <setHeader headerName="CamelHttpUri">  
        <constant>https://www.oschina.net/action/oauth2/authorize</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>

注意:

<!-- 配置ssl证书 --> 除了(trustManagers)
<camel:sslContextParameters id="sslContextParameters">  
    <camel:trustManagers>  
        <camel:keyStore resource="D:/opt/ssl/key/certs.jks" password="123456" />  
    </camel:trustManagers>  
</camel:sslContextParameters>  

方式,还有另外一种方式(keyManagers)

<camel:sslContextParameters
      id="sslContextParameters">
    <camel:keyManagers
        keyPassword="123456">
      <camel:keyStore
          resource="D:/users/home/server/keystore.jks"
          password="12345678"/>
    </camel:keyManagers>
</camel:sslContextParameters>

但是这两种方式有很大区别

区别1:keyManagers指定自己的私钥证书,trustManagers指定受信任的证书库;

区别2:keyManagers一般是自己的证书,trustManagers里面一般是别人的证书;

区别3:别人给过来的jks文件里面如果是私钥,那么用keyManagers,如果是公钥则直接用trustManagers;


你可能感兴趣的:(apache,camel,Http4)