Search in sources :

Example 76 with Conduit

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

the class MAPAggregatorTest method setUpConduit.

private void setUpConduit(Message message, Exchange exchange) {
    setUpMessageExchange(message, exchange);
    Conduit conduit = EasyMock.createMock(Conduit.class);
    setUpExchangeConduit(message, exchange, conduit);
    EndpointReferenceType to = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
    to.setAddress(ContextUtils.getAttributedURI(expectedTo));
    conduit.getTarget();
    EasyMock.expectLastCall().andReturn(to).anyTimes();
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Conduit(org.apache.cxf.transport.Conduit)

Example 77 with Conduit

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

the class ClientPolicyInFaultInterceptor method handle.

protected void handle(Message msg) {
    if (!MessageUtils.isRequestor(msg)) {
        LOG.fine("Not a requestor.");
        return;
    }
    Exchange exchange = msg.getExchange();
    assert null != exchange;
    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }
    EndpointInfo ei = e.getEndpointInfo();
    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Conduit conduit = exchange.getConduit(msg);
    LOG.fine("conduit: " + conduit);
    List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<Interceptor<? extends Message>>();
    Collection<Assertion> assertions = new ArrayList<>();
    // 1. Check overridden policy
    Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
    if (p != null) {
        EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
        EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
        effectivePolicy.initialise(endpi, pe, true, true, msg);
        PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
        faultInterceptors.addAll(effectivePolicy.getInterceptors());
        assertions.addAll(effectivePolicy.getChosenAlternative());
    } else {
        // 2. Process endpoint policy
        // We do not know the underlying message type yet - so we pre-emptively add interceptors
        // that can deal with all faults returned to this client endpoint.
        EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg);
        LOG.fine("ep: " + ep);
        if (ep != null) {
            faultInterceptors.addAll(ep.getFaultInterceptors(msg));
            assertions.addAll(ep.getFaultVocabulary(msg));
        }
    }
    // add interceptors into message chain
    LOG.fine("faultInterceptors: " + faultInterceptors);
    for (Interceptor<? extends Message> i : faultInterceptors) {
        msg.getInterceptorChain().add(i);
        LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
    }
    // insert assertions of endpoint's fault vocabulary into message
    if (!assertions.isEmpty()) {
        msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) Assertion(org.apache.neethi.Assertion) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 78 with Conduit

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

the class JMSDestinationTest method testProperty.

@Test
public void testProperty() throws Exception {
    EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
    final String customPropertyName = "THIS_PROPERTY_WILL_NOT_BE_AUTO_COPIED";
    // set up the conduit send to be true
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    final Message outMessage = new MessageImpl();
    setupMessageHeader(outMessage, null);
    JMSMessageHeadersType headers = (JMSMessageHeadersType) outMessage.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
    headers.putProperty(customPropertyName, customPropertyName);
    final JMSDestination destination = setupJMSDestination(ei);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            verifyReceivedMessage(m);
            verifyHeaders(m, outMessage);
            // setup the message for
            Conduit backConduit;
            try {
                backConduit = destination.getBackChannel(m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                // copy the message encoding
                replyMessage.put(Message.ENCODING, m.get(Message.ENCODING));
                sendOneWayMessage(backConduit, replyMessage);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    destination.setMessageObserver(observer);
    sendMessageSync(conduit, outMessage);
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    verifyRequestResponseHeaders(inMessage, outMessage);
    JMSMessageHeadersType inHeader = (JMSMessageHeadersType) inMessage.get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
    assertNotNull("The inHeader should not be null", inHeader);
    // TODO we need to check the SOAP JMS transport properties here
    // wait for a while for the jms session recycling
    Thread.sleep(1000);
    conduit.close();
    destination.shutdown();
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) IOException(java.io.IOException) InvalidClientIDException(javax.jms.InvalidClientIDException) JMSException(javax.jms.JMSException) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 79 with Conduit

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

the class RequestResponseTest method sendAndReceiveMessages.

protected void sendAndReceiveMessages(EndpointInfo ei, boolean synchronous) throws IOException {
    inMessage = null;
    // set up the conduit send to be true
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    final Message outMessage = createMessage();
    final JMSDestination destination = setupJMSDestination(ei);
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            verifyReceivedMessage(m);
            verifyHeaders(m, outMessage);
            // setup the message for
            Conduit backConduit;
            try {
                backConduit = destination.getBackChannel(m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                sendOneWayMessage(backConduit, replyMessage);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    destination.setMessageObserver(observer);
    try {
        sendMessage(conduit, outMessage, synchronous);
        // wait for the message to be got from the destination,
        // create the thread to handler the Destination incoming message
        waitForReceiveInMessage();
        verifyReceivedMessage(inMessage);
    } finally {
        conduit.close();
        destination.shutdown();
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) IOException(java.io.IOException)

Example 80 with Conduit

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

the class RetransmissionQueueImpl method buildConduit.

/**
 * @param message
 * @param endpoint
 * @param to
 * @return
 */
protected Conduit buildConduit(SoapMessage message, final Endpoint endpoint, AttributedURIType to) {
    Conduit c;
    final String address = to.getValue();
    DeferredConduitSelector cs = new DeferredConduitSelector() {

        @Override
        public synchronized Conduit selectConduit(Message message) {
            Conduit conduit = null;
            EndpointInfo endpointInfo = endpoint.getEndpointInfo();
            EndpointReferenceType original = endpointInfo.getTarget();
            try {
                if (null != address) {
                    endpointInfo.setAddress(address);
                }
                conduit = super.selectConduit(message);
            } finally {
                endpointInfo.setAddress(original);
            }
            conduits.clear();
            return conduit;
        }
    };
    cs.setEndpoint(endpoint);
    c = cs.selectConduit(message);
    // REVISIT
    // use application endpoint message observer instead?
    c.setMessageObserver(new MessageObserver() {

        public void onMessage(Message message) {
            LOG.fine("Ignoring response to resent message.");
        }
    });
    cs.close();
    message.getExchange().setConduit(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) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) 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