Search in sources :

Example 31 with NetworkListener

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

the class ConfigListenerTest method removeListenerTest.

@Test
public void removeListenerTest() throws TransactionFailure {
    Transactions transactions = getHabitat().getService(Transactions.class);
    HttpListenerContainer container = registerAndCreateHttpListenerContainer(habitat);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(container.httpListener);
    bean.removeListener(container);
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8989");
            return null;
        }
    }, container.httpListener);
    transactions.waitForDrain();
    assertFalse(container.received);
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        @Override
        public Object run(NetworkListener param) {
            param.setPort("8080");
            return null;
        }
    }, container.httpListener);
}
Also used : Transactions(org.jvnet.hk2.config.Transactions) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 32 with NetworkListener

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

the class DirectAccessTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkConfig networkConfig = habitat.getService(NetworkConfig.class);
    final NetworkListener listener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = listener.findHttpProtocol().getHttp();
    ConfigBean config = (ConfigBean) ConfigBean.unwrap(http.getFileCache());
    ConfigBean config2 = (ConfigBean) ConfigBean.unwrap(http);
    Map<ConfigBean, Map<String, String>> changes = new HashMap<ConfigBean, Map<String, String>>();
    Map<String, String> configChanges = new HashMap<String, String>();
    configChanges.put("max-age-seconds", "12543");
    configChanges.put("max-cache-size-bytes", "1200");
    Map<String, String> config2Changes = new HashMap<String, String>();
    config2Changes.put("http2-enabled", "false");
    changes.put(config, configChanges);
    changes.put(config2, config2Changes);
    JavaConfig javaConfig = habitat.getService(JavaConfig.class);
    ConfigBean javaConfigBean = (ConfigBean) ConfigBean.unwrap(javaConfig);
    Map<String, String> javaConfigChanges = new HashMap<String, String>();
    javaConfigChanges.put("jvm-options", "-XFooBar=false");
    changes.put(javaConfigBean, javaConfigChanges);
    getHabitat().<ConfigSupport>getService(ConfigSupport.class).apply(changes);
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) HashMap(java.util.HashMap) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) ConfigBean(org.jvnet.hk2.config.ConfigBean) Map(java.util.Map) HashMap(java.util.HashMap) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 33 with NetworkListener

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

the class DirectRemovalTest method doTest.

public void doTest() throws TransactionFailure {
    NetworkListeners listeners = habitat.getService(NetworkListeners.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(listeners);
    for (NetworkListener listener : listeners.getNetworkListener()) {
        if (listener.getName().endsWith("http-listener-1")) {
            ConfigSupport.deleteChild(serviceBean, (ConfigBean) ConfigBean.unwrap(listener));
            break;
        }
    }
}
Also used : NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigBean(org.jvnet.hk2.config.ConfigBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 34 with NetworkListener

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

the class HttpServiceTest method validTransaction.

@Test
public void validTransaction() throws TransactionFailure {
    final String max = listener.findHttpProtocol().getHttp().getMaxConnections();
    ConfigSupport.apply(new SingleConfigCode<NetworkListener>() {

        public Object run(NetworkListener okToChange) throws TransactionFailure {
            final Http http = okToChange.createChild(Http.class);
            http.setMaxConnections("100");
            http.setTimeoutSeconds("65");
            http.setFileCache(http.createChild(FileCache.class));
            ConfigSupport.apply(new SingleConfigCode<Protocol>() {

                @Override
                public Object run(Protocol param) {
                    param.setHttp(http);
                    return null;
                }
            }, okToChange.findHttpProtocol());
            return http;
        }
    }, listener);
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        @Override
        public Object run(Http param) {
            param.setMaxConnections(max);
            return null;
        }
    }, listener.findHttpProtocol().getHttp());
    try {
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) throws TransactionFailure {
                param.setMaxConnections("7");
                throw new TransactionFailure("Sorry, changed my mind", null);
            }
        }, listener.findHttpProtocol().getHttp());
    } catch (TransactionFailure e) {
        logger.fine("good, got my exception about changing my mind");
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Http(org.glassfish.grizzly.config.dom.Http) Protocol(org.glassfish.grizzly.config.dom.Protocol) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

Example 35 with NetworkListener

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

the class GetApplicationLaunchURLsCommand method getURLsForServer.

private List<URL> getURLsForServer(Server server, String appName, String contextRoot, Logger logger) {
    List<URL> serverURLs = new ArrayList<URL>();
    String virtualServers = server.getApplicationRef(appName).getVirtualServers();
    if (virtualServers == null || virtualServers.trim().equals("")) {
        return serverURLs;
    }
    String nodeName = server.getNodeRef();
    String host = null;
    if (nodeName != null) {
        Node node = domain.getNodeNamed(nodeName);
        host = node.getNodeHost();
    }
    if (host == null || host.trim().equals("") || host.trim().equalsIgnoreCase("localhost")) {
        host = DeploymentCommandUtils.getLocalHostName();
    }
    List<String> vsList = StringUtils.parseStringList(virtualServers, " ,");
    Config config = domain.getConfigNamed(server.getConfigRef());
    HttpService httpService = config.getHttpService();
    for (String vsName : vsList) {
        VirtualServer vs = httpService.getVirtualServerByName(vsName);
        String vsHttpListeners = vs.getNetworkListeners();
        if (vsHttpListeners == null || vsHttpListeners.trim().equals("")) {
            continue;
        }
        List<String> vsHttpListenerList = StringUtils.parseStringList(vsHttpListeners, " ,");
        List<NetworkListener> httpListenerList = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
        for (String vsHttpListener : vsHttpListenerList) {
            for (NetworkListener httpListener : httpListenerList) {
                if (!httpListener.getName().equals(vsHttpListener)) {
                    continue;
                }
                if (!Boolean.valueOf(httpListener.getEnabled())) {
                    continue;
                }
                Protocol protocol = httpListener.findHttpProtocol();
                // Do not include jk enabled listeners
                if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
                    continue;
                }
                boolean securityEnabled = Boolean.valueOf(protocol.getSecurityEnabled());
                String proto = (securityEnabled ? "https" : "http");
                String portStr = httpListener.getPort();
                String redirPort = protocol.getHttp().getRedirectPort();
                if (redirPort != null && !redirPort.trim().equals("")) {
                    portStr = redirPort;
                }
                // we need to resolve port for non-DAS instances
                if (!DeploymentUtils.isDASTarget(server.getName())) {
                    PropertyResolver resolver = new PropertyResolver(domain, server.getName());
                    portStr = resolver.getPropertyValue(portStr);
                }
                try {
                    int port = Integer.parseInt(portStr);
                    URL url = new URL(proto, host, port, contextRoot);
                    serverURLs.add(url);
                } catch (Exception ee) {
                    logger.log(Level.WARNING, ee.getMessage(), ee);
                }
            }
        }
    }
    return serverURLs;
}
Also used : ArrayList(java.util.ArrayList) PropertyResolver(org.glassfish.config.support.PropertyResolver) URL(java.net.URL) RestEndpoint(org.glassfish.api.admin.RestEndpoint) 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