使用camel-http4进行https调用的正确语法

时间:2018-04-24 22:32:16

标签: apache-camel camel-http

我无法让HTTP4正常工作。我试图对https网站发出POST请求。然而,似乎没有任何作用。谁能告诉我用HTTP4执行HTTPS POST的正确方法是什么?非常感谢你,真的很挣扎。只需要知道我做错了什么......简单的东西总是转向南方。

我已经尝试过了。

http4://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token
https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io/oauth/token
http4://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io/oauth/token
https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token
http4:https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token

但似乎什么都没有用?

3 个答案:

答案 0 :(得分:1)

请使用bridgeEndpoint = true,以便您可以走出服务器

答案 1 :(得分:0)

camel-http4组件适合我想要实现的目标。我只需要生成一个端点。我不是要尝试公开Web服务。但是,谢谢你的回复。

camel-http4 vs camel-jetty

您只能生成由camel-http4组件生成的端点。因此,它永远不应该用作Camel路由的输入。要通过HTTP服务器绑定/公开HTTP端点作为Camel路由的输入,请改用Jetty组件。

我发现定义HTTP4端点的正确方法是

http4:hostname[:port][/resourceUri][?options]

我遇到的问题是动态的toD路由,以及Exchange.HTTP_URI设置的替换,这不应该正常工作。

因此,使用诸如

之类的uri
http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.uaa.run.aws-us.ice.io:443/oauth/token

的工作原理。机制,不起作用。

Exchange.HTTP_URI

要调用的URI。此选项的值将覆盖直接在端点上设置的现有URI。它与Camel端点URI不同,您可以在其中配置端点选项,例如安全性等。此标头不支持它,它只是HTTP服务器的URI。

    <route 
        id="core.getToken.route"
        autoStartup="true" >
        <from id="getToken" ref="getToken" />
        <process ref="uAARequestTokenProcessor" />
<!--        <log message="Message after uAARequestTokenProcessor:  ${body}" loggingLevel="INFO"/>   -->
         <setHeader headerName="CamelHttpMethod">
            <constant>POST</constant>
         </setHeader>
<!--         <setHeader headerName="CamelHttpUri">
            <simple>${header.TOKENURL}</simple>
         </setHeader>  -->
        <log message="HTTP4 POST headers: ${headers}" loggingLevel="DEBUG"/>
        <log message="HTTP4 POST body: ${body}" loggingLevel="DEBUG"/> 
        <to uri="http4://d1e-uaa.run.aws-usw02-pr.ice.io:443/oauth/token?throwExceptionOnFailure=false" />
        <toD uri="${header.TOKENURL}?throwExceptionOnFailure=false" />
        <log message="After HTTP4 POST: ${body}" loggingLevel="INFO"/>
        <to uri="{{accessToken}}" />    
    </route>    

所以对我来说,设置Exchange.HTTP_URI并不是要覆盖端点中定义的URI

其中Exchange.HTTP_URI定义为: TOKENURL = http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.uaa.run.aws-usw02-pr.ice.io:443 /的OAuth /令牌

这是不起作用的。谢谢。

答案 2 :(得分:0)

好吧,我希望这有助于某人,解决方案是2折。首先代理没有得到确认,由于领先的协议def,http://我只使用IP地址和没有http://的cononical名称,我能够收到504网关超时错误。所以HTTP4端点正常工作,因为它设置为

http4://myhost:443/path
http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token

我能够通过首先制作硬终端

来获得请求
    <to uri="http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token?throwExceptionOnFailure=false" />

所以端点http4通过设置

覆盖
m.setHeader(Exchange.HTTP_URI, tokenUrl);

的工作。

然后我尝试使用他在路由中覆盖的XML设置。

<log message="HTTP4 POST headers: ${headers}" loggingLevel="DEBUG"/>
<setHeader headerName="CamelHttpUri">
    <simple>${header.TOKENURL}?throwExceptionOnFailure=false</simple>
</setHeader>
<to uri="http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token?throwExceptionOnFailure=false" />

这也有效。 :)但是我仍然得到返回504网关超时错误。

我尝试将https:// URI用于覆盖URI

https://uaa-svc-prod.app-api.aws-usw02-pr.io/oauth/token

并使用https:// URI覆盖了http4://端点,现在我得到了CamelHttpResponseCode = 401,CamelHttpResponseText =未经授权

所以,现在正在工作,幸福快乐的喜悦...... 总之,在代理设置中不包括http:// protocol def。使用IP或标准名称。

   <camelContext     
      id="com.ge.digital.passthru.coreCamelContext"
      trace="true"
      xmlns="http://camel.apache.org/schema/blueprint"
      allowUseOriginalMessage="false"
      streamCache="true"
      errorHandlerRef="deadLetterErrorHandler" >
      <properties>
           <property key="http.proxyHost" value="PITC-Zscaler.proxy.corporate.america.com"/>
           <property key="http.proxyPort" value="80"/>
      </properties>

定义HTTP4://端点时使用语法

http4:hostname[:port][/resourceUri][?options]

并且Exchange.HTTP_URI设置的URI越过端点def包含您正在呼叫的https://myhost/path

这对我有用,我希望这能帮助像我这样的新手。 感谢大家。

相关问题