Search in sources :

Example 66 with NetworkListener

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

the class AdminConsoleAdapter method initRest.

void initRest() {
    InputStream is = null;
    try {
        NetworkListener nl = domain.getServerNamed("server").getConfig().getNetworkConfig().getNetworkListener("admin-listener");
        SecureAdmin secureAdmin = habitat.getService(SecureAdmin.class);
        URL url = new URL((SecureAdmin.Util.isEnabled(secureAdmin) ? "https" : "http"), nl.getAddress(), Integer.parseInt(nl.getPort()), "/management/domain");
        URLConnection conn = url.openConnection();
        is = conn.getInputStream();
        isRestStarted = true;
    } catch (Exception ex) {
        logger.log(Level.FINE, null, ex);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ex1) {
                logger.log(Level.FINE, null, ex1);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) PropertyVetoException(java.beans.PropertyVetoException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 67 with NetworkListener

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

the class AdminEndpointDecider method setValues.

private void setValues() {
    // can't change
    asadminContextRoot = AdminAdapter.PREFIX_URI;
    // asadminHosts       = Collections.emptyList();  //asadmin is handled completely by the adapter, no VS needed
    NetworkListener nl = cfg.getAdminListener();
    ThreadPool tp = nl.findThreadPool();
    if (tp != null) {
        try {
            maxThreadPoolSize = Integer.parseInt(tp.getMaxThreadPoolSize());
        } catch (NumberFormatException ne) {
        }
    }
    String dvs = nl.findHttpProtocol().getHttp().getDefaultVirtualServer();
    guiHosts = Collections.unmodifiableList(Arrays.asList(dvs));
    // same for now
    asadminHosts = guiHosts;
    try {
        address = InetAddress.getByName(nl.getAddress());
    } catch (UnknownHostException e) {
        throw new IllegalStateException(e);
    }
    if (ServerTags.ADMIN_LISTENER_ID.equals(nl.getName())) {
        // at the root context for separate admin-listener
        guiContextRoot = "";
        try {
            port = Integer.parseInt(nl.getPort());
        } catch (NumberFormatException ne) {
            port = ADMIN_PORT;
        }
    } else {
        try {
            port = Integer.parseInt(nl.getPort());
        } catch (NumberFormatException ne) {
            // this is the last resort
            port = 8080;
        }
        // get the context root from admin-service
        AdminService as = cfg.getAdminService();
        if (as == null)
            guiContextRoot = ServerEnvironmentImpl.DEFAULT_ADMIN_CONSOLE_CONTEXT_ROOT;
        else
            setGuiContextRootFromAdminService(as);
    }
}
Also used : AdminService(com.sun.enterprise.config.serverbeans.AdminService) UnknownHostException(java.net.UnknownHostException) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 68 with NetworkListener

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

the class ServerHelper method getAdminListener.

public static NetworkListener getAdminListener(Config config) {
    NetworkConfig nwc = config.getNetworkConfig();
    if (nwc == null)
        throw new IllegalStateException("Can't operate without <http-service>");
    List<NetworkListener> lss = nwc.getNetworkListeners().getNetworkListener();
    if (lss == null || lss.isEmpty())
        throw new IllegalStateException("Can't operate without at least one <network-listener>");
    for (NetworkListener ls : lss) {
        if (ServerTags.ADMIN_LISTENER_ID.equals(ls.getName())) {
            return ls;
        }
    }
    // if we can't find the admin-listener, then use the first one
    return lss.get(0);
}
Also used : NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 69 with NetworkListener

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

the class ServerHelper method translateAddressAndPort.

/**
 * @param adminListener
 * @param server
 * @param config
 * @return ret[0] == address, ret[1] == port
 */
private static String[] translateAddressAndPort(NetworkListener adminListener, Server server, Config config) {
    NetworkListener adminListenerRaw = null;
    String[] ret = new String[2];
    String portString = null;
    String addressString = null;
    try {
        Dom serverDom = Dom.unwrap(server);
        Domain domain = serverDom.getHabitat().getService(Domain.class);
        adminListenerRaw = GlassFishConfigBean.getRawView(adminListener);
        portString = adminListenerRaw.getPort();
        addressString = adminListenerRaw.getAddress();
        PropertyResolver resolver = new PropertyResolver(domain, server.getName());
        if (isToken(portString))
            ret[1] = resolver.getPropertyValue(portString);
        else
            ret[1] = portString;
        if (isToken(addressString))
            ret[0] = resolver.getPropertyValue(addressString);
        else
            ret[0] = addressString;
    } catch (ClassCastException e) {
        // jc: workaround for issue 12354
        // TODO severe error
        ret[0] = translatePortOld(addressString, server, config);
        ret[1] = translatePortOld(portString, server, config);
    }
    return ret;
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) PropertyResolver(org.glassfish.config.support.PropertyResolver) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 70 with NetworkListener

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

the class TransactionListenerTest method transactionEvents.

@Test
public void transactionEvents() throws Exception, TransactionFailure {
    httpService = getHabitat().getService(HttpService.class);
    NetworkConfig networkConfig = getHabitat().getService(NetworkConfig.class);
    final NetworkListener netListener = networkConfig.getNetworkListeners().getNetworkListener().get(0);
    final Http http = netListener.findHttpProtocol().getHttp();
    final TransactionListener listener = new TransactionListener() {

        public void transactionCommited(List<PropertyChangeEvent> changes) {
            events = changes;
        }

        public void unprocessedTransactedEvents(List<UnprocessedChangeEvents> changes) {
        }
    };
    Transactions transactions = getHabitat().getService(Transactions.class);
    try {
        transactions.addTransactionsListener(listener);
        assertTrue(httpService != null);
        logger.fine("Max connections = " + http.getMaxConnections());
        ConfigSupport.apply(new SingleConfigCode<Http>() {

            public Object run(Http param) {
                param.setMaxConnections("500");
                return null;
            }
        }, http);
        assertTrue("500".equals(http.getMaxConnections()));
        transactions.waitForDrain();
        assertTrue(events != null);
        logger.fine("Number of events " + events.size());
        assertTrue(events.size() == 1);
        PropertyChangeEvent event = events.iterator().next();
        assertTrue("max-connections".equals(event.getPropertyName()));
        assertTrue("500".equals(event.getNewValue().toString()));
        assertTrue("250".equals(event.getOldValue().toString()));
    } catch (Exception t) {
        t.printStackTrace();
        throw t;
    } finally {
        transactions.removeTransactionsListener(listener);
    }
    // put back the right values in the domain to avoid test collisions
    ConfigSupport.apply(new SingleConfigCode<Http>() {

        public Object run(Http param) {
            param.setMaxConnections("250");
            return null;
        }
    }, http);
}
Also used : TransactionListener(org.jvnet.hk2.config.TransactionListener) Transactions(org.jvnet.hk2.config.Transactions) PropertyChangeEvent(java.beans.PropertyChangeEvent) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Http(org.glassfish.grizzly.config.dom.Http) List(java.util.List) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Test(org.junit.Test)

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