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