Search in sources :

Example 1 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class CreateVirtualServer method execute.

/**
 * Executes the command with the command parameters passed as Properties where the keys are the paramter names and
 * the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    final ActionReport report = context.getActionReport();
    if (networkListeners != null && httpListeners != null) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_BOTH_HTTP_NETWORK), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // use the listener parameter provided by the user.
    if (networkListeners == null) {
        networkListeners = httpListeners;
    }
    HttpService httpService = config.getHttpService();
    // ensure we don't already have one of this name
    for (VirtualServer virtualServer : httpService.getVirtualServer()) {
        if (virtualServer.getId().equals(virtualServerId)) {
            report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_DUPLICATE), virtualServerId));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                // default
                String docroot = "${com.sun.aas.instanceRoot}/docroot";
                // default
                String accessLog = "${com.sun.aas.instanceRoot}/logs/access";
                VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
                newVirtualServer.setId(virtualServerId);
                newVirtualServer.setHosts(hosts);
                newVirtualServer.setNetworkListeners(networkListeners);
                newVirtualServer.setDefaultWebModule(defaultWebModule);
                newVirtualServer.setState(state);
                newVirtualServer.setLogFile(logFile);
                // values if the properties have not been specified.
                if (properties != null) {
                    for (Map.Entry entry : properties.entrySet()) {
                        String pn = (String) entry.getKey();
                        String pv = (String) entry.getValue();
                        if ("docroot".equals(pn)) {
                            docroot = pv;
                        } else if ("accesslog".equals(pn)) {
                            accessLog = pv;
                        } else {
                            Property property = newVirtualServer.createChild(Property.class);
                            property.setName(pn);
                            property.setValue(pv);
                            newVirtualServer.getProperty().add(property);
                        }
                    }
                }
                newVirtualServer.setDocroot(docroot);
                newVirtualServer.setAccessLog(accessLog);
                param.getVirtualServer().add(newVirtualServer);
                return newVirtualServer;
            }
        }, httpService);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_FAIL), virtualServerId));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ActionReport(org.glassfish.api.ActionReport) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 2 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class HttpServiceStatsProviderBootstrap method postConstruct.

public void postConstruct() {
    if (config == null) {
        Object[] params = { VirtualServerInfoStatsProvider.class.getName(), HttpServiceStatsProvider.class.getName(), "http service", "virtual server" };
        logger.log(Level.SEVERE, LogFacade.UNABLE_TO_REGISTER_STATS_PROVIDERS, params);
        throw new ConfigurationException(rb.getString(LogFacade.NULL_CONFIG));
    }
    HttpService httpService = config.getHttpService();
    for (VirtualServer vs : httpService.getVirtualServer()) {
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId(), new VirtualServerInfoStatsProvider(vs));
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + vs.getId() + "/request", new HttpServiceStatsProvider(vs.getId(), vs.getNetworkListeners(), config.getNetworkConfig()));
    }
}
Also used : ConfigurationException(org.jvnet.hk2.config.ConfigurationException) HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 3 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class WebContainer method updateHost.

/**
 * Updates a virtual-server element.
 *
 * @param vsBean the virtual-server config bean.
 */
