use of org.apache.cxf.message.ExchangeImpl in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithOneWayClientMessage.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithOneWayClientMessage() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
InterceptorChain mockIc = mock(InterceptorChain.class);
ex.put(Bus.class, mockBus);
ex.setOneWay(true);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
when(mockMessage.getInterceptorChain()).thenReturn(mockIc);
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that LatencyTimeRecorder.beginHandling was called once
verify(mockMessage, times(1)).getInterceptorChain();
}
use of org.apache.cxf.message.ExchangeImpl in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithTwoWayClientMessageWithoutLatencyTimeRecorder() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
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.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn(true);
// Perform test
outInterceptor.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 handleMessagePaosResponseBasicGood.
@Test
public void handleMessagePaosResponseBasicGood() 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 = 200;
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);
assertThat(IOUtils.toString(message.getContent(InputStream.class)), is("actual content"));
}
use of org.apache.cxf.message.ExchangeImpl in project camel by apache.
the class CxfProducer method process.
// As the cxf client async and sync api is implement different,
// so we don't delegate the sync process call to the async process
public boolean process(Exchange camelExchange, AsyncCallback callback) {
LOG.trace("Process exchange: {} in an async way.", camelExchange);
try {
// create CXF exchange
ExchangeImpl cxfExchange = new ExchangeImpl();
// set the Bus on the exchange in case the CXF interceptor need to access it from exchange
cxfExchange.put(Bus.class, endpoint.getBus());
// prepare binding operation info
BindingOperationInfo boi = prepareBindingOperation(camelExchange, cxfExchange);
Map<String, Object> invocationContext = new HashMap<String, Object>();
Map<String, Object> responseContext = new HashMap<String, Object>();
invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
invocationContext.put(Client.REQUEST_CONTEXT, prepareRequest(camelExchange, cxfExchange));
CxfClientCallback cxfClientCallback = new CxfClientCallback(callback, camelExchange, cxfExchange, boi, endpoint);
// send the CXF async request
client.invoke(cxfClientCallback, boi, getParams(endpoint, camelExchange), invocationContext, cxfExchange);
if (boi.getOperationInfo().isOneWay()) {
callback.done(false);
}
} catch (Throwable ex) {
// error occurred before we had a chance to go async
// so set exception and invoke callback true
camelExchange.setException(ex);
callback.done(true);
return true;
}
return false;
}
use of org.apache.cxf.message.ExchangeImpl in project camel by apache.
the class CxfProducer method process.
/**
* This processor binds Camel exchange to a CXF exchange and
* invokes the CXF client.
*/
public void process(Exchange camelExchange) throws Exception {
LOG.trace("Process exchange: {} in sync way.", camelExchange);
// create CXF exchange
ExchangeImpl cxfExchange = new ExchangeImpl();
// set the Bus on the exchange in case the CXF interceptor need to access it from exchange
cxfExchange.put(Bus.class, endpoint.getBus());
// prepare binding operation info
BindingOperationInfo boi = prepareBindingOperation(camelExchange, cxfExchange);
Map<String, Object> invocationContext = new HashMap<String, Object>();
Map<String, Object> responseContext = new HashMap<String, Object>();
invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
invocationContext.put(Client.REQUEST_CONTEXT, prepareRequest(camelExchange, cxfExchange));
try {
// send the CXF request
client.invoke(boi, getParams(endpoint, camelExchange), invocationContext, cxfExchange);
} catch (Exception exception) {
camelExchange.setException(exception);
} finally {
// add cookies to the cookie store
if (endpoint.getCookieHandler() != null) {
try {
Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>) cxfExchange.getInMessage().get(Message.PROTOCOL_HEADERS));
endpoint.getCookieHandler().storeCookies(camelExchange, endpoint.getRequestUri(camelExchange), cxfHeaders);
} catch (IOException e) {
LOG.error("Cannot store cookies", e);
}
}
// bind the CXF response to Camel exchange
if (!boi.getOperationInfo().isOneWay()) {
endpoint.getCxfBinding().populateExchangeFromCxfResponse(camelExchange, cxfExchange, responseContext);
}
}
}
Aggregations