Search in sources :

Example 16 with VirtualServer

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

the class WarHandler method configureContextXmlAttribute.

protected void configureContextXmlAttribute(WebappClassLoader cloader, File base, DeploymentContext dc) throws XMLStreamException, IOException {
    boolean consistent = true;
    Boolean value = null;
    File warContextXml = new File(base.getAbsolutePath(), WAR_CONTEXT_XML);
    if (warContextXml.exists()) {
        ContextXmlParser parser = new ContextXmlParser(warContextXml);
        value = parser.getClearReferencesStatic();
    }
    if (value == null) {
        Boolean domainCRS = null;
        File defaultContextXml = new File(serverEnvironment.getInstanceRoot(), DEFAULT_CONTEXT_XML);
        if (defaultContextXml.exists()) {
            ContextXmlParser parser = new ContextXmlParser(defaultContextXml);
            domainCRS = parser.getClearReferencesStatic();
        }
        List<Boolean> csrs = new ArrayList<Boolean>();
        HttpService httpService = serverConfig.getHttpService();
        DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
        String vsIDs = params.virtualservers;
        List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
        if (httpService != null && vsList != null && !vsList.isEmpty()) {
            for (VirtualServer vsBean : httpService.getVirtualServer()) {
                if (vsList.contains(vsBean.getId())) {
                    Boolean csr = null;
                    Property prop = vsBean.getProperty("contextXmlDefault");
                    if (prop != null) {
                        File contextXml = new File(serverEnvironment.getInstanceRoot(), prop.getValue());
                        if (contextXml.exists()) {
                            // vs context.xml
                            ContextXmlParser parser = new ContextXmlParser(contextXml);
                            csr = parser.getClearReferencesStatic();
                        }
                    }
                    if (csr == null) {
                        csr = domainCRS;
                    }
                    csrs.add(csr);
                }
            }
            // check that it is consistent
            for (Boolean b : csrs) {
                if (b != null) {
                    if (value != null && !b.equals(value)) {
                        consistent = false;
                        break;
                    }
                    value = b;
                }
            }
        }
    }
    if (consistent) {
        if (value != null) {
            cloader.setClearReferencesStatic(value);
        }
    } else if (logger.isLoggable(Level.WARNING)) {
        logger.log(Level.WARNING, LogFacade.INCONSISTENT_CLEAR_REFERENCE_STATIC);
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) Property(org.jvnet.hk2.config.types.Property) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 17 with VirtualServer

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

the class CreateHttpListener 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) {
    final ActionReport report = context.getActionReport();
    if (!validateInputs(report)) {
        return;
    }
    Target targetUtil = services.getService(Target.class);
    Config newConfig = targetUtil.getConfig(target);
    if (newConfig != null) {
        config = newConfig;
    }
    networkConfig = config.getNetworkConfig();
    HttpService httpService = config.getHttpService();
    if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
        return;
    }
    VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
    boolean listener = false;
    boolean protocol = false;
    boolean transport = false;
    try {
        transport = createOrGetTransport(null);
        protocol = createProtocol(context);
        createHttp(context);
        final ThreadPool threadPool = getThreadPool(networkConfig);
        listener = createNetworkListener(networkConfig, transport, threadPool);
        updateVirtualServer(vs);
    } catch (TransactionFailure e) {
        try {
            if (listener) {
                deleteListener(context);
            }
            if (protocol) {
                deleteProtocol(context);
            }
            if (transport) {
                deleteTransport(context);
            }
        } catch (Exception e1) {
            if (logger.isLoggable(Level.INFO)) {
                logger.log(Level.INFO, e.getMessage(), e);
            }
            throw new RuntimeException(e.getMessage());
        }
        if (logger.isLoggable(Level.INFO)) {
            logger.log(Level.INFO, e.getMessage(), e);
        }
        report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, e.getMessage()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : 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) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) HttpService(com.sun.enterprise.config.serverbeans.HttpService) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ActionReport(org.glassfish.api.ActionReport) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) PropertyVetoException(java.beans.PropertyVetoException)

Example 18 with VirtualServer

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

the class MapperListener method init.

/**
 * Initialize associated mapper.
 */