public void updateHost(com.sun.enterprise.config.serverbeans.VirtualServer vsBean) throws LifecycleException {
    if (org.glassfish.api.web.Constants.ADMIN_VS.equals(vsBean.getId())) {
        return;
    }
    final VirtualServer vs = (VirtualServer) getEngine().findChild(vsBean.getId());
    if (vs == null) {
        logger.log(Level.WARNING, LogFacade.CANNOT_UPDATE_NON_EXISTENCE_VS, vsBean.getId());
        return;
    }
    boolean updateListeners = false;
    // Only update connectors if virtual-server.http-listeners is changed dynamically
    if (vs.getNetworkListeners() == null) {
        if (vsBean.getNetworkListeners() == null) {
            updateListeners = false;
        } else {
            updateListeners = true;
        }
    } else if (vs.getNetworkListeners().equals(vsBean.getNetworkListeners())) {
        updateListeners = false;
    } else {
        List<String> vsList = StringUtils.parseStringList(vs.getNetworkListeners(), ",");
        List<String> vsBeanList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
        for (String vsBeanName : vsBeanList) {
            if (!vsList.contains(vsBeanName)) {
                updateListeners = true;
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.UPDATE_LISTENER, new Object[] { vsBeanName, vs.getNetworkListeners() });
                }
                break;
            }
        }
    }
    // Must retrieve the old default-web-module before updating the
    // virtual server with the new vsBean, because default-web-module is
    // read from vsBean
    String oldDefaultWebModule = vs.getDefaultWebModuleID();
    vs.setBean(vsBean);
    String vsLogFile = vsBean.getLogFile();
    vs.setLogFile(vsLogFile, logLevel, logServiceFile);
    vs.configureState();
    vs.clearAliases();
    vs.configureAliases();
    // support both docroot property and attribute
    String docroot = vsBean.getPropertyValue("docroot");
    if (docroot == null) {
        docroot = vsBean.getDocroot();
    }
    if (docroot != null) {
        // Only update docroot if it is modified
        if (!vs.getDocRoot().getAbsolutePath().equals(docroot)) {
            updateDocroot(docroot, vs, vsBean);
        }
    }
    List<Property> props = vs.getProperties();
    for (Property prop : props) {
        updateHostProperties(vsBean, prop.getName(), prop.getValue(), securityService, vs);
    }
    vs.configureSingleSignOn(globalSSOEnabled, webContainerFeatureFactory, isSsoFailoverEnabled());
    vs.reconfigureAccessLog(globalAccessLogBufferSize, globalAccessLogWriteInterval, habitat, domain, globalAccessLoggingEnabled);
    // old listener names
    List<String> oldListenerList = StringUtils.parseStringList(vsBean.getNetworkListeners(), ",");
    String[] oldListeners = (oldListenerList != null) ? oldListenerList.toArray(new String[oldListenerList.size()]) : new String[0];
    // new listener config
    HashSet<NetworkListener> networkListeners = new HashSet<NetworkListener>();
    if (oldListenerList != null) {
        for (String listener : oldListeners) {
            boolean found = false;
            for (NetworkListener httpListener : serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener()) {
                if (httpListener.getName().equals(listener)) {
                    networkListeners.add(httpListener);
                    found = true;
                    break;
                }
            }
            if (!found) {
                String msg = rb.getString(LogFacade.LISTENER_REFERENCED_BY_HOST_NOT_EXIST);
                msg = MessageFormat.format(msg, listener, vs.getName());
                logger.log(Level.SEVERE, msg);
            }
        }
        // Update the port numbers with which the virtual server is
        // associated
        configureHostPortNumbers(vs, networkListeners);
    } else {
        // The virtual server is not associated with any http listeners
        vs.setNetworkListenerNames(new String[0]);
    }
    // have been removed from its http-listeners attribute
    for (String oldListener : oldListeners) {
        boolean found = false;
        for (NetworkListener httpListener : networkListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was removed
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (oldListener.equals(conn.getName())) {
                    try {
                        conn.getMapperListener().unregisterHost(vs.getJmxName());
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // have been added to its http-listeners attribute
    for (NetworkListener httpListener : networkListeners) {
        boolean found = false;
        for (String oldListener : oldListeners) {
            if (httpListener.getName().equals(oldListener)) {
                found = true;
            }
        }
        if (!found) {
            // http listener was added
            Connector[] connectors = _embedded.findConnectors();
            for (Connector connector : connectors) {
                WebConnector conn = (WebConnector) connector;
                if (httpListener.getName().equals(conn.getName())) {
                    if (!conn.isAvailable()) {
                        conn.start();
                    }
                    try {
                        conn.getMapperListener().registerHost(vs);
                    } catch (Exception e) {
                        throw new LifecycleException(e);
                    }
                }
            }
        }
    }
    // passing in "null" as the default context path
    if (oldDefaultWebModule != null) {
        updateDefaultWebModule(vs, oldListeners, null);
    }
    /*
         * Add default web module if one has been configured for the
         * virtual server. If the module declared as the default web module
         * has already been deployed at the root context, we don't have
         * to do anything.
         */
    WebModuleConfig wmInfo = vs.getDefaultWebModule(domain, habitat.<WebArchivist>getService(WebArchivist.class), appRegistry);
    if ((wmInfo != null) && (wmInfo.getContextPath() != null) && !"".equals(wmInfo.getContextPath()) && !"/".equals(wmInfo.getContextPath())) {
        // Remove dummy context that was created off of docroot, if such
        // a context exists
        removeDummyModule(vs);
        updateDefaultWebModule(vs, vs.getNetworkListenerNames(), wmInfo);
    } else {
        WebModuleConfig wmc = vs.createSystemDefaultWebModuleIfNecessary(habitat.<WebArchivist>getService(WebArchivist.class));
        if (wmc != null) {
            loadStandaloneWebModule(vs, wmc);
        }
    }
    if (updateListeners) {
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, LogFacade.VS_UPDATED_NETWORK_LISTENERS, new Object[] { vs.getName(), vs.getNetworkListeners(), vsBean.getNetworkListeners() });
        }
        /*
             * Need to update connector and mapper restart is required
             * when virtual-server.http-listeners is changed dynamically
             */
        List<NetworkListener> httpListeners = serverConfig.getNetworkConfig().getNetworkListeners().getNetworkListener();
        if (httpListeners != null) {
            for (NetworkListener httpListener : httpListeners) {
                updateConnector(httpListener, habitat.<HttpService>getService(HttpService.class));
            }
        }
    }
}
Also used : PECoyoteConnector(com.sun.enterprise.web.connector.coyote.PECoyoteConnector) Connector(org.apache.catalina.Connector) LifecycleException(org.apache.catalina.LifecycleException) LifecycleException(org.apache.catalina.LifecycleException) NamingException(javax.naming.NamingException) BindException(java.net.BindException) MalformedURLException(java.net.MalformedURLException) WebArchivist(org.glassfish.web.deployment.archivist.WebArchivist) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) HashSet(java.util.HashSet)

