Seymour Glass
Seymour Glass

Reputation: 161

Quarkus 1.5.2.Final: quarkus-resteasy automatic JAXB marshalling/unmarshalling doesn't work

I have a Quarkus micro-service exposing a REST interface having endpoints as follows:

...
@POST
@Consumes(value = MediaType.APPLICATION_XML)
public Response createMoneyTransferOrder(MoneyTransfer moneyTransfer);
...

The MoneyTransfer is a JAXB object:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MoneyTransfer",propOrder = {"sourceAccount", "targetAccount", "amount"})
public class MoneyTransfer 
{
  ...
}

When calling the endpoint above with a valid MoneyTransfer object, the following exception is raised:

2020-07-26 12:41:26,306 ERROR [org.apa.cam.pro.err.DefaultErrorHandler] (Camel (camel-1) thread #0 - file://src/main/resources/inbox) 
Failed delivery for (MessageId: 1F4B4F8FC3E51AB-0000000000000005 on ExchangeId: 1F4B4F8FC3E51AB-0000000000000005). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: 
No body available of type: java.io.InputStream but has value: fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer@2bfa4bb4 of type: fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer on: money-xfer.xml. 
Caused by: No type converter available to convert from type: fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer to the required type: java.io.InputStream with value fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer@2bfa4bb4. Exchange[1F4B4F8FC3E51AB-0000000000000005]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - 
No type converter available to convert from type: fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer to the required type: java.io.InputStream with value fr.simplex_software.eip.money_transfer.jaxb.MoneyTransfer@2bfa4bb4]

What seems to happen is that quarkus-resteasy is not able to marshal/unmarshall the MoneyTransfer object to/from XML, as required by thge JAX-RS specs, and expects a customized converter. However, the JAX-RS specs, which quarkus-resteasy is the implementation, explicitly require an automatic marshalling/unmarshalling of classes annotated with @XmlType, as this is the my case.

Does anyone know what might be the issue here ? I would like to mention that this kind of automatic marshalling/unmarshalling works since ages with RESTeasy on JBoss/Wildfly/Thorntail. And last but not least, the REST service call is made by Camel 3.3.0 (quarkus-camel-rest), should this detail make any difference. Here is the code:

...
restConfiguration().host("localhost:8081/api")
  .producerComponent("http").bindingMode(RestBindingMode.xml);
...
.to("http://localhost:8081/api?consumes=application/xml");

Kind regards, Seymour

Upvotes: 0

Views: 1765

Answers (1)

Seymour Glass
Seymour Glass

Reputation: 161

I'm answering my own question. Finally, it appears that Camel "rest" endpoint doesn't support, for some reason, the automatic marshalling/unmarshalling from/to Java to/from XML. Hence, I needed to replace the following route:

...
restConfiguration().host("localhost:8081/api").producerComponent("http").bindingMode(RestBindingMode.xml);
...
.to("rest://post:api")

by:

...
//restConfiguration().host("localhost:8081/api").producerComponent("http").bindingMode(RestBindingMode.xml);
...
.bean("moneyTransferBean","sendMoney");

where moneyTransferBean looks as follows:

@Singleton
@Named("moneyTransferBean")
public class MoneyTransferBean
{
  @Inject
  @RestClient
  private MoneyTransferResource moneyTransferResource;
  ...
  public void sendMoney(MoneyTransfer moneyTransfer)
  {
    moneyTransferResource.createMoneyTransferOrder(moneyTransfer);
  }
  ...
}

and this way it works as expected. I'm however very disapointed not beeing able to use Camel endpoints and having to recourse at this kind of hacks :-(

Kind regards, Seymour

Upvotes: 1

Related Questions