Search in sources :

Example 1 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl 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 2 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl 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 3 with ExchangeImpl

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

the class CamelTransportTestSupport method sendoutMessage.

protected void sendoutMessage(Conduit conduit, Message message, Boolean isOneWay, String content) throws IOException {
    Exchange cxfExchange = message.getExchange();
    if (cxfExchange == null) {
        cxfExchange = new ExchangeImpl();
        cxfExchange.setOneWay(isOneWay);
        message.setExchange(cxfExchange);
        cxfExchange.setInMessage(message);
    }
    try {
        conduit.prepare(message);
    } catch (IOException ex) {
        assertFalse("CamelConduit can't perpare to send out message", false);
        ex.printStackTrace();
    }
    OutputStream os = message.getContent(OutputStream.class);
    assertTrue("The OutputStream should not be null ", os != null);
    os.write(content.getBytes());
    os.close();
}
Also used : Exchange(org.apache.cxf.message.Exchange) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 4 with ExchangeImpl

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

the class DefaultCxfMessageMapperTest method setupCamelExchange.

private Exchange setupCamelExchange(String requestURI, String requestPath, HttpServletRequest request) {
    org.apache.camel.Message camelMessage = EasyMock.createMock(org.apache.camel.Message.class);
    Exchange camelExchange = EasyMock.createMock(Exchange.class);
    camelExchange.getProperty(CamelTransportConstants.CXF_EXCHANGE, org.apache.cxf.message.Exchange.class);
    EasyMock.expectLastCall().andReturn(new ExchangeImpl());
    camelExchange.hasOut();
    EasyMock.expectLastCall().andReturn(false);
    camelExchange.getIn();
    EasyMock.expectLastCall().andReturn(camelMessage).times(3);
    camelMessage.getHeaders();
    EasyMock.expectLastCall().andReturn(Collections.emptyMap()).times(2);
    camelMessage.getHeader(Exchange.CONTENT_TYPE, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader("Accept", String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.CHARSET_NAME, String.class);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getHeader(Exchange.HTTP_URI, String.class);
    EasyMock.expectLastCall().andReturn(requestURI);
    camelMessage.getHeader(Exchange.HTTP_PATH, String.class);
    EasyMock.expectLastCall().andReturn(requestPath);
    camelMessage.getHeader(Exchange.HTTP_BASE_URI, String.class);
    EasyMock.expectLastCall().andReturn(requestPath);
    camelMessage.getHeader(Exchange.HTTP_METHOD, String.class);
    EasyMock.expectLastCall().andReturn("GET");
    camelMessage.getHeader(Exchange.HTTP_QUERY, String.class);
    EasyMock.expectLastCall().andReturn("");
    camelMessage.getHeader(Exchange.HTTP_SERVLET_REQUEST);
    EasyMock.expectLastCall().andReturn(request);
    camelMessage.getHeader(Exchange.HTTP_SERVLET_RESPONSE);
    EasyMock.expectLastCall().andReturn(null);
    camelMessage.getBody(InputStream.class);
    EasyMock.expectLastCall().andReturn(new ByteArrayInputStream("".getBytes()));
    EasyMock.replay(camelExchange, camelMessage);
    return camelExchange;
}
Also used : Exchange(org.apache.camel.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 5 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project ddf by codice.

the class MetricsInInterceptorTest method testHandleMessageWithOneWayClientMessage.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithOneWayClientMessage() {
    // Setup
    MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    ex.put(Bus.class, mockBus);
    ex.setOneWay(true);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
    // Perform test
    inInterceptor.handleMessage(mockMessage);
    // validate that there is not an instance of LatencyTimeRecorder on the
    // exchange
    assertNull(ex.get(LatencyTimeRecorder.class));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14