[ https://issues.apache.org/jira/browse/CAMEL-12217?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348325#comment-16348325 ]
Claus Ibsen commented on CAMEL-12217: ------------------------------------- You need to use jaxb.index files for your JAXB classes. Or you can turn off the data format to require a JAXBElement by .dataFormatProperty("mustBeJAXBElement", "false"); > Camel REST DSL API - Multiple Content Type - XML Error > ------------------------------------------------------ > > Key: CAMEL-12217 > URL: https://issues.apache.org/jira/browse/CAMEL-12217 > Project: Camel > Issue Type: Bug > Components: camel-core, camel-jaxb, camel-servlet > Affects Versions: 2.20.1, 2.20.2 > Environment: * Windows 10 > * JVM 1.8 > * IntelliJ IDEA > * Maven 3.3.3 > Reporter: Rafael Manzoni > Priority: Major > Fix For: 2.21.0 > > Attachments: credits-v1.zip > > > I am trying to create a Camel REST service via Java DSL that can > consume/produce both json and xml and the JSON works but I receive the an > error when I try to retrieve the result in XML. > RestConfiguration: > {code:java} > /** > * This configuration is for start the Apache Camel application with the > Spring Boot servlet > * @author rafael.manzoni > */ > public class RestConfiguration extends RouteBuilder { > @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", "true"); > } > }{code} > RestMethods: > {code:java} > /** > * Rest methods configuration. Apply all HTTP routes to Camel Routes > * @author REST Methods Configuration > */ > public class RestMethods extends RouteBuilder { > @Override > public void configure() throws Exception { > rest() > .bindingMode(RestBindingMode.auto) > .consumes("application/json, application/xml") > .produces("application/json, application/xml") > .get("/rating") > .toD("direct:getRatingByClient"); > } > }{code} > > Route Implementation: > {code:java} > 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.getIn().setBody(test); > }) > // Response > .to("log:end"); > > } > }{code} > When I run with Content-Type application/json works like a charm. But, when i > run with Content-Type application/xml i got this error: > *_java.io.IOException: org.apache.camel.InvalidPayloadException: No body > available of type: javax.xml.bind.JAXBElement but has value: class > GetRatingByClientRouteResponse_* > Follow the requisition that I´m testing: > _*Success:*_ > curl -X GET \ > '[http://localhost:8080/credits/v1/rating?client_cpf_cnpj=11111111111]' \ -H > 'Accept: application/json' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: > application/json' > > _*Failure:*_ > 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' > > I´m attaching the project to this issue. -- This message was sent by Atlassian JIRA (v7.6.3#76005)