Search in sources :

Example 1 with ExternalAttachmentProvider

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);
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) DomainExpressionBuilder(org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilder) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) DomainExpressionBuilderRegistry(org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry) ServiceModelPolicyProvider(org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider) Wsdl11AttachmentPolicyProvider(org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider) ServiceModelPolicyProvider(org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider) ExternalAttachmentProvider(org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider) Wsdl11AttachmentPolicyProvider(org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider) Test(org.junit.Test)

Example 2 with ExternalAttachmentProvider

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);
    }
}
Also used : PolicyEngineImpl(org.apache.cxf.ws.policy.PolicyEngineImpl) Bus(org.apache.cxf.Bus) MaximalAlternativeSelector(org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) PolicyProvider(org.apache.cxf.ws.policy.PolicyProvider) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) ExternalAttachmentProvider(org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider) Test(org.junit.Test)

Example 3 with ExternalAttachmentProvider

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());
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) ExternalAttachmentProvider(org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider)

Aggregations

ExternalAttachmentProvider (org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider)3 Bus (org.apache.cxf.Bus)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 Test (org.junit.Test)2 Endpoint (org.apache.cxf.endpoint.Endpoint)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 PolicyEngine (org.apache.cxf.ws.policy.PolicyEngine)1 PolicyEngineImpl (org.apache.cxf.ws.policy.PolicyEngineImpl)1 PolicyProvider (org.apache.cxf.ws.policy.PolicyProvider)1 ServiceModelPolicyProvider (org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider)1 DomainExpressionBuilder (org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilder)1 DomainExpressionBuilderRegistry (org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry)1 Wsdl11AttachmentPolicyProvider (org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider)1 MaximalAlternativeSelector (org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector)1 Policy (org.apache.neethi.Policy)1