use of org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider in project cxf by apache.
the class PolicyExtensionsTest method testExtensions.
@Test
public void testExtensions() {
Bus bus = null;
try {
bus = new SpringBusFactory().createBus("/org/apache/cxf/ws/policy/policy-bus.xml", false);
AssertionBuilderRegistry abr = bus.getExtension(AssertionBuilderRegistry.class);
assertNotNull(abr);
AssertionBuilder<?> ab = abr.getBuilder(KNOWN);
assertNotNull(ab);
ab = abr.getBuilder(UNKNOWN);
assertNull(ab);
PolicyInterceptorProviderRegistry pipr = bus.getExtension(PolicyInterceptorProviderRegistry.class);
assertNotNull(pipr);
Set<PolicyInterceptorProvider> pips = pipr.get(KNOWN);
assertNotNull(pips);
assertFalse(pips.isEmpty());
pips = pipr.get(UNKNOWN);
assertNotNull(pips);
assertTrue(pips.isEmpty());
DomainExpressionBuilderRegistry debr = bus.getExtension(DomainExpressionBuilderRegistry.class);
assertNotNull(debr);
DomainExpressionBuilder deb = debr.get(KNOWN_DOMAIN_EXPR_TYPE);
assertNotNull(deb);
deb = debr.get(UNKNOWN);
assertNull(deb);
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
assertNotNull(pe);
PolicyEngineImpl engine = (PolicyEngineImpl) pe;
assertNotNull(engine.getPolicyProviders());
assertNotNull(engine.getRegistry());
Collection<PolicyProvider> pps = engine.getPolicyProviders();
assertEquals(3, pps.size());
boolean wsdlProvider = false;
boolean externalProvider = false;
boolean serviceProvider = false;
for (PolicyProvider pp : pps) {
if (pp instanceof Wsdl11AttachmentPolicyProvider) {
wsdlProvider = true;
} else if (pp instanceof ExternalAttachmentProvider) {
externalProvider = true;
} else if (pp instanceof ServiceModelPolicyProvider) {
serviceProvider = true;
}
}
assertTrue(wsdlProvider);
assertTrue(externalProvider);
assertTrue(serviceProvider);
PolicyBuilder builder = bus.getExtension(PolicyBuilder.class);
assertNotNull(builder);
} finally {
if (null != bus) {
bus.shutdown(true);
BusFactory.setDefaultBus(null);
}
}
}
use of org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider in project cxf by apache.
the class PolicyBeansTest method testParse.
@Test
public void testParse() {
Bus bus = new SpringBusFactory().createBus("org/apache/cxf/ws/policy/spring/beans.xml");
try {
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
assertTrue("Policy engine is not enabled", pe.isEnabled());
assertTrue("Unknown assertions are not ignored", pe.isIgnoreUnknownAssertions());
assertEquals(MaximalAlternativeSelector.class.getName(), pe.getAlternativeSelector().getClass().getName());
PolicyEngineImpl pei = (PolicyEngineImpl) pe;
Collection<PolicyProvider> providers = pei.getPolicyProviders();
assertEquals(4, providers.size());
int n = 0;
for (PolicyProvider pp : providers) {
if (pp instanceof ExternalAttachmentProvider) {
n++;
}
}
assertEquals("Unexpected number of external providers", 2, n);
} finally {
bus.shutdown(true);
}
}
use of org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider 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());
}
}
}
Aggregations