Search in sources :

Example 21 with NetworkConfig

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

the class DeleteVirtualServer method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter 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;
    }
    ActionReport report = context.getActionReport();
    httpService = config.getHttpService();
    networkConfig = config.getNetworkConfig();
    if (!exists()) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_NOT_EXISTS), vsid));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    // reference check
    String referencedBy = getReferencingListener();
    if (referencedBy != null && referencedBy.length() != 0) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_REFERENCED), vsid, referencedBy));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        // we need to determine which deployed applications reference this virtual-server
        List<ApplicationRef> appRefs = new ArrayList<ApplicationRef>();
        for (ApplicationRef appRef : server.getApplicationRef()) {
            if (appRef.getVirtualServers() != null && appRef.getVirtualServers().contains(vsid)) {
                appRefs.add(appRef);
            }
        }
        // transfer into the array of arguments
        ConfigBeanProxy[] proxies = new ConfigBeanProxy[appRefs.size() + 1];
        proxies[0] = httpService;
        for (int i = 0; i < appRefs.size(); i++) {
            proxies[i + 1] = appRefs.get(i);
        }
        ConfigSupport.apply(new ConfigUpdate(vsid), proxies);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_VIRTUAL_SERVER_FAIL), vsid));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) ApplicationRef(com.sun.enterprise.config.serverbeans.ApplicationRef)

Example 22 with NetworkConfig

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

the class InstanceReaderImpl method getListeners.

/**
 * Enlists both http and https listeners of this server instance
 * It will be form "http:<hostname>:<port> https:<hostname>:<port>"
 *
 * @return String   Listener(s) info.
 */
@Override
public String getListeners() throws LbReaderException {
    StringBuffer listenerStr = new StringBuffer();
    Config config = _domain.getConfigNamed(_server.getConfigRef());
    NetworkConfig networkConfig = config.getNetworkConfig();
    Protocols protocols = networkConfig.getProtocols();
    NetworkListeners nls = networkConfig.getNetworkListeners();
    Iterator<NetworkListener> listenerIter = nls.getNetworkListener().iterator();
    int i = 0;
    PropertyResolver resolver = new PropertyResolver(_domain, _server.getName());
    while (listenerIter.hasNext()) {
        NetworkListener listener = listenerIter.next();
        NetworkListener rawListener = GlassFishConfigBean.getRawView(listener);
        if (rawListener.getName().equals(ADMIN_LISTENER)) {
            continue;
        }
        String prot = rawListener.getProtocol();
        Protocol protocol = protocols.findProtocol(prot);
        if (i > 0) {
            // space between listener names
            listenerStr.append(' ');
        }
        i++;
        if (Boolean.valueOf(protocol.getHttp().getJkEnabled())) {
            listenerStr.append(AJP_PROTO);
        } else {
            if (Boolean.valueOf(protocol.getSecurityEnabled()).booleanValue()) {
                listenerStr.append(HTTPS_PROTO);
            } else {
                listenerStr.append(HTTP_PROTO);
            }
        }
        String hostName = getResolvedHostName(rawListener.getAddress());
        listenerStr.append(hostName);
        listenerStr.append(':');
        // resolve the port name
        String port = rawListener.getPort();
        // If it is system variable, resolve it
        if ((port != null) && (port.length() > 1) && (port.charAt(0) == '$') && (port.charAt(1) == '{') && (port.charAt(port.length() - 1) == '}')) {
            String portVar = port.substring(2, port.length() - 1);
            port = resolver.getPropertyValue(portVar);
            if (port == null) {
                throw new LbReaderException(LbLogUtil.getStringManager().getString("UnableToResolveSystemProperty", portVar, _server.getName()));
            }
        }
        listenerStr.append(port);
    }
    return listenerStr.toString();
}
Also used : Protocols(org.glassfish.grizzly.config.dom.Protocols) Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) PropertyResolver(org.glassfish.config.support.PropertyResolver) Protocol(org.glassfish.grizzly.config.dom.Protocol) LbReaderException(org.glassfish.loadbalancer.admin.cli.reader.api.LbReaderException) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 23 with NetworkConfig

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

the class WebContainer method postConstruct.

