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();
}
}
}
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;
}
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);
}
});
}
}
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();
}
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);
}
}
Aggregations