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

The following examples show how to use org.apache.cxf.Bus#getExtension() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: cxf   File: CXFBusImplTest.java    License: 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 Project: cxf   File: BusApplicationListenerTest.java    License: 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 3
Source Project: cxf   File: HTTPTransportFactoryTest.java    License: 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 4
Source Project: cxf   File: EndpointReferenceUtils.java    License: 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 5
Source Project: cxf   File: SequenceTimeoutTest.java    License: 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 Project: cxf   File: MetricsFeature.java    License: 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 7
Source Project: cxf   File: AbstractToolContainer.java    License: 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 8
Source Project: cxf   File: SpringBusFactoryTest.java    License: 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 9
Source Project: cxf   File: RedeliveryQueueImpl.java    License: 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 10
Source Project: cxf   File: MAPAggregatorTest.java    License: 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 Project: tomee   File: CxfUtil.java    License: 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 12
Source Project: fuchsia   File: ProtobufferImporterTest.java    License: 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 13
Source Project: cxf   File: WebSocketDestinationFactory.java    License: 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 14
Source Project: cxf   File: MemoryIdentityCache.java    License: 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 Project: cxf   File: PolicyBuilderImpl.java    License: 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 Project: cxf   File: MAPCodec.java    License: 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 Project: cxf   File: SpringBeansTest.java    License: 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
public AddressingWSDLExtensionLoader(Bus b) {
    WSDLManager manager = b.getExtension(WSDLManager.class);

    createExtensor(manager, javax.wsdl.Binding.class,
                   org.apache.cxf.ws.addressing.wsdl.UsingAddressing.class);
}
 
Example 19
Source Project: cxf   File: JettyDestinationFactory.java    License: 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 20
Source Project: cxf   File: Activator.java    License: 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);
}