Search in sources :

Example 21 with Policy

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

the class ServerPolicyOutFaultInterceptor method handle.

protected void handle(Message msg) {
    if (MessageUtils.isRequestor(msg)) {
        LOG.fine("Is a requestor.");
        return;
    }
    Exchange exchange = msg.getExchange();
    assert null != exchange;
    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();
    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = exchange.getDestination();
    Exception ex = exchange.get(Exception.class);
    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, false, true, msg);
        PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
        faultInterceptors.addAll(effectivePolicy.getInterceptors());
        assertions.addAll(effectivePolicy.getChosenAlternative());
    } else {
        // 2. Process effective server policy
        BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
        if (bfi == null && msg.get(FaultMode.class) != FaultMode.UNCHECKED_APPLICATION_FAULT && msg.get(FaultMode.class) != FaultMode.CHECKED_APPLICATION_FAULT) {
            return;
        }
        EffectivePolicy effectivePolicy = pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, msg);
        if (effectivePolicy != null) {
            faultInterceptors.addAll(effectivePolicy.getInterceptors());
            assertions.addAll(effectivePolicy.getChosenAlternative());
        }
    }
    // add interceptors into message chain
    for (Interceptor<? extends Message> oi : faultInterceptors) {
        msg.getInterceptorChain().add(oi);
        LOG.log(Level.FINE, "Added interceptor of type {0}", oi.getClass().getSimpleName());
    }
    // insert assertions of the chosen alternative into the message
    if (null != assertions && !assertions.isEmpty()) {
        msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
    }
}
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) FaultMode(org.apache.cxf.message.FaultMode) Endpoint(org.apache.cxf.endpoint.Endpoint) Interceptor(org.apache.cxf.interceptor.Interceptor) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 22 with Policy

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

the class WSPolicyFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    Endpoint endpoint = server.getEndpoint();
    Policy p = initializeEndpointPolicy(endpoint, bus);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    EndpointInfo ei = endpoint.getEndpointInfo();
    EndpointPolicy ep = pe.getServerEndpointPolicy(ei, null, null);
    pe.setServerEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus)));
    // Add policy to the service model (and consequently to the WSDL)
    // FIXME - ideally this should probably be moved up to where the policies are applied to the
    // endpoint, rather than this late.  As a consequence of its location, you have to declare a
    // ws policy feature on every endpoint in order to get any policy attachments into the
    // wsdl.  Alternatively add to the WSDLServiceBuilder somehow.
    ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei);
    for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) {
        if (pp instanceof ExternalAttachmentProvider) {
            pu.addPolicyAttachments(((ExternalAttachmentProvider) pp).getAttachments());
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) ExternalAttachmentProvider(org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider)

Example 23 with Policy

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

the class WSPolicyFeature method initialize.

@Override
public void initialize(Client client, Bus bus) {
    Endpoint endpoint = client.getEndpoint();
    Policy p = initializeEndpointPolicy(endpoint, bus);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    EndpointInfo ei = endpoint.getEndpointInfo();
    EndpointPolicy ep = pe.getClientEndpointPolicy(ei, null, null);
    pe.setClientEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus)));
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 24 with Policy

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

the class WSPolicyFeature method resolveReference.

Policy resolveReference(PolicyReference ref, PolicyBuilder builder, Bus bus, DescriptionInfo i) {
    Policy p = null;
    if (!ref.getURI().startsWith("#")) {
        String base = i == null ? null : i.getBaseURI();
        p = resolveExternal(ref, base, bus);
    } else {
        p = resolveLocal(ref, bus, i);
    }
    if (null == p) {
        throw new PolicyException(new Message("UNRESOLVED_POLICY_REFERENCE_EXC", BUNDLE, ref.getURI()));
    }
    return p;
}
Also used : Policy(org.apache.neethi.Policy) Message(org.apache.cxf.common.i18n.Message)

Example 25 with Policy

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

the class WSPolicyFeature method resolveLocal.

Policy resolveLocal(PolicyReference ref, final Bus bus, DescriptionInfo i) {
    String uri = ref.getURI().substring(1);
    String absoluteURI = i == null ? uri : i.getBaseURI() + uri;
    PolicyRegistry registry = bus.getExtension(PolicyEngine.class).getRegistry();
    Policy resolved = registry.lookup(absoluteURI);
    if (null != resolved) {
        return resolved;
    }
    ReferenceResolver resolver = new ReferenceResolver() {

        public Policy resolveReference(String uri) {
            PolicyBean pb = bus.getExtension(ConfiguredBeanLocator.class).getBeanOfType(uri, PolicyBean.class);
            if (null != pb) {
                PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
                return builder.getPolicy(pb.getElement());
            }
            return null;
        }
    };
    resolved = resolver.resolveReference(uri);
    if (null != resolved) {
        ref.setURI(absoluteURI);
        registry.register(absoluteURI, resolved);
    }
    return resolved;
}
Also used : Policy(org.apache.neethi.Policy) ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) PolicyRegistry(org.apache.neethi.PolicyRegistry) ReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver) RemoteReferenceResolver(org.apache.cxf.ws.policy.attachment.reference.RemoteReferenceResolver)

Aggregations

Policy (org.apache.neethi.Policy)122 Test (org.junit.Test)47 Assertion (org.apache.neethi.Assertion)27 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)21 All (org.apache.neethi.All)18 ExactlyOne (org.apache.neethi.ExactlyOne)18 Message (org.apache.cxf.message.Message)15 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)14 Element (org.w3c.dom.Element)13 Bus (org.apache.cxf.Bus)12 PrimitiveAssertion (org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion)12 List (java.util.List)9 Interceptor (org.apache.cxf.interceptor.Interceptor)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 HashMap (java.util.HashMap)7 OMElement (org.apache.axiom.om.OMElement)7 MessageImpl (org.apache.cxf.message.MessageImpl)7 ReferenceResolver (org.apache.cxf.ws.policy.attachment.reference.ReferenceResolver)6 InputStream (java.io.InputStream)5