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