apache的http4是否可以使用HttpOperationFailedException?

时间:2019-09-11 19:15:30

标签: apache-camel httpexception camel-http

我将Apache骆驼http4用于http服务器。 JBoss Fuse Karaf容器6.3.0.redhat-310 捆绑了骆驼核心2.17-(2.17.0.redhat-630310)

我正在尝试使用异常类 org.apache.camel.component.http.HttpOperationFailedException 捕获HTTP响应异常。

但是,由于以下原因,相关路由无法启动 引起原因:java.lang.ClassNotFoundException:org.apache.camel.component.http.HttpOperationFailedException

我已将骆驼http添加为依赖项,但没有更改,仍然失败。

似乎不再包含该类了吗?

问:原因是:java.lang.ClassNotFoundException:org.apache.camel.component.http.HttpOperationFailedException可用于http4服务器,还是有人知道我在做什么错。

    <when id="w2">
        <ognl>request.headers.TKNDB == true</ognl>
        <process id="a3" ref="assetUploadProcessor"/>
        <setHeader headerName="CamelHttpUri" id="h1">
            <simple>${header.UPLOADURL}</simple>
        </setHeader>
        <setHeader headerName="CamelHttpMethod" id="h2">
            <constant>GET</constant>
        </setHeader>
        <doTry id="_doTry1">
            <to id="http4-1" uri="http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.predix-uaa.run.aws-usw02-pr.ice.predix.io:443/oauth/token?throwExceptionOnFailure=false"/>
            <doCatch id="_doCatch1">
                <exception>org.apache.camel.component.http.HttpOperationFailedException</exception>
                <onWhen>
                <simple>${header.HTTP_RESPONSE_CODE} range "400..600"</simple>
                </onWhen>
                <log id="_log2" loggingLevel="ERROR" message="HTTP FAILURE - HTTP Response Code: ${header.HTTP_RESPONSE_CODE}"/>
            </doCatch>
        </doTry>
        <log id="l1" loggingLevel="INFO" message="JSON Response: ${body}"/>
        <process id="jsonmapperassets" ref="jsonMapperAssets"/>
        <split id="as1"

成品 ...由于org.apache.camel.component.http.HttpOperationFailedException 引起原因:java.lang.ClassNotFoundException:org.apache.camel.component.http.HttpOperationFailedException

我也尝试过使用全局异常处理程序

<exception>org.apache.camel.component.http.HttpOperationFailedException</exception>
      <continued>true</continued>
    </onException>

但是,这里我收到一个ERROR异常,说Continue不能再有孩子了???

谢谢!

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,正确的课程是

org.apache.camel.http.common.HttpOperationFailedException

它应该在http4组件内部

答案 1 :(得分:0)

我只是用简单的语言来实现我所需要的。我只需要在http错误代码不正确或200之后继续路由。这种方法行得通,但是我很想了解如何通过我的原始问题来完成此任务。

可以用骆驼的http4组件完成此操作,看来这些类已不再是它的一部分吗?

如果有人可以,我的onException子句怎么了?

谢谢!

这就是我所做的

<to id="http4-1" uri="http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.predix-uaa.run.aws-usw02-pr.ice.predix.io:443/oauth/token?throwExceptionOnFailure=false"/>
<choice>
 <when>
  <simple>${header.CamelHttpResponseCode} == '200'</simple>
    <log id="l1" loggingLevel="INFO" message="JSON Response Body: ${body}"/>
    <process id="jsonmapperassets" ref="jsonMapperAssets"/>
  <split id="as1"
    strategyRef="tsAggregationStrategy" streaming="true">
    <simple>${body}</simple>
    <log id="al6" loggingLevel="INFO" message="Split line ${body}"/>
    <process id="p1" ref="getAssets"/>
  </split>
  <process id="getassetlisting" ref="getAssetListing"/>
  <split id="as2"
    strategyRef="tsAggregationStrategy" streaming="true">
    <simple>${body}</simple>
    <log id="sl2" loggingLevel="INFO" message="Split assets ${body}"/>
    <process id="gtags" ref="setTagURL"/>
    <to id="surl" ref="setURL"/>
  </split>
 </when>
 <otherwise>
   <log id="logError1" loggingLevel="ERROR" message="HTTP FAILURE - Response Code: ${header.CamelHttpResponseCode}"/>
   <log id="logError2" loggingLevel="ERROR" message="HTTP FAILURE - Response: ${header.CamelHttpResponseText}"/>
 </otherwise>
</choice>