Search in sources :

Example 6 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class AbstractConduitSelector method findCompatibleConduit.

/**
 * If address protocol was changed, conduit should be re-initialised
 *
 * @param message the current Message
 */
protected Conduit findCompatibleConduit(Message message) {
    Conduit c = message.get(Conduit.class);
    if (c == null && message.getExchange() != null && message.getExchange().getOutMessage() != null && message.getExchange().getOutMessage() != message) {
        c = message.getExchange().getOutMessage().get(Conduit.class);
    }
    if (c != null) {
        return c;
    }
    ContextualBooleanGetter cbg = new ContextualBooleanGetter(message);
    for (Conduit c2 : conduits) {
        if (c2.getTarget() == null || c2.getTarget().getAddress() == null || c2.getTarget().getAddress().getValue() == null) {
            continue;
        }
        String conduitAddress = c2.getTarget().getAddress().getValue();
        EndpointInfo ei = endpoint.getEndpointInfo();
        String actualAddress = ei.getAddress();
        String messageAddress = (String) message.get(Message.ENDPOINT_ADDRESS);
        if (messageAddress != null) {
            actualAddress = messageAddress;
        }
        if (matchAddresses(conduitAddress, actualAddress, cbg)) {
            return c2;
        }
    }
    for (Conduit c2 : conduits) {
        if (c2.getTarget() == null || c2.getTarget().getAddress() == null || c2.getTarget().getAddress().getValue() == null) {
            return c2;
        }
    }
    return null;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit)

Example 7 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class AbstractConduitSelector method getSelectedConduit.

/**
 * Mechanics to actually get the Conduit from the ConduitInitiator
 * if necessary.
 *
 * @param message the current Message
 */
protected Conduit getSelectedConduit(Message message) {
    Conduit c = findCompatibleConduit(message);
    if (c == null) {
        Exchange exchange = message.getExchange();
        EndpointInfo ei = endpoint.getEndpointInfo();
        String transportID = ei.getTransportId();
        try {
            ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus().getExtension(ConduitInitiatorManager.class);
            if (conduitInitiatorMgr != null) {
                ConduitInitiator conduitInitiator = conduitInitiatorMgr.getConduitInitiator(transportID);
                if (conduitInitiator != null) {
                    c = createConduit(message, exchange, conduitInitiator);
                } else {
                    getLogger().warning("ConduitInitiator not found: " + ei.getAddress());
                }
            } else {
                getLogger().warning("ConduitInitiatorManager not found");
            }
        } catch (BusException ex) {
            throw new Fault(ex);
        } catch (IOException ex) {
            throw new Fault(ex);
        }
    }
    if (c != null && c.getTarget() != null && c.getTarget().getAddress() != null) {
        replaceEndpointAddressPropertyIfNeeded(message, c.getTarget().getAddress().getValue(), c);
    }
    // the search for the conduit could cause extra properties to be reset/loaded.
    message.resetContextCache();
    message.put(Conduit.class, c);
    return c;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) BusException(org.apache.cxf.BusException)

Example 8 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class DeferredConduitSelector method selectConduit.

/**
 * Called when a Conduit is actually required.
 *
 * @param message
 * @return the Conduit to use for mediation of the message
 */
public Conduit selectConduit(Message message) {
    Conduit c = message.get(Conduit.class);
    if (c == null) {
        c = getSelectedConduit(message);
        message.put(Conduit.class, c);
    }
    return c;
}
Also used : Conduit(org.apache.cxf.transport.Conduit)

Example 9 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class MessageSenderInterceptor method getConduit.

public static Conduit getConduit(Message message) throws IOException {
    Exchange exchange = message.getExchange();
    Conduit conduit = exchange.getConduit(message);
    if (conduit == null && (exchange.getOutMessage() != null || exchange.getOutFaultMessage() != null)) {
        conduit = OutgoingChainInterceptor.getBackChannelConduit(message);
    }
    return conduit;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Conduit(org.apache.cxf.transport.Conduit)

Example 10 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class OneWayProcessorInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    if (message.getExchange().isOneWay() && !isRequestor(message) && message.get(OneWayProcessorInterceptor.class) == null && message.getExchange().get(Executor.class) == null) {
        // one way on server side, fork the rest of this chain onto the
        // workqueue, call the Outgoing chain directly.
        message.put(OneWayProcessorInterceptor.class, this);
        final InterceptorChain chain = message.getInterceptorChain();
        boolean robust = MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
        boolean useOriginalThread = MessageUtils.getContextualBoolean(message, USE_ORIGINAL_THREAD, false);
        if (!useOriginalThread && !robust) {
            // need to suck in all the data from the input stream as
            // the transport might discard any data on the stream when this
            // thread unwinds or when the empty response is sent back
            DelegatingInputStream in = message.getContent(DelegatingInputStream.class);
            if (in != null) {
                in.cacheInput();
            }
        }
        if (robust) {
            // continue to invoke the chain
            chain.pause();
            chain.resume();
            if (message.getContent(Exception.class) != null) {
                // CXF-5629 fault has been delivered alread in resume()
                return;
            }
        }
        try {
            Message partial = createMessage(message.getExchange());
            partial.remove(Message.CONTENT_TYPE);
            partial.setExchange(message.getExchange());
            Conduit conduit = message.getExchange().getDestination().getBackChannel(message);
            if (conduit != null) {
                message.getExchange().setInMessage(null);
                // for a one-way, the back channel could be
                // null if it knows it cannot send anything.
                conduit.prepare(partial);
                conduit.close(partial);
                message.getExchange().setInMessage(message);
            }
        } catch (IOException e) {
        // IGNORE
        }
        if (!useOriginalThread && !robust) {
            chain.pause();
            try {
                final Object lock = new Object();
                synchronized (lock) {
                    message.getExchange().getBus().getExtension(WorkQueueManager.class).getAutomaticWorkQueue().execute(new Runnable() {

                        public void run() {
                            synchronized (lock) {
                                lock.notifyAll();
                            }
                            chain.resume();
                        }
                    });
                    // wait a few milliseconds for the background thread to start processing
                    // Mostly just to make an attempt at keeping the ordering of the
                    // messages coming in from a client.  Not guaranteed though.
                    lock.wait(20);
                }
            } catch (RejectedExecutionException e) {
                LOG.warning("Executor queue is full, run the oneway invocation task in caller thread." + "  Users can specify a larger executor queue to avoid this.");
                // only block the thread if the prop is unset or set to false, otherwise let it go
                if (!MessageUtils.getContextualBoolean(message, "org.apache.cxf.oneway.rejected_execution_exception", false)) {
                    // the executor queue is full, so run the task in the caller thread
                    chain.unpause();
                }
            } catch (InterruptedException e) {
            // ignore - likely a busy work queue so we'll just let the one-way go
            }
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) DelegatingInputStream(org.apache.cxf.io.DelegatingInputStream) Conduit(org.apache.cxf.transport.Conduit) IOException(java.io.IOException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)83 Test (org.junit.Test)36 Message (org.apache.cxf.message.Message)35 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 Exchange (org.apache.cxf.message.Exchange)28 IOException (java.io.IOException)18 MessageImpl (org.apache.cxf.message.MessageImpl)17 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)13 MessageObserver (org.apache.cxf.transport.MessageObserver)12 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)12 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 Destination (org.apache.cxf.transport.Destination)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)10 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6