Search in sources :

Example 41 with ExchangeImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) JAXRSInvoker(org.apache.cxf.jaxrs.JAXRSInvoker) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 42 with ExchangeImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 43 with ExchangeImpl

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);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) Fault(org.apache.cxf.interceptor.Fault) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UncheckedException(org.apache.cxf.common.i18n.UncheckedException) MessageContentsList(org.apache.cxf.message.MessageContentsList) List(java.util.List) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 44 with ExchangeImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Example 45 with ExchangeImpl

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));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14