NoTypeConversionAvailableException:骆驼休息DSL

时间:2019-02-05 08:57:30

标签: rest post apache-camel postman

我有这样的Web服务:

<camelContext id="camel-CallAPI" xmlns="http://camel.apache.org/schema/blueprint" >
             <!--Web service starts working -->
           <restConfiguration bindingMode="auto" component="restlet" host="localhost" port="8889"/>
           <rest path="/check">
           <post uri="/version" consumes="application/json" produces="application/json">
           <to uri="direct:first"/>                
            </post> 
           </rest>     
           <route>         
          <from uri="direct:first"/>
              <setHeader headerName="Content-Type" id="header_contentType">
                  <constant>application/json</constant>
              </setHeader>
             <log message="after set header :: ${body}"/>
             <to uri="http4://..."/>
             <convertBodyTo type="java.lang.String"/>                  
             <log message="the result of the testCheckLastVersion :: ${body}"/>

我正在邮递员的帮助下将json内容发送到此Web服务,并且我需要我的Web服务将json发送到在direct:first中提到的另一个API。 但是当我用邮递员打电话给我的Web服务时,发生了错误:

org.apache.camel.InvalidPayloadException:没有可用的正文,类型为:java.io.InputStream,但是值:{version = apk.1.10.0},类型为:java.util.LinkedHashMap,位于:Message [ID-localhost -localdomain-1549348033140-14-4]。原因:没有可用的类型转换器将类型:java.util.LinkedHashMap转换为所需类型:值{version = apk.1.10.0}的java.io.InputStream。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:2)

我找到了解决方案,这是由于在camelContext中将bindingMode =“ auto”设置为不适用于此处而引起的异常,通过删除该设置,问题得以解决。

<camelContext id="camel-CallAPI" xmlns="http://camel.apache.org/schema/blueprint" >
             <!--Web service starts working -->
           <restConfiguration component="restlet" host="localhost" port="8889"/>
           <rest path="/say">
              <post uri="/hi" consumes="application/json" produces="application/json">
                <to uri="direct:first"/>
              </post> 
           </rest>         
           <route>         
              <from uri="direct:first"/>
                 <setHeader headerName="Content-Type" id="_setHeader2">
                     <constant>application/json</constant>
                 </setHeader>
           <to uri="http4://..."/>
           <convertBodyTo type="java.lang.String"/>
           <log message="the result of the testCheckLastVersion :: ${body}"/>  
          </route> 

</camelContext>