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

Camel REST DSL API-多内容类型-XML错误

郗浩言
2023-03-14
@Override
public void configure() throws Exception {
    rest()
            .bindingMode(RestBindingMode.json_xml)
            .consumes("application/json, application/xml")
            .produces("application/json, application/xml")
            .get("/rating")
            .toD("direct:getRatingByClient");
}
public class GetRatingByClientRoute extends RouteBuilder{

// Use to created the mock
private final ObjectMapper objectMapper = new ObjectMapper();

@Override
public void configure() throws Exception {

    from("direct:getRatingByClient")

    // Request
    .to("log:init")

    // Mediation
    .process(exchange -> {

        // TODO Implement route
        TestEntity test = new TestEntity();
        test.setTestAttribute("Teste");
        exchange.getOut().setBody(test);

    // Response
    .to("log:end");

}

}

遵循我正在测试的请求:curl-x GET\'http://localhost:8080/credits/v1/rating?client_cpf_cnpj=11111111111'\-h'accept:application/xml'\-h'cache-control:no-cache'\-h'content-type:application/xml'

共有1个答案

马涵蓄
2023-03-14

我为camel打开了一个bug,结果得到了响应:

需要为JAXB类使用JAXB.index文件。也可以通过以下方法关闭数据格式以要求JAXBElement

.dataFormatProperty("mustBeJAXBElement", "false");

此配置在RestConfiguration DSL上进行,如下所示:

    @Override
    public void configure() throws Exception {
        restConfiguration()
            .component("servlet")
            .contextPath("/credits/v1")
            .enableCORS(true)
            .apiContextPath("/api-doc")
            .apiProperty("api.title", "REST API")
            .apiProperty("api.version", "v1")
            .apiContextRouteId("doc-api")
            .bindingMode(RestBindingMode.auto)
            .dataFormatProperty("prettyPrint", "true")
            .dataFormatProperty("mustBeJAXBElement", "false");

    }
 类似资料:
  • 问题内容: 我正在使用Express创建网站和API,我想在同一路径上提供多种内容类型(JSON,XML,HTML)。在Express中,有一种更好的方法可以编写以下内容: 特别是上面的代码似乎很重复,可能有一种更标准的编写方式。 问题答案: 有response.format方法,该方法使用基于“ Accept”标头选择某些呈现方法。http://expressjs.com/4x/api.html

  • 我有一个支持json和XML的REST api。我想测试XML方面,但自从升级到2.4.0版本后,我得到了一个错误: 预期的内容类型“xml”与实际的内容类型“application/json”不匹配。

  • 在SpringMVC请求头中可以有多种内容类型吗?我要通过: 通过邮递员到我的API。目前,我得到了

  • Axis2默认情况下发送多部分响应,即使没有附件 为什么axis2发送多部分响应&如何要求它发送“应用程序/XML”或“应用程序/SOAP+XML”如何摆脱多部分?在axis2.xml中 在回复中,我看到HTTP/1.1 200 OK Date:Fri,17 Feb 2017 01:07:08 GMT Transfer-Encoding:chunked Content-Type:Multipart

  • <_comments><_comment> 再次是新的注释这是一种文本类型bp注释需要在文本json 1 2017-01-18t21:07:15 雪佛龙公司

  • 我试图使用独立的应用程序使用WCF web服务。我可以使用Internet Explorer查看此服务,也可以在Visual studio服务引用中查看。 这就是我得到的错误 如何更改它以使用正确的内容类型? 这是我的配置文件 这是堆栈