@Override
public void postConstruct() {
    final ReentrantReadWriteLock mapperLock = grizzlyService.obtainMapperLock();
    mapperLock.writeLock().lock();
    try {
        createProbeProviders();
        injectionMgr = habitat.getService(InjectionManager.class);
        invocationMgr = habitat.getService(InvocationManager.class);
        tldProviders = habitat.getAllServices(TldProvider.class);
        createStatsProviders();
        setJspFactory();
        _appsWorkRoot = instance.getApplicationCompileJspPath().getAbsolutePath();
        _modulesRoot = instance.getApplicationRepositoryPath();
        // START S1AS 6178005
        appsStubRoot = instance.getApplicationStubPath().getAbsolutePath();
        // END S1AS 6178005
        // TODO: ParserUtils should become a @Service and it should initialize itself.
        // TODO: there should be only one EntityResolver for both DigesterFactory
        // and ParserUtils
        File root = _serverContext.getInstallRoot();
        File libRoot = new File(root, "lib");
        File schemas = new File(libRoot, "schemas");
        File dtds = new File(libRoot, "dtds");
        try {
            ParserUtils.setSchemaResourcePrefix(schemas.toURI().toURL().toString());
            ParserUtils.setDtdResourcePrefix(dtds.toURI().toURL().toString());
            ParserUtils.setEntityResolver(habitat.<EntityResolver>getService(EntityResolver.class, "web"));
        } catch (MalformedURLException e) {
            logger.log(Level.SEVERE, LogFacade.EXCEPTION_SET_SCHEMAS_DTDS_LOCATION, e);
        }
        instanceName = _serverContext.getInstanceName();
        webContainerFeatureFactory = getWebContainerFeatureFactory();
        configureDynamicReloadingSettings();
        setDebugLevel();
        String maxDepth = null;
        org.glassfish.web.config.serverbeans.WebContainer configWC = serverConfig.getExtensionByType(org.glassfish.web.config.serverbeans.WebContainer.class);
        if (configWC != null)
            maxDepth = configWC.getPropertyValue(DISPATCHER_MAX_DEPTH);
        if (maxDepth != null) {
            int depth = -1;
            try {
                depth = Integer.parseInt(maxDepth);
            } catch (NumberFormatException e) {
            }
            if (depth > 0) {
                Request.setMaxDispatchDepth(depth);
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, LogFacade.MAX_DISPATCH_DEPTH_SET, maxDepth);
                }
            }
        }
        File currentLogFile = loggingRuntime.getCurrentLogFile();
        if (currentLogFile != null) {
            logServiceFile = currentLogFile.getAbsolutePath();
        }
        Level level = Logger.getLogger("org.apache.catalina.level").getLevel();
        if (level != null) {
            logLevel = level.getName();
        }
        _embedded = habitat.getService(EmbeddedWebContainer.class);
        _embedded.setWebContainer(this);
        _embedded.setLogServiceFile(logServiceFile);
        _embedded.setLogLevel(logLevel);
        _embedded.setFileLoggerHandlerFactory(fileLoggerHandlerFactory);
        _embedded.setWebContainerFeatureFactory(webContainerFeatureFactory);
        _embedded.setCatalinaHome(instance.getDomainRoot().getAbsolutePath());
        _embedded.setCatalinaBase(instance.getDomainRoot().getAbsolutePath());
        _embedded.setUseNaming(false);
        if (_debug > 1)
            _embedded.setDebug(_debug);
        _embedded.setLogger(new IASLogger(logger));
        engine = _embedded.createEngine();
        engine.setParentClassLoader(EmbeddedWebContainer.class.getClassLoader());
        engine.setService(_embedded);
        _embedded.addEngine(engine);
        ((StandardEngine) engine).setDomain(_serverContext.getDefaultDomainName());
        engine.setName(_serverContext.getDefaultDomainName());
        /*
            * Set the server info.
            * By default, the server info is taken from Version#getVersion.
            * However, customers may override it via the product.name system
            * property.
            * Some customers prefer not to disclose the server info
            * for security reasons, in which case they would set the value of the
            * product.name system property to the empty string. In this case,
            * the server name will not be publicly disclosed via the "Server"
            * HTTP response header (which will be suppressed) or any container
            * generated error pages. However, it will still appear in the
            * server logs (see IT 6900).
            */
        String serverInfo = System.getProperty("product.name");
        if (serverInfo == null) {
            ServerInfo.setServerInfo(Version.getVersion());
            ServerInfo.setPublicServerInfo(Version.getVersion());
        } else if (serverInfo.isEmpty()) {
            ServerInfo.setServerInfo(Version.getVersion());
            ServerInfo.setPublicServerInfo(serverInfo);
        } else {
            ServerInfo.setServerInfo(serverInfo);
            ServerInfo.setPublicServerInfo(serverInfo);
        }
        initInstanceSessionProperties();
        configListener = addAndGetWebConfigListener();
        ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
        bean.addListener(configListener);
        bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
        bean.addListener(configListener);
        if (serverConfig.getAvailabilityService() != null) {
            bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getAvailabilityService());
            bean.addListener(configListener);
        }
        transactions.addListenerForType(SystemProperty.class, configListener);
        configListener.setNetworkConfig(serverConfig.getNetworkConfig());
        // embedded mode does not have manager-propertie in domain.xml
        if (configListener.managerProperties != null) {
            ObservableBean managerBean = (ObservableBean) ConfigSupport.getImpl(configListener.managerProperties);
            managerBean.addListener(configListener);
        }
        if (serverConfig.getJavaConfig() != null) {
            ((ObservableBean) ConfigSupport.getImpl(serverConfig.getJavaConfig())).addListener(configListener);
        }
        configListener.setContainer(this);
        configListener.setLogger(logger);
        events.register(this);
        grizzlyService.addMapperUpdateListener(configListener);
        HttpService httpService = serverConfig.getHttpService();
        NetworkConfig networkConfig = serverConfig.getNetworkConfig();
        if (networkConfig != null) {
            // continue;
            securityService = serverConfig.getSecurityService();
            // Configure HTTP listeners
            NetworkListeners networkListeners = networkConfig.getNetworkListeners();
            if (networkListeners != null) {
                List<NetworkListener> listeners = networkListeners.getNetworkListener();
                for (NetworkListener listener : listeners) {
                    createHttpListener(listener, httpService);
                }
            }
            setDefaultRedirectPort(defaultRedirectPort);
            // Configure virtual servers
            createHosts(httpService, securityService);
        }
        loadSystemDefaultWebModules();
        // _lifecycle.fireLifecycleEvent(START_EVENT, null);
        _started = true;
        /*
             * Start the embedded container.
             * Make sure to set the thread's context classloader to the
             * classloader of this class (see IT 8866 for details)
             */
        ClassLoader current = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        try {
            /*
                 * Trigger a call to sun.awt.AppContext.getAppContext().
                 * This will pin the classloader of this class in memory
                 * and fix a memory leak affecting instances of WebappClassLoader
                 * that was caused by a JRE implementation change in 1.6.0_15
                 * onwards. See IT 11110
                 */
            ImageIO.getCacheDirectory();
            _embedded.start();
        } catch (LifecycleException le) {
            logger.log(Level.SEVERE, LogFacade.UNABLE_TO_START_WEB_CONTAINER, le);
            return;
        } finally {
            // Restore original context classloader
            Thread.currentThread().setContextClassLoader(current);
        }
    } finally {
        mapperLock.writeLock().unlock();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) InvocationManager(org.glassfish.api.invocation.InvocationManager) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) StandardEngine(org.apache.catalina.core.StandardEngine) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) WebappClassLoader(org.glassfish.web.loader.WebappClassLoader) TldProvider(org.glassfish.api.web.TldProvider) LifecycleException(org.apache.catalina.LifecycleException) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) EntityResolver(org.xml.sax.EntityResolver) HttpService(com.sun.enterprise.config.serverbeans.HttpService) IASLogger(com.sun.enterprise.web.logger.IASLogger) Level(java.util.logging.Level) ObservableBean(org.jvnet.hk2.config.ObservableBean) File(java.io.File) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 24 with NetworkConfig

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

