Search in sources :

Example 1 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project camel by apache.

the class CxfBeanDestination method process.

public void process(Exchange camelExchange) throws Exception {
    LOG.trace("Received request : {}", camelExchange);
    org.apache.cxf.message.Message cxfMessage = endpoint.getCxfBeanBinding().createCxfMessageFromCamelExchange(camelExchange, endpoint.getHeaderFilterStrategy());
    cxfMessage.put(CamelTransportConstants.CAMEL_EXCHANGE, camelExchange);
    ((MessageImpl) cxfMessage).setDestination(this);
    // Handling the incoming message
    // The response message will be send back by the outgoing chain
    incomingObserver.onMessage(cxfMessage);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 2 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project camel by apache.

the class CxfMessageHelper method getCxfInMessage.

public static org.apache.cxf.message.Message getCxfInMessage(HeaderFilterStrategy headerFilterStrategy, org.apache.camel.Exchange exchange, boolean isClient) {
    MessageImpl answer = new MessageImpl();
    org.apache.cxf.message.Exchange cxfExchange = exchange.getProperty(CamelTransportConstants.CXF_EXCHANGE, org.apache.cxf.message.Exchange.class);
    org.apache.camel.Message message;
    if (isClient && exchange.hasOut()) {
        message = exchange.getOut();
    } else {
        message = exchange.getIn();
    }
    assert message != null;
    if (cxfExchange == null) {
        cxfExchange = new ExchangeImpl();
        exchange.setProperty(CamelTransportConstants.CXF_EXCHANGE, cxfExchange);
    }
    CxfHeaderHelper.propagateCamelToCxf(headerFilterStrategy, message.getHeaders(), answer, exchange);
    // body can be empty in case of GET etc.
    InputStream body = message.getBody(InputStream.class);
    if (body != null) {
        answer.setContent(InputStream.class, body);
    } else if (message.getBody() != null) {
        // fallback and set the body as what it is
        answer.setContent(Object.class, body);
    }
    answer.putAll(message.getHeaders());
    answer.setExchange(cxfExchange);
    cxfExchange.setInMessage(answer);
    return answer;
}
Also used : InputStream(java.io.InputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 3 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project camel by apache.

the class CamelDestinationTest method testRoundTripDestinationWithFault.

@Test
public void testRoundTripDestinationWithFault() throws Exception {
    inMessage = null;
    EndpointInfo conduitEpInfo = new EndpointInfo();
    conduitEpInfo.setAddress("camel://direct:Producer");
    // set up the conduit send to be true
    CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
    final Message outMessage = new MessageImpl();
    endpointInfo.setAddress("camel://direct:EndpointA");
    final CamelDestination destination = setupCamelDestination(endpointInfo, true);
    destination.setCheckException(true);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            try {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                verifyReceivedMessage(m, "HelloWorld");
                //verifyHeaders(m, outMessage);
                // setup the message for
                Conduit backConduit;
                backConduit = getBackChannel(destination, m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                replyMessage.setContent(Exception.class, new RuntimeCamelException());
                sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
    error.expectedMessageCount(1);
    //this call will active the camelDestination
    destination.setMessageObserver(observer);
    // set is one way false for get response from destination
    // need to use another thread to send the request message
    sendoutMessage(conduit, outMessage, false, "HelloWorld");
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    verifyReceivedMessage(inMessage, "HelloWorld Fault");
    error.assertIsSatisfied();
    destination.shutdown();
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) RuntimeCamelException(org.apache.camel.RuntimeCamelException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 4 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project camel by apache.

the class CamelConduitTest method testPrepareSend.

@Test
public void testPrepareSend() throws Exception {
    endpointInfo.setAddress("camel://direct:Producer");
    CamelConduit conduit = setupCamelConduit(endpointInfo, false, false);
    Message message = new MessageImpl();
    try {
        conduit.prepare(message);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    verifyMessageContent(message);
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) IOException(java.io.IOException) Test(org.junit.Test)

Example 5 with MessageImpl

use of org.apache.cxf.message.MessageImpl in project camel by apache.

the class CamelConduitTest method testSendOutRunTrip.

@Test
public void testSendOutRunTrip() throws Exception {
    endpointInfo.setAddress("camel://direct:Producer");
    CamelConduit conduit = setupCamelConduit(endpointInfo, true, false);
    MockEndpoint endpoint = getMockEndpoint("mock:EndpointA");
    endpoint.expectedMessageCount(1);
    Message message = new MessageImpl();
    // set the isOneWay to be false
    sendoutMessage(conduit, message, false, "HelloWorld");
    // verify the endpoint get the response
    assertMockEndpointsSatisfied();
    verifyReceivedMessage("HelloWorld");
}
Also used : Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58