Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/core/api-exporter-fragment/pom.xml b/appserver/core/api-exporter-fragment/pom.xml
new file mode 100755
index 0000000..742c455
--- /dev/null
+++ b/appserver/core/api-exporter-fragment/pom.xml
@@ -0,0 +1,336 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>core</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>api-exporter-fragment</artifactId>
+ <packaging>jar</packaging>
+ <name>GlassFish API Exporter Module Fragment</name>
+ <description>This bundle attached itself as a fragment to api-exporter bundle</description>
+
+ <!--
+ Since DynamicImport-Package resolution happens incremantally, that can lead to minor performance issues,
+ so we attach this fragment to api-exporter bundle. This bundle statically imports packages. Since it
+ optionally imports them, even if some package is absent, it is not an issue. Please note,
+ any package imported by this bundle is also visible to "Common Class Loader."
+ -->
+ <developers>
+ <developer>
+ <id>ss141213</id>
+ <name>Sahoo</name>
+ <organization>Oracle, Inc.</organization>
+ <roles>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <!-- tmp workaround for http://jira.codehaus.org/browse/MJAR-153 -->
+ <version>2.3</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Bundle-SymbolicName>GlassFish-Application-Common-Module-Fragment</Bundle-SymbolicName>
+ <Bundle-ManifestVersion>2</Bundle-ManifestVersion>
+ <Fragment-Host>GlassFish-Application-Common-Module</Fragment-Host>
+ <Bundle-Name>${project.name}</Bundle-Name>
+ <!-- This is the most important attribute of this bundle
+ We currently import all EE6 APIs. We could include some appserver pkgs as well.
+ Tune this as per performance requirement.
+ -->
+ <Import-Package>
+javax.accessibility; \
+javax.activation; \
+javax.activity; \
+javax.annotation; \
+javax.annotation.processing; \
+javax.annotation.security; \
+javax.annotation.sql; \
+javax.crypto; \
+javax.crypto.interfaces; \
+javax.crypto.spec; \
+javax.decorator; \
+javax.ejb; \
+javax.ejb.embeddable; \
+javax.ejb.spi; \
+javax.el; \
+javax.enterprise.context; \
+javax.enterprise.context.spi; \
+javax.enterprise.deploy.model; \
+javax.enterprise.deploy.model.exceptions; \
+javax.enterprise.deploy.shared; \
+javax.enterprise.deploy.shared.factories; \
+javax.enterprise.deploy.spi; \
+javax.enterprise.deploy.spi.exceptions; \
+javax.enterprise.deploy.spi.factories; \
+javax.enterprise.deploy.spi.status; \
+javax.enterprise.event; \
+javax.enterprise.inject; \
+javax.enterprise.inject.spi; \
+javax.enterprise.util; \
+javax.faces; \
+javax.faces.application; \
+javax.faces.bean; \
+javax.faces.component; \
+javax.faces.component.behavior; \
+javax.faces.component.html; \
+javax.faces.component.visit; \
+javax.faces.context; \
+javax.faces.convert; \
+javax.faces.el; \
+javax.faces.event ; \
+javax.faces.lifecycle; \
+javax.faces.model; \
+javax.faces.render; \
+javax.faces.validator; \
+javax.faces.view.facelets; \
+javax.faces.webapp; \
+javax.inject; \
+javax.imageio; \
+javax.imageio.event; \
+javax.imageio.metadata; \
+javax.imageio.plugins.bmp; \
+javax.imageio.plugins.jpeg; \
+javax.imageio.spi; \
+javax.imageio.stream; \
+javax.interceptor; \
+javax.jms; \
+javax.jws; \
+javax.jws.soap; \
+javax.lang.model; \
+javax.lang.model.element; \
+javax.lang.model.type; \
+javax.lang.model.util; \
+javax.mail; \
+javax.mail.event; \
+javax.mail.internet; \
+javax.mail.search; \
+javax.mail.util; \
+javax.management; \
+javax.management.j2ee; \
+javax.management.j2ee.statistics; \
+javax.management.loading; \
+javax.management.modelmbean; \
+javax.management.monitor; \
+javax.management.openmbean; \
+javax.management.relation; \
+javax.management.remote; \
+javax.management.remote.generic; \
+javax.management.remote.jmxmp; \
+javax.management.remote.rmi; \
+javax.management.remote.message; \
+javax.management.timer; \
+javax.naming; \
+javax.naming.directory; \
+javax.naming.event; \
+javax.naming.ldap; \
+javax.naming.spi; \
+javax.net; \
+javax.net.ssl; \
+javax.persistence; \
+javax.persistence.criteria; \
+javax.persistence.metamodel; \
+javax.persistence.spi; \
+javax.print; \
+javax.print.attribute; \
+javax.print.attribute.standard; \
+javax.print.event; \
+javax.resource; \
+javax.resource.cci; \
+javax.resource.spi; \
+javax.resource.spi.endpoint; \
+javax.resource.spi.security; \
+javax.resource.spi.work; \
+javax.rmi; \
+javax.rmi.CORBA; \
+javax.rmi.ssl; \
+javax.script; \
+javax.security.auth; \
+javax.security.auth.callback; \
+javax.security.auth.kerberos; \
+javax.security.auth.message; \
+javax.security.auth.message.callback; \
+javax.security.auth.message.config; \
+javax.security.auth.message.module; \
+javax.security.auth.login; \
+javax.security.auth.spi; \
+javax.security.auth.x500; \
+javax.security.cert; \
+javax.security.jacc; \
+javax.security.sasl; \
+javax.servlet; \
+javax.servlet.annotation; \
+javax.servlet.descriptor; \
+javax.servlet.http; \
+javax.servlet.jsp; \
+javax.servlet.jsp.el; \
+javax.servlet.jsp.jstl.core; \
+javax.servlet.jsp.jstl.fmt; \
+javax.servlet.jsp.jstl.sql; \
+javax.servlet.jsp.jstl.tlv; \
+javax.servlet.jsp.tagext; \
+javax.sound.midi; \
+javax.sound.midi.spi; \
+javax.sound.sampled; \
+javax.sound.sampled.spi; \
+javax.sql; \
+javax.sql.rowset; \
+javax.sql.rowset.serial; \
+javax.sql.rowset.spi; \
+javax.swing; \
+javax.swing.border; \
+javax.swing.colorchooser; \
+javax.swing.event; \
+javax.swing.filechooser; \
+javax.swing.plaf; \
+javax.swing.plaf.basic; \
+javax.swing.plaf.metal; \
+javax.swing.plaf.multi; \
+javax.swing.plaf.synth; \
+javax.swing.table; \
+javax.swing.text; \
+javax.swing.text.html; \
+javax.swing.text.html.parser; \
+javax.swing.text.rtf; \
+javax.swing.tree; \
+javax.swing.undo; \
+javax.tools; \
+javax.transaction; \
+javax.validation; \
+javax.validation.bootstrap; \
+javax.validation.constraints; \
+javax.validation.groups; \
+javax.validation.metadata; \
+javax.validation.spi; \
+javax.ws.rs; \
+javax.ws.rs.core; \
+javax.ws.rs.ext; \
+javax.xml.bind; \
+javax.xml.bind.annotation; \
+javax.xml.bind.annotation.adapters; \
+javax.xml.bind.attachment; \
+javax.xml.bind.helpers; \
+javax.xml.bind.util; \
+javax.xml.crypto; \
+javax.xml.crypto.dom; \
+javax.xml.crypto.dsig; \
+javax.xml.crypto.dsig.dom; \
+javax.xml.crypto.dsig.keyinfo; \
+javax.xml.crypto.dsig.spec; \
+javax.xml.datatype; \
+javax.xml.namespace; \
+javax.xml.parsers; \
+javax.xml.registry; \
+javax.xml.registry.infomodel; \
+javax.xml.rpc; \
+javax.xml.rpc.encoding; \
+javax.xml.rpc.handler; \
+javax.xml.rpc.handler.soap; \
+javax.xml.rpc.holders; \
+javax.xml.rpc.server; \
+javax.xml.rpc.soap; \
+javax.xml.soap; \
+javax.xml.stream; javax.xml.stream.events; javax.xml.stream.util; \
+javax.xml.transform; \
+javax.xml.transform.dom; \
+javax.xml.transform.sax; \
+javax.xml.transform.stax; \
+javax.xml.transform.stream; \
+javax.xml.validation; \
+javax.xml.ws; \
+javax.xml.ws.handler; \
+javax.xml.ws.handler.soap; \
+javax.xml.ws.http; \
+javax.xml.ws.soap; \
+javax.xml.ws.spi; \
+javax.xml.ws.spi.http; \
+javax.xml.ws.wsaddressing; \
+javax.xml.xpath; \
+org.ietf.jgss; \
+org.omg.CORBA; \
+org.omg.CORBA_2_3; \
+org.omg.CORBA_2_3.portable; \
+org.omg.CORBA.DynAnyPackage; \
+org.omg.CORBA.ORBPackage; \
+org.omg.CORBA.portable; \
+org.omg.CORBA.TypeCodePackage; \
+org.omg.CosNaming; \
+org.omg.CosNaming.NamingContextExtPackage; \
+org.omg.CosNaming.NamingContextPackage; \
+org.omg.Dynamic; \
+org.omg.DynamicAny; \
+org.omg.DynamicAny.DynAnyFactoryPackage; \
+org.omg.DynamicAny.DynAnyPackage; \
+org.omg.IOP; \
+org.omg.IOP.CodecFactoryPackage; \
+org.omg.IOP.CodecPackage; \
+org.omg.Messaging; \
+org.omg.PortableInterceptor; \
+org.omg.PortableInterceptor.ORBInitInfoPackage; \
+org.omg.PortableServer; \
+org.omg.PortableServer.CurrentPackage; \
+org.omg.PortableServer.POAManagerPackage; \
+org.omg.PortableServer.POAPackage; \
+org.omg.PortableServer.portable; \
+org.omg.PortableServer.ServantLocatorPackage; \
+org.omg.SendingContext; \
+org.w3c.dom; \
+org.w3c.dom.bootstrap; \
+org.w3c.dom.events; \
+org.w3c.dom.ls; \
+org.xml.sax; \
+org.xml.sax.ext; \
+org.xml.sax.helpers; \
+org.glassfish.hk2.v3.admin; \
+org.glassfish.hk2.naming.impl; \
+org.glassfish.grizzly.http.server.res; \
+org.glassfish.hk2.security.ssl; \
+com.sun.org.apache.xerces.internal.jaxp; \
+com.sun.org.apache.xalan.internal.xsltc.trax; \
+com.sun.org.apache.xerces.internal.parsers; \
+com.ctc.wstx.stax; \
+org.glassfish.hk2.security.provider; \
+org.glassfish.hk2.security.auth.realm.file; \
+org.glassfish.hk2.security.auth.realm.certificate; \
+org.glassfish.hk2.security; \
+com.sun.faces.config; \
+com.sun.jersey.server.impl.container.servlet; \
+org.apache.jasper.runtime; \
+com.sun.xml.ws.transport.http.servlet; \
+org.apache.jasper.servlet; \
+ resolution:=optional
+ </Import-Package>
+ <Bundle-Description>${project.description}</Bundle-Description>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/appserver/core/api-exporter-fragment/src/main/resources/META-INF/MANIFEST.MF b/appserver/core/api-exporter-fragment/src/main/resources/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/core/api-exporter-fragment/src/main/resources/META-INF/MANIFEST.MF
diff --git a/appserver/core/javaee-kernel/pom.xml b/appserver/core/javaee-kernel/pom.xml
new file mode 100755
index 0000000..6ad310a
--- /dev/null
+++ b/appserver/core/javaee-kernel/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>core</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>javaee-kernel</artifactId>
+ <packaging>glassfish-jar</packaging>
+
+ <name>Java EE related distributions kernel Classes</name>
+
+ <developers>
+ <developer>
+ <id>dochez</id>
+ <name>Jerome Dochez</name>
+ <url>http://blogs.sun.com/dochez</url>
+ <organization>Oracle, Inc.</organization>
+ <roles>
+ <role>lead</role>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>glassfish-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>internal-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.admin</groupId>
+ <artifactId>config-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.hk2</groupId>
+ <artifactId>hk2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>kernel</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.annotations</groupId>
+ <artifactId>logging-annotation-processor</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBNamingObjectProxy.java b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBNamingObjectProxy.java
new file mode 100644
index 0000000..ec44fdf
--- /dev/null
+++ b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBNamingObjectProxy.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.kernel.javaee;
+
+import com.sun.enterprise.config.serverbeans.Server;
+import com.sun.logging.LogDomains;
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.admin.ServerEnvironment;
+import org.glassfish.api.deployment.DeployCommandParameters;
+import org.glassfish.api.naming.GlassfishNamingManager;
+import org.glassfish.api.naming.NamingObjectProxy;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.internal.api.ServerContext;
+import org.glassfish.internal.deployment.Deployment;
+import org.glassfish.internal.deployment.ExtendedDeploymentContext;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+
+/**
+ * Used to register MEJB for MEJB lazy initialization
+ */
+public class MEJBNamingObjectProxy implements NamingObjectProxy {
+
+ private static final String NON_PORTABLE_MEJB_JNDI_NAME = "ejb/mgmt/MEJB";
+ private static final String PORTABLE_MEJB_JNDI_NAME_SHORT = "java:global/mejb/MEJBBean";
+ private static final String PORTABLE_MEJB_JNDI_NAME_LONG =
+ "java:global/mejb/MEJBBean!org.glassfish.admin.mejb.MEJBHome";
+
+ private static String[] jndiNames = new String[]
+ {NON_PORTABLE_MEJB_JNDI_NAME,
+ PORTABLE_MEJB_JNDI_NAME_SHORT,
+ PORTABLE_MEJB_JNDI_NAME_LONG};
+
+ private ServiceLocator habitat;
+
+ private static final Logger _logger = LogDomains.getLogger(
+ MEJBNamingObjectProxy.class, LogDomains.EJB_LOGGER);
+
+
+ public MEJBNamingObjectProxy(ServiceLocator habitat) {
+ this.habitat = habitat;
+ }
+
+ static String[] getJndiNames() {
+ return jndiNames;
+ }
+
+ public Object create(Context ic) throws NamingException {
+
+ Object mEJBHome = null;
+ try {
+ unpublishJndiNames();
+ deployMEJB();
+ mEJBHome = ic.lookup(NON_PORTABLE_MEJB_JNDI_NAME);
+ } catch (NamingException ne) {
+ throw ne;
+ } catch (Exception e) {
+ NamingException namingException =
+ new NamingException(e.getMessage());
+ namingException.initCause(e);
+ throw namingException;
+ }
+ return mEJBHome;
+ }
+
+ private void unpublishJndiNames() throws NamingException {
+ GlassfishNamingManager gfNamingManager = habitat.getService(GlassfishNamingManager.class);
+ for (String next : getJndiNames()) {
+ gfNamingManager.unpublishObject(next);
+ }
+ }
+
+ private void deployMEJB() throws IOException {
+ _logger.info("Loading MEJB app on JNDI look up");
+ ServerContext serverContext = habitat.getService(ServerContext.class);
+ File mejbArchive = new File(serverContext.getInstallRoot(),
+ "lib/install/applications/mejb.jar");
+ DeployCommandParameters deployParams =
+ new DeployCommandParameters(mejbArchive);
+ String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
+ deployParams.target = targetName;
+ deployParams.name = "mejb";
+ ActionReport report = habitat.getService(ActionReport.class, "plain");
+ Deployment deployment = habitat.getService(Deployment.class);
+ ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
+ deployment.deploy(dc);
+
+ if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
+ throw new RuntimeException("Failed to deploy MEJB app: " +
+ report.getFailureCause());
+ }
+ }
+}
diff --git a/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBService.java b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBService.java
new file mode 100755
index 0000000..ae55d4f
--- /dev/null
+++ b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/MEJBService.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.kernel.javaee;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.glassfish.hk2.runlevel.RunLevel;
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.PostConstruct;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.glassfish.internal.api.InitRunLevel;
+import org.glassfish.internal.api.Globals;
+import org.glassfish.api.naming.GlassfishNamingManager;
+
+import com.sun.logging.LogDomains;
+
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+/**
+ * MEJB service to register mejb with a temporary NamingObjectProxy at server
+ * start up time
+ */
+@Service
+@RunLevel(InitRunLevel.VAL)
+public class MEJBService implements PostConstruct {
+
+ // we need to inject Globals as it used by the naming manager and
+ // therefore needs to be allocated.
+ @Inject
+ Globals globals;
+
+ @Inject
+ ServiceLocator habitat;
+
+ @Inject
+ Provider<GlassfishNamingManager> gfNamingManagerProvider;
+
+ private static final Logger _logger = LogDomains.getLogger(
+ MEJBService.class, LogDomains.EJB_LOGGER);
+
+ public void postConstruct() {
+ GlassfishNamingManager gfNamingManager =
+ gfNamingManagerProvider.get();
+
+ MEJBNamingObjectProxy mejbProxy =
+ new MEJBNamingObjectProxy(habitat);
+ for(String next : MEJBNamingObjectProxy.getJndiNames()) {
+ try {
+ gfNamingManager.publishObject(next, mejbProxy, true);
+ } catch (Exception e) {
+ _logger.log(Level.WARNING, "Problem in publishing temp proxy for MEJB: " +
+ e.getMessage(), e);
+ }
+ }
+ }
+}
diff --git a/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/WebContainerStarter.java b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/WebContainerStarter.java
new file mode 100644
index 0000000..74b24f8
--- /dev/null
+++ b/appserver/core/javaee-kernel/src/main/java/org/glassfish/kernel/javaee/WebContainerStarter.java
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.kernel.javaee;
+
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.config.serverbeans.ConfigBeansUtilities;
+import com.sun.enterprise.config.serverbeans.Domain;
+import com.sun.enterprise.config.serverbeans.HttpService;
+import com.sun.enterprise.config.serverbeans.VirtualServer;
+import com.sun.enterprise.module.ModulesRegistry;
+import com.sun.enterprise.v3.server.ContainerStarter;
+import java.beans.PropertyChangeEvent;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Provider;
+import org.glassfish.api.StartupRunLevel;
+import org.glassfish.api.admin.ServerEnvironment;
+import org.glassfish.api.container.Sniffer;
+import org.glassfish.grizzly.config.dom.NetworkConfig;
+import org.glassfish.grizzly.config.dom.NetworkListener;
+import org.glassfish.grizzly.config.dom.NetworkListeners;
+import org.glassfish.hk2.api.PostConstruct;
+import org.glassfish.hk2.runlevel.RunLevel;
+import org.glassfish.internal.data.ContainerRegistry;
+import org.glassfish.internal.data.EngineInfo;
+import org.glassfish.logging.annotation.LogMessageInfo;
+import org.glassfish.logging.annotation.LogMessagesResourceBundle;
+import org.glassfish.logging.annotation.LoggerInfo;
+import org.jvnet.hk2.annotations.Service;
+import org.jvnet.hk2.config.Changed;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.ConfigListener;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.NotProcessed;
+import org.jvnet.hk2.config.ObservableBean;
+import org.jvnet.hk2.config.UnprocessedChangeEvents;
+import org.jvnet.hk2.config.types.Property;
+
+/**
+ * Startup service for the web container.
+ *
+ * This service checks if any domain.xml configuration, or changes in
+ * such configuration, that can be handled only by the web container
+ * (e.g., access logging) have been specified, and if so, starts the
+ * web container (unless already started).
+ *
+ * @author jluehe
+ */
+@Service
+@RunLevel(StartupRunLevel.VAL)
+public class WebContainerStarter
+ implements PostConstruct, ConfigListener {
+
+ private static final String LOGMSG_PREFIX = "AS-CORE-JAVAEE";
+
+ @LogMessagesResourceBundle
+ private static final String SHARED_LOGMESSAGE_RESOURCE = "org.glassfish.kernel.javaee.LogMessages";
+
+ @LoggerInfo(subsystem = "AS-CORE", description = "Java EE Core Kernel", publish = true)
+ private static final String ASCORE_LOGGER = "javax.enterprise.system.core.ee";
+ private static final Logger logger = Logger.getLogger(
+ ASCORE_LOGGER, SHARED_LOGMESSAGE_RESOURCE);
+ private static final ResourceBundle rb = logger.getResourceBundle();
+
+ @LogMessageInfo(
+ message = "Web Container not installed",
+ cause = "The web container does not install properly.",
+ action = "Please check the web container libraries are installed properly.",
+ level = "INFO")
+ public static final String mWebContainerNotInstalled = LOGMSG_PREFIX + "-0001";
+
+ @LogMessageInfo(
+ message = "Done with starting {0} container.",
+ level = "INFO")
+ public static final String mStartContainerDone = LOGMSG_PREFIX + "-0002";
+
+ @LogMessageInfo(
+ message = "Unable to start container (no exception provided)",
+ cause = "The web container does not start properly.",
+ action = "Please check the web container libraries are installed properly.",
+ level = "SEVERE")
+ public static final String mUnableStartContainerNoException = LOGMSG_PREFIX + "-0003";
+
+ @LogMessageInfo(
+ message = "Unable to start container {0}",
+ cause = "The web container does not start properly. Most probably, there is a class loading issue.",
+ action = "Please resolve issues mentioned in the stack trace.",
+ level = "SEVERE")
+ public static final String mUnableStartContainer = LOGMSG_PREFIX + "-0004";
+
+ private static final String AUTH_PASSTHROUGH_ENABLED_PROP =
+ "authPassthroughEnabled";
+
+ private static final String PROXY_HANDLER_PROP = "proxyHandler";
+
+ private static final String TRACE_ENABLED_PROP = "traceEnabled";
+
+ @Inject
+ private Provider<Domain> domainProvider;
+
+ @Inject
+ private ContainerRegistry containerRegistry;
+
+ @Inject
+ private ContainerStarter containerStarter;
+
+ @Inject
+ private ModulesRegistry modulesRegistry;
+
+ @Inject @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
+ private Provider<Config> serverConfigProvider;
+
+ @Inject @Named("web")
+ private Provider<Sniffer> webSnifferProvider;
+
+ /**
+ * Scans the domain.xml to see if it specifies any configuration
+ * that can be handled only by the web container, and if so, starts
+ * the web container
+ */
+ public void postConstruct() {
+ domainProvider.get();
+ Config serverConfig = serverConfigProvider.get();
+
+ boolean isStartNeeded = false;
+ if (serverConfig != null) {
+ if (isStartNeeded(serverConfig.getHttpService())) {
+ isStartNeeded = true;
+ }
+ if (!isStartNeeded && isStartNeeded(serverConfig.getNetworkConfig())) {
+ isStartNeeded = true;
+ }
+ }
+
+ if (isStartNeeded) {
+ startWebContainer();
+ } else {
+ ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getHttpService());
+ bean.addListener(this);
+ bean = (ObservableBean) ConfigSupport.getImpl(serverConfig.getNetworkConfig().getNetworkListeners());
+ bean.addListener(this);
+ }
+ }
+
+ public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
+ return ConfigSupport.sortAndDispatch(events, new Changed() {
+ public <T extends ConfigBeanProxy> NotProcessed changed(
+ TYPE type, Class<T> tClass, T t) {
+ if (tClass == HttpService.class) {
+ if (type == TYPE.CHANGE) {
+ if (isStartNeeded((HttpService) t)) {
+ startWebContainer();
+ }
+ }
+ } else if (tClass == VirtualServer.class) {
+ if (type == TYPE.ADD || type == TYPE.CHANGE) {
+ if (isStartNeeded((VirtualServer) t)) {
+ startWebContainer();
+ }
+ }
+ } else if (tClass == NetworkListener.class) {
+ if (type == TYPE.ADD || type == TYPE.CHANGE) {
+ if (isStartNeeded((NetworkListener) t)) {
+ startWebContainer();
+ }
+ }
+ }
+ return null;
+ }
+ }
+ , logger);
+ }
+
+ /**
+ * Starts the web container
+ */
+ private void startWebContainer() {
+ Sniffer webSniffer = webSnifferProvider.get();
+ if (webSniffer==null) {
+ if (logger.isLoggable(Level.INFO)) {
+ logger.info(mWebContainerNotInstalled);
+ }
+ return;
+ }
+
+ if (containerRegistry.getContainer(
+ webSniffer.getContainersNames()[0]) != null) {
+ containerRegistry.getContainer(
+ webSniffer.getContainersNames()[0]).getContainer();
+ } else {
+ try {
+ Collection<EngineInfo> containersInfo =
+ containerStarter.startContainer(webSniffer);
+ if (containersInfo != null && !containersInfo.isEmpty()) {
+ // Start each container
+ for (EngineInfo info : containersInfo) {
+ info.getContainer();
+ if (logger.isLoggable(Level.INFO)) {
+ logger.log(Level.INFO, mStartContainerDone,
+ webSniffer.getModuleType());
+ }
+ }
+ } else {
+ logger.severe(mUnableStartContainerNoException);
+ }
+ } catch (Exception e) {
+ String msg;
+ if ( rb != null ) {
+ msg = MessageFormat.format( rb.getString(mUnableStartContainer), webSniffer.getContainersNames()[0]);
+ } else {
+ msg = "Unable to start Web Container: " + webSniffer.getContainersNames()[0];
+ }
+ logger.log(Level.SEVERE, msg, e);
+ }
+ }
+ }
+
+ /*
+ * @return true if the given HttpService contains any configuration
+ * that can be handled only by the web container and therefore requires
+ * the web container to be started, false otherwise
+ */
+ private boolean isStartNeeded(HttpService httpService) {
+ if (httpService == null) {
+ return false;
+ }
+
+ if (ConfigBeansUtilities.toBoolean(
+ httpService.getAccessLoggingEnabled()) ||
+ ConfigBeansUtilities.toBoolean(
+ httpService.getSsoEnabled())) {
+ return true;
+ }
+
+ List<Property> props = httpService.getProperty();
+ if (props != null) {
+ for (Property prop : props) {
+ String propName = prop.getName();
+ String propValue = prop.getValue();
+ if (AUTH_PASSTHROUGH_ENABLED_PROP.equals(propName)) {
+ if (ConfigBeansUtilities.toBoolean(propValue)) {
+ return true;
+ }
+ } else if (PROXY_HANDLER_PROP.equals(propName)) {
+ return true;
+ } else if (TRACE_ENABLED_PROP.equals(propName)) {
+ if (!ConfigBeansUtilities.toBoolean(propValue)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ List<VirtualServer> hosts = httpService.getVirtualServer();
+ if (hosts != null) {
+ for (VirtualServer host : hosts) {
+ if (isStartNeeded(host)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * @return true if the given VirtualServer contains any configuration
+ * that can be handled only by the web container and therefore requires
+ * the web container to be started, false otherwise
+ */
+ private boolean isStartNeeded(VirtualServer host) {
+ if (host == null) {
+ return false;
+ }
+
+ if (ConfigBeansUtilities.toBoolean(host.getAccessLoggingEnabled()) ||
+ ConfigBeansUtilities.toBoolean(host.getSsoEnabled())) {
+ return true;
+ }
+
+ String state = host.getState();
+ if (state != null &&
+ ("disabled".equals(state) ||
+ !ConfigBeansUtilities.toBoolean(state))) {
+ return true;
+ }
+
+ List<Property> props = host.getProperty();
+ if (props != null && !props.isEmpty()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /*
+ * @return true if the given NetworkConfig contains any configuration
+ * that can be handled only by the web container and therefore requires
+ * the web container to be started, false otherwise
+ */
+ private boolean isStartNeeded(NetworkConfig networkConfig) {
+ if (networkConfig == null) {
+ return false;
+ }
+
+ NetworkListeners networkListeners = networkConfig.getNetworkListeners();
+ if (networkListeners == null) {
+ return false;
+ }
+
+ for (NetworkListener networkListener : networkListeners.getNetworkListener()) {
+ if (isStartNeeded(networkListener)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /*
+ * @return true if the given NetworkListener contains any configuration
+ * that can be handled only by the web container and therefore requires
+ * the web container to be started, false otherwise
+ */
+ private boolean isStartNeeded(NetworkListener networkListener) {
+ if (networkListener == null) {
+ return false;
+ }
+
+ return ConfigBeansUtilities.toBoolean(networkListener.getJkEnabled());
+ }
+}
diff --git a/appserver/core/pom.xml b/appserver/core/pom.xml
new file mode 100644
index 0000000..e01f75a8
--- /dev/null
+++ b/appserver/core/pom.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.glassfish.main</groupId>
+ <artifactId>glassfish-parent</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>core</artifactId>
+ <packaging>pom</packaging>
+ <name>GlassFish Core modules</name>
+ <modules>
+ <module>javaee-kernel</module>
+ <module>api-exporter-fragment</module>
+ </modules>
+</project>