Search in sources :

Example 1 with ClientLifeCycleManager

use of org.apache.cxf.endpoint.ClientLifeCycleManager in project cxf by apache.

the class OSGiBusListenerTest method setUpClientLifeCycleListeners.

private void setUpClientLifeCycleListeners(String[] names, String[] restricted, String excludes) throws Exception {
    ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
    EasyMock.expect(bundleContext.getServiceReferences(ClientLifeCycleListener.class.getName(), null)).andReturn(svcrefs);
    ClientLifeCycleManager lcmanager = control.createMock(ClientLifeCycleManager.class);
    EasyMock.expect(bus.getExtension(ClientLifeCycleManager.class)).andReturn(lcmanager).anyTimes();
    for (int i = 0; i < names.length; i++) {
        ClientLifeCycleListener cl = control.createMock(ClientLifeCycleListener.class);
        EasyMock.expect(bundleContext.getService(svcrefs[i])).andReturn(cl).anyTimes();
        if (!isExcluded(BUNDLE_NAME, names[i], restricted[i], excludes)) {
            lcmanager.registerListener(cl);
            EasyMock.expectLastCall();
        }
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ClientLifeCycleManager

use of org.apache.cxf.endpoint.ClientLifeCycleManager in project cxf by apache.

the class AbstractClient method close.

public void close() {
    if (closed.compareAndSet(false, true)) {
        if (cfg.getBus() == null) {
            return;
        }
        for (Closeable c : cfg.getEndpoint().getCleanupHooks()) {
            try {
                c.close();
            } catch (IOException e) {
            // ignore
            }
        }
        ClientLifeCycleManager mgr = cfg.getBus().getExtension(ClientLifeCycleManager.class);
        if (null != mgr) {
            mgr.clientDestroyed(new FrontendClientAdapter(getConfiguration()));
        }
        if (cfg.getConduitSelector() instanceof Closeable) {
            try {
                ((Closeable) cfg.getConduitSelector()).close();
            } catch (IOException e) {
            // ignore, we're destroying anyway
            }
        } else {
            cfg.getConduit().close();
        }
        state.reset();
        if (cfg.isShutdownBusOnClose()) {
            cfg.getBus().shutdown(false);
        }
        state = null;
        cfg = null;
    }
    closed = null;
}
Also used : Closeable(java.io.Closeable) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) IOException(java.io.IOException)

Example 3 with ClientLifeCycleManager

use of org.apache.cxf.endpoint.ClientLifeCycleManager in project cxf by apache.

the class RMManager method registerListeners.

@PostConstruct
void registerListeners() {
    if (null == bus) {
        return;
    }
    ServerLifeCycleManager slm = bus.getExtension(ServerLifeCycleManager.class);
    if (null != slm) {
        slm.registerListener(new ServerLifeCycleListener() {

            public void startServer(Server server) {
                RMManager.this.startServer(server);
            }

            public void stopServer(Server server) {
                RMManager.this.stopServer(server);
            }
        });
    }
    ClientLifeCycleManager clm = bus.getExtension(ClientLifeCycleManager.class);
    if (null != clm) {
        clm.registerListener(new ClientLifeCycleListener() {

            public void clientCreated(Client client) {
                RMManager.this.clientCreated(client);
            }

            public void clientDestroyed(Client client) {
                RMManager.this.clientDestroyed(client);
            }
        });
    }
}
Also used : ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) Server(org.apache.cxf.endpoint.Server) ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) Client(org.apache.cxf.endpoint.Client) PostConstruct(javax.annotation.PostConstruct)

Example 4 with ClientLifeCycleManager

use of org.apache.cxf.endpoint.ClientLifeCycleManager in project cxf by apache.

the class JAXRSHttpsBookTest method doTestGetBook123ProxyFromSpring.

private void doTestGetBook123ProxyFromSpring(String cfgFile) throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { cfgFile });
    Object bean = ctx.getBean("bookService.proxyFactory");
    assertNotNull(bean);
    JAXRSClientFactoryBean cfb = (JAXRSClientFactoryBean) bean;
    Bus bus = cfb.getBus();
    ClientLifeCycleManager manager = bus.getExtension(ClientLifeCycleManager.class);
    TestClientLifeCycleListener listener = new TestClientLifeCycleListener();
    manager.registerListener(listener);
    BookStore bs = cfb.create(BookStore.class);
    assertNotNull(listener.getEp());
    assertEquals("{http://service.rs}BookService", listener.getEp().getEndpointInfo().getName().toString());
    assertEquals("https://localhost:" + PORT, WebClient.client(bs).getBaseURI().toString());
    Book b = bs.getSecureBook("123");
    assertEquals(b.getId(), 123);
    b = bs.getSecureBook("123");
    assertEquals(b.getId(), 123);
    ctx.close();
}
Also used : Bus(org.apache.cxf.Bus) BookStore(org.apache.cxf.systest.jaxrs.BookStore) JAXRSClientFactoryBean(org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Book(org.apache.cxf.systest.jaxrs.Book) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager)

Example 5 with ClientLifeCycleManager

use of org.apache.cxf.endpoint.ClientLifeCycleManager in project jbossws-cxf by jbossws.

the class ClientServerLifeCycleTestCase method testCustomClientLifeCycleListener.

@Test
@RunAsClient
public void testCustomClientLifeCycleListener() throws Exception {
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        URL wsdlOneURL = new URL(baseURL + "/ServiceOne/EndpointOne?wsdl");
        QName serviceOneName = new QName("http://org.jboss.ws.jaxws.cxf/jbws3098", "ServiceOne");
        Service serviceOne = Service.create(wsdlOneURL, serviceOneName, new UseThreadBusFeature());
        CustomClientLifeCycleListener listener = new CustomClientLifeCycleListener();
        ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
        try {
            mgr.registerListener(listener);
            assertEquals(0, listener.getCount());
            EndpointOne portOne = (EndpointOne) serviceOne.getPort(EndpointOne.class);
            assertEquals(1, listener.getCount());
            assertEquals("Foo", portOne.echo("Foo"));
        } finally {
            mgr.unRegisterListener(listener);
        }
    } finally {
        bus.shutdown(true);
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) QName(javax.xml.namespace.QName) ClientLifeCycleManager(org.apache.cxf.endpoint.ClientLifeCycleManager) Service(javax.xml.ws.Service) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

ClientLifeCycleManager (org.apache.cxf.endpoint.ClientLifeCycleManager)11 ClientLifeCycleListener (org.apache.cxf.endpoint.ClientLifeCycleListener)4 ServerLifeCycleManager (org.apache.cxf.endpoint.ServerLifeCycleManager)3 ServiceReference (org.osgi.framework.ServiceReference)3 PostConstruct (javax.annotation.PostConstruct)2 Bus (org.apache.cxf.Bus)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)1 BusLifeCycleManager (org.apache.cxf.buslifecycle.BusLifeCycleManager)1 Client (org.apache.cxf.endpoint.Client)1 Server (org.apache.cxf.endpoint.Server)1 ServerLifeCycleListener (org.apache.cxf.endpoint.ServerLifeCycleListener)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 Book (org.apache.cxf.systest.jaxrs.Book)1