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;
}
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();
}
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);
}
}
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();
}
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);
}
}
Aggregations