Search in sources :

Example 26 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class ParentConfigListenerTest method addHttpListenerTest.

@Test
public void addHttpListenerTest() throws TransactionFailure {
    NetworkListenersContainer container = habitat.getService(NetworkListenersContainer.class);
    ConfigSupport.apply(new SingleConfigCode<NetworkListeners>() {

        public Object run(NetworkListeners param) throws TransactionFailure {
            NetworkListener newListener = param.createChild(NetworkListener.class);
            newListener.setName("Funky-Listener");
            newListener.setPort("8078");
            param.getNetworkListener().add(newListener);
            return null;
        }
    }, container.httpService);
    getHabitat().<Transactions>getService(Transactions.class).waitForDrain();
    assertTrue(container.received);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpService);
    // let's check that my newly added listener is available in the habitat.
    List<ServiceHandle<NetworkListener>> networkListeners = habitat.getAllServiceHandles(NetworkListener.class);
    boolean found = false;
    for (ServiceHandle<NetworkListener> nlSH : networkListeners) {
        NetworkListener nl = (NetworkListener) nlSH.getService();
        if (nl.getName().equals("Funky-Listener")) {
            found = true;
        }
    }
    Assert.assertTrue("Newly added listener not found", found);
    // direct access.
    NetworkListener nl = habitat.getService(NetworkListener.class, "Funky-Listener");
    Assert.assertTrue("Direct access to newly added listener failed", nl != null);
    bean.removeListener(container);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transactions(org.jvnet.hk2.config.Transactions) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 27 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class ParentTest method parents.

@Test
public void parents() {
    NetworkListeners service = getHabitat().getService(NetworkListeners.class);
    assertNotNull(service);
    NetworkListener listener = service.getNetworkListener().get(0);
    assertNotNull(listener);
    ConfigBeanProxy parent = service.getParent();
    assertNotNull(parent);
    NetworkListeners myService = listener.getParent(NetworkListeners.class);
    assertNotNull(myService);
    assertNotNull(myService.getNetworkListener().get(0).getName());
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 28 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class Ssl2EnabledTest method sslEnabledTest.

@Test
public void sslEnabledTest() {
    for (final NetworkListener listener : config.getNetworkListeners().getNetworkListener()) {
        Ssl ssl = listener.findHttpProtocol().getSsl();
        if (ssl != null) {
            try {
                logger.fine("SSL2 ENABLED = " + ssl.getSsl2Enabled());
                assertFalse(Boolean.parseBoolean(ssl.getSsl2Enabled()));
                assertFalse(Boolean.parseBoolean(ssl.getSsl3Enabled()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Ssl(org.glassfish.grizzly.config.dom.Ssl) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 29 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class TransactionCallBackTest method doTest.

public void doTest() throws TransactionFailure {
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(habitat.<NetworkListeners>getService(NetworkListeners.class));
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("name", "funky-listener");
    ConfigSupport.createAndSet(serviceBean, NetworkListener.class, configChanges, new TransactionCallBack<WriteableView>() {

        @SuppressWarnings({ "unchecked" })
        public void performOn(WriteableView param) throws TransactionFailure {
            // if you know the type...
            NetworkListener listener = param.getProxy(NetworkListener.class);
            listener.setName("Aleksey");
            // if you don't know the type
            Method m;
            try {
                m = param.getProxyType().getMethod("setAddress", String.class);
                m.invoke(param.getProxy(param.getProxyType()), "localhost");
            } catch (NoSuchMethodException e) {
                throw new TransactionFailure("Cannot find getProperty method", e);
            } catch (IllegalAccessException e) {
                throw new TransactionFailure("Cannot call getProperty method", e);
            } catch (InvocationTargetException e) {
                throw new TransactionFailure("Cannot call getProperty method", e);
            }
        }
    });
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HashMap(java.util.HashMap) ConfigBean(org.jvnet.hk2.config.ConfigBean) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) WriteableView(org.jvnet.hk2.config.WriteableView) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 30 with NetworkListener

use of org.glassfish.grizzly.config.dom.NetworkListener in project Payara by payara.

the class GrizzlyConfigSchemaMigrator method addAsadminProtocol.

private void addAsadminProtocol(NetworkConfig config) throws TransactionFailure {
    ensureAdminThreadPool();
    final Protocols protocols = getProtocols(config);
    Protocol adminProtocol = protocols.findProtocol(ASADMIN_LISTENER);
    if (adminProtocol == null) {
        adminProtocol = (Protocol) ConfigSupport.apply(new SingleConfigCode<Protocols>() {

            public Object run(Protocols param) throws TransactionFailure {
                final Protocol protocol = param.createChild(Protocol.class);
                param.getProtocol().add(protocol);
                protocol.setName(ASADMIN_LISTENER);
                Http http = protocol.createChild(Http.class);
                http.setFileCache(http.createChild(FileCache.class));
                protocol.setHttp(http);
                http.setDefaultVirtualServer(ASADMIN_VIRTUAL_SERVER);
                http.setMaxConnections("250");
                return protocol;
            }
        }, protocols);
    }
    for (NetworkListener listener : adminProtocol.findNetworkListeners()) {
        ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

            @Override
            public Object run(NetworkListener param) {
                param.setThreadPool("admin-thread-pool");
                return null;
            }
        }, listener);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Protocols(org.glassfish.grizzly.config.dom.Protocols) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)74 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)21 Protocol (org.glassfish.grizzly.config.dom.Protocol)18 Config (com.sun.enterprise.config.serverbeans.Config)17 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)14 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)12 Test (org.junit.Test)11 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)9 Target (org.glassfish.internal.api.Target)9 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 HttpService (com.sun.enterprise.config.serverbeans.HttpService)7 ArrayList (java.util.ArrayList)7 Protocols (org.glassfish.grizzly.config.dom.Protocols)7 ObservableBean (org.jvnet.hk2.config.ObservableBean)7 Transactions (org.jvnet.hk2.config.Transactions)7 IOException (java.io.IOException)6 Http (org.glassfish.grizzly.config.dom.Http)6 PropertyVetoException (java.beans.PropertyVetoException)5 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)5