Search in sources :

Example 11 with MessageImpl

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

the class DefaultCxfBindingTest method testOverridePayloadBodyNamespace.

@Test
public void testOverridePayloadBodyNamespace() throws Exception {
    MessageImpl message = new MessageImpl();
    Map<String, String> nsMap = new HashMap<String, String>();
    Document document = getDocument(SOAP_MESSAGE_2);
    message.setContent(Node.class, document);
    DefaultCxfBinding.getPayloadBodyElements(message, nsMap);
    assertEquals(2, nsMap.size());
    assertEquals("http://www.mycompany.com/test/", nsMap.get("xmlns"));
    Element element = (Element) document.getElementsByTagName("ns1:identifier").item(0);
    assertNotNull("We should get the element", element);
    DefaultCxfBinding.addNamespace(element, nsMap);
    assertEquals("http://www.mycompany.com/test/1/", element.getAttribute("xmlns"));
    assertEquals("http://www.mycompany.com/test/", element.getAttribute("xmlns:ns1"));
}
Also used : HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 12 with MessageImpl

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

the class CamelDestination method incoming.

protected void incoming(org.apache.camel.Exchange camelExchange) {
    LOG.debug("server received request: ", camelExchange);
    DefaultCxfMessageMapper beanBinding = new DefaultCxfMessageMapper();
    org.apache.cxf.message.Message inMessage = beanBinding.createCxfMessageFromCamelExchange(camelExchange, headerFilterStrategy);
    inMessage.put(CamelTransportConstants.CAMEL_EXCHANGE, camelExchange);
    ((MessageImpl) inMessage).setDestination(this);
    // Handling the incoming message
    // The response message will be send back by the outgoing chain
    incomingObserver.onMessage(inMessage);
}
Also used : Message(org.apache.cxf.message.Message) DefaultCxfMessageMapper(org.apache.camel.component.cxf.common.message.DefaultCxfMessageMapper) MessageImpl(org.apache.cxf.message.MessageImpl)

Example 13 with MessageImpl

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

the class CamelDestinationTest method testRoundTripDestination.

@Test
public void testRoundTripDestination() 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);
    // 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();
                sendoutMessage(backConduit, replyMessage, true, "HelloWorld Response");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
    error.expectedMessageCount(0);
    //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 Response");
    error.assertIsSatisfied();
    destination.shutdown();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Example 14 with MessageImpl

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

the class CamelDestinationTest method testOneWayDestination.

@Test
public void testOneWayDestination() throws Exception {
    destMessage = null;
    inMessage = null;
    EndpointInfo conduitEpInfo = new EndpointInfo();
    conduitEpInfo.setAddress("camel://direct:Producer");
    CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
    Message outMessage = new MessageImpl();
    CamelDestination destination = null;
    try {
        endpointInfo.setAddress("camel://direct:EndpointA");
        destination = setupCamelDestination(endpointInfo, true);
    // destination.activate();
    } catch (IOException e) {
        assertFalse("The CamelDestination activate should not through exception ", false);
        e.printStackTrace();
    }
    sendoutMessage(conduit, outMessage, true, "HelloWorld");
    // just verify the Destination inMessage
    assertTrue("The destiantion should have got the message ", destMessage != null);
    verifyReceivedMessage(destMessage, "HelloWorld");
    destination.shutdown();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) IOException(java.io.IOException) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 15 with MessageImpl

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

the class CamelConduitTest method testSendOut.

@Test
public void testSendOut() 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 true
    sendoutMessage(conduit, message, true, "HelloWorld");
    assertMockEndpointsSatisfied();
// verify the endpoint get the response
}
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)20 Message (org.apache.cxf.message.Message)16 Test (org.junit.Test)15 HashMap (java.util.HashMap)9 List (java.util.List)7 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)7 IOException (java.io.IOException)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 Document (org.w3c.dom.Document)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)3 Map (java.util.Map)2 WebServiceException (javax.xml.ws.WebServiceException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 OutgoingChainInterceptor (org.apache.cxf.interceptor.OutgoingChainInterceptor)2 Exchange (org.apache.cxf.message.Exchange)2