public PolicyOutInterceptor() {
super(PolicyConstants.POLICY_OUT_INTERCEPTOR_ID, Phase.SETUP);
}
protected void handle(Message msg) {
Exchange exchange = msg.getExchange();
Bus bus = exchange.get(Bus.class);
BindingOperationInfo boi = exchange.get(BindingOperationInfo.class);
if (null == boi) {
LOG.fine("No binding operation info.");
return;
}
Endpoint e = exchange.get(Endpoint.class);
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Policy p = (Policy)msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, (PolicyEngineImpl)pe, false);
msg.put(EffectivePolicy.class, effectivePolicy);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ",
effectivePolicy.getPolicy());
List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
for (Interceptor<? extends Message> i : interceptors) {
msg.getInterceptorChain().add(i);
LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
}
// insert assertions of the chosen alternative into the message
Collection<PolicyAssertion> assertions = effectivePolicy.getChosenAlternative();
if (null != assertions && !assertions.isEmpty()) {
if (LOG.isLoggable(Level.FINEST)) {
StringBuilder buf = new StringBuilder();
buf.append("Chosen alternative: ");
String nl = System.getProperty("line.separator");
buf.append(nl);
for (PolicyAssertion a : assertions) {
PolicyUtils.printPolicyComponent(a, buf, 1);
}
LOG.finest(buf.toString());
}
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
}
} else if (MessageUtils.isRequestor(msg)) {
Conduit conduit = exchange.getConduit(msg);
// add the required interceptors
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit);
msg.put(EffectivePolicy.class, effectivePolicy);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
for (Interceptor<? extends Message> i : interceptors) {
msg.getInterceptorChain().add(i);
LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
}
// insert assertions of the chosen alternative into the message
Collection<PolicyAssertion> assertions = effectivePolicy.getChosenAlternative();
if (null != assertions && !assertions.isEmpty()) {
if (LOG.isLoggable(Level.FINEST)) {
StringBuilder buf = new StringBuilder();
buf.append("Chosen alternative: ");
String nl = System.getProperty("line.separator");
buf.append(nl);
for (PolicyAssertion a : assertions) {
PolicyUtils.printPolicyComponent(a, buf, 1);
}
LOG.finest(buf.toString());
}
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
}
} else {
Destination destination = exchange.getDestination();
EffectivePolicy effectivePolicy = pe.getEffectiveServerResponsePolicy(ei, boi, destination);
msg.put(EffectivePolicy.class, effectivePolicy);
List<Interceptor<? extends Message>> interceptors = effectivePolicy.getInterceptors();
for (Interceptor<? extends Message> oi : interceptors) {