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();
}
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;
}
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));
}
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));
}
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);
}
Aggregations