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