当前位置: 首页 > 知识库问答 >
问题:

如何在Apache Camel中使用REST DSL生成xml响应

班泽语
2023-03-14

我试图使用Apache camel中的rest DSL来消费和生成xml响应,但它以一个例外结束,我如何将输出的POJO对象封送为xml。下面是西阿帕奇骆驼路线

<camelContext id="camelContext-02bcd908-03ed-4c2c-878a-b87e3a3668ca"
        xmlns="http://camel.apache.org/schema/blueprint">
        <restConfiguration bindingMode="xml" component="servlet"
            contextPath="/camel-example-servlet-rest-blueprint/rest" port="8181">
            <dataFormatProperty key="mustBeJAXBElement" value="true" />
        </restConfiguration>
        <!-- defines the rest services using the context-path /user -->
        <rest consumes="application/xml" path="/user" produces="application/xml">
            <description>User rest service</description>
            <!-- this is a rest GET to view an user by the given id -->
            <get outType="org.apache.camel.example.rest.User" uri="/{id}">
                <description>Find user by id</description>
                <to uri="bean:userService?method=getUser(${header.id})" />
            </get>
            <!-- this is a rest GET to find all users -->
            <get outType="org.apache.camel.example.rest.User[]" uri="/findAll">
                <description>Find all users</description>
                <to uri="bean:userService?method=listUsers" />
            </get>
        </rest>
    </camelContext>

java.io.IOException:org.apache.camel.invalidPayloadException:没有类型为javax.xml.bind.jaxbelEment但具有值为[org.apache.camel.example.rest.user@7f98bc82,org.apache.camel.example.rest.user@4502b96]类型为java.util.TreeMap.values on:消息[ID-NISB-TEC-C3880-56991-1499145269945-37-3]的正文。Exchange[ID-NISB-TEC-C3880-56991-14991459945-37-2]在org.apache.camel.converter.jaxb.jaxbDataFormat.Marshal(jaxbDataFormat.java:153)在org.apache.camel.processor.MarshalProcessor.Process(MarshalProcessor.java:69)在org.apache.camel.util.AsyncProcessorHelper.Process(AsyncProcessorHelper.java:109)在org.apache.camel.processor.MarshalProcessor.Process(

共有1个答案

后星河
2023-03-14

您可以尝试将bindingMode更改为“Off”。

在创建get方法时,可以使用“consumes”和“produces”参数等于“application/xml”,如下所示:

 <get outType="org.apache.camel.example.rest.User[]" uri="/findAll"consumes="application/xml" produces="application/xml">
    <description>Find all users</description>
    <to uri="bean:userService?method=listUsers" />
 </get>
 类似资料:
  • 我正在用Spring Boot、Kotlin和Thymeleaf构建一个web应用程序。我有一些HTML模板,但我想让其中一个返回XML文件。这个XML将是一个使用ThymleLab属性的ThymleLab模板。在Spring Boot中,正确的方法是什么?此外,还应下载XML。 我看过这个:Spring靴

  • 问题内容: 正如我们所知,中 Elasticsearch 回报。但是,我需要从那些API。 我正在寻找与.Solr提供的功能类似的功能,Solr提供了使用它的功能,我们可以轻松地在中获得响应。 我如何实现此目标? 注意 : 我不希望只是将ElasticSearch集群的所有内容导出为csv格式。 我想要获得响应而不是json。 更新 我一直在尝试使用答案中@Val建议的方法。 以下是内容 以下是内

  • 问题内容: 我有一个简单的代码,可为特定路由提供JSON响应。这是我当前的代码: 如何使XML响应等效于上述JSON? 问题答案: 您可以使用npm上可用的任何数量的XML库。这是使用简单命名的“ xml ”库的示例: 有关如何将JavaScript对象转换为XML的描述,请参见模块的文档。当然,如果您需要以特定的XML格式返回的内容,则还有更多工作要做。

  • 我必须在运行时动态生成一个xml文件。请帮助我使用PHP动态生成下面的XML文件。 null

  • 问题内容: 我正在开发一个在Go中接受JSONP请求的API。我可以将结构序列化为JSON并返回它,但是将JSON包装在padding或回调函数中有点尴尬,因为to的参数需要是字节切片: 我想我会将其封装在某些函数中。通常,我发现字符串/ [] byte转换很时髦。有一个更好的方法吗? 问题答案: 使用简化它: 或者,如果您只想在一个地方写东西:

  • 显然,是一种新的建议的HTTP请求方式,所以我尝试使用它向美味的API发出请求,它返回一个XML响应。我得到的是: 但是,它会在位上引发异常, 其他信息:无法加载文件或程序集“NewtonSoft.json,Version=4.5.0.0,Culture=Neutral,PublicKeyToken=30AD4FE6B2A6AEED”或其依赖项之一.系统找不到指定的文件。 也许我错过了一些集会,但