无法从http端点消耗

时间:2015-12-02 06:02:14

标签: http apache-camel

我的路线如下所示我正在尝试使用HTTP组件交换数据,URI包含提交数据并获得响应应该获取数据但是它无法正常工作

  <route>
    <from uri="http://gatest.dnb.com/daasaccess/scripts/broker.asp?request=%3C%3Fxml+version%3D%271.0%27+encoding%3D%27UTF-8%27%3F%3E%3CDGX%3E%3CSIGNONMSGSRQV1%3E%3CSONRQ%3E%3CDTCLIENT%3E2007-05-04%3C%2FDTCLIENT%3E%3CUSERID%3Esalesautomation%3C%2FUSERID%3E%3CUSERPASS%3ESFAAdmin%3C%2FUSERPASS%3E%3CLANGUAGE%3EEN%3C%2FLANGUAGE%3E%3CFI%3E%3CORG%3EDandB%3C%2FORG%3E%3C%2FFI%3E%3CAPPID%3EXML%3C%2FAPPID%3E%3CAPPVER%3E0010%3C%2FAPPVER%3E%3C%2FSONRQ%3E%3C%2FSIGNONMSGSRQV1%3E%3CCREDITMSGSRQV2%3E%3CDATATRNRQ%3E%3CTRNUID%3E2D995FE0173B2C%3C%2FTRNUID%3E%3CDATARQ%3E%3CSRVRTID%3E%3C%2FSRVRTID%3E%3CSVC_TYPE_CD%3E%3C%2FSVC_TYPE_CD%3E%3CREAS_CD%3E%3C%2FREAS_CD%3E%3CCUST_ENDR%3E%3C%2FCUST_ENDR%3E%3CCUST_RQ%3E%3C%2FCUST_RQ%3E%3CREFRESH_IND%3E%3C%2FREFRESH_IND%3E%3CIGNORE_REQD_FLDS_IND%3E%3C%2FIGNORE_REQD_FLDS_IND%3E%3CSUBJ_DET%3E%3CDUNS_NBR%3E829654420%3C%2FDUNS_NBR%3E%3CCTRY_CD%3E%3C%2FCTRY_CD%3E%3CTRD_UP_IND%3E%3C%2FTRD_UP_IND%3E%3CPRIM_NME%3E%3C%2FPRIM_NME%3E%3CBUS_REGN_NBR%3E%3C%2FBUS_REGN_NBR%3E%3CBUS_REGN_NBR_TYPE_CD%3E%3C%2FBUS_REGN_NBR_TYPE_CD%3E%3CADR_LINE%3E%3C%2FADR_LINE%3E%3CPOST_TOWN%3E%3C%2FPOST_TOWN%3E%3CPRIM_GEO_AREA%3E%3C%2FPRIM_GEO_AREA%3E%3CPOST_CODE%3E%3C%2FPOST_CODE%3E%3CTLCM_NBR%3E%3C%2FTLCM_NBR%3E%3C%2FSUBJ_DET%3E%3CPROD%3EEnterprise+Management%3C%2FPROD%3E%3CPROD_TYPE_CD%3ED%3C%2FPROD_TYPE_CD%3E%3CDELV_REQS_NOW%3E%3CDELV_MODE_CD%3EDIRECT%3C%2FDELV_MODE_CD%3E%3CDELV_FMT_CD%3EXML%3C%2FDELV_FMT_CD%3E%3CLANG%3EEN%3C%2FLANG%3E%3CDELV_EMAIL%3E%3C%2FDELV_EMAIL%3E%3CDELV_EMAIL_CC%3E%3C%2FDELV_EMAIL_CC%3E%3C%2FDELV_REQS_NOW%3E%3CDELV_REQS_INV%3E%3CDELV_MODE_CD%3E%3C%2FDELV_MODE_CD%3E%3CDELV_FMT_CD%3E%3C%2FDELV_FMT_CD%3E%3CLANG%3E%3C%2FLANG%3E%3CDELV_EMAIL%3E%3C%2FDELV_EMAIL%3E%3CDELV_EMAIL_CC%3E%3C%2FDELV_EMAIL_CC%3E%3C%2FDELV_REQS_INV%3E%3CDELV_REQS_NTFY%3E%3CDELV_MODE_CD%3E%3C%2FDELV_MODE_CD%3E%3CDELV_FMT_CD%3E%3C%2FDELV_FMT_CD%3E%3CLANG%3E%3C%2FLANG%3E%3CDELV_EMAIL%3E%3C%2FDELV_EMAIL%3E%3CDELV_EMAIL_CC%3E%3C%2FDELV_EMAIL_CC%3E%3C%2FDELV_REQS_NTFY%3E%3C%2FDATARQ%3E%3C%2FDATATRNRQ%3E%3C%2FCREDITMSGSRQV2%3E%3C%2FDGX%3E"/>
    <log message="starting....."/>
    <process ref="nextgenProcessor"/>
    <to uri="file://src/test"/>
    <log message="ending....."/>
  </route>

