17.9. How to consume a message from a camel-cxf endpoint in CloudEvent data format
camel-cxf 엔드포인트 소비자 데이터 형식은 CXF 호출자 를 기반으로 하므로 메시지 헤더에는 CxfConstants.OPERATION_NAME 이라는 속성이 있고 메시지 본문은 SEI 메서드 매개변수 목록입니다.
PersonProcessor 예제 코드를 고려하십시오.
public class PersonProcessor implements Processor {
private static final Logger LOG = LoggerFactory.getLogger(PersonProcessor.class);
@Override
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
LOG.info("processing exchange in camel");
BindingOperationInfo boi = (BindingOperationInfo) exchange.getProperty(BindingOperationInfo.class.getName());
if (boi != null) {
LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
}
// Get the parameters list which element is the holder.
MessageContentsList msgList = (MessageContentsList) exchange.getIn().getBody();
Holder<String> personId = (Holder<String>) msgList.get(0);
Holder<String> ssn = (Holder<String>) msgList.get(1);
Holder<String> name = (Holder<String>) msgList.get(2);
if (personId.value == null || personId.value.length() == 0) {
LOG.info("person id 123, so throwing exception");
// Try to throw out the soap fault message
org.apache.camel.wsdl_first.types.UnknownPersonFault personFault
= new org.apache.camel.wsdl_first.types.UnknownPersonFault();
personFault.setPersonId("");
org.apache.camel.wsdl_first.UnknownPersonFault fault
= new org.apache.camel.wsdl_first.UnknownPersonFault("Get the null value of person name", personFault);
exchange.getMessage().setBody(fault);
return;
}
name.value = "Bonjour";
ssn.value = "123";
LOG.info("setting Bonjour as the response");
// Set the response message, first element is the return value of the operation,
// the others are the holders of method parameters
exchange.getMessage().setBody(new Object[] { null, personId, ssn, name });
}
}