Example 4 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class WebConfigListener method changed.

/**
 * Handles HttpService change events
 * @param events the PropertyChangeEvent
 */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    return ConfigSupport.sortAndDispatch(events, new Changed() {

        @Override
        public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
            }
            try {
                if (tClass == HttpService.class) {
                    container.updateHttpService((HttpService) t);
                } else if (tClass == NetworkListener.class) {
                    if (type == TYPE.ADD) {
                        container.addConnector((NetworkListener) t, httpService, true);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteConnector((NetworkListener) t);
                    } else if (type == TYPE.CHANGE) {
                        container.updateConnector((NetworkListener) t, httpService);
                    }
                } else if (tClass == VirtualServer.class) {
                    if (type == TYPE.ADD) {
                        container.createHost((VirtualServer) t, httpService, null);
                        container.loadDefaultWebModule((VirtualServer) t);
                    } else if (type == TYPE.REMOVE) {
                        container.deleteHost(httpService);
                    } else if (type == TYPE.CHANGE) {
                        container.updateHost((VirtualServer) t);
                    }
                } else if (tClass == AccessLog.class) {
                    container.updateAccessLog(httpService);
                } else if (tClass == ManagerProperties.class) {
                    return new NotProcessed("ManagerProperties requires restart");
                } else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
                    // container.updateHttpService handles SingleSignOn valve configuration
                    container.updateHttpService(httpService);
                } else if (tClass == NetworkListeners.class) {
                // skip updates
                } else if (tClass == Property.class) {
                    ConfigBeanProxy config = ((Property) t).getParent();
                    if (config instanceof HttpService) {
                        container.updateHttpService((HttpService) config);
                    } else if (config instanceof VirtualServer) {
                        container.updateHost((VirtualServer) config);
                    } else if (config instanceof NetworkListener) {
                        container.updateConnector((NetworkListener) config, httpService);
                    } else {
                        container.updateHttpService(httpService);
                    }
                } else if (tClass == SystemProperty.class) {
                    if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
                        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
                            if (listener.getPort().equals(((SystemProperty) t).getValue())) {
                                container.updateConnector(listener, httpService);
                            }
                        }
                    }
                } else if (tClass == JavaConfig.class) {
                    JavaConfig jc = (JavaConfig) t;
                    final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
                    for (String jvmOption : jvmOptions) {
                        if (jvmOption.startsWith("-DjvmRoute=")) {
                            container.updateJvmRoute(httpService, jvmOption);
                        }
                    }
                } else {
                // Ignore other unrelated events
                }
            } catch (LifecycleException le) {
                logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
            }
            return null;
        }
    }, logger);
}
Also used : LifecycleException(org.apache.catalina.LifecycleException) AvailabilityService(com.sun.enterprise.config.serverbeans.AvailabilityService) ArrayList(java.util.ArrayList) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ManagerProperties(org.glassfish.web.config.serverbeans.ManagerProperties) WebContainerAvailability(org.glassfish.web.config.serverbeans.WebContainerAvailability) HttpService(com.sun.enterprise.config.serverbeans.HttpService) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Property(org.jvnet.hk2.config.types.Property) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 5 with HttpService

use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.

the class WebContainerImpl method addVirtualServer.

/**
 * Adds the given <tt>VirtualServer</tt> to this
 * <tt>WebContainer</tt>.
 *
 * <p>If this <tt>WebContainer</tt> has already been started,
 * the given <tt>virtualServer</tt> will be started as well.
 *
 * @param virtualServer the <tt>VirtualServer</tt> to add
 *
 * @throws ConfigException if a <tt>VirtualServer</tt> with the
 * same id has already been registered with this
 * <tt>WebContainer</tt>
 * @throws GlassFishException if the given <tt>virtualServer</tt> fails
 * to be started
 */