我收到以下错误:

[ERROR] Error occurred while running main from: org.apache.camel.spring.Main
[ERROR] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.camel.maven.RunMojo$1.run(RunMojo.java:488)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.camel.RuntimeCamelException: java.lang.UnsupportedOperationException: Cannot consume from http endpoint

3 个答案:

答案 0 :(得分:5)

基本上错误消息是正确的,您不能将http component用作消费者。但是文档有点无益。第一行说“ http:组件为消费外部HTTP资源提供基于HTTP的端点”,但是在下一节中它指出“你只能生成到HTTP组件生成的端点。因此,它永远不能用作骆驼路由的输入。

一种方法是使用诸如'direct'或'quartz2'组件之类的东西作为消费者,然后在生产者中使用'http'组件。例如,此路由将每分钟运行一次,提交到指定的URL并将响应保存在/ tmp中,并带有带时间戳的文件名: -

<route id="httpFetch">
    <from uri="quartz2://httpFetch?cron=00+/1+*+?+*+1-5" />
    <to uri="http://gatest.dnb.com/daasaccess/scripts/broker.asp?request=%3C%3Fxml+version%3D%271.0%27+encoding%3D%27UTF-8%27%3F%3E%3CDGX%3E%3CSIGNONMSGSRQV1%3E%3CSONRQ%3E%3CDTCLIENT%3E2007-05-04%3C%2FDTCLIENT%3E%3CUSERID%3Esalesautomation%3C%2FUSERID%3E%3CUSERPASS%3ESFAAdmin%3C%2FUSERPASS%3E%3CLANGUAGE%3EEN%3C%2FLANGUAGE%3E%3CFI%3E%3CORG%3EDandB%3C%2FORG%3E%3C%2FFI%3E%3CAPPID%3EXML%3C%2FAPPID%3E%3CAPPVER%3E0010%3C%2FAPPVER%3E%3C%2FSONRQ%3E%3C%2FSIGNONMSGSRQV1%3E%3CCREDITMSGSRQV2%3E%3CDATATRNRQ%3E%3CTRNUID%3E2D995FE0173B2C%3C%2FTRNUID%3E%3CDATARQ%3E%3CSRVRTID%3E%3C%2FSRVRTID%3E%3CSVC_TYPE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_CC%3E%3C%2FDELV_EMAIL_CC%3E%3C%2FDELV_REQS_INV%3E%3CDELV_REQS_NTFY%3E%3CDELV_MODE_CD%3E%3C%2FDELV_MODE_CD%3E%3CDELV_FMT_CD%3E%3C%2FDELV_FMT_CD%3E%3CLANG%3E%3C%2FLANG%3E%3CDELV_EMAIL%3E%3C%2FDELV_EMAIL%3E%3CDELV_EMAIL_CC%3E%3C%2FDELV_EMAIL_CC%3E%3C%2FDELV_REQS_NTFY%3E%3C%2FDATARQ%3E%3C%2FDATATRNRQ%3E%3C%2FCREDITMSGSRQV2%3E%3C%2FDGX%3E"/>
    <to uri="file:/tmp?fileName=data-${date:now:yyyyMMdd-HHmm}.xml&amp;tempFileName=data-${date:now:yyyyMMdd-HHmm}.xml.part" />
</route>

答案 1 :(得分:0)

您必须指定该组件,该组件负责从http:

进行消费
from("jetty:http://localhost:8080/test")
    .to(...something else...);

别忘了将组件的jar包含到您的maven / gradle项目中。

答案 2 :(得分:0)

或者你可以这样做:

<route>
<from uri="timer://runOnce?repeatCount=1&delay=1000"/>
<to uri="http://your-url"/>
<log message="starting....."/>
<process ref="nextgenProcessor"/>
<to uri="file://src/test"/>
<log message="ending....."/>