Mule 骡子';无法在流中使用的http代理?
我想为后端rest服务做一个代理,但是在我将请求转发到后端之前,我需要做一些检查。我查看了文档,有一个http代理可以用来做代理,但是当我放入流时,有例外。如果使用http:outbound端点,则该方法不能是动态MEL表达式(rest方法可以是POST、GET、PUT、DELTE等) 你能给我一个建议吗?举个例子会更好,非常感谢。 我的配置:Mule 骡子';无法在流中使用的http代理?,mule,Mule,我想为后端rest服务做一个代理,但是在我将请求转发到后端之前,我需要做一些检查。我查看了文档,有一个http代理可以用来做代理,但是当我放入流时,有例外。如果使用http:outbound端点,则该方法不能是动态MEL表达式(rest方法可以是POST、GET、PUT、DELTE等) 你能给我一个建议吗?举个例子会更好,非常感谢。 我的配置: <flow name="demo.routerFlow1" doc:name="demo.routerFlow1"> <http:
<flow name="demo.routerFlow1" doc:name="demo.routerFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="HTTP" />
<logger
message="Method: #[message.inboundProperties['http.method']], URI: #[message.inboundProperties['http.request.path']], Params: #[message.inboundProperties['http.query.params']]"
level="INFO" doc:name="Logger" />
<http:body-to-parameter-map-transformer doc:name="Body to Parameter Map" />
<choice doc:name="Choice">
<when expression="(payload['timestamp'] == null || payload['nonce'] == null)">
<expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA001\", \"message\":\"missing required parameter timestamp and nonce\"}"]]>
</expression-component>
</when>
<otherwise>
<choice doc:name="Choice">
<when expression="!replayAttackCheck.validate(payload)" evaluator="groovy">
<expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA002\", \"message\":\"timestamp or nonce is illegal\"}"]]>
</expression-component>
</when>
<otherwise>
<processor-chain doc:name="Processor Chain">
<pattern:http-proxy name="http-proxy-sample"> <!--line 38-->
<http:inbound-endpoint address="http://localhost:8080/"></http:inbound-endpoint>
<http:outbound-endpoint address="http://localhost:8081/"></http:outbound-endpoint>
</pattern:http-proxy>
</processor-chain>
</otherwise>
</choice>
</otherwise>
</choice>
</flow>
配置模式是独立的,独立于任何流,不能在一个流中配置。它们是用于常见场景的预定义集成模式。流量是用来滚动你自己的。请看这里: 作为旁注:您已经在localhost:8080上侦听了,所以我认为您只需要在8081上运行的服务上有一个http:outbound端点
<http:outbound-endpoint address="http://localhost:8081/" />
您只需要一个http:outbound到块中的实际rest服务 尝试使用以下命令
<otherwise>
<http:outbound-endpoint address="http://localhost:8081/"></http:outbound-endpoint>
</otherwise>
希望这能有所帮助。但我无法设置动态方法,例如:请求的负载将自动跨端点传播。如果要跨出站端点传播所有入站属性,可以使用:或手动复制所需的属性。如果需要动态构造URL,那么scheme:e“http://”在“address”字段中必须是静态的,而不能是动态的。或者我用过,没关系。谢谢Ryan。我用过,get和post没问题,但是PUT和DELTE出现了错误:HTTP方法或内容类型不受支持!这是另一个问题。您正在使用的http:body-to-parameter映射转换器只支持GET和POST。请参见此处:。您可以将该变压器封装在a选择路由器中,即,谢谢,请参阅我上面的评论?
<otherwise>
<http:outbound-endpoint address="http://localhost:8081/"></http:outbound-endpoint>
</otherwise>