public void addVirtualServer(VirtualServer virtualServer) throws ConfigException, GlassFishException {
    if (!initialized) {
        init();
    }
    if (log.isLoggable(Level.INFO)) {
        log.info("Adding virtual server " + virtualServer.getID());
    }
    com.sun.enterprise.web.VirtualServer vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(virtualServer.getID());
    if (vs != null) {
        throw new ConfigException("VirtualServer with id " + virtualServer.getID() + " is already registered");
    }
    Collection<WebListener> webListeners = virtualServer.getWebListeners();
    List<String> names = new ArrayList<String>();
    if ((webListeners != null) && (!webListeners.isEmpty())) {
        for (WebListener listener : webListeners) {
            names.add(listener.getId());
        }
    } else {
        for (NetworkListener networkListener : networkConfig.getNetworkListeners().getNetworkListener()) {
            names.add(networkListener.getName());
        }
        webListeners = listeners;
    }
    StringBuffer networkListeners = new StringBuffer("");
    if (names.size() > 0) {
        networkListeners.append(names.get(0));
    }
    for (int i = 1; i < names.size(); i++) {
        networkListeners.append(",");
        networkListeners.append(names.get(i));
    }
    String docRoot = null;
    if (virtualServer.getDocRoot() != null) {
        docRoot = virtualServer.getDocRoot().getAbsolutePath();
    }
    String hostName = null;
    if (virtualServer.getConfig() != null) {
        hostName = virtualServer.getConfig().getHostNames();
    }
    final String root = docRoot;
    final String nl = networkListeners.toString();
    final String id = virtualServer.getID();
    final String hosts = hostName;
    try {
        ConfigSupport.apply(new SingleConfigCode<HttpService>() {

            public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
                com.sun.enterprise.config.serverbeans.VirtualServer newVirtualServer = param.createChild(com.sun.enterprise.config.serverbeans.VirtualServer.class);
                newVirtualServer.setId(id);
                newVirtualServer.setNetworkListeners(nl);
                if (hosts != null) {
                    newVirtualServer.setHosts(hosts);
                }
                Property property = newVirtualServer.createChild(Property.class);
                property.setName("docroot");
                property.setValue(root);
                newVirtualServer.getProperty().add(property);
                param.getVirtualServer().add(newVirtualServer);
                return newVirtualServer;
            }
        }, httpService);
    } catch (Exception ex) {
        throw new GlassFishException(ex);
    }
    if ((webListeners != null) && (!webListeners.isEmpty())) {
        for (WebListener listener : webListeners) {
            if (getWebListener(listener.getId()) == null) {
                addWebListener(listener, virtualServer.getID());
            }
        }
    }
    vs = (com.sun.enterprise.web.VirtualServer) engine.findChild(id);
    if (vs != null) {
        if (log.isLoggable(Level.INFO)) {
            log.info("Added virtual server " + id + " docroot " + docRoot + " networklisteners " + nl);
        }
        if (virtualServer instanceof VirtualServerFacade) {
            ((VirtualServerFacade) virtualServer).setVirtualServer(vs);
        }
        vs.setNetworkListenerNames(names.toArray(new String[names.size()]));
    } else {
        log.severe("Could not add virtual server " + id);
        throw new GlassFishException(new Exception("Cannot add virtual server " + id));
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) ConfigException(org.glassfish.embeddable.web.ConfigException) VirtualServerFacade(com.sun.enterprise.web.VirtualServerFacade) Property(org.jvnet.hk2.config.types.Property) VirtualServer(org.glassfish.embeddable.web.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException) PropertyVetoException(java.beans.PropertyVetoException) WebListener(org.glassfish.embeddable.web.WebListener) HttpService(com.sun.enterprise.config.serverbeans.HttpService) org.jvnet.hk2.config(org.jvnet.hk2.config) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Aggregations

HttpService (com.sun.enterprise.config.serverbeans.HttpService)16 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)10 Property (org.jvnet.hk2.config.types.Property)8 PropertyVetoException (java.beans.PropertyVetoException)5 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 Test (org.junit.Test)5 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 Config (com.sun.enterprise.config.serverbeans.Config)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 LifecycleException (org.apache.catalina.LifecycleException)3 ActionReport (org.glassfish.api.ActionReport)3 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 MalformedURLException (java.net.MalformedURLException)2 CommandTarget (org.glassfish.config.support.CommandTarget)2 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)2 Target (org.glassfish.internal.api.Target)2 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)2