Search in sources :

Example 1 with ServerLifeCycleListener

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

the class OSGIBusListener method registerServerLifecycleListeners.

private void registerServerLifecycleListeners() {
    ServiceReference<?>[] refs = getServiceReferences(defaultContext, ServerLifeCycleListener.class);
    ServerLifeCycleManager clcm = bus.getExtension(ServerLifeCycleManager.class);
    for (ServiceReference<?> ref : refs) {
        if (!isPrivate(ref) && !isExcluded(ref)) {
            ServerLifeCycleListener listener = (ServerLifeCycleListener) defaultContext.getService(ref);
            clcm.registerListener(listener);
        }
    }
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with ServerLifeCycleListener

use of org.apache.cxf.endpoint.ServerLifeCycleListener 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 3 with ServerLifeCycleListener

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

the class LifeCycleTest method testGetActiveFeatures.

@Test
public void testGetActiveFeatures() {
    assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
    manager.registerListener(new ServerLifeCycleListener() {

        public void startServer(Server server) {
            org.apache.cxf.endpoint.Endpoint endpoint = server.getEndpoint();
            updateMap(startNotificationMap, endpoint.getEndpointInfo().getAddress());
            String portName = endpoint.getEndpointInfo().getName().getLocalPart();
            if ("SoapPort".equals(portName)) {
                List<Feature> active = endpoint.getActiveFeatures();
                assertNotNull(active);
                assertEquals(1, active.size());
                assertTrue(active.get(0) instanceof WSAddressingFeature);
                assertSame(active.get(0), AbstractFeature.getActive(active, WSAddressingFeature.class));
            } else {
                List<Feature> active = endpoint.getActiveFeatures();
                assertNotNull(active);
                assertEquals(0, active.size());
                assertNull(AbstractFeature.getActive(active, WSAddressingFeature.class));
            }
        }

        public void stopServer(Server server) {
            updateMap(stopNotificationMap, server.getEndpoint().getEndpointInfo().getAddress());
        }
    });
    Endpoint greeter = Endpoint.publish(ADDRESSES[0], new GreeterImpl());
    Endpoint control = Endpoint.publish(ADDRESSES[1], new ControlImpl());
    greeter.stop();
    control.stop();
    for (int i = 0; i < 2; i++) {
        verifyNotification(startNotificationMap, ADDRESSES[i], 1);
        verifyNotification(stopNotificationMap, ADDRESSES[i], 1);
    }
}
Also used : WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Server(org.apache.cxf.endpoint.Server) Endpoint(javax.xml.ws.Endpoint) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) List(java.util.List) ControlImpl(org.apache.cxf.greeter_control.ControlImpl) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 4 with ServerLifeCycleListener

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

the class LifeCycleTest method testRecursive.

@Test
public void testRecursive() {
    assertNotNull("unexpected non-null ServerLifeCycleManager", manager);
    manager.registerListener(new ServerLifeCycleListener() {

        public void startServer(Server server) {
            String address = server.getEndpoint().getEndpointInfo().getAddress();
            verifyNotification(startNotificationMap, address, 0);
            updateMap(startNotificationMap, address);
            if (recursiveCount < RECURSIVE_LIMIT) {
                recursiveEndpoints[recursiveCount++] = Endpoint.publish(ADDRESSES[recursiveCount], new GreeterImpl());
            }
        }

        public void stopServer(Server server) {
            String address = server.getEndpoint().getEndpointInfo().getAddress();
            verifyNotification(stopNotificationMap, address, 0);
            updateMap(stopNotificationMap, address);
            if (recursiveCount > 0) {
                recursiveEndpoints[--recursiveCount].stop();
            }
        }
    });
    Endpoint.publish(ADDRESSES[0], new GreeterImpl()).stop();
    for (int i = 0; i < ADDRESSES.length; i++) {
        verifyNotification(startNotificationMap, ADDRESSES[i], 1);
        verifyNotification(stopNotificationMap, ADDRESSES[i], 1);
    }
}
Also used : Server(org.apache.cxf.endpoint.Server) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) Endpoint(javax.xml.ws.Endpoint) Test(org.junit.Test)

Example 5 with ServerLifeCycleListener

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

the class OSGiBusListenerTest method setUpServerLifeCycleListeners.

private void setUpServerLifeCycleListeners(String[] names, String[] restricted, String excludes) throws Exception {
    ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
    EasyMock.expect(bundleContext.getServiceReferences(ServerLifeCycleListener.class.getName(), null)).andReturn(svcrefs);
    ServerLifeCycleManager lcmanager = control.createMock(ServerLifeCycleManager.class);
    EasyMock.expect(bus.getExtension(ServerLifeCycleManager.class)).andReturn(lcmanager).anyTimes();
    for (int i = 0; i < names.length; i++) {
        ServerLifeCycleListener cl = control.createMock(ServerLifeCycleListener.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 : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) ServerLifeCycleListener(org.apache.cxf.endpoint.ServerLifeCycleListener) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ServerLifeCycleListener (org.apache.cxf.endpoint.ServerLifeCycleListener)5 Server (org.apache.cxf.endpoint.Server)3 ServerLifeCycleManager (org.apache.cxf.endpoint.ServerLifeCycleManager)3 Endpoint (javax.xml.ws.Endpoint)2 Test (org.junit.Test)2 ServiceReference (org.osgi.framework.ServiceReference)2 List (java.util.List)1 PostConstruct (javax.annotation.PostConstruct)1 Client (org.apache.cxf.endpoint.Client)1 ClientLifeCycleListener (org.apache.cxf.endpoint.ClientLifeCycleListener)1 ClientLifeCycleManager (org.apache.cxf.endpoint.ClientLifeCycleManager)1 ControlImpl (org.apache.cxf.greeter_control.ControlImpl)1 WSAddressingFeature (org.apache.cxf.ws.addressing.WSAddressingFeature)1