Java Code Examples for org.apache.cxf.Bus#getExtension()

The following examples show how to use org.apache.cxf.Bus#getExtension() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CXFBusImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testShutdownWithBusLifecycle() {
    final Bus bus = new ExtensionManagerBus();
    BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
    BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
    EasyMock.reset(listener);
    listener.preShutdown();
    EasyMock.expectLastCall();
    listener.postShutdown();
    EasyMock.expectLastCall();
    EasyMock.replay(listener);
    lifeCycleManager.registerLifeCycleListener(listener);
    bus.shutdown(true);
    EasyMock.verify(listener);
    bus.shutdown(true);
}
 
Example 2
Source File: SpringBusFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testForLifeCycle() {
    BusLifeCycleListener bl = EasyMock.createMock(BusLifeCycleListener.class);
    Bus bus = new SpringBusFactory().createBus();
    BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
    lifeCycleManager.registerLifeCycleListener(bl);
    EasyMock.reset(bl);
    bl.preShutdown();
    EasyMock.expectLastCall();
    bl.postShutdown();
    EasyMock.expectLastCall();
    EasyMock.replay(bl);
    bus.shutdown(true);
    EasyMock.verify(bl);

}
 
Example 3
Source File: AbstractToolContainer.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Bus getBus() {
    Bus bus = BusFactory.getDefaultBus();

    OASISCatalogManager catalogManager = bus.getExtension(OASISCatalogManager.class);

    String catalogLocation = getCatalogURL();
    if (!StringUtils.isEmpty(catalogLocation)) {
        try {
            catalogManager.loadCatalog(new URI(catalogLocation).toURL());
        } catch (Exception e) {
            e.printStackTrace(err);
            throw new ToolException(new Message("FOUND_NO_FRONTEND", LOG, catalogLocation));
        }
    }

    return bus;
}
 
Example 4
Source File: MetricsFeature.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void createDefaultProvidersIfNeeded(Bus bus) {
    if (providers == null) {
        ConfiguredBeanLocator b = bus.getExtension(ConfiguredBeanLocator.class);
        if (b != null) {
            Collection<?> coll = b.getBeansOfType(MetricsProvider.class);
            if (coll != null) {
                providers = coll.toArray(new MetricsProvider[]{});
            }
        }
    }
    if (providers == null) {
        try {
            Class<?> cls = ClassLoaderUtils.loadClass("org.apache.cxf.metrics.codahale.CodahaleMetricsProvider",
                    org.apache.cxf.metrics.MetricsFeature.class);
            Constructor<?> c = cls.getConstructor(Bus.class);
            providers = new MetricsProvider[] {(MetricsProvider)c.newInstance(bus)};
        } catch (Throwable t) {
            // ignore;
        }
    }
}
 
Example 5
Source File: SequenceTimeoutTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void run()  {
    SpringBusFactory bf = new SpringBusFactory();
    System.setProperty("db.name", "rdbm");
    Bus bus = bf.createBus("org/apache/cxf/systest/ws/rm/rminterceptors.xml");
    System.clearProperty("db.name");
    BusFactory.setDefaultBus(bus);

    setBus(bus);

    rmManager = bus.getExtension(RMManager.class);
    rmManager.getConfiguration().setInactivityTimeout(1000L);

    //System.out.println("Created control bus " + bus);
    GreeterImpl greeterImplementor = new GreeterImpl();
    endpoint = Endpoint.publish(ADDRESS, greeterImplementor);

    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
}
 
Example 6
Source File: EndpointReferenceUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static MultiplexDestination getMatchingMultiplexDestination(QName serviceQName, String portName,
                                                                    Bus bus) {
    MultiplexDestination destination = null;
    ServerRegistry serverRegistry = bus.getExtension(ServerRegistry.class);
    if (null != serverRegistry) {
        List<Server> servers = serverRegistry.getServers();
        for (Server s : servers) {
            QName targetServiceQName = s.getEndpoint().getEndpointInfo().getService().getName();
            if (serviceQName.equals(targetServiceQName) && portNameMatches(s, portName)) {
                Destination dest = s.getDestination();
                if (dest instanceof MultiplexDestination) {
                    destination = (MultiplexDestination)dest;
                    break;
                }
            }
        }
    } else {
        LOG.log(Level.WARNING,
                "Failed to locate service matching " + serviceQName
                + ", because the bus ServerRegistry extension provider is null");
    }
    return destination;
}
 
