Search in sources :

Example 16 with Conduit

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

the class JettyHTTPDestinationTest method testGetBackChannelSend.

@Test
public void testGetBackChannelSend() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false, true);
    destination.doService(request, response);
    setUpInMessage();
    Conduit backChannel = destination.getBackChannel(inMessage);
    outMessage = setUpOutMessage();
    backChannel.prepare(outMessage);
    verifyBackChannelSend(backChannel, outMessage, 200);
}
Also used : Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Example 17 with Conduit

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

the class JettyHTTPDestinationTest method testGetAnonBackChannel.

@Test
public void testGetAnonBackChannel() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    destination.doService(request, response);
    setUpInMessage();
    Conduit backChannel = destination.getBackChannel(inMessage);
    assertNotNull("expected back channel", backChannel);
    assertEquals("unexpected target", EndpointReferenceUtils.ANONYMOUS_ADDRESS, backChannel.getTarget().getAddress().getValue());
}
Also used : Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Example 18 with Conduit

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

the class Destination method acknowledge.

/**
 * Acknowledges receipt of a message. If the message is the last in the
 * sequence, sends an out-of-band SequenceAcknowledgement unless there a
 * response will be sent to the acksTo address onto which the acknowldegment
 * can be piggybacked.
 *
 * @param sequenceType the sequenceType object that includes identifier and
 *            message number (and possibly a lastMessage element) for the
 *            message to be acknowledged)
 * @param replyToAddress the replyTo address of the message that carried
 *            this sequence information
 * @throws SequenceFault if the sequence specified in
 *             <code>sequenceType</code> does not exist
 */
public void acknowledge(Message message) throws SequenceFault, RMException {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType sequenceType = rmps.getSequence();
    if (null == sequenceType) {
        return;
    }
    DestinationSequence seq = getSequence(sequenceType.getIdentifier());
    if (null != seq) {
        if (seq.applyDeliveryAssurance(sequenceType.getMessageNumber(), message)) {
            if (PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
                return;
            }
            seq.acknowledge(message);
            if (null != rmps.getCloseSequence()) {
                seq.setLastMessageNumber(sequenceType.getMessageNumber());
                ackImmediately(seq, message);
            }
        } else {
            try {
                message.getInterceptorChain().abort();
                if (seq.sendAcknowledgement()) {
                    ackImmediately(seq, message);
                }
                Exchange exchange = message.getExchange();
                Conduit conduit = exchange.getDestination().getBackChannel(message);
                if (conduit != null) {
                    // null if it knows it cannot send anything.
                    if (seq.sendAcknowledgement()) {
                        AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
                        InternalContextUtils.rebaseResponse(null, maps, message);
                    } else {
                        Message response = createMessage(exchange);
                        response.setExchange(exchange);
                        response.remove(Message.CONTENT_TYPE);
                        conduit.prepare(response);
                        conduit.close(response);
                    }
                }
            } catch (IOException e) {
                LOG.log(Level.SEVERE, e.getMessage());
                throw new RMException(e);
            }
        }
    } else {
        ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
        RMConstants consts = protocol.getConstants();
        SequenceFaultFactory sff = new SequenceFaultFactory(consts);
        throw sff.createUnknownSequenceFault(sequenceType.getIdentifier());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException)

Example 19 with Conduit

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

the class PolicyInInterceptor method handle.

protected void handle(Message msg) {
    Exchange exchange = msg.getExchange();
    Bus bus = exchange.getBus();
    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }
    EndpointInfo ei = e.getEndpointInfo();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    List<Interceptor<? extends Message>> interceptors = 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, msg);
        msg.put(EffectivePolicy.class, effectivePolicy);
        PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
        interceptors.addAll(effectivePolicy.getInterceptors());
        assertions.addAll(effectivePolicy.getChosenAlternative());
    } else if (MessageUtils.isRequestor(msg)) {
        // 2. Process client policy
        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        if (boi == null) {
            Conduit conduit = exchange.getConduit(msg);
            EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg);
            if (ep != null) {
                interceptors.addAll(ep.getInterceptors(msg));
                assertions.addAll(ep.getVocabulary(msg));
            }
        } else {
            // We do not know the underlying message type yet - so we pre-emptively add interceptors
            // that can deal with any resposes or faults returned to this client endpoint.
            EffectivePolicy ep = pe.getEffectiveClientResponsePolicy(ei, boi, msg);
            if (ep != null) {
                interceptors.addAll(ep.getInterceptors());
                // insert assertions of endpoint's vocabulary into message
                if (ep.getPolicy() != null) {
                    msg.put(AssertionInfoMap.class, new AssertionInfoMap(ep.getPolicy()));
                    msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
                }
            }
        }
    } else {
        // 3. Process server policy
        Destination destination = exchange.getDestination();
        // We do not know the underlying message type yet - so we pre-emptively add interceptors
        // that can deal with any messages to this endpoint
        EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, msg);
        if (ep != null) {
            interceptors.addAll(ep.getInterceptors(msg));
            assertions.addAll(ep.getVocabulary(msg));
        }
    }
    // add interceptors into message chain
    for (Interceptor<? extends Message> i : interceptors) {
        msg.getInterceptorChain().add(i);
    }
    // Insert assertions of endpoint's vocabulary into message
    if (!assertions.isEmpty()) {
        msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) 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 20 with Conduit

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

the class PolicyOutInterceptor method handle.

protected void handle(Message msg) {
    Exchange exchange = msg.getExchange();
    Bus bus = exchange.getBus();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (null == boi) {
        LOG.fine("No binding operation info.");
        return;
    }
    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }
    EndpointInfo ei = e.getEndpointInfo();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    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, false, msg);
        msg.put(EffectivePolicy.class, effectivePolicy);
        PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
        addInterceptors(effectivePolicy.getInterceptors(), msg);
        assertions.addAll(effectivePolicy.getChosenAlternative());
    } else if (MessageUtils.isRequestor(msg)) {
        // 2. Process client policy
        Conduit conduit = exchange.getConduit(msg);
        // add the required interceptors
        EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit, msg);
        msg.put(EffectivePolicy.class, effectivePolicy);
        if (effectivePolicy != null) {
            PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
            addInterceptors(effectivePolicy.getInterceptors(), msg);
            assertions.addAll(effectivePolicy.getChosenAlternative());
        }
    } else {
        // 3. Process server policy
        Destination destination = exchange.getDestination();
        List<List<Assertion>> incoming = CastUtils.cast((List<?>) exchange.get("ws-policy.validated.alternatives"));
        EffectivePolicy effectivePolicy = pe.getEffectiveServerResponsePolicy(ei, boi, destination, incoming, msg);
        msg.put(EffectivePolicy.class, effectivePolicy);
        if (effectivePolicy != null) {
            PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
            addInterceptors(effectivePolicy.getInterceptors(), msg);
            assertions.addAll(effectivePolicy.getChosenAlternative());
        }
    }
    // insert assertions of endpoint's fault vocabulary into message
    if (null != assertions && !assertions.isEmpty()) {
        if (LOG.isLoggable(Level.FINEST)) {
            StringBuilder buf = new StringBuilder();
            buf.append("Chosen alternative: ");
            String nl = SystemPropertyAction.getProperty("line.separator");
            buf.append(nl);
            for (Assertion a : assertions) {
                PolicyUtils.printPolicyComponent(a, buf, 1);
            }
            LOG.finest(buf.toString());
        }
        msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
    }
}
Also used : Policy(org.apache.neethi.Policy) Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) List(java.util.List)

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