public void init() {
    if (webContainer == null) {
        logger.log(Level.SEVERE, LogFacade.CANNOT_FIND_WEB_CONTAINER);
        return;
    }
    try {
        httpService = webContainer.getHttpService();
        engine = webContainer.getEngine();
        if (engine == null) {
            logger.log(Level.SEVERE, LogFacade.CANNOT_FIND_ENGINE);
            return;
        }
        if (defaultHost != null) {
            mapper.setDefaultHostName(defaultHost);
        }
        for (VirtualServer vs : httpService.getVirtualServer()) {
            Container host = engine.findChild(vs.getId());
            if (host instanceof StandardHost) {
                registerHost((StandardHost) host);
                for (Container context : host.findChildren()) {
                    if (context instanceof StandardContext) {
                        registerContext((StandardContext) context);
                        for (Container wrapper : context.findChildren()) {
                            if (wrapper instanceof StandardWrapper) {
                                registerWrapper((StandardWrapper) wrapper);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, LogFacade.ERROR_REGISTERING_CONTEXTS, e);
    }
}
Also used : WebContainer(com.sun.enterprise.web.WebContainer) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) StandardWrapper(org.apache.catalina.core.StandardWrapper)

Example 19 with VirtualServer

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

the class SecureAdminConfigUpgrade method createAdminVirtualServer.

private VirtualServer createAdminVirtualServer(final Transaction t, final Config config_w) throws TransactionFailure, PropertyVetoException {
    final HttpService hs_w = t.enroll(config_w.getHttpService());
    final VirtualServer vs_w = hs_w.createChild(VirtualServer.class);
    hs_w.getVirtualServer().add(vs_w);
    vs_w.setId(ASADMIN_VS_NAME);
    vs_w.setNetworkListeners(ADMIN_LISTENER_NAME);
    return vs_w;
}
Also used : HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 20 with VirtualServer

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

the class GrizzlyService method createNetworkProxy.

/*
     * Creates a new NetworkProxy for a particular HttpListner
     * @param listener NetworkListener
     * @param networkConfig HttpService
     */
public synchronized Future<Result<Thread>> createNetworkProxy(NetworkListener listener) {
    if (!Boolean.valueOf(listener.getEnabled())) {
        // in case the listener will be enabled
        addChangeListener(listener);
        LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyPortDisabled, new Object[] { listener.getName(), listener.getPort() });
        return null;
    }
    // create the proxy for the port.
    GrizzlyProxy proxy = new GrizzlyProxy(this, listener);
    Future<Result<Thread>> future = null;
    try {
        proxy.initialize();
        if (!isLightWeightListener(listener)) {
            final NetworkConfig networkConfig = listener.getParent(NetworkListeners.class).getParent(NetworkConfig.class);
            // attach all virtual servers to this port
            for (VirtualServer vs : networkConfig.getParent(Config.class).getHttpService().getVirtualServer()) {
                List<String> vsListeners = StringUtils.parseStringList(vs.getNetworkListeners(), " ,");
                if (vsListeners == null || vsListeners.isEmpty() || vsListeners.contains(listener.getName())) {
                    if (!hosts.contains(vs.getId())) {
                        hosts.add(vs.getId());
                    }
                }
            }
            addChangeListener(listener);
            addChangeListener(listener.findThreadPool());
            addChangeListener(listener.findTransport());
            final Protocol protocol = listener.findHttpProtocol();
            if (protocol != null) {
                addChangeListener(protocol);
                addChangeListener(protocol.getHttp());
                addChangeListener(protocol.getHttp().getFileCache());
                addChangeListener(protocol.getSsl());
            }
        }
        future = proxy.start();
        // add the new proxy to our list of proxies.
        proxies.add(proxy);
    } catch (Throwable e) {
        final Future<Result<Thread>> errorFuture = Futures.createReadyFuture(new Result<Thread>(e));
        future = errorFuture;
    } finally {
        if (future == null) {
            final FutureImpl<Result<Thread>> errorFuture = Futures.<Result<Thread>>createUnsafeFuture();
            errorFuture.result(new Result<Thread>(new IllegalStateException("Unexpected error")));
            future = errorFuture;
        }
        futures.add(future);
    }
    return future;
}
Also used : NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Result(com.sun.enterprise.util.Result) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) Future(java.util.concurrent.Future) Protocol(org.glassfish.grizzly.config.dom.Protocol)

Aggregations

VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)23 HttpService (com.sun.enterprise.config.serverbeans.HttpService)10 Property (org.jvnet.hk2.config.types.Property)8 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)7 Config (com.sun.enterprise.config.serverbeans.Config)6 PropertyVetoException (java.beans.PropertyVetoException)6 ActionReport (org.glassfish.api.ActionReport)5 Protocol (org.glassfish.grizzly.config.dom.Protocol)5 Target (org.glassfish.internal.api.Target)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 CommandTarget (org.glassfish.config.support.CommandTarget)4 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)4 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)4 NetworkListeners (org.glassfish.grizzly.config.dom.NetworkListeners)3 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)2 HostAndPort (com.sun.enterprise.util.HostAndPort)2 List (java.util.List)2 ThreadPool (org.glassfish.grizzly.config.dom.ThreadPool)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2