Search in sources :

Example 16 with ExchangeImpl

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

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

the class CamelDestinationTest method setupCamelDestination.

public CamelDestination setupCamelDestination(EndpointInfo endpointInfo, boolean send) throws IOException {
    ConduitInitiator conduitInitiator = EasyMock.createMock(ConduitInitiator.class);
    CamelDestination camelDestination = new CamelDestination(context, bus, conduitInitiator, endpointInfo);
    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {

            public void onMessage(Message m) {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                destMessage = m;
            }
        };
        camelDestination.setMessageObserver(observer);
    }
    return camelDestination;
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 18 with ExchangeImpl

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

the class MetricsInInterceptorTest method testHandleMessageWithNonClientMessageWithoutLatencyTimeRecorder.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithNonClientMessageWithoutLatencyTimeRecorder() {
    // Setup
    MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    ex.put(Bus.class, mockBus);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn("false");
    // Perform test
    inInterceptor.handleMessage(mockMessage);
    // validate that an instance of LatencyTimeRecorder was put onto the
    // exchange
    assertThat(ex.get(LatencyTimeRecorder.class), instanceOf(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)

Example 19 with ExchangeImpl

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

the class MetricsInInterceptorTest method testHandleMessageWithNonClientMessageWithLatencyTimeRecorder.

/**
     * Test method for
     * {@link ddf.metrics.interceptor.MetricsInInterceptor#handleMessage(org.apache.cxf.message.Message)}
     * .
     *
     * @throws InterruptedException
     */
@Test
public void testHandleMessageWithNonClientMessageWithLatencyTimeRecorder() {
    // Setup
    MetricsInInterceptor inInterceptor = new MetricsInInterceptor();
    Message mockMessage = mock(Message.class);
    Exchange ex = new ExchangeImpl();
    Bus mockBus = mock(Bus.class);
    LatencyTimeRecorder mockLtr = mock(LatencyTimeRecorder.class);
    ex.put(Bus.class, mockBus);
    ex.put(LatencyTimeRecorder.class, mockLtr);
    when(mockBus.getId()).thenReturn("bus_id");
    when(mockMessage.getExchange()).thenReturn(ex);
    when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn("false");
    // Perform test
    inInterceptor.handleMessage(mockMessage);
    // validate that an instance of LatencyTimeRecorder was put onto the
    // exchange
    assertThat(ex.get(LatencyTimeRecorder.class), instanceOf(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)

Example 20 with ExchangeImpl

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

the class PaosInInterceptorTest method handleMessagePaosResponseBasicBad.

@Test(expected = Fault.class)
public void handleMessagePaosResponseBasicBad() throws IOException {
    Message message = new MessageImpl();
    message.setContent(InputStream.class, PaosInInterceptorTest.class.getClassLoader().getResource("ecprequest.xml").openStream());
    message.put(Message.CONTENT_TYPE, "application/vnd.paos+xml");
    Message outMessage = new MessageImpl();
    HashMap<String, List> protocolHeaders = new HashMap<>();
    outMessage.put(Message.PROTOCOL_HEADERS, protocolHeaders);
    outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
    protocolHeaders.put("Authorization", Collections.singletonList("BASIC dGVzdDp0ZXN0"));
    ExchangeImpl exchange = new ExchangeImpl();
    exchange.setOutMessage(outMessage);
    message.setExchange(exchange);
    PaosInInterceptor paosInInterceptor = new PaosInInterceptor(Phase.RECEIVE) {

        HttpResponseWrapper getHttpResponse(String responseConsumerURL, String soapResponse, Message message) throws IOException {
            HttpResponseWrapper httpResponseWrapper = new HttpResponseWrapper();
            if (responseConsumerURL.equals("https://sp.example.org/PAOSConsumer")) {
                httpResponseWrapper.statusCode = 400;
                httpResponseWrapper.content = new ByteArrayInputStream("actual content".getBytes());
            } else if (responseConsumerURL.equals("https://idp.example.org/saml2/sso")) {
                httpResponseWrapper.statusCode = 200;
                httpResponseWrapper.content = PaosInInterceptorTest.class.getClassLoader().getResource("idpresponse.xml").openStream();
            }
            return httpResponseWrapper;
        }
    };
    paosInInterceptor.handleMessage(message);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)22 Message (org.apache.cxf.message.Message)17 Test (org.junit.Test)16 Exchange (org.apache.cxf.message.Exchange)14 Bus (org.apache.cxf.Bus)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 HashMap (java.util.HashMap)6 List (java.util.List)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 DefaultExchange (org.apache.camel.impl.DefaultExchange)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 WebServiceException (javax.xml.ws.WebServiceException)2 NoSuchEndpointException (org.apache.camel.NoSuchEndpointException)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Conduit (org.apache.cxf.transport.Conduit)2 InputStream (java.io.InputStream)1