Search in sources :

Example 36 with MessageContentsList

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"));
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) MessageContentsList(org.apache.cxf.message.MessageContentsList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header)

Example 37 with MessageContentsList

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);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) MessageContentsList(org.apache.cxf.message.MessageContentsList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header)

Example 38 with MessageContentsList

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);
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList)

Example 39 with MessageContentsList

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
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with MessageContentsList

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);
    }
}
Also used : Message(org.apache.camel.Message) MessageContentsList(org.apache.cxf.message.MessageContentsList) SecurityContext(org.apache.cxf.security.SecurityContext) LoginSecurityContext(org.apache.cxf.security.LoginSecurityContext) LoginSecurityContext(org.apache.cxf.security.LoginSecurityContext) Subject(javax.security.auth.Subject)

Aggregations

MessageContentsList (org.apache.cxf.message.MessageContentsList)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)24 Exchange (org.apache.cxf.message.Exchange)22 Fault (org.apache.cxf.interceptor.Fault)19 Message (org.apache.cxf.message.Message)19 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)18 ArrayList (java.util.ArrayList)13 List (java.util.List)13 MessageImpl (org.apache.cxf.message.MessageImpl)11 Endpoint (org.apache.cxf.endpoint.Endpoint)10 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)10 Method (java.lang.reflect.Method)9 OperationInfo (org.apache.cxf.service.model.OperationInfo)9 Response (javax.ws.rs.core.Response)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)8 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)8 MessageInfo (org.apache.cxf.service.model.MessageInfo)8 Test (org.junit.Test)8 Service (org.apache.cxf.service.Service)7