Search in sources :

Example 41 with Assertion

use of org.apache.neethi.Assertion 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<>();
    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 42 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class EndpointPolicyImpl method initializeInterceptors.

void initializeInterceptors(PolicyInterceptorProviderRegistry reg, Set<Interceptor<? extends Message>> out, Assertion a, boolean fault, Message msg) {
    QName qn = a.getName();
    List<Interceptor<? extends org.apache.cxf.message.Message>> i = fault ? reg.getInFaultInterceptorsForAssertion(qn) : reg.getInInterceptorsForAssertion(qn);
    out.addAll(i);
    if (a instanceof PolicyContainingAssertion) {
        Policy p = ((PolicyContainingAssertion) a).getPolicy();
        if (p != null) {
            for (Assertion a2 : getSupportedAlternatives(p, msg)) {
                initializeInterceptors(reg, out, a2, fault, msg);
            }
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) Interceptor(org.apache.cxf.interceptor.Interceptor) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion)

Example 43 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class EndpointPolicyImpl method initializeVocabulary.

synchronized void initializeVocabulary(Message m) {
    if (vocabulary != null) {
        return;
    }
    List<Assertion> v = new ArrayList<>();
    List<Assertion> fv = null;
    if (requestor) {
        fv = new ArrayList<>();
    }
    // vocabulary of alternative chosen for endpoint
    if (getChosenAlternative() != null) {
        for (Assertion a : getChosenAlternative()) {
            if (a.isOptional()) {
                continue;
            }
            v.add(a);
            if (null != fv) {
                fv.add(a);
            }
        }
    }
    // (in case of a client endpoint) messages
    for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
        EffectivePolicy p;
        if (!this.requestor) {
            p = engine.getEffectiveServerRequestPolicy(ei, boi, m);
            Collection<Assertion> c = engine.getAssertions(p, false);
            if (c != null) {
                addAll(v, c);
            }
        } else {
            p = engine.getEffectiveClientResponsePolicy(ei, boi, m);
            Collection<Assertion> c = engine.getAssertions(p, false);
            if (c != null) {
                addAll(v, c);
                if (null != fv) {
                    addAll(fv, c);
                }
            }
            if (boi.getFaults() != null && null != fv) {
                for (BindingFaultInfo bfi : boi.getFaults()) {
                    p = engine.getEffectiveClientFaultPolicy(ei, boi, bfi, m);
                    c = engine.getAssertions(p, false);
                    if (c != null) {
                        addAll(fv, c);
                    }
                }
            }
        }
    }
    if (requestor) {
        faultVocabulary = fv;
    }
    vocabulary = v;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 44 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class PolicyDataEngineImpl method getServerEndpointPolicy.

public <T> T getServerEndpointPolicy(Message m, EndpointInfo ei, Destination d, PolicyCalculator<T> policyCalculator) {
    Collection<Assertion> alternative = getPolicyEngine().getServerEndpointPolicy(ei, d, m).getChosenAlternative();
    List<T> filteredPolicies = new ArrayList<>();
    for (Assertion a : alternative) {
        if (policyCalculator.getDataClassName().equals(a.getName())) {
            T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData();
            filteredPolicies.add(p);
        }
    }
    return getPolicy(filteredPolicies, policyCalculator);
}
Also used : JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) ArrayList(java.util.ArrayList)

Example 45 with Assertion

use of org.apache.neethi.Assertion in project cxf by apache.

the class PolicyEngineImpl method getVocabulary.

/**
 * Return the vocabulary of a policy component, i.e. the set of QNames of
 * the assertions used in the componente, duplicates removed.
 * @param pc the policy component
 * @param includeOptional flag indicating if optional assertions should be included
 * @return the vocabulary
 */
Set<QName> getVocabulary(PolicyComponent pc, boolean includeOptional) {
    Collection<Assertion> assertions = getAssertions(pc, includeOptional);
    Set<QName> vocabulary = new HashSet<>();
    for (Assertion a : assertions) {
        vocabulary.add(a.getName());
    }
    return vocabulary;
}
Also used : QName(javax.xml.namespace.QName) Assertion(org.apache.neethi.Assertion)

Aggregations

Assertion (org.apache.neethi.Assertion)64 Policy (org.apache.neethi.Policy)27 Message (org.apache.cxf.message.Message)25 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 QName (javax.xml.namespace.QName)21 Interceptor (org.apache.cxf.interceptor.Interceptor)19 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)19 PolicyContainingAssertion (org.apache.neethi.PolicyContainingAssertion)9 Element (org.w3c.dom.Element)9 MessageImpl (org.apache.cxf.message.MessageImpl)7 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 All (org.apache.neethi.All)7 ExactlyOne (org.apache.neethi.ExactlyOne)7 Bus (org.apache.cxf.Bus)6 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)6 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)6 PolicyContainingPrimitiveAssertion (org.apache.neethi.builders.PolicyContainingPrimitiveAssertion)6 XMLPrimitiveAssertionBuilder (org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder)6 List (java.util.List)5