Example 7
Source File: HTTPTransportFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDestination() {
    Bus bus = BusFactory.getDefaultBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPTransportFactory factory = bus.getExtension(HTTPTransportFactory.class);
    if (factory != null) {
        try {
            factory.getDestination(ei, bus);
            fail("Expect exception here.");
        } catch (IOException ex) {
            assertTrue("We should find some exception related to the HttpDestination",
                   ex.getMessage().indexOf("HttpDestinationFactory") > 0);
        }
    }
}
 
Example 8
Source File: BusApplicationListenerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testParentApplicationEvent() {
    AbstractRefreshableApplicationContext parent = new ClassPathXmlApplicationContext();
    parent.refresh();
    SpringBusFactory factory = new SpringBusFactory(parent);
    Bus bus = factory.createBus();
    CXFBusLifeCycleManager manager = bus.getExtension(CXFBusLifeCycleManager.class);
    BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
    manager.registerLifeCycleListener(listener);
    EasyMock.reset(listener);
    listener.preShutdown();
    EasyMock.expectLastCall().times(1);
    listener.postShutdown();
    EasyMock.expectLastCall().times(1);
    EasyMock.replay(listener);
    parent.close();
    EasyMock.verify(listener);
}
 
Example 9
Source File: CxfUtil.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void destroy(@Observes final AssemblerBeforeApplicationDestroyed ignored) {
    final SystemInstance systemInstance = SystemInstance.get();
    final Bus bus = getBus();

    // avoid to leak, we can enhance it to remove endpoints by app but not sure it does worth the effort
    // alternative can be a bus per app but would enforce us to change some deeper part of our config/design
    if ("true".equalsIgnoreCase(systemInstance.getProperty("openejb.cxf.monitoring.jmx.clear-on-undeploy", "true"))) {
        final CounterRepository repo = bus.getExtension(CounterRepository.class);
        if (repo != null) {
            repo.getCounters().clear();
        }
    }
}
 
Example 10
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Exchange getExchange() {
    Bus bus = control.createMock(Bus.class);
    bus.getExtension(PhaseManager.class);
    EasyMock.expectLastCall().andReturn(new PhaseManagerImpl()).anyTimes();

    Exchange exchange = control.createMock(Exchange.class);
    exchange.getBus();
    EasyMock.expectLastCall().andReturn(bus).anyTimes();
    EasyMock.expect(exchange.isEmpty()).andReturn(true).anyTimes();
    return exchange;
}
 
Example 11
Source File: ProtobufferImporterTest.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
protected void startStandaloneServer(ProtobufferImportDeclarationWrapper pojo) {

        Bus cxfbus = BusFactory.getDefaultBus(true);
        BindingFactoryManager mgr = cxfbus.getExtension(BindingFactoryManager.class);
        mgr.registerBindingFactory(ProtobufBindingFactory.PROTOBUF_BINDING_ID, new ProtobufBindingFactory(cxfbus));
        ProtobufServerFactoryBean serverFactoryBean = new ProtobufServerFactoryBean();
        serverFactoryBean.setAddress(pojo.getAddress());
        serverFactoryBean.setBus(cxfbus);
        serverFactoryBean.setServiceBean(protobufferRemoteService);
        serverFactoryBean.setMessageClass(AddressBookProtos.AddressBookServiceMessage.class);
        Thread.currentThread().setContextClassLoader(Container.class.getClassLoader());
        server = serverFactoryBean.create();

    }
 
Example 12
Source File: WebSocketDestinationFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static DestinationRegistry getDestinationRegistry(Bus bus) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        DestinationFactory df = dfm
            .getDestinationFactory("http://cxf.apache.org/transports/http/configuration");
        if (df instanceof HTTPTransportFactory) {
            HTTPTransportFactory transportFactory = (HTTPTransportFactory)df;
            return transportFactory.getRegistry();
        }
    } catch (Exception e) {
        // why are we throwing a busexception if the DF isn't found?
    }
    return null;
}
 
