Search in sources :

Example 71 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class EndpointPolicyImpl method initializeInterceptors.

synchronized void initializeInterceptors(Message m) {
    if (interceptors != null) {
        return;
    }
    if (engine == null || engine.getBus() == null || engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class) == null) {
        return;
    }
    PolicyInterceptorProviderRegistry reg = engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
    Set<Interceptor<? extends Message>> out = new LinkedHashSet<Interceptor<? extends Message>>();
    if (getChosenAlternative() != null) {
        for (Assertion a : getChosenAlternative()) {
            initializeInterceptors(reg, out, a, false, m);
        }
    }
    List<Interceptor<? extends Message>> tmp = null;
    if (requestor) {
        tmp = new ArrayList<Interceptor<? extends Message>>(out);
        out.clear();
        for (Assertion a : getChosenAlternative()) {
            initializeInterceptors(reg, out, a, true, m);
        }
        faultInterceptors = new ArrayList<Interceptor<? extends Message>>(out);
    } else if (ei != null && ei.getBinding() != null) {
        for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
            EffectivePolicy p = engine.getEffectiveServerRequestPolicy(ei, boi, m);
            if (p == null || p.getPolicy() == null || p.getPolicy().isEmpty()) {
                continue;
            }
            Collection<Assertion> c = engine.getAssertions(p, true);
            if (c != null) {
                for (Assertion a : c) {
                    initializeInterceptors(reg, out, a, false, m);
                    initializeInterceptors(reg, out, a, true, m);
                }
            }
        }
        tmp = new ArrayList<Interceptor<? extends Message>>(out);
    } else {
        tmp = new ArrayList<Interceptor<? extends Message>>(out);
    }
    interceptors = tmp;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Assertion(org.apache.neethi.Assertion) PolicyContainingAssertion(org.apache.neethi.PolicyContainingAssertion) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 72 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class PolicyEngineTest method testGetEffectiveClientRequestPolicy.

@Test
public void testGetEffectiveClientRequestPolicy() throws Exception {
    Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {});
    engine = EasyMock.createMockBuilder(PolicyEngineImpl.class).addMockedMethod(m).createMock(control);
    engine.init();
    EndpointInfo ei = createMockEndpointInfo();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    AssertingConduit conduit = control.createMock(AssertingConduit.class);
    EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class);
    EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi);
    epi.initialise(ei, boi, engine, conduit, true, true, msg);
    EasyMock.expectLastCall();
    control.replay();
    assertSame(epi, engine.getEffectiveClientRequestPolicy(ei, boi, conduit, msg));
    assertSame(epi, engine.getEffectiveClientRequestPolicy(ei, boi, conduit, msg));
    control.verify();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 73 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class ExternalAttachmentProviderTest method setUpAttachment.

void setUpAttachment(Object subject, boolean applies, ExternalAttachmentProvider eap) {
    attachments.clear();
    attachment = control.createMock(PolicyAttachment.class);
    attachments.add(attachment);
    policy = new Policy();
    assertion = new PrimitiveAssertion(TEST_ASSERTION_TYPE);
    policy.addAssertion(assertion);
    eap.setAttachments(attachments);
    if (subject instanceof ServiceInfo) {
        EasyMock.expect(attachment.appliesTo((ServiceInfo) subject)).andReturn(applies);
    } else if (subject instanceof EndpointInfo) {
        EasyMock.expect(attachment.appliesTo((EndpointInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingOperationInfo) {
        EasyMock.expect(attachment.appliesTo((BindingOperationInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingMessageInfo) {
        EasyMock.expect(attachment.appliesTo((BindingMessageInfo) subject)).andReturn(applies);
    } else if (subject instanceof BindingFaultInfo) {
        EasyMock.expect(attachment.appliesTo((BindingFaultInfo) subject)).andReturn(applies);
    } else {
        System.err.println("subject class: " + subject.getClass());
    }
    if (applies) {
        EasyMock.expect(attachment.getPolicy()).andReturn(policy);
    }
}
Also used : Policy(org.apache.neethi.Policy) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 74 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo in project cxf by apache.

the class PolicyAttachmentTest method testAppliesToOperation.

@Test
public void testAppliesToOperation() {
    BindingOperationInfo boi1 = control.createMock(BindingOperationInfo.class);
    BindingOperationInfo boi2 = control.createMock(BindingOperationInfo.class);
    DomainExpression de = control.createMock(DomainExpression.class);
    Collection<DomainExpression> des = Collections.singletonList(de);
    PolicyAttachment pa = new PolicyAttachment();
    pa.setDomainExpressions(des);
    EasyMock.expect(de.appliesTo(boi1)).andReturn(false);
    EasyMock.expect(de.appliesTo(boi2)).andReturn(true);
    control.replay();
    assertTrue(!pa.appliesTo(boi1));
    assertTrue(pa.appliesTo(boi2));
    control.verify();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Test(org.junit.Test)

Example 75 with BindingOperationInfo

use of org.apache.cxf.service.model.BindingOperationInfo 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)

Aggregations

BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)214 QName (javax.xml.namespace.QName)82 BindingInfo (org.apache.cxf.service.model.BindingInfo)57 Test (org.junit.Test)55 Exchange (org.apache.cxf.message.Exchange)50 OperationInfo (org.apache.cxf.service.model.OperationInfo)47 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)42 Endpoint (org.apache.cxf.endpoint.Endpoint)41 Message (org.apache.cxf.message.Message)36 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)36 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)32 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)31 Service (org.apache.cxf.service.Service)29 Fault (org.apache.cxf.interceptor.Fault)24 MessageInfo (org.apache.cxf.service.model.MessageInfo)24 MessageContentsList (org.apache.cxf.message.MessageContentsList)23 Method (java.lang.reflect.Method)22 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)22 ArrayList (java.util.ArrayList)21 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)16