use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JAXRSUtilsTest method invokeCustomerMethod.
private void invokeCustomerMethod(ClassResourceInfo cri, Customer customer, Server server) throws Exception {
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(Customer.class.getMethod("test", new Class[] {}));
JAXRSInvoker invoker = new JAXRSInvoker();
Exchange exc = new ExchangeImpl();
exc.put(Endpoint.class, server.getEndpoint());
Message inMessage = new MessageImpl();
exc.setInMessage(inMessage);
exc.put(OperationResourceInfo.class, ori);
invoker.invoke(exc, Collections.emptyList(), customer);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ClientImpl method getConduit.
public Conduit getConduit() {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
message.putAll(getRequestContext());
setExchangeProperties(exchange, getEndpoint(), null);
return getConduitSelector().selectConduit(message);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ClientImpl method doInvoke.
private Object[] doInvoke(final ClientCallback callback, BindingOperationInfo oi, Object[] params, Map<String, Object> context, Exchange exchange) throws Exception {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
Map<String, Object> resContext = null;
try {
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (exchange == null) {
exchange = new ExchangeImpl();
}
exchange.setSynchronous(callback == null);
Endpoint endpoint = getEndpoint();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params));
}
Message message = endpoint.getBinding().createMessage();
// on message
if (context == null) {
context = new HashMap<>();
}
Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>) context.get(REQUEST_CONTEXT));
resContext = CastUtils.cast((Map<?, ?>) context.get(RESPONSE_CONTEXT));
if (reqContext == null) {
reqContext = new HashMap<>(getRequestContext());
context.put(REQUEST_CONTEXT, reqContext);
}
if (resContext == null) {
resContext = new ResponseContext(responseContext);
context.put(RESPONSE_CONTEXT, resContext);
}
message.put(Message.INVOCATION_CONTEXT, context);
setContext(reqContext, message);
exchange.putAll(reqContext);
setParameters(params, message);
if (null != oi) {
exchange.setOneWay(oi.getOutput() == null);
}
exchange.setOutMessage(message);
exchange.put(ClientCallback.class, callback);
setOutMessageProperties(message, oi);
setExchangeProperties(exchange, endpoint, oi);
PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
message.setInterceptorChain(chain);
if (callback == null) {
chain.setFaultObserver(outFaultObserver);
} else {
// We need to wrap the outFaultObserver if the callback is not null
// calling the conduitSelector.complete to make sure the fail over feature works
chain.setFaultObserver(new MessageObserver() {
public void onMessage(Message message) {
Exception ex = message.getContent(Exception.class);
if (ex != null) {
completeExchange(message.getExchange());
if (message.getContent(Exception.class) == null) {
// handle the right response
Message inMsg = message.getExchange().getInMessage();
Map<String, Object> ctx = responseContext.get(Thread.currentThread());
List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
Object[] result = resList == null ? null : resList.toArray();
callback.handleResponse(ctx, result);
return;
}
}
outFaultObserver.onMessage(message);
}
});
}
prepareConduitSelector(message);
// add additional interceptors and such
modifyChain(chain, message, false);
try {
chain.doIntercept(message);
} catch (Fault fault) {
enrichFault(fault);
throw fault;
}
if (callback != null) {
return null;
}
return processResult(message, exchange, oi, resContext);
} finally {
// ensure ResponseContext has HTTP RESPONSE CODE
if (null != exchange) {
Integer responseCode = (Integer) exchange.get(Message.RESPONSE_CODE);
resContext.put(MessageContext.HTTP_RESPONSE_CODE, responseCode);
resContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, responseCode);
setResponseContext(resContext);
}
if (origLoader != null) {
origLoader.reset();
}
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
}
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class GZIPAcceptEncodingTest method setUp.
@Before
public void setUp() throws Exception {
interceptor = new GZIPOutInterceptor();
inMessage = new MessageImpl();
outMessage = new MessageImpl();
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
inMessage.setExchange(exchange);
inMessage.setContent(InputStream.class, new ByteArrayInputStream(new byte[0]));
exchange.setOutMessage(outMessage);
outMessage.setExchange(exchange);
outMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
outInterceptors = EasyMock.createMock(InterceptorChain.class);
outMessage.setInterceptorChain(outInterceptors);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ContextUtilsTest method testIsOutbound.
@Test
public void testIsOutbound() throws Exception {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
exchange.setOutMessage(message);
message.setExchange(exchange);
assertTrue(ContextUtils.isOutbound(message));
}
Aggregations