2014-10-06 358 views
0

流中的传出HTTP端点返回状态500,但Mule不引发异常。当我步调试流程,显然存在一个例外有效载荷目前HTTP调用后,但贯穿始终的流动游行:Mule HTTP端点返回状态500但不会抛出异常

<flow name="pocFlow2" doc:name="pocFlow2"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8081" path="poc/error" doc:name="HTTP"/> 
    <!-- This one returns 500 error --> 
    <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/> 
    <object-to-string-transformer doc:name="Object to String"/> 
    <set-payload value="All good" doc:name="Set Payload"/> 
    <catch-exception-strategy doc:name="Catch Exception Strategy"> 
     <logger level="INFO" doc:name="Logger"/> 
    </catch-exception-strategy> 
</flow> 

这是预期的行为?每次HTTP调用后,我都必须自己抛出错误吗?

回答

0

是的,您需要检查响应的状态代码并采取适当的措施。 Mule不知道你在做什么,或者你期望什么状态码,所以http连接器不会抛出异常。关于骡的一个小问题是,没有简单的方法来抛出异常。我写了一个非常简单的小ExceptionThrower java类来处理这种情况。

<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" path="api/1.0/connections/connections" method="GET" doc:name="Returns 500"/> 
    <choice doc:name="Choice"> 
     <when expression="#[message.inboundProperties['http.status'] == '200']"> 
      <!-- Handle my payload --> 
     </when> 
     <otherwise> 
      <!-- This isn't what I expected, so throw an exception to let the catch-exception-strategy handle it. --> 
      <component class="com.example.ExceptionThrower" doc:name="Java"/> 
     </otherwise> 
    </choice> 
+0

在这条大道上,我会保持简单并创建一个HttpResponseResolver类,它可以抛出或不抛出 - 即将状态检查烘焙到类中。这样,您可以将它附加到HTTP的响应变换器,并且没有额外的块。最终,可以扩展HTTP组件本身(使用devkit)。国际海事组织有点不赞成骡子,不运送这个OTB。 – Gilbert 2014-10-07 16:11:14

相关问题