【问题标题】:NoTypeConversionAvailableException: camel rest dslNoTypeConversionAvailableException:骆驼休息 dsl
【发布时间】:2019-06-29 01:18:30
【问题描述】:

我有一个这样的网络服务:

<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。 但是当我在邮递员中调用我的网络服务时,发生了错误:

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

谁能帮我解决这个问题?

【问题讨论】:

  • 您在 Camel 路线的哪个位置看到该异常,Camel 也记录了该异常。还请告诉我们您使用的 Camel 版本。
  • 当我调用 API () 时发生异常,我的骆驼版本是 2.21
  • 那是因为您首先记录消息正文并基于其流式传输,请参阅此常见问题解答:camel.apache.org/why-is-my-message-body-empty.html
  • 我试过没有任何日志,但仍然有同样的问题!
  • 请尝试将以下属性添加到您的camelContext或您的路线元素streamCache="true"

标签: rest post apache-camel postman


【解决方案1】:

我找到了解决方案,由于我在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>

【讨论】:

    猜你喜欢
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 2019-07-07
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多