Search in sources :

Example 1 with WebContainerConfig

use of org.glassfish.embeddable.web.config.WebContainerConfig in project Payara by payara.

the class WebContainerImpl method setConfiguration.

// --------------------------------------------------------- Public Methods
public void setConfiguration(WebContainerConfig config) {
    if (!initialized) {
        init();
    }
    this.config = config;
    final WebContainerConfig webConfig = config;
    try {
        VirtualServer vs = getVirtualServer(config.getVirtualServerId());
        if (vs != null) {
            ((StandardHost) vs).setDefaultWebXmlLocation(config.getDefaultWebXml().getPath());
        }
        com.sun.enterprise.config.serverbeans.VirtualServer vsBean = httpService.getVirtualServerByName(config.getVirtualServerId());
        if (vsBean != null) {
            ConfigSupport.apply(new SingleConfigCode<com.sun.enterprise.config.serverbeans.VirtualServer>() {

                public Object run(com.sun.enterprise.config.serverbeans.VirtualServer avs) throws PropertyVetoException, TransactionFailure {
                    avs.setId(webConfig.getVirtualServerId());
                    if (webConfig.getDocRootDir() != null) {
                        avs.setDocroot(webConfig.getDocRootDir().getAbsolutePath());
                    }
                    avs.setHosts(webConfig.getHostNames());
                    avs.setNetworkListeners(webConfig.getListenerName());
                    Property property = avs.createChild(Property.class);
                    property.setName("default-web-xml");
                    property.setValue(webConfig.getDefaultWebXml().getPath());
                    avs.getProperty().add(property);
                    return avs;
                }
            }, vsBean);
        } else {
            vs = createVirtualServer(config.getVirtualServerId(), config.getDocRootDir());
            addVirtualServer(vs);
        }
        EmbeddedWebArchivist archivist = habitat.<EmbeddedWebArchivist>getService(EmbeddedWebArchivist.class);
        archivist.setDefaultWebXml(config.getDefaultWebXml());
        embedded.setDirectoryListing(config.getListings());
        WebListener listener = getWebListener(config.getListenerName());
        if (listener == null) {
            listener = getWebListener(config.getPort());
            if (listener == null) {
                boolean found = false;
                for (Map.Entry entry : webContainer.getConnectorMap().entrySet()) {
                    if (((WebConnector) entry.getValue()).getPort() == config.getPort()) {
                        found = true;
                        log.info("Port " + config.getPort() + " is already configured");
                    }
                }
                if (!found) {
                    listener = createWebListener(config.getListenerName(), HttpListener.class);
                    listener.setPort(config.getPort());
                    addWebListener(listener, config.getVirtualServerId());
                }
            }
        } else {
            if (listener.getPort() != config.getPort()) {
                listener.setPort(config.getPort());
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : WebContainerConfig(org.glassfish.embeddable.web.config.WebContainerConfig) 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) StandardHost(org.apache.catalina.core.StandardHost) HttpListener(org.glassfish.embeddable.web.HttpListener) org.jvnet.hk2.config(org.jvnet.hk2.config) Property(org.jvnet.hk2.config.types.Property)

Example 2 with WebContainerConfig

use of org.glassfish.embeddable.web.config.WebContainerConfig in project Payara by payara.

the class WebContainerImpl method init.

// --------------------------------------------------------- Private Methods
private void init() {
    if (initialized) {
        return;
    }
    if (config == null) {
        // use default settings
        config = new WebContainerConfig();
    }
    container = habitat.getServiceHandle(org.glassfish.api.container.Container.class, "com.sun.enterprise.web.WebContainer");
    if (container == null) {
        log.severe("Cannot find webcontainer implementation");
        return;
    }
    ActiveDescriptor<?> activeDescriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("com.sun.enterprise.web.EmbeddedWebContainer"));
    if (activeDescriptor == null) {
        log.severe("Cannot find embedded implementation");
        return;
    }
    embeddedInhabitant = habitat.getServiceHandle(activeDescriptor);
    try {
        webContainer = (com.sun.enterprise.web.WebContainer) container.getService();
        embedded = (EmbeddedWebContainer) embeddedInhabitant.getService();
        if ((webContainer == null) || (embedded == null)) {
            log.severe("Cannot find webcontainer implementation");
            return;
        }
        engine = webContainer.getEngine();
        if (engine == null) {
            log.severe("Cannot find engine implementation");
            return;
        }
        initialized = true;
    } catch (Exception e) {
        log.severe("Init exception " + e.getMessage());
    }
}
Also used : EmbeddedWebContainer(com.sun.enterprise.web.EmbeddedWebContainer) WebContainer(org.glassfish.embeddable.web.WebContainer) Container(org.apache.catalina.Container) WebContainerConfig(org.glassfish.embeddable.web.config.WebContainerConfig) PropertyVetoException(java.beans.PropertyVetoException) ConfigException(org.glassfish.embeddable.web.ConfigException) GlassFishException(org.glassfish.embeddable.GlassFishException)

Aggregations

PropertyVetoException (java.beans.PropertyVetoException)2 GlassFishException (org.glassfish.embeddable.GlassFishException)2 ConfigException (org.glassfish.embeddable.web.ConfigException)2 WebContainerConfig (org.glassfish.embeddable.web.config.WebContainerConfig)2 EmbeddedWebContainer (com.sun.enterprise.web.EmbeddedWebContainer)1 Container (org.apache.catalina.Container)1 StandardHost (org.apache.catalina.core.StandardHost)1 HttpListener (org.glassfish.embeddable.web.HttpListener)1 VirtualServer (org.glassfish.embeddable.web.VirtualServer)1 WebContainer (org.glassfish.embeddable.web.WebContainer)1 WebListener (org.glassfish.embeddable.web.WebListener)1 org.jvnet.hk2.config (org.jvnet.hk2.config)1 Property (org.jvnet.hk2.config.types.Property)1