16.10. how to prepare the message for the camel-cxf endpoint in#177 data format
camel-cxf 끝점 프로듀서는 CXF 클라이언트 API 를 기반으로 합니다. 먼저 메시지 헤더에 작업 이름을 지정한 다음 메서드 매개변수를 목록에 추가하고 이 매개변수 목록으로 메시지를 초기화해야 합니다. 응답 메시지의 본문은 messageContentsList이며 해당 목록의 결과를 가져올 수 있습니다.
메시지 헤더에 작업 이름을 지정하지 않으면 CxfProducer 는 CxfEndpoint 에 기본OperationName 을 사용하려고 합니다. CxfEndpoint 에 기본OperationName 이 설정되지 않은 경우 Operation 목록에서 첫 번째 operationName을 선택합니다.
메시지 본문에서 개체 배열을 가져오려면 CxfProducerRouterTest.testInvokingSimpleServerWithParams 와 같이 message.getBody(Object[].class) 를 사용하여 본문을 가져올 수 있습니다.
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<String> params = new ArrayList<>();
// 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.getMessage();
// The response message's body is an MessageContentsList which first element is the return value of the operation,
// If there are some holder parameters, the holder parameter will be filled in the reset of List.
// The result will be extract 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("UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING),
"We should get the response context here");
assertEquals("echo " + TEST_MESSAGE, result.get(0), "Reply body on Camel is wrong");