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

proper syntax using camel-http4 for an https call

我只是无法让这个 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

但似乎没有任何效果?

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

camel-http4 对比 camel-jetty

您只能生产到由 camel-http4 组件生成的端点。因此,它永远不应该用作您的骆驼路线的输入。要通过 HTTP 服务器 bind/expose 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 不同,您可以在其中配置端点选项,例如安全性等。header 不支持它,它只是 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/token

这是行不通的。谢谢。

好的,我希望这对某人有所帮助,解决方案是 2 倍。首先代理没有得到确认,由于领先的协议 def,http:// 我只使用了 IP 地址和锥形名称,没有 http:// 并且我能够收到 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

并且 http4:// 端点被 https:// URI 覆盖,现在我得到一个 CamelHttpResponseCode=401, CamelHttpResponseText=Unauthorized

所以,它现在正在工作,happy happy happy joy joy... 总之,不要在代理设置中包含 http:// 协议定义。使用 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

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

请使用 bridgeEndpoint=true 以便您可以离开服务器