0
votes

I receive a SOAP message to a CXF endpoint, with a Long and String value. eg. [5, 'test']

The camel route receiving messages is already using dataformat=POJO I need to send these parameters on ActiveMQ to another application.

If I use:

<convertBodyTo type="java.lang.String"/>     

The logs show the body contains 5 only. 'test' is not sent.

I tried converting to a POJO before converting to a String, but I can't find proper documentation on making TypeConverters, (seriously, who can read this and figure out actual code from it?)

eg.

<convertBodyTo type="com.company.InfoPojo"/>
<convertBodyTo type="java.lang.String"/>     

If I try to just forward the CXF data to the queue without any converting, I get:

Failed to extract body due to: javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class org.apache.cxf.message.MessageContentsList! This class is not allowed to be serialized. Add package with 'org.apache.activemq.SERIALIZABLE_PACKAGES' system property..

Anyone know what the best option here is?

Thanks

2

2 Answers

2
votes

You should marshal the parameters to XML or JSON (or any other format that takes your fancy) before sending them to the queue. The consumer will then need to unmarshal them.

No need to mess around with type converters. Camel's data formats make this really easy: https://github.com/apache/camel/blob/master/components/readme.adoc#data-formats

JSON: https://github.com/apache/camel/blob/master/docs/user-manual/en/json.adoc

JAXB: https://github.com/apache/camel/blob/master/components/camel-jaxb/src/main/docs/jaxb-dataformat.adoc

0
votes

Made a bean and sent to the bean:

public void process(Exchange exchange) throws Exception {
    log.info("Converting CXF values for queue.");
    Object[] args = exchange.getIn().getBody(Object[].class);
    patientKey = String.valueOf((Long)args[0]);
    destinationUrl = (String)args[1];
    exchange.getOut().setBody(new String(patientKey + "|" + destinationUrl));
}