the class SecureAdminConfigUpgrade method prepareDASConfig.

private void prepareDASConfig() throws TransactionFailure, PropertyVetoException {
    final Config dasConfig = writableConfig(configs.getConfigByName(DAS_CONFIG_NAME));
    final NetworkConfig nc = dasConfig.getNetworkConfig();
    final NetworkListener nl_w = transaction().enroll(nc.getNetworkListener(SecureAdminCommand.ADMIN_LISTENER_NAME));
    nl_w.setProtocol(SecureAdminCommand.ADMIN_LISTENER_NAME);
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 25 with NetworkConfig

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

the class SecureAdminConfigUpgrade method isOriginalAdminSecured.

private boolean isOriginalAdminSecured() {
    /*
         * The Grizzly conversion has already occurred.  So look for
         * 
         * <server-config>
         *   <network-config>
         *     <protocols>
         *       <protocol name="admin-listener">
         *         <ssl ...>
         *
         */
    final Config serverConfig;
    final NetworkConfig nc;
    final Protocol p;
    final Ssl ssl;
    if ((serverConfig = configs.getConfigByName(SecureAdminUpgradeHelper.DAS_CONFIG_NAME)) == null) {
        return false;
    }
    if ((nc = serverConfig.getNetworkConfig()) == null) {
        return false;
    }
    if ((p = nc.findProtocol(ADMIN_LISTENER_NAME)) == null) {
        return false;
    }
    if ((ssl = p.getSsl()) == null) {
        return false;
    }
    return true;
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) Protocol(org.glassfish.grizzly.config.dom.Protocol) Ssl(org.glassfish.grizzly.config.dom.Ssl)

Aggregations

NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)33 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Config (com.sun.enterprise.config.serverbeans.Config)18 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)16 Protocol (org.glassfish.grizzly.config.dom.Protocol)14 ActionReport (org.glassfish.api.ActionReport)10 CommandTarget (org.glassfish.config.support.CommandTarget)10 Target (org.glassfish.internal.api.Target)10 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)6 Protocols (org.glassfish.grizzly.config.dom.Protocols)6 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)5 HttpService (com.sun.enterprise.config.serverbeans.HttpService)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 PropertyVetoException (java.beans.PropertyVetoException)3 Http (org.glassfish.grizzly.config.dom.Http)3 Ssl (org.glassfish.grizzly.config.dom.Ssl)3 Transport (org.glassfish.grizzly.config.dom.Transport)3 JavaConfig (com.sun.enterprise.config.serverbeans.JavaConfig)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 Result (com.sun.enterprise.util.Result)2