use of org.apache.cxf.message.MessageContentsList in project camel by apache.
the class CxfMessageHeadersRelayTest method doTestInOutOfBandHeaderCamelTemplate.
protected void doTestInOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<Object> params = new ArrayList<Object>();
Me me = new Me();
me.setFirstName("john");
me.setLastName("Doh");
params.add(me);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inOutOfBandHeader");
List<Header> headers = buildOutOfBandHeaderList(false);
Map<String, Object> requestContext = new HashMap<String, Object>();
requestContext.put(Header.HEADER_LIST, headers);
senderExchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
Exchange exchange = template.send(producerUri, senderExchange);
org.apache.camel.Message out = exchange.getOut();
MessageContentsList result = (MessageContentsList) out.getBody();
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me) result.get(0)).getFirstName().equals("pass"));
}
use of org.apache.cxf.message.MessageContentsList in project camel by apache.
the class CxfMessageHeadersRelayTest method doTestInOutOutOfBandHeaderCamelTemplate.
public void doTestInOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<Object> params = new ArrayList<Object>();
Me me = new Me();
me.setFirstName("john");
me.setLastName("Doh");
params.add(me);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "inoutOutOfBandHeader");
List<Header> inHeaders = buildOutOfBandHeaderList(false);
Map<String, Object> requestContext = new HashMap<String, Object>();
requestContext.put(Header.HEADER_LIST, inHeaders);
senderExchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
Exchange exchange = template.send(producerUri, senderExchange);
org.apache.camel.Message out = exchange.getOut();
MessageContentsList result = (MessageContentsList) out.getBody();
assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me) result.get(0)).getFirstName().equals("pass"));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
validateReturnedOutOfBandHeader(responseContext);
}
use of org.apache.cxf.message.MessageContentsList in project camel by apache.
the class CxfMessageHeadersRelayTest method doTestOutOutOfBandHeaderCamelTemplate.
protected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<Object> params = new ArrayList<Object>();
Me me = new Me();
me.setFirstName("john");
me.setLastName("Doh");
params.add(me);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader");
Exchange exchange = template.send(producerUri, senderExchange);
org.apache.camel.Message out = exchange.getOut();
MessageContentsList result = (MessageContentsList) out.getBody();
assertTrue("Expected the out of band header to propagate but it didn't", result.get(0) != null && ((Me) result.get(0)).getFirstName().equals("pass"));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>) out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
validateReturnedOutOfBandHeader(responseContext);
}
use of org.apache.cxf.message.MessageContentsList in project camel by apache.
the class CxfProducerRouterTest method testInvokingSimpleServerWithParams.
@Test
public void testInvokingSimpleServerWithParams() throws Exception {
// START SNIPPET: sending
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 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("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));
// END SNIPPET: sending
}
use of org.apache.cxf.message.MessageContentsList in project camel by apache.
the class DefaultCxfRsBinding method populateExchangeFromCxfRsRequest.
public void populateExchangeFromCxfRsRequest(org.apache.cxf.message.Exchange cxfExchange, Exchange camelExchange, Method method, Object[] paramArray) {
Message camelMessage = camelExchange.getIn();
//Copy the CXF message header into the Camel inMessage
org.apache.cxf.message.Message cxfMessage = cxfExchange.getInMessage();
CxfHeaderHelper.copyHttpHeadersFromCxfToCamel(headerFilterStrategy, cxfMessage, camelMessage, camelExchange);
// TODO move to CxfHeaderHelper and use header filter strategy and CXF_TO_CAMEL_HEADERS
// setup the charset from content-type header
setCharsetWithContentType(camelExchange);
//copy the protocol header
copyProtocolHeader(cxfMessage, camelMessage, camelMessage.getExchange());
camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, method.getReturnType());
camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_GENERIC_TYPE, method.getGenericReturnType());
copyOperationResourceInfoStack(cxfMessage, camelMessage);
camelMessage.setHeader(CxfConstants.OPERATION_NAME, method.getName());
camelMessage.setHeader(CxfConstants.CAMEL_CXF_MESSAGE, cxfMessage);
camelMessage.setBody(new MessageContentsList(paramArray));
// propagate the security subject from CXF security context
SecurityContext securityContext = cxfMessage.get(SecurityContext.class);
if (securityContext instanceof LoginSecurityContext && ((LoginSecurityContext) securityContext).getSubject() != null) {
camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, ((LoginSecurityContext) securityContext).getSubject());
} else if (securityContext != null && securityContext.getUserPrincipal() != null) {
Subject subject = new Subject();
subject.getPrincipals().add(securityContext.getUserPrincipal());
camelExchange.getIn().getHeaders().put(Exchange.AUTHENTICATION, subject);
}
}
Aggregations