Example 13
Source File: RedeliveryQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static InterceptorChain getRedeliveryInterceptorChain(Message m, String phase) {
    Exchange exchange = m.getExchange();
    Endpoint ep = exchange.getEndpoint();
    Bus bus = exchange.getBus();

    PhaseManager pm = bus.getExtension(PhaseManager.class);
    SortedSet<Phase> phases = new TreeSet<>(pm.getInPhases());
    for (Iterator<Phase> it = phases.iterator(); it.hasNext();) {
        Phase p = it.next();
        if (phase.equals(p.getName())) {
            break;
        }
        it.remove();
    }
    PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
    List<Interceptor<? extends Message>> il = ep.getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getService().getInInterceptors();
    addInterceptors(chain, il);
    il = ep.getBinding().getInInterceptors();
    addInterceptors(chain, il);
    il = bus.getInInterceptors();
    addInterceptors(chain, il);
    if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
        il = ((InterceptorProvider)ep.getService().getDataBinding()).getInInterceptors();
        addInterceptors(chain, il);
    }

    return chain;
}
 
Example 14
Source File: MemoryIdentityCache.java    From cxf with Apache License 2.0 5 votes vote down vote up
public MemoryIdentityCache(Bus bus, IdentityMapper identityMapper) {
    super(bus, identityMapper);
    if (bus != null) {
        InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
        if (im != null) {
            try {
                im.register(this);
            } catch (JMException e) {
                LOG.log(Level.WARNING, "Registering MemoryIdentityCache failed.", e);
            }
        }
    }
}
 
Example 15
Source File: PolicyBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public final void setBus(Bus theBus) {
    bus = theBus;
    if (bus != null) {
        theBus.setExtension(this, PolicyBuilder.class);
        AssertionBuilderRegistry reg = theBus.getExtension(AssertionBuilderRegistry.class);
        if (reg != null) {
            factory = reg;
        }
        org.apache.cxf.ws.policy.PolicyEngine e
            = bus.getExtension(org.apache.cxf.ws.policy.PolicyEngine.class);
        if (e != null) {
            this.setPolicyRegistry(e.getRegistry());
        }
    }
}
 
Example 16
Source File: MAPCodec.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static synchronized MAPCodec createMAPCodec(Bus bus) {
    MAPCodec mc = bus.getExtension(MAPCodec.class);
    if (mc == null) {
        bus.setExtension(new MAPCodec(), MAPCodec.class);
        mc = bus.getExtension(MAPCodec.class);
    }
    return mc;
}
 
Example 17
Source File: SpringBeansTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testChildContext() throws Exception {
    //Test for CXF-2283 - if a Child context is closed,
    //we shouldn't be shutting down
    ClassPathXmlApplicationContext ctx =
        new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/servers.xml"});

    final Bus b = (Bus)ctx.getBean("cxf");
    BusLifeCycleManager lifeCycleManager = b.getExtension(BusLifeCycleManager.class);
    BusLifeCycleListener listener = new BusLifeCycleListener() {
        public void initComplete() {
        }

        public void postShutdown() {
            b.setProperty("post.was.called", Boolean.TRUE);
        }

        public void preShutdown() {
            b.setProperty("pre.was.called", Boolean.TRUE);
        }
    };
    lifeCycleManager.registerLifeCycleListener(listener);
    ClassPathXmlApplicationContext ctx2 =
            new ClassPathXmlApplicationContext(new String[] {"/org/apache/cxf/jaxws/spring/child.xml"},
                                               ctx);

    ctx2.close();

    assertNull(b.getProperty("post.was.called"));
    assertNull(b.getProperty("pre.was.called"));
}
 
Example 18
Source File: JettyDestinationFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
public AbstractHTTPDestination createDestination(EndpointInfo endpointInfo, Bus bus,
                                                 DestinationRegistry registry) throws IOException {
    JettyHTTPServerEngineFactory serverEngineFactory = bus
        .getExtension(JettyHTTPServerEngineFactory.class);
    return new JettyHTTPDestination(bus, registry, endpointInfo, serverEngineFactory);
}
 
Example 19
Source File: Activator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void configureConduitFactory(Bus bus) {
    AsyncHTTPConduitFactory conduitFactory = bus.getExtension(AsyncHTTPConduitFactory.class);
    conduitFactory.update(this.currentConfig);
}
 
Example 20
Source File: AddressingWSDLExtensionLoader.java    From cxf with Apache License 2.0 4 votes vote down vote up
public AddressingWSDLExtensionLoader(Bus b) {
    WSDLManager manager = b.getExtension(WSDLManager.class);

    createExtensor(manager, javax.wsdl.Binding.class,
                   org.apache.cxf.ws.addressing.wsdl.UsingAddressing.class);
}