The camel-cxf
endpoint producer is based on the CXF client API. First you
need to specify the operation name in the message header, then add the method parameters to
a list, and initialize the message with this parameter list. The response message's body is
a messageContentsList; you can get the result from that list.
Note: the message body is a
MessageContentsList
. If you want to get the object array from the message
body, you can get the body using message.getbody(Object[].class)
, as follows:
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut); final List<String> params = new ArrayList<String>(); // Prepare the request message for the camel-cxf procedure params.add(TEST_MESSAGE); senderExchange.getIn().setBody(params); senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION); Exchange exchange = template.send("direct:EndpointA", senderExchange); org.apache.camel.Message out = exchange.getOut(); // The response message's body is a MessageContentsList whose first // element is the return value of the operation. If there are some holder // parameters, the holder parameter will be filled in the rest of List. // The result will be extracted from the MessageContentsList with the // String class type MessageContentsList result = (MessageContentsList)out.getBody(); LOG.info("Received output text: " + result.get(0)); Map<String, Object> responseContext = CastUtils.cast((Map)out.getHeader(Client.RESPONSE_CONTEXT)); assertNotNull(responseContext); assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING)); assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));