Search in sources :

Example 66 with Conduit

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

the class AbstractConduitSelector method createConduit.

protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator) throws IOException {
    Conduit c = null;
    synchronized (endpoint) {
        if (!conduits.isEmpty()) {
            c = findCompatibleConduit(message);
            if (c != null) {
                return c;
            }
        }
        EndpointInfo ei = endpoint.getEndpointInfo();
        String add = (String) message.get(Message.ENDPOINT_ADDRESS);
        String basePath = (String) message.get(Message.BASE_PATH);
        if (StringUtils.isEmpty(add) || add.equals(ei.getAddress())) {
            c = conduitInitiator.getConduit(ei, exchange.getBus());
            replaceEndpointAddressPropertyIfNeeded(message, add, c);
        } else {
            EndpointReferenceType epr = new EndpointReferenceType();
            AttributedURIType ad = new AttributedURIType();
            ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
            epr.setAddress(ad);
            c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
        }
        MessageObserver observer = exchange.get(MessageObserver.class);
        if (observer != null) {
            c.setMessageObserver(observer);
        } else {
            getLogger().warning("MessageObserver not found");
        }
        conduits.add(c);
    }
    return c;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Conduit(org.apache.cxf.transport.Conduit) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType)

Example 67 with Conduit

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

the class UpfrontConduitSelector method prepare.

/**
 * Called prior to the interceptor chain being traversed.
 *
 * @param message the current Message
 */
public void prepare(Message message) {
    Conduit c = message.get(Conduit.class);
    if (c == null) {
        c = getSelectedConduit(message);
        message.put(Conduit.class, c);
    }
}
Also used : Conduit(org.apache.cxf.transport.Conduit)

Example 68 with Conduit

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

the class UpfrontConduitSelector 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 69 with Conduit

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

the class InternalContextUtils method rebaseResponse.

/**
 * Rebase response on replyTo
 *
 * @param reference the replyTo reference
 * @param inMAPs the inbound MAPs
 * @param inMessage the current message
 */
// CHECKSTYLE:OFF Max executable statement count limitation
public static void rebaseResponse(EndpointReferenceType reference, AddressingProperties inMAPs, final Message inMessage) {
    String namespaceURI = inMAPs.getNamespaceURI();
    if (!ContextUtils.retrievePartialResponseSent(inMessage)) {
        ContextUtils.storePartialResponseSent(inMessage);
        Exchange exchange = inMessage.getExchange();
        Message fullResponse = exchange.getOutMessage();
        Message partialResponse = ContextUtils.createMessage(exchange);
        ensurePartialResponseMAPs(partialResponse, namespaceURI);
        // ensure the inbound MAPs are available in the partial response
        // message (used to determine relatesTo etc.)
        ContextUtils.propogateReceivedMAPs(inMAPs, partialResponse);
        Destination target = inMessage.getDestination();
        if (target == null) {
            return;
        }
        try {
            if (reference == null) {
                reference = ContextUtils.getNoneEndpointReference();
            }
            Conduit backChannel = target.getBackChannel(inMessage);
            if (backChannel != null) {
                partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                partialResponse.put(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                boolean robust = MessageUtils.getContextualBoolean(inMessage, Message.ROBUST_ONEWAY, false);
                if (robust) {
                    BindingOperationInfo boi = exchange.getBindingOperationInfo();
                    // insert the executor in the exchange to fool the OneWayProcessorInterceptor
                    exchange.put(Executor.class, getExecutor(inMessage));
                    // pause dispatch on current thread and resume...
                    inMessage.getInterceptorChain().pause();
                    inMessage.getInterceptorChain().resume();
                    // restore the BOI for the partial response handling
                    exchange.put(BindingOperationInfo.class, boi);
                }
                // set up interceptor chains and send message
                InterceptorChain chain = fullResponse != null ? fullResponse.getInterceptorChain() : OutgoingChainInterceptor.getOutInterceptorChain(exchange);
                exchange.setOutMessage(partialResponse);
                partialResponse.setInterceptorChain(chain);
                exchange.put(ConduitSelector.class, new PreexistingConduitSelector(backChannel, exchange.getEndpoint()));
                if (chain != null && !chain.doIntercept(partialResponse) && partialResponse.getContent(Exception.class) != null) {
                    if (partialResponse.getContent(Exception.class) instanceof Fault) {
                        throw (Fault) partialResponse.getContent(Exception.class);
                    }
                    throw new Fault(partialResponse.getContent(Exception.class));
                }
                if (chain != null) {
                    chain.reset();
                }
                exchange.put(ConduitSelector.class, new NullConduitSelector());
                if (fullResponse == null) {
                    fullResponse = ContextUtils.createMessage(exchange);
                }
                exchange.setOutMessage(fullResponse);
                Destination destination = createDecoupledDestination(exchange, reference);
                exchange.setDestination(destination);
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Destination(org.apache.cxf.transport.Destination) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) Fault(org.apache.cxf.interceptor.Fault) PreexistingConduitSelector(org.apache.cxf.endpoint.PreexistingConduitSelector) IOException(java.io.IOException) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector)

Example 70 with Conduit

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

the class Proxy method createClient.

protected Client createClient(Bus bus, Endpoint endpoint, final ProtocolVariation protocol, Conduit conduit, final EndpointReferenceType address) {
    ConduitSelector cs = new DeferredConduitSelector(conduit) {

        @Override
        public synchronized Conduit selectConduit(Message message) {
            Conduit conduit = null;
            EndpointInfo endpointInfo = getEndpoint().getEndpointInfo();
            EndpointReferenceType original = endpointInfo.getTarget();
            try {
                if (null != address) {
                    endpointInfo.setAddress(address);
                }
                conduit = super.selectConduit(message);
            } finally {
                endpointInfo.setAddress(original);
            }
            return conduit;
        }
    };
    RMClient client = new RMClient(bus, endpoint, cs);
    // WS-RM requires ws-addressing
    WSAddressingFeature wsa = new WSAddressingFeature();
    wsa.setAddressingRequired(true);
    wsa.initialize(client, bus);
    Map<String, Object> context = client.getRequestContext();
    context.put(MAPAggregator.ADDRESSING_NAMESPACE, protocol.getWSANamespace());
    context.put(RMManager.WSRM_VERSION_PROPERTY, protocol.getWSRMNamespace());
    context.put(RMManager.WSRM_WSA_VERSION_PROPERTY, protocol.getWSANamespace());
    return client;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) DeferredConduitSelector(org.apache.cxf.endpoint.DeferredConduitSelector) DeferredConduitSelector(org.apache.cxf.endpoint.DeferredConduitSelector)

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