Initial Contribution
Signed-off-by: Vinay Vishal <vinay.vishal@oracle.com>
diff --git a/appserver/orb/orb-connector/exclude.xml b/appserver/orb/orb-connector/exclude.xml
new file mode 100644
index 0000000..90d5374
--- /dev/null
+++ b/appserver/orb/orb-connector/exclude.xml
@@ -0,0 +1,47 @@
+<!--
+
+ Copyright (c) 2011, 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
+
+-->
+
+<FindBugsFilter>
+ <!--
+ FindBugs can't figure out that these fields are only ever
+ set in methods that are only called from the constructor.
+ -->
+ <Match>
+ <Class name="org.glassfish.enterprise.iiop.util.ThreadPoolStatsImpl"/>
+ <Or>
+ <Field name="averageTimeInQueue"/>
+ <Field name="averageWorkCompletionTime"/>
+ <Field name="currentNumberOfThreads"/>
+ <Field name="numberOfAvailableThreads"/>
+ <Field name="numberOfBusyThreads"/>
+ <Field name="numberOfWorkItemsInQueue"/>
+ <Field name="totalWorkItemsAdded"/>
+ </Or>
+ <Bug pattern="IS2_INCONSISTENT_SYNC"/>
+ </Match>
+
+ <!--
+ This is a safe use of double-check locking.
+ http://en.wikipedia.org/wiki/Double-checked_locking
+ -->
+ <Match>
+ <Class name="org.glassfish.enterprise.iiop.api.GlassFishORBHelper"/>
+ <Method name="getORB"/>
+ <Bug pattern="UG_SYNC_SET_UNSYNC_GET"/>
+ </Match>
+</FindBugsFilter>
diff --git a/appserver/orb/orb-connector/osgi.bundle b/appserver/orb/orb-connector/osgi.bundle
new file mode 100644
index 0000000..f8366c4
--- /dev/null
+++ b/appserver/orb/orb-connector/osgi.bundle
@@ -0,0 +1,23 @@
+#
+# 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
+#
+
+-exportcontents: \
+ org.glassfish.enterprise.iiop.api; \
+ org.glassfish.orb.admin.config.handler; \
+ org.glassfish.enterprise.iiop.util; \
+ org.glassfish.enterprise.iiop.spi; version=${project.osgi.version}
+
+
diff --git a/appserver/orb/orb-connector/pom.xml b/appserver/orb/orb-connector/pom.xml
new file mode 100755
index 0000000..3624e4f
--- /dev/null
+++ b/appserver/orb/orb-connector/pom.xml
@@ -0,0 +1,153 @@
+<?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.orb</groupId>
+ <artifactId>orb</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>orb-connector</artifactId>
+ <packaging>glassfish-jar</packaging>
+
+ <name>GlassFish ORB connector implementation</name>
+
+ <properties>
+ <findbugs.exclude>${project.basedir}/exclude.xml</findbugs.exclude>
+ </properties>
+
+ <developers>
+ <developer>
+ <id>mk111283</id>
+ <name>Mahesh Kannan</name>
+ <url>http://forum.java.sun.com/profile.jspa?userID=487934</url>
+ <organization>Oracle, Inc.</organization>
+ <roles>
+ <role>lead</role>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.main.orb</groupId>
+ <artifactId>orb-enabler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.admin</groupId>
+ <artifactId>admin-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.pfl</groupId>
+ <artifactId>pfl-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.corba</groupId>
+ <artifactId>glassfish-corba-omgapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.corba</groupId>
+ <artifactId>glassfish-corba-internal-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.hk2</groupId>
+ <artifactId>hk2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.deployment</groupId>
+ <artifactId>dol</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.cluster</groupId>
+ <artifactId>cluster-admin</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>glassfish-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.main.admin</groupId>
+ <artifactId>monitoring-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.external</groupId>
+ <artifactId>management-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.gmbal</groupId>
+ <artifactId>gmbal</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>kernel</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.main.tests</groupId>
+ <artifactId>utils</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish</groupId>
+ <artifactId>javax.el</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*.xml</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+</project>
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBFactory.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBFactory.java
new file mode 100644
index 0000000..043771f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBFactory.java
@@ -0,0 +1,55 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.jvnet.hk2.annotations.Contract;
+import org.omg.CORBA.ORB;
+import org.omg.PortableInterceptor.ServerRequestInfo;
+
+import java.util.Properties;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 17, 2009
+ */
+@Contract
+public interface GlassFishORBFactory {
+ // This is ORBConstants.ENV_IS_SERVER_PROPERTY. We cannot
+ // reference ORBConstants from this class.
+ public static final String ENV_IS_SERVER_PROPERTY =
+ "com.sun.corba.ee.ORBEnvironmentIsGlassFishServer" ;
+
+ public ORB createORB(Properties props);
+
+ public int getOTSPolicyType();
+
+ public int getCSIv2PolicyType();
+
+ public Properties getCSIv2Props();
+
+ public void setCSIv2Prop(String name, String value);
+
+ public int getORBInitialPort();
+
+ public String getORBHost(ORB orb);
+
+ public int getORBPort(ORB orb);
+
+ public boolean isEjbCall (ServerRequestInfo sri);
+
+ public String getIIOPEndpoints() ;
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBHelper.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBHelper.java
new file mode 100644
index 0000000..8357d0d
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBHelper.java
@@ -0,0 +1,251 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.omg.CORBA.ORB;
+import org.omg.PortableInterceptor.ServerRequestInfo;
+
+import org.glassfish.api.admin.ProcessEnvironment;
+
+import org.glassfish.api.naming.GlassfishNamingManager;
+import org.glassfish.internal.api.ORBLocator;
+
+import java.util.Properties;
+import java.rmi.Remote;
+import java.nio.channels.SelectableChannel;
+
+import org.glassfish.hk2.api.PostConstruct;
+
+import org.glassfish.api.event.Events;
+import org.glassfish.api.event.EventTypes;
+import org.glassfish.api.event.Events;
+import org.glassfish.api.event.EventListener;
+import com.sun.logging.LogDomains;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class exposes any orb/iiop functionality needed by modules in the app server.
+ * This prevents modules from needing any direct dependencies on the orb-iiop module.
+ * @author Mahesh Kannan
+ * Date: Jan 17, 2009
+ */
+@Service
+public class GlassFishORBHelper implements PostConstruct, ORBLocator {
+
+ @Inject
+ private ServiceLocator services;
+
+ @Inject
+ private ProcessEnvironment processEnv;
+
+ private static final Logger _logger =
+ LogDomains.getLogger(GlassFishORBHelper.class, LogDomains.CORBA_LOGGER);
+
+ private volatile ORB orb = null ;
+
+ private ProtocolManager protocolManager = null ;
+
+ private ORBLazyServiceInitializer lazyServiceInitializer;
+
+ private SelectableChannelDelegate selectableChannelDelegate;
+
+ @Inject
+ Provider<ProtocolManager> protocolManagerProvider;
+
+
+ @Inject
+ Provider<GlassfishNamingManager> glassfishNamingManagerProvider;
+
+ @Inject
+ private Provider<Events> eventsProvider;
+
+ //@Inject
+ private GlassFishORBFactory orbFactory;
+
+ public void postConstruct() {
+ orbFactory = services.getService(GlassFishORBFactory.class);
+ }
+
+
+ public void onShutdown() {
+ _logger.log(Level.FINE, ("ORB Shutdown started"));
+ orb.destroy();
+ }
+
+ public synchronized void setORB( ORB orb ) {
+ this.orb = orb ;
+
+ if (orb != null) {
+ EventListener glassfishEventListener = new org.glassfish.api.event.EventListener() {
+
+ public void event(org.glassfish.api.event.EventListener.Event event) {
+ if (event.is(EventTypes.SERVER_SHUTDOWN)) {
+ onShutdown();
+ }
+ }
+ };
+ eventsProvider.get().register(glassfishEventListener);
+ }
+ }
+
+ /**
+ * Get or create the default orb. This can be called for any process type. However,
+ * protocol manager and CosNaming initialization only take place for the Server.
+ */
+ public ORB getORB() {
+ // Use a volatile double-checked locking idiom here so that we can publish
+ // a partly-initialized ORB early, so that lazy init can come into getORB()
+ // and allow an invocation to the transport to complete.
+ if (orb == null) {
+
+ synchronized( this ) {
+ if (orb == null) {
+ try {
+ final boolean isServer = processEnv.getProcessType().isServer() ;
+
+ Properties props = new Properties();
+ props.setProperty( GlassFishORBFactory.ENV_IS_SERVER_PROPERTY,
+ Boolean.valueOf( isServer ).toString() ) ;
+
+ // Create orb and make it visible. This will allow
+ // loopback calls to getORB() from
+ // portable interceptors activated as a side-effect of the
+ // remaining initialization. If it's a
+ // server, there's a small time window during which the
+ // ProtocolManager won't be available. Any callbacks that
+ // result from the protocol manager initialization itself
+ // cannot depend on having access to the protocol manager.
+ orb = orbFactory.createORB(props);
+
+ if (isServer) {
+ if (protocolManager == null) {
+ ProtocolManager tempProtocolManager =
+ protocolManagerProvider.get();
+
+ tempProtocolManager.initialize(orb);
+ // Move startup of naming to PEORBConfigurator so it runs
+ // before interceptors.
+ // tempProtocolManager.initializeNaming();
+ tempProtocolManager.initializePOAs();
+
+ // Now make protocol manager visible.
+ protocolManager = tempProtocolManager;
+
+ GlassfishNamingManager namingManager =
+ glassfishNamingManagerProvider.get();
+
+ Remote remoteSerialProvider =
+ namingManager.initializeRemoteNamingSupport(orb);
+
+ protocolManager.initializeRemoteNaming(remoteSerialProvider);
+ }
+ }
+ } catch(Exception e) {
+ orb = null;
+ protocolManager = null;
+ throw new RuntimeException("Orb initialization erorr", e);
+ }
+ }
+ }
+ }
+
+ return orb;
+ }
+
+
+ public void setSelectableChannelDelegate(SelectableChannelDelegate d) {
+ selectableChannelDelegate = d;
+ }
+
+ public SelectableChannelDelegate getSelectableChannelDelegate() {
+ return this.selectableChannelDelegate;
+ }
+
+ public static interface SelectableChannelDelegate {
+
+ public void handleRequest(SelectableChannel channel);
+
+ }
+
+
+ /**
+ * Get a protocol manager for creating remote references. ProtocolManager is only
+ * available in the server. Otherwise, this method returns null.
+ *
+ * If it's the server and the orb hasn't been already created, calling
+ * this method has the side effect of creating the orb.
+ */
+ public ProtocolManager getProtocolManager() {
+
+ if( !processEnv.getProcessType().isServer() ) {
+ return null;
+ }
+
+ synchronized (this) {
+ if (protocolManager == null) {
+ getORB();
+ }
+
+ return protocolManager;
+ }
+ }
+
+ public boolean isORBInitialized() {
+ return (orb != null);
+ }
+
+ public int getOTSPolicyType() {
+ return orbFactory.getOTSPolicyType();
+ }
+
+ public int getCSIv2PolicyType() {
+ return orbFactory.getCSIv2PolicyType();
+ }
+
+ public Properties getCSIv2Props() {
+ return orbFactory.getCSIv2Props();
+ }
+
+ public void setCSIv2Prop(String name, String value) {
+ orbFactory.setCSIv2Prop(name, value);
+ }
+
+ public int getORBInitialPort() {
+ return orbFactory.getORBInitialPort();
+ }
+
+ public String getORBHost(ORB orb) {
+ return orbFactory.getORBHost(orb);
+ }
+
+ public int getORBPort(ORB orb) {
+ return orbFactory.getORBPort(orb);
+ }
+
+ public boolean isEjbCall(ServerRequestInfo sri) {
+ return orbFactory.isEjbCall(sri);
+ }
+
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBLifeCycleListener.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBLifeCycleListener.java
new file mode 100644
index 0000000..f5834d9
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/GlassFishORBLifeCycleListener.java
@@ -0,0 +1,35 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.jvnet.hk2.annotations.Contract;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 16, 2009
+ */
+@Contract
+public interface GlassFishORBLifeCycleListener {
+
+ public void initializeORBInitProperties(List<String> args, Properties props);
+
+ public void orbCreated(org.omg.CORBA.ORB orb);
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateFacade.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateFacade.java
new file mode 100644
index 0000000..2640760
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateFacade.java
@@ -0,0 +1,28 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.jvnet.hk2.annotations.Contract;
+
+import javax.ejb.spi.HandleDelegate;
+
+@Contract
+public interface HandleDelegateFacade {
+
+ public HandleDelegate getHandleDelegate();
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.java
new file mode 100644
index 0000000..1c3af6e
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/HandleDelegateNamingProxy.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.enterprise.iiop.api;
+
+import org.glassfish.api.naming.NamespacePrefixes;
+import org.glassfish.api.naming.NamedNamingObjectProxy;
+
+import org.jvnet.hk2.annotations.Service;
+import javax.inject.Inject;
+
+import javax.ejb.spi.HandleDelegate;
+
+import javax.inject.Provider;
+import javax.naming.NamingException;
+
+/**
+ * Proxy for java:comp/ORB lookups
+ *
+ *
+ * @author Ken Saks
+ */
+@Service
+@NamespacePrefixes(HandleDelegateNamingProxy.HANDLE_DELEGATE)
+public class HandleDelegateNamingProxy implements NamedNamingObjectProxy {
+
+ static final String HANDLE_DELEGATE
+ = "java:comp/HandleDelegate";
+
+ @Inject
+ private Provider<HandleDelegateFacade> handleDelegateFacadeProvider;
+
+ private volatile HandleDelegateFacade facade;
+
+ public Object handle(String name) throws NamingException {
+
+ HandleDelegate delegate = null;
+
+ if (HANDLE_DELEGATE.equals(name)) {
+ try {
+ if (facade == null) {
+ HandleDelegateFacade hd = handleDelegateFacadeProvider.get();
+ facade = hd;
+ }
+ delegate = facade.getHandleDelegate();
+
+ } catch(Throwable t) {
+ NamingException ne = new NamingException
+ ("Error resolving java:comp/HandleDelegate lookup");
+ ne.initCause(t);
+ throw ne;
+ }
+ }
+
+ return delegate;
+ }
+
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPConstants.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPConstants.java
new file mode 100644
index 0000000..6ae2dd2
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPConstants.java
@@ -0,0 +1,28 @@
+/*
+ * 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.enterprise.iiop.api;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 16, 2009
+ */
+public interface IIOPConstants {
+
+ public static final int PASS_BY_VALUE_ID = 0;
+
+ public static final int PASS_BY_REFERENCE_ID = 1;
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPInterceptorFactory.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPInterceptorFactory.java
new file mode 100644
index 0000000..bbb13ed
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPInterceptorFactory.java
@@ -0,0 +1,35 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.jvnet.hk2.annotations.Contract;
+import org.omg.IOP.Codec;
+import org.omg.PortableInterceptor.ClientRequestInterceptor;
+import org.omg.PortableInterceptor.ORBInitInfo;
+import org.omg.PortableInterceptor.ServerRequestInterceptor;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 16, 2009
+ */
+@Contract
+public interface IIOPInterceptorFactory {
+
+ public ClientRequestInterceptor createClientRequestInterceptor(ORBInitInfo info, Codec codec);
+
+ public ServerRequestInterceptor createServerRequestInterceptor(ORBInitInfo info, Codec codec);
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPSSLUtil.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPSSLUtil.java
new file mode 100644
index 0000000..15a8de5
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/IIOPSSLUtil.java
@@ -0,0 +1,40 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import java.security.SecureRandom;
+import org.jvnet.hk2.annotations.Contract;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.TrustManager;
+import org.omg.IOP.TaggedComponent;
+import org.omg.PortableInterceptor.IORInfo;
+/**
+ * This class tries to avoid the need for orb-iiop to
+ * depend on some security modules for getting SSL related info
+ * @author Kumar
+ */
+@Contract
+public interface IIOPSSLUtil {
+ public Object getAppClientSSL();
+ public void setAppClientSSL(Object ssl);
+ public KeyManager[] getKeyManagers(String certNickname);
+ public TrustManager[] getTrustManagers();
+ public SecureRandom getInitializedSecureRandom();
+ public Object getSSLPortsAsSocketInfo(Object ior);
+ public TaggedComponent createSSLTaggedComponent(IORInfo iorInfo, Object socketInfos);
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBLazyServiceInitializer.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBLazyServiceInitializer.java
new file mode 100644
index 0000000..e655c9f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBLazyServiceInitializer.java
@@ -0,0 +1,93 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.glassfish.internal.grizzly.LazyServiceInitializer;
+
+import org.jvnet.hk2.annotations.Service;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.glassfish.hk2.api.PostConstruct;
+
+import org.omg.CORBA.ORB;
+
+import javax.naming.NamingException;
+import java.nio.channels.SelectableChannel;
+import java.util.logging.Level;
+import com.sun.logging.LogDomains;
+import java.util.logging.Logger;
+
+
+
+/**
+ *
+ * @author Ken Saks
+ */
+@Service
+@Named("iiop-service")
+public class ORBLazyServiceInitializer implements LazyServiceInitializer, PostConstruct {
+
+static Logger logger = LogDomains.getLogger(ORBLazyServiceInitializer.class, LogDomains.SERVER_LOGGER);
+
+
+ @Inject
+ private GlassFishORBHelper orbHelper;
+
+ boolean initializedSuccessfully = false;
+
+ public void postConstruct() {
+ }
+
+ public String getServiceName() {
+
+ return "iiop-service";
+ }
+
+
+ public boolean initializeService() {
+
+ try {
+
+ orbHelper.getORB();
+
+ initializedSuccessfully = true;
+
+ // TODO add check to ensure that lazy init is enabled for the orb
+ // and throw exception if not
+
+ } catch(Exception e) {
+ logger.log(Level.WARNING, "ORB initialization failed in lazy init", e);
+ }
+
+ return initializedSuccessfully;
+ }
+
+
+ public void handleRequest(SelectableChannel channel) {
+ if( initializedSuccessfully) {
+ orbHelper.getSelectableChannelDelegate().handleRequest(channel);
+ } else {
+ logger.log(Level.WARNING, "Cannot handle SelectableChannel request in ORBLazyServiceInitializer." +
+ "ORB did not initialize successfully");
+ }
+ }
+
+
+
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java
new file mode 100644
index 0000000..3511996
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ORBNamingProxy.java
@@ -0,0 +1,63 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import org.glassfish.api.naming.NamespacePrefixes;
+import org.glassfish.api.naming.NamedNamingObjectProxy;
+
+import org.jvnet.hk2.annotations.Service;
+import javax.inject.Inject;
+
+import org.omg.CORBA.ORB;
+
+import javax.naming.NamingException;
+
+/**
+ * Proxy for java:comp/ORB lookups
+ *
+ *
+ * @author Ken Saks
+ */
+@Service
+@NamespacePrefixes(ORBNamingProxy.ORB_CONTEXT)
+public class ORBNamingProxy implements NamedNamingObjectProxy {
+
+ static final String ORB_CONTEXT
+ = "java:comp/ORB";
+
+ @Inject
+ private GlassFishORBHelper orbHelper;
+
+ public Object handle(String name) throws NamingException {
+
+ ORB orb = null;
+
+ if (ORB_CONTEXT.equals(name)) {
+ try {
+ orb = orbHelper.getORB();
+ } catch(Throwable t) {
+ NamingException ne = new NamingException("Error retrieving orb for java:comp/ORB lookup");
+ ne.initCause(t);
+ throw ne;
+ }
+ }
+
+ return orb;
+ }
+
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ProtocolManager.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ProtocolManager.java
new file mode 100644
index 0000000..95d771b
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/ProtocolManager.java
@@ -0,0 +1,99 @@
+/*
+ * 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.enterprise.iiop.api;
+
+import java.rmi.*;
+
+import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
+import org.glassfish.enterprise.iiop.spi.EjbService;
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+import org.jvnet.hk2.annotations.Contract;
+import org.omg.CORBA.ORB;
+import java.rmi.Remote;
+
+
+/**
+ * The ProtocolManager interface specifies the functionality of the
+ * remote communication layer, which provides the support for
+ * distribution described in Chapter 13 of the EJB spec.
+ * Possible implementations of the ProtocolManager include RMI/IIOP,
+ * RMI/JRMP, RMI/DCOM, RMI/HTTP ....
+ * @author Vivek Nagar
+ */
+
+@Contract
+public interface ProtocolManager {
+
+ void initialize(ORB o);
+
+
+ public void initializePOAs() throws Exception;
+
+
+ public void initializeNaming() throws Exception;
+
+ public void initializeRemoteNaming(Remote remoteNamingProvider) throws Exception;
+
+ /**
+ * Return a factory that can be used to create/destroy remote
+ * references for a particular EJB type.
+ */
+ RemoteReferenceFactory getRemoteReferenceFactory(EjbContainerFacade container,
+ boolean remoteHomeView,
+ String id);
+
+
+ /**
+ * Return true if the two object references refer to the same
+ * remote object.
+ */
+ boolean isIdentical(Remote obj1, Remote obj2);
+
+ /**
+ * Check that all Remote interfaces implemented by target object
+ * conform to the rules for valid RMI-IIOP interfaces. Throws
+ * runtime exception if validation fails.
+ */
+ void validateTargetObjectInterfaces(Remote targetObj);
+
+ /**
+ * Map the RMI exception to a protocol-specific (e.g. CORBA) exception
+ */
+ Throwable mapException(Throwable exception);
+
+ /**
+ * True if object is a corba stub
+ */
+ boolean isStub(Object obj);
+
+ boolean isLocal(Object obj);
+
+ byte[] getObjectID(org.omg.CORBA.Object obj);
+
+ /**
+ * Connect the RMI object to the protocol.
+ */
+ void connectObject(Remote remoteObj) throws RemoteException;
+
+
+ EjbDescriptor getEjbDescriptor(byte[] ejbKey);
+
+}
+
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/RemoteReferenceFactory.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/RemoteReferenceFactory.java
new file mode 100644
index 0000000..f030ff6
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/api/RemoteReferenceFactory.java
@@ -0,0 +1,93 @@
+/*
+ * 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.enterprise.iiop.api;
+
+
+import java.rmi.Remote;
+
+/**
+ * The RemoteReferenceFactory interface provides methods to
+ * create and destroy remote EJB references. Instances of the
+ * RemoteReferenceFactory are obtained from the ProtocolManager.
+ *
+ */
+public interface RemoteReferenceFactory {
+
+ /**
+ * Create a remote reference for an EJBObject which can
+ * be used for performing remote invocations.
+ * The key specifies the unique
+ * "object-id" of the EJBObject. This operation should not
+ * create any "tie" for the particular remote object instance.
+ * This operation should not cause the ProtocolManager to maintain
+ * any instance-specific state about the EJB instance.
+ *
+ * @param instanceKey a unique identifier for the EJB instance
+ * which is unique across all EJB refs created using this
+ * RemoteReferenceFactory instance.
+ * @return the protocol-specific stub of the proper derived type.
+ * It should not be necessary to narrow this stub again.
+ */
+ Remote createRemoteReference(byte[] instanceKey);
+
+
+ /**
+ * Create a remote reference for an EJBHome which can
+ * be used for performing remote invocations.
+ * The key specifies the unique
+ * "object-id" of the EJBHome. This operation should not
+ * create any "tie" for the particular remote object instance.
+ * This operation should not cause the ProtocolManager to maintain
+ * any instance-specific state about the EJB instance.
+ *
+ * @param homeKey a unique identifier for the EJB instance
+ * which is unique across all EJB refs created using this
+ * RemoteReferenceFactory instance.
+ * @return the protocol-specific stub of the proper derived type.
+ * It should not be necessary to narrow this stub again.
+ */
+ Remote createHomeReference(byte[] homeKey);
+
+ /**
+ * Destroy an EJBObject or EJBHome remote ref
+ * so that it can no longer be used for remote invocations.
+ * This operation should destroy any state such as "tie" objects
+ * maintained by the ProtocolManager for the EJBObject or EJBHome.
+ *
+ * @param remoteRef the remote reference for the EJBObject/EJBHome
+ * @param remoteObj the servant corresponding to the remote reference.
+ */
+ void destroyReference(Remote remoteRef, Remote remoteObj);
+
+ /**
+ * Destroy the factory itself. Called during shutdown / undeploy.
+ * The factory is expected to release all resources in this method.
+ */
+ public void destroy();
+
+
+ public boolean hasSameContainerID(org.omg.CORBA.Object ref)
+ throws Exception;
+
+ public void setRepositoryIds(Class homeIntf, Class remoteIntf);
+
+ public void cleanupClass(Class clazz);
+
+ public int getCSIv2PolicyType();
+
+}
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbContainerFacade.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbContainerFacade.java
new file mode 100644
index 0000000..9643073
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbContainerFacade.java
@@ -0,0 +1,43 @@
+/*
+ * 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.enterprise.iiop.spi;
+
+import java.rmi.Remote;
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+/**
+ * Provides ejb-specific services to iiop glue code.
+ */
+public interface EjbContainerFacade {
+
+ EjbDescriptor getEjbDescriptor();
+
+ ClassLoader getClassLoader();
+
+ Remote getTargetObject(byte[] instanceKey,
+ String generatedRemoteBusinessIntf);
+
+ void releaseTargetObject(Remote remoteObj);
+
+ String getUseThreadPoolId();
+
+ boolean getPassByReference();
+
+}
+
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbService.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbService.java
new file mode 100644
index 0000000..4888bff
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/spi/EjbService.java
@@ -0,0 +1,37 @@
+/*
+ * 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.enterprise.iiop.spi;
+
+import java.rmi.*;
+import org.jvnet.hk2.annotations.Contract;
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+/**
+ * Provides general EJB container services needed by iiop glue code.
+ */
+@Contract
+public interface EjbService {
+
+
+ EjbDescriptor ejbIdToDescriptor(long ejbId);
+
+
+
+}
+
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/GenericStatsImpl.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/GenericStatsImpl.java
new file mode 100644
index 0000000..791dd32
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/GenericStatsImpl.java
@@ -0,0 +1,204 @@
+/*
+ * 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.enterprise.iiop.util;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.HashMap;
+import org.glassfish.external.statistics.Stats;
+import org.glassfish.external.statistics.Statistic;
+
+/** Provides for generic implementation of any Stats interface. This class facilitates
+ * composition over inheritance for all the classes that implement their
+ * specific Stats interfaces. None of them has to implement the methods defined
+ * by the {@link javax.management.j2ee.statistics.Stats} interface. This class
+ * implements the same interface and does that job. All that implementing classes
+ * have to do is implement the specific accessing methods in their Stats interfaces
+ * and delegate the rest to this class. <b> This class invokes all these methods in
+ * implementing class through introspection. </b>
+ * @author Kedar Mhaswade
+ * @since S1AS8.0
+ * @version $Version$
+ */
+public class GenericStatsImpl implements Stats {
+
+ private final Class statsInterface;
+ private final Object statsProvider;
+ /** A map with binding of a String XXX to a method with name <b>get</b>XXX */
+ private final Map getters;
+
+ /**
+ */
+ public GenericStatsImpl(String statsInterfaceName, Object statsProvider)
+ throws ClassNotFoundException {
+ this(statsInterfaceName, GenericStatsImpl.class.getClassLoader(), statsProvider);
+ }
+
+ /**
+ */
+ public GenericStatsImpl(String statsInterfaceName, ClassLoader loader,
+ Object statsProvider) throws ClassNotFoundException {
+ this(Class.forName(statsInterfaceName, true, loader), statsProvider);
+ }
+
+ /** Constructs a new instance of this class for a given interface and its implementation.
+ * It is mandatory that following contract is satisfied to call this satisfactorily:
+ * <ul>
+ * <li> None of the parameters are null. </li>
+ * <li> Given statsProvider implements the given statsInterface. </li>
+ * <li> Given statsInterface has to extend the @{link Stats} interface. </li>
+ * </ul>
+ * Note that it is expected (though not mandatory) to have a getXXX method that
+ * does not return an instance of {@link Statistic} interface.
+ * @throws NullPointerException if any of the given parameters are null
+ * @throws IllegalArgumentException if the contract is not satisfied by given parameters
+ */
+ public GenericStatsImpl(Class statsInterface, Object statsProvider) {
+ if (!implementsInterface(statsInterface, statsProvider) ||
+ ! extendsStatsInterface(statsInterface)) {
+ throw new IllegalArgumentException("Contract violation: invalid interface-implementation pair");
+ }
+ this.statsProvider = statsProvider;
+ this.statsInterface = statsInterface;
+ this.getters = new HashMap();
+ populateGetterMap();
+ }
+
+ public Statistic getStatistic(String statisticName) {
+ final Method getter = (Method) getters.get(statisticName);
+ assert (getter != null) : ("Getter not initialized properly: " + statisticName);
+ Object result = null;
+ try {
+ result = getter.invoke(statsProvider);
+ }
+ catch(Exception e) {
+ final RuntimeException oe = new IllegalStateException();
+ oe.initCause(e);
+ throw oe;
+ }
+ return ( (Statistic)result );
+ }
+
+ public String[] getStatisticNames() {
+ /* The return array is fixed at the construction time */
+ final String[] names = new String[getters.size()];
+ return ( (String[])getters.keySet().toArray(names) ); //TODOOOOOOO
+ }
+
+ public Statistic[] getStatistics() {
+ return ( getStatisticsOneByOne() ); //invokes sequentially
+ }
+
+ private Statistic[] getStatisticsOneByOne() {
+ final Iterator iter = getters.keySet().iterator();
+ final Statistic[] stats = new Statistic[getters.keySet().size()];
+ int i = 0;
+ while (iter.hasNext()) {
+ final String sn = (String) iter.next();
+ stats[i++] = this.getStatistic(sn);
+ }
+ assert (stats.length == i);
+ return ( stats );
+ }
+
+ private boolean implementsInterface(Class c, Object o) {
+ boolean impls = false;
+ final Class[] interfaces = o.getClass().getInterfaces();
+ for (int i = 0 ; i < interfaces.length ; i++) {
+ if (interfaces[i].equals(c)){
+ impls = true;
+ break;
+ }
+ }
+ return ( impls );
+ }
+
+ private boolean extendsStatsInterface(Class i) {
+ final Class statInterface = org.glassfish.external.statistics.Stats.class;
+ return ( statInterface.isAssignableFrom(i) );
+ }
+
+ private void populateGetterMap() {
+ // Fix for Bugs 5045435, 6172088
+ //final Method[] apis = statsInterface.getDeclaredMethods(); //all of these should be PUBLIC.
+ final Method[] m = statsInterface.getMethods();
+ // exclude methods that belong to the javax.management.j2ee.Stats
+ final Method[] apis = filterStatsMethods(m);
+ final Method[] methods = getGetters(apis);
+ final String[] names = methods2Statistics(methods);
+ assert (names.length == methods.length) : ("Statistic names array is not having same length as that of array of getters");
+ int i;
+ for (i = 0 ; i < names.length ; i++) {
+ getters.put(names[i], methods[i]);
+ }
+ assert (getters.size() == i) : ("Getters map is incorrect, names.length = " + names.length + " methods.length = " + methods.length);
+ }
+
+ private Method[] getGetters(Method[] all) {
+ final ArrayList l = new ArrayList();
+ for (int i = 0 ; i < all.length ; i++) {
+ final Method am = all[i];
+ if (isValidGetter(am)) {
+ l.add(am);
+ }
+ }
+ final Method[] m = new Method[l.size()];
+ return ( (Method[])l.toArray(m) );
+ }
+
+ private boolean isValidGetter(Method m) {
+ final boolean startsWithGet = m.getName().startsWith("get");
+ final boolean hasNoParams = m.getParameterTypes().length == 0;
+ final boolean returnsStatistic = Statistic.class.isAssignableFrom(m.getReturnType());
+
+ return ( startsWithGet && hasNoParams && returnsStatistic );
+ }
+
+ private String[] methods2Statistics(Method[] methods) {
+ final String[] names = new String[methods.length];
+ for (int i = 0 ; i < methods.length ; i++) {
+ final String m = methods[i].getName();
+ final int s = "get".length();
+ names[i] = m.substring(s);
+ }
+ return ( names );
+ }
+
+ private boolean isStatsInterfaceMethod(String name) {
+ final Method[] methods = org.glassfish.external.statistics.Stats.class.getMethods();
+ boolean isInterfaceMethod = false;
+ for (int i = 0 ; i < methods.length ; i++) {
+ if (methods[i].getName().equals(name)) {
+ isInterfaceMethod = true;
+ break;
+ }
+ }
+ return ( isInterfaceMethod );
+ }
+
+ private Method[] filterStatsMethods(Method[] m) {
+ ArrayList methodList = new ArrayList();
+ for(int i = 0; i < m.length; i++) {
+ if(! isStatsInterfaceMethod(m[i].getName()))
+ methodList.add(m[i]);
+ }
+ final Method[] methods = new Method[methodList.size()];
+ return (Method[])methodList.toArray(methods);
+ }
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/IIOPUtils.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/IIOPUtils.java
new file mode 100644
index 0000000..d384672
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/IIOPUtils.java
@@ -0,0 +1,185 @@
+/*
+ * 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.enterprise.iiop.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.config.serverbeans.Configs;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.config.serverbeans.ServerRef;
+import org.glassfish.grizzly.config.dom.NetworkListener;
+import org.glassfish.grizzly.config.dom.ThreadPool;
+import org.glassfish.api.admin.ProcessEnvironment;
+import org.glassfish.api.admin.ProcessEnvironment.ProcessType;
+import org.glassfish.api.admin.ServerEnvironment;
+import org.glassfish.enterprise.iiop.api.GlassFishORBLifeCycleListener;
+import org.glassfish.enterprise.iiop.api.IIOPInterceptorFactory;
+import org.glassfish.internal.api.ClassLoaderHierarchy;
+import javax.inject.Inject;
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.PostConstruct;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.omg.CORBA.ORB;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 15, 2009
+ */
+@Service
+public class IIOPUtils implements PostConstruct {
+
+ private static IIOPUtils _me;
+
+ @Inject
+ ServiceLocator services;
+
+ @Inject
+ private ClassLoaderHierarchy clHierarchy;
+
+ @Inject
+ private ProcessEnvironment processEnv;
+
+ private ProcessType processType;
+
+ // The following info is only available for ProcessType.Server
+ private Collection<ThreadPool> threadPools;
+ private IiopService iiopService;
+ private Collection<ServerRef> serverRefs;
+
+ // Set during init
+ private ORB defaultORB;
+
+ //private GlassFishORBManager gfORBMgr;
+
+ public void postConstruct() {
+
+ processType = processEnv.getProcessType();
+
+ if( processEnv.getProcessType().isServer()) {
+
+ Config c = services.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
+ iiopService =c.getExtensionByType(IiopService.class);
+
+ final Collection<ThreadPool> threadPool = c.getThreadPools().getThreadPool();
+ final Collection<NetworkListener> listeners = allByContract(NetworkListener.class);
+ final Set<String> names = new TreeSet<String>();
+ threadPools = new ArrayList<ThreadPool>();
+ for (NetworkListener listener : listeners) {
+ names.add(listener.getThreadPool());
+ }
+ for (ThreadPool pool : threadPool) {
+ if(!names.contains(pool.getName())) {
+ threadPools.add(pool);
+ }
+ }
+ serverRefs = allByContract(ServerRef.class);
+ }
+
+ IIOPUtils.initMe(this);
+
+ }
+
+ private static void initMe(IIOPUtils utils) {
+ _me = utils;
+ }
+
+ public static IIOPUtils getInstance() {
+ return _me;
+ }
+
+
+ public static void setInstance(IIOPUtils utils) {
+ _me = utils;
+ }
+
+ /*
+ void setGlassFishORBManager(GlassFishORBManager orbMgr) {
+ gfORBMgr = orbMgr;
+ }
+
+ GlassFishORBManager getGlassFishORBManager() {
+ return gfORBMgr;
+ }
+ */
+
+ public ClassLoader getCommonClassLoader() {
+ return clHierarchy.getCommonClassLoader();
+ }
+
+ private void assertServer() {
+ if ( !processType.isServer() ) {
+ throw new IllegalStateException("Only available in Server mode");
+ }
+ }
+
+ public IiopService getIiopService() {
+ assertServer();
+ return iiopService;
+ }
+
+ public Collection<ThreadPool> getAllThreadPools() {
+ assertServer();
+ return threadPools;
+ }
+
+ public Collection<ServerRef> getServerRefs() {
+ assertServer();
+ return serverRefs;
+ }
+
+ public List<IiopListener> getIiopListeners() {
+ assertServer();
+ return iiopService.getIiopListener();
+ }
+
+ public Collection<IIOPInterceptorFactory> getAllIIOPInterceptrFactories() {
+ return allByContract(IIOPInterceptorFactory.class);
+ }
+
+ public Collection<GlassFishORBLifeCycleListener> getGlassFishORBLifeCycleListeners() {
+ return allByContract(GlassFishORBLifeCycleListener.class);
+ }
+
+ public ProcessType getProcessType() {
+ return processType;
+ }
+
+ public ServiceLocator getHabitat() {
+ return services;
+ }
+
+ public void setORB(ORB orb) {
+ defaultORB = orb;
+ }
+
+ // For internal use only. All other modules should use orb-connector
+ // GlassFishORBHelper to acquire default ORB.
+ public ORB getORB() {
+ return defaultORB;
+ }
+
+ private <T> Collection<T> allByContract(Class<T> contractClass) {
+ return services.getAllServices(contractClass);
+ }
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/MonitoringConstants.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/MonitoringConstants.java
new file mode 100644
index 0000000..6d4f0ed
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/MonitoringConstants.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2000, 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.enterprise.iiop.util;
+
+public interface MonitoringConstants
+{
+ public static final String DEFAULT_MONITORING_ROOT = "orb";
+ public static final String DEFAULT_MONITORING_ROOT_DESCRIPTION =
+ "ORB Management and Monitoring Root";
+
+ //
+ // Connection Monitoring
+ //
+
+ public static final String CONNECTION_MONITORING_ROOT =
+ "Connections";
+ public static final String CONNECTION_MONITORING_ROOT_DESCRIPTION =
+ "Statistics on inbound/outbound connections";
+
+ public static final String INBOUND_CONNECTION_MONITORING_ROOT =
+ "Inbound";
+ public static final String INBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION=
+ "Statistics on inbound connections";
+
+ public static final String OUTBOUND_CONNECTION_MONITORING_ROOT =
+ "Outbound";
+ public static final String OUTBOUND_CONNECTION_MONITORING_ROOT_DESCRIPTION=
+ "Statistics on outbound connections";
+
+ public static final String CONNECTION_MONITORING_DESCRIPTION =
+ "Connection statistics";
+
+ public static final String CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS =
+ "NumberOfConnections";
+ public static final String CONNECTION_TOTAL_NUMBER_OF_CONNECTIONS_DESCRIPTION =
+ "The total number of connections";
+ public static final String CONNECTION_NUMBER_OF_IDLE_CONNECTIONS =
+ "NumberOfIdleConnections";
+ public static final String CONNECTION_NUMBER_OF_IDLE_CONNECTIONS_DESCRIPTION =
+ "The number of idle connections";
+ public static final String CONNECTION_NUMBER_OF_BUSY_CONNECTIONS =
+ "NumberOfBusyConnections";
+ public static final String CONNECTION_NUMBER_OF_BUSY_CONNECTIONS_DESCRIPTION =
+ "The number of busy connections";
+
+ //
+ // ThreadPool and WorkQueue monitoring constants
+ //
+
+ public static final String THREADPOOL_MONITORING_ROOT = "threadpool";
+ public static final String THREADPOOL_MONITORING_ROOT_DESCRIPTION =
+ "Monitoring for all ThreadPool instances";
+ public static final String THREADPOOL_MONITORING_DESCRIPTION =
+ "Monitoring for a ThreadPool";
+ public static final String THREADPOOL_CURRENT_NUMBER_OF_THREADS =
+ "currentNumberOfThreads";
+ public static final String THREADPOOL_CURRENT_NUMBER_OF_THREADS_DESCRIPTION =
+ "Current number of total threads in the ThreadPool";
+ public static final String THREADPOOL_NUMBER_OF_AVAILABLE_THREADS =
+ "numberOfAvailableThreads";
+ public static final String THREADPOOL_NUMBER_OF_AVAILABLE_THREADS_DESCRIPTION =
+ "Number of available threads in the ThreadPool";
+ public static final String THREADPOOL_NUMBER_OF_BUSY_THREADS =
+ "numberOfBusyThreads";
+ public static final String THREADPOOL_NUMBER_OF_BUSY_THREADS_DESCRIPTION =
+ "Number of busy threads in the ThreadPool";
+ public static final String THREADPOOL_AVERAGE_WORK_COMPLETION_TIME =
+ "averageWorkCompletionTime";
+ public static final String THREADPOOL_AVERAGE_WORK_COMPLETION_TIME_DESCRIPTION =
+ "Average elapsed time taken to complete a work item by the ThreadPool";
+ public static final String THREADPOOL_CURRENT_PROCESSED_COUNT =
+ "currentProcessedCount";
+ public static final String THREADPOOL_CURRENT_PROCESSED_COUNT_DESCRIPTION =
+ "Number of Work items processed by the ThreadPool";
+
+ public static final String WORKQUEUE_MONITORING_DESCRIPTION =
+ "Monitoring for a Work Queue";
+ public static final String WORKQUEUE_TOTAL_WORK_ITEMS_ADDED =
+ "totalWorkItemsAdded";
+ public static final String WORKQUEUE_TOTAL_WORK_ITEMS_ADDED_DESCRIPTION =
+ "Total number of Work items added to the Queue";
+ public static final String WORKQUEUE_WORK_ITEMS_IN_QUEUE =
+ "workItemsInQueue";
+ public static final String WORKQUEUE_WORK_ITEMS_IN_QUEUE_DESCRIPTION =
+ "Number of Work items in the Queue to be processed";
+ public static final String WORKQUEUE_AVERAGE_TIME_IN_QUEUE =
+ "averageTimeInQueue";
+ public static final String WORKQUEUE_AVERAGE_TIME_IN_QUEUE_DESCRIPTION =
+ "Average time a work item waits in the work queue";
+}
+
+// End of file.
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ORBCommonStatsImpl.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ORBCommonStatsImpl.java
new file mode 100644
index 0000000..700ba2d
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ORBCommonStatsImpl.java
@@ -0,0 +1,56 @@
+/*
+ * 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.enterprise.iiop.util;
+import org.glassfish.external.statistics.Statistic;
+
+/**
+ * This is the common base class for the collection of statistics
+ * for the threadpool and orb connection manager.
+ *
+ * @author Pramod Gopinath
+ */
+
+public class ORBCommonStatsImpl {
+
+ private GenericStatsImpl genericStatsDelegate;
+
+ protected ORBCommonStatsImpl() {
+ }
+
+ protected void initialize(String statInterfaceName) {
+ try{
+ genericStatsDelegate = new GenericStatsImpl(statInterfaceName, this);
+ } catch(ClassNotFoundException cnfEx) {
+ throw new RuntimeException(statInterfaceName + " not found", cnfEx);
+ }
+ }
+
+ public Statistic getStatistic(String statName) {
+ return genericStatsDelegate.getStatistic(statName);
+ }
+
+ public String[] getStatisticNames() {
+ return genericStatsDelegate.getStatisticNames();
+ }
+
+ public Statistic[] getStatistics() {
+ return genericStatsDelegate.getStatistics();
+ }
+
+
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/S1ASThreadPoolManager.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/S1ASThreadPoolManager.java
new file mode 100644
index 0000000..421b92e
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/S1ASThreadPoolManager.java
@@ -0,0 +1,314 @@
+/*
+ * 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.enterprise.iiop.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.sun.corba.ee.spi.threadpool.NoSuchThreadPoolException;
+import com.sun.corba.ee.spi.threadpool.ThreadPool;
+import com.sun.corba.ee.spi.threadpool.ThreadPoolChooser;
+import com.sun.corba.ee.spi.threadpool.ThreadPoolFactory;
+import com.sun.corba.ee.spi.threadpool.ThreadPoolManager;
+import com.sun.logging.LogDomains;
+import org.glassfish.internal.api.Globals;
+
+public class S1ASThreadPoolManager implements ThreadPoolManager {
+
+ static Logger _logger = LogDomains.getLogger(S1ASThreadPoolManager.class,
+ LogDomains.UTIL_LOGGER);
+
+ private static final int DEFAULT_NUMBER_OF_QUEUES = 0;
+ private static final int DEFAULT_MIN_THREAD_COUNT = 10;
+ private static final int DEFAULT_MAX_THREAD_COUNT = 200;
+
+ private static HashMap idToIndexTable = new HashMap();
+ private static HashMap indexToIdTable = new HashMap();
+ private static ArrayList threadpoolList = new ArrayList();
+ private static String defaultID;
+
+ private static ThreadPoolManager s1asThreadPoolMgr = new S1ASThreadPoolManager();
+ private static IIOPUtils _iiopUtils;
+
+ public static ThreadPoolManager getThreadPoolManager() {
+ return s1asThreadPoolMgr;
+ }
+
+
+ static {
+ try {
+ _iiopUtils = Globals.getDefaultHabitat().getService(IIOPUtils.class);
+ Collection<org.glassfish.grizzly.config.dom.ThreadPool> tpCol = _iiopUtils.getAllThreadPools();
+ org.glassfish.grizzly.config.dom.ThreadPool[] allThreadPools = tpCol.toArray(new org.glassfish.grizzly.config.dom.ThreadPool[tpCol.size()]);
+ for (int i = 0; i < allThreadPools.length; i++) {
+ createThreadPools(allThreadPools[i], i);
+ }
+ defaultID = (String) indexToIdTable.get(Integer.valueOf(0));
+ } catch (NullPointerException npe) {
+ _logger.log(Level.FINE, "Server Context is NULL. Ignoring and proceeding.");
+ }
+
+
+ }
+
+ S1ASThreadPoolManager() {
+ }
+
+
+ private static void createThreadPools(org.glassfish.grizzly.config.dom.ThreadPool
+ threadpoolBean, int index) {
+ String threadpoolId = null;
+ String minThreadsValue, maxThreadsValue, timeoutValue;//, numberOfQueuesValue;
+ int minThreads = DEFAULT_MIN_THREAD_COUNT;
+ int maxThreads = DEFAULT_MAX_THREAD_COUNT;
+ int idleTimeoutInSeconds = 120000;
+// int numberOfQueues = DEFAULT_NUMBER_OF_QUEUES;
+
+ try {
+ threadpoolId = threadpoolBean.getName();
+ } catch (NullPointerException npe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
+ }
+ }
+ try {
+ minThreadsValue = threadpoolBean.getMinThreadPoolSize();
+ minThreads = Integer.parseInt(minThreadsValue);
+ } catch (NullPointerException npe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
+ _logger.log(Level.WARNING,
+ "Using default value for steady-threadpool-size = " + minThreads);
+ }
+ } catch (NumberFormatException nfe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "enterprise_util.excep_orbmgr_numfmt", nfe);
+ _logger.log(Level.WARNING,
+ "Using default value for min-threadpool-size = " + minThreads);
+ }
+ }
+ try {
+ maxThreadsValue = threadpoolBean.getMaxThreadPoolSize();
+ maxThreads = Integer.parseInt(maxThreadsValue);
+ } catch (NullPointerException npe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
+ _logger.log(Level.WARNING,
+ "Using default value for max-threadpool-size = " + maxThreads);
+ }
+ } catch (NumberFormatException nfe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "enterprise_util.excep_orbmgr_numfmt", nfe);
+ _logger.log(Level.WARNING,
+ "Using default value for max-threadpool-size = " + maxThreads);
+ }
+ }
+ try {
+ timeoutValue = threadpoolBean.getIdleThreadTimeoutSeconds();
+ idleTimeoutInSeconds = Integer.parseInt(timeoutValue);
+ } catch (NullPointerException npe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
+ _logger.log(Level.WARNING,
+ "Using default value for idle-thread-timeout-in-seconds = " +
+ idleTimeoutInSeconds);
+ }
+ } catch (NumberFormatException nfe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "enterprise_util.excep_orbmgr_numfmt", nfe);
+ _logger.log(Level.WARNING,
+ "Using default value for idle-thread-timeout-in-seconds = " +
+ idleTimeoutInSeconds);
+ }
+ }
+
+ // Currently this value is not used but when multi-queue threadpools are
+ // implemented this could be used to decide which one to instantiate and
+ // number of queues in the multi-queue threadpool
+/*
+ try {
+ numberOfQueuesValue = threadpoolBean.getNumWorkQueues();
+ numberOfQueues = Integer.parseInt(numberOfQueuesValue);
+ } catch (NullPointerException npe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "ThreadPoolBean may be null ", npe);
+ _logger.log(Level.WARNING,
+ "Using default value for num-work-queues = " +
+ numberOfQueues);
+ }
+ } catch (NumberFormatException nfe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "enterprise_util.excep_orbmgr_numfmt", nfe);
+ _logger.log(Level.WARNING,
+ "Using default value for num-work-queues = " +
+ numberOfQueues);
+ }
+ }
+*/
+
+ // Mutiplied the idleTimeoutInSeconds by 1000 to convert to milliseconds
+ ThreadPoolFactory threadPoolFactory = new ThreadPoolFactory();
+ ThreadPool threadpool =
+ threadPoolFactory.create(minThreads, maxThreads,
+ idleTimeoutInSeconds * 1000L, threadpoolId,
+ _iiopUtils.getCommonClassLoader());
+
+ // Add the threadpool instance to the threadpoolList
+ threadpoolList.add(threadpool);
+
+ // Associate the threadpoolId to the index passed
+ idToIndexTable.put(threadpoolId, Integer.valueOf(index));
+
+ // Associate the threadpoolId to the index passed
+ indexToIdTable.put(Integer.valueOf(index), threadpoolId);
+ }
+
+ /**
+ * This method will return an instance of the threadpool given a threadpoolId,
+ * that can be used by any component in the app. server.
+ *
+ * @throws NoSuchThreadPoolException thrown when invalid threadpoolId is passed
+ * as a parameter
+ */
+ public ThreadPool
+ getThreadPool(String id)
+ throws NoSuchThreadPoolException {
+
+ Integer i = (Integer) idToIndexTable.get(id);
+ if (i == null) {
+ throw new NoSuchThreadPoolException();
+ }
+ try {
+ ThreadPool threadpool =
+ (ThreadPool)
+ threadpoolList.get(i.intValue());
+ return threadpool;
+ } catch (IndexOutOfBoundsException iobe) {
+ throw new NoSuchThreadPoolException();
+ }
+ }
+
+ /**
+ * This method will return an instance of the threadpool given a numeric threadpoolId.
+ * This method will be used by the ORB to support the functionality of
+ * dedicated threadpool for EJB beans
+ *
+ * @throws NoSuchThreadPoolException thrown when invalidnumericIdForThreadpool is passed
+ * as a parameter
+ */
+ public ThreadPool getThreadPool(int numericIdForThreadpool)
+ throws NoSuchThreadPoolException {
+
+ try {
+ ThreadPool threadpool =
+ (ThreadPool)
+ threadpoolList.get(numericIdForThreadpool);
+ return threadpool;
+ } catch (IndexOutOfBoundsException iobe) {
+ throw new NoSuchThreadPoolException();
+ }
+ }
+
+ /**
+ * This method is used to return the numeric id of the threadpool, given a String
+ * threadpoolId. This is used by the POA interceptors to add the numeric threadpool
+ * Id, as a tagged component in the IOR. This is used to provide the functionality of
+ * dedicated threadpool for EJB beans
+ */
+ public int getThreadPoolNumericId(String id) {
+ Integer i = (Integer) idToIndexTable.get(id);
+ return ((i == null) ? 0 : i.intValue());
+ }
+
+ /**
+ * Return a String Id for a numericId of a threadpool managed by the threadpool
+ * manager
+ */
+ public String getThreadPoolStringId(int numericIdForThreadpool) {
+ String id = (String) indexToIdTable.get(Integer.valueOf(numericIdForThreadpool));
+ return ((id == null) ? defaultID : id);
+ }
+
+ /**
+ * Returns the first instance of ThreadPool in the ThreadPoolManager
+ */
+ public ThreadPool
+ getDefaultThreadPool() {
+ try {
+ return getThreadPool(0);
+ } catch (NoSuchThreadPoolException nstpe) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "No default ThreadPool defined ", nstpe);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return an instance of ThreadPoolChooser based on the componentId that was
+ * passed as argument
+ */
+ public ThreadPoolChooser getThreadPoolChooser(String componentId) {
+ //FIXME: This method is not used, but should be fixed once
+ //ORB's nio select starts working and we start using ThreadPoolChooser
+ //This will be mostly used by the ORB
+ return null;
+ }
+
+ /**
+ * Return an instance of ThreadPoolChooser based on the componentIndex that was
+ * passed as argument. This is added for improved performance so that the caller
+ * does not have to pay the cost of computing hashcode for the componentId
+ */
+ public ThreadPoolChooser getThreadPoolChooser(int componentIndex) {
+ //FIXME: This method is not used, but should be fixed once
+ //ORB's nio select starts working and we start using ThreadPoolChooser
+ //This will be mostly used by the ORB
+ return null;
+ }
+
+ /**
+ * Sets a ThreadPoolChooser for a particular componentId in the ThreadPoolManager. This
+ * would enable any component to add a ThreadPoolChooser for their specific use
+ */
+ public void setThreadPoolChooser(String componentId, ThreadPoolChooser aThreadPoolChooser) {
+ //FIXME: This method is not used, but should be fixed once
+ //ORB's nio select starts working and we start using ThreadPoolChooser
+ //This will be mostly used by the ORB
+ }
+
+ /**
+ * Gets the numeric index associated with the componentId specified for a
+ * ThreadPoolChooser. This method would help the component call the more
+ * efficient implementation i.e. getThreadPoolChooser(int componentIndex)
+ */
+ public int getThreadPoolChooserNumericId(String componentId) {
+ //FIXME: This method is not used, but should be fixed once
+ //ORB's nio select starts working and we start using ThreadPoolChooser
+ //This will be mostly used by the ORB
+ return 0;
+ }
+
+ public void close() {
+ //TODO
+ }
+}
+
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStats.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStats.java
new file mode 100755
index 0000000..413970a
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStats.java
@@ -0,0 +1,73 @@
+/*
+ * 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.enterprise.iiop.util;
+
+import org.glassfish.external.statistics.CountStatistic;
+import org.glassfish.external.statistics.BoundedRangeStatistic;
+import org.glassfish.external.statistics.RangeStatistic;
+import org.glassfish.external.statistics.Stats;
+/**
+ * Stats interface for the monitorable attributes of the
+ * a generic ThreadPool. This combines the statistics that were exposed in 7.0
+ * with the new ones. In 8.0, the generic Thread Pool that can be used by any component
+ * in the server runtime is introduced.
+ * @author Kedar Mhaswade
+ * @since S1AS8.0
+ */
+
+public interface ThreadPoolStats extends Stats {
+
+ /** Returns the statistical information about the number of Threads in the associated ThreaPool, as an instance of BoundedRangeStatistic.
+ * This returned value gives an idea about how the pool is changing.
+ * @return an instance of {@link BoundedRangeStatistic}
+ */
+ public BoundedRangeStatistic getCurrentNumberOfThreads();
+
+ /** Returns the total number of available threads, as an instance of {@link CountStatistic}.
+ * @return an instance of {@link CountStatistic}
+ */
+ public CountStatistic getNumberOfAvailableThreads();
+
+ /** Returns the number of busy threads, as an instance of {@link CountStatistic}.
+ * @return an instance of {@link CountStatistic}
+ */
+ public CountStatistic getNumberOfBusyThreads();
+
+ /**
+ * Returns the statistical information about the average completion time of a work item in milliseconds.
+ * @return an instance of {@link RangeStatistic}
+ */
+ public RangeStatistic getAverageWorkCompletionTime();
+
+ /** Returns the the total number of work items added so far to the work queue associated with threadpool.
+ * @return an instance of {@link CountStatistic}
+ */
+ public CountStatistic getTotalWorkItemsAdded();
+
+ /**
+ * Returns average time in milliseconds a work item waited in the work queue before getting processed.
+ * @return an instance of {@link RangeStatistic}
+ */
+ public RangeStatistic getAverageTimeInQueue();
+
+ /**
+ * Returns the work items in queue
+ * @return an instance of {@link BoundedRangeStatistic}
+ */
+ public BoundedRangeStatistic getNumberOfWorkItemsInQueue();
+
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStatsImpl.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStatsImpl.java
new file mode 100644
index 0000000..bb217a6
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/enterprise/iiop/util/ThreadPoolStatsImpl.java
@@ -0,0 +1,205 @@
+/*
+ * 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.enterprise.iiop.util;
+
+import com.sun.corba.ee.spi.threadpool.NoSuchWorkQueueException;
+import org.glassfish.external.statistics.CountStatistic;
+import org.glassfish.external.statistics.BoundedRangeStatistic;
+import org.glassfish.external.statistics.RangeStatistic;
+
+import org.glassfish.external.statistics.impl.BoundedRangeStatisticImpl;
+import org.glassfish.external.statistics.impl.CountStatisticImpl;
+import com.sun.corba.ee.spi.threadpool.ThreadPool;
+import com.sun.corba.ee.spi.threadpool.WorkQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.glassfish.gmbal.ManagedAttribute;
+import org.glassfish.gmbal.ManagedObject;
+import org.glassfish.gmbal.Description;
+
+/**
+ * This is the implementation for the ThreadPoolStats
+ * and provides the implementation required to get the statistics
+ * for a threadpool
+ *
+ * @author Pramod Gopinath
+ */
+@ManagedObject
+@Description("The implementation for the ThreadPoolStats")
+public class ThreadPoolStatsImpl
+ extends ORBCommonStatsImpl
+ implements ThreadPoolStats {
+
+ private ThreadPool threadPool;
+ private WorkQueue workQueue;
+ private String workQueueName;
+ private CountStatisticImpl numberOfBusyThreads;
+ private CountStatisticImpl numberOfAvailableThreads;
+ private BoundedRangeStatisticImpl currentNumberOfThreads;
+ private BoundedRangeStatisticImpl averageWorkCompletionTime;
+ private CountStatisticImpl totalWorkItemsAdded;
+ private BoundedRangeStatisticImpl numberOfWorkItemsInQueue;
+ private BoundedRangeStatisticImpl averageTimeInQueue;
+ private static final String stringNumberOfBusyThreads =
+ MonitoringConstants.THREADPOOL_NUMBER_OF_BUSY_THREADS;
+ private static final String stringNumberOfAvailableThreads =
+ MonitoringConstants.THREADPOOL_NUMBER_OF_AVAILABLE_THREADS;
+ private static final String stringCurrentNumberOfThreads =
+ MonitoringConstants.THREADPOOL_CURRENT_NUMBER_OF_THREADS;
+ private static final String stringAverageWorkCompletionTime =
+ MonitoringConstants.THREADPOOL_AVERAGE_WORK_COMPLETION_TIME;
+ private static final String stringTotalWorkItemsAdded =
+ MonitoringConstants.WORKQUEUE_TOTAL_WORK_ITEMS_ADDED;
+ private static final String stringNumberOfWorkItemsInQueue =
+ MonitoringConstants.WORKQUEUE_WORK_ITEMS_IN_QUEUE;
+ private static final String stringAverageTimeInQueue =
+ MonitoringConstants.WORKQUEUE_AVERAGE_TIME_IN_QUEUE;
+
+ public ThreadPoolStatsImpl(ThreadPool threadPool) throws NoSuchWorkQueueException {
+ this.threadPool = threadPool;
+
+ getWorkQueueForThreadPool();
+
+ initializeStats();
+ }
+
+ private void getWorkQueueForThreadPool() {
+ try {
+ workQueue = threadPool.getWorkQueue(0);
+ workQueueName = workQueue.getName();
+ } catch (NoSuchWorkQueueException ex) {
+
+ Logger.getLogger(workQueueName).log(Level.SEVERE, workQueueName);
+ throw new RuntimeException(ex);
+
+ }
+ }
+
+ private void initializeStats() throws NoSuchWorkQueueException {
+ super.initialize("org.glassfish.enterprise.iiop.util.ThreadPoolStats");
+
+ final long time = System.currentTimeMillis();
+
+ numberOfBusyThreads =
+ new CountStatisticImpl(threadPool.numberOfBusyThreads(), stringNumberOfBusyThreads, "COUNT",
+ threadPool.getWorkQueue(0).toString(),
+ time, time);
+
+ numberOfAvailableThreads =
+ new CountStatisticImpl(
+ threadPool.numberOfAvailableThreads(), stringNumberOfAvailableThreads, "count",
+ threadPool.getWorkQueue(0).toString(),
+ time, time);
+
+ currentNumberOfThreads =
+ new BoundedRangeStatisticImpl(
+ threadPool.currentNumberOfThreads(), threadPool.maximumNumberOfThreads(), threadPool.minimumNumberOfThreads(), java.lang.Long.MAX_VALUE, 0,
+ stringCurrentNumberOfThreads, "count",
+ threadPool.getWorkQueue(0).toString(),
+ time, time);
+
+ averageWorkCompletionTime =
+ new BoundedRangeStatisticImpl(
+ threadPool.averageWorkCompletionTime(), 0, 0, java.lang.Long.MAX_VALUE, 0,
+ stringAverageWorkCompletionTime, "Milliseconds",
+ threadPool.getWorkQueue(0).toString(),
+ time, time);
+
+ // WorkQueue workItems = threadPool.getWorkQueue(0);
+
+ totalWorkItemsAdded =
+ new CountStatisticImpl(
+ workQueue.totalWorkItemsAdded(), stringTotalWorkItemsAdded, "count",
+ workQueue.getName(),
+ time, time);
+
+ numberOfWorkItemsInQueue =
+ new BoundedRangeStatisticImpl(
+ workQueue.workItemsInQueue(), 0, 0, java.lang.Long.MAX_VALUE, 0,
+ stringNumberOfWorkItemsInQueue, "count",
+ workQueue.getName(),
+ time, time);
+
+ averageTimeInQueue =
+ new BoundedRangeStatisticImpl(
+ workQueue.averageTimeInQueue(), 0, 0, java.lang.Long.MAX_VALUE, 0,
+ stringAverageTimeInQueue, "Milliseconds",
+ workQueue.getName(),
+ time, time);
+
+ }
+
+ @ManagedAttribute(id = "currentbusythreads")
+ @Description("Total number of busy threads")
+ public synchronized CountStatistic getNumberOfBusyThreads() {
+ int numBusyThreads = threadPool.numberOfBusyThreads();
+ numberOfBusyThreads.setCount(numBusyThreads);
+ return (CountStatistic) numberOfBusyThreads;
+ }
+
+ @ManagedAttribute
+ @Description("Total number of available threads")
+ public synchronized CountStatistic getNumberOfAvailableThreads() {
+ long numAvailableThreads = (long) threadPool.numberOfAvailableThreads();
+
+ numberOfAvailableThreads.setCount(numAvailableThreads);
+
+ return (CountStatistic) numberOfAvailableThreads;
+ }
+
+ @ManagedAttribute
+ @Description("Total number of current threads")
+ public synchronized BoundedRangeStatistic getCurrentNumberOfThreads() {
+ int numCurrentThreads = threadPool.currentNumberOfThreads();
+ currentNumberOfThreads.setCurrent(numCurrentThreads);
+ return (BoundedRangeStatistic) currentNumberOfThreads;
+ }
+
+ @ManagedAttribute
+ @Description("Average time to complete work")
+ public synchronized RangeStatistic getAverageWorkCompletionTime() {
+ long avgWorkCompletionTime = threadPool.averageWorkCompletionTime();
+ averageWorkCompletionTime.setCurrent(avgWorkCompletionTime);
+ return (RangeStatistic) averageWorkCompletionTime;
+ }
+
+ @ManagedAttribute
+ @Description("Total number of work items added to the queue")
+ public synchronized CountStatistic getTotalWorkItemsAdded() {
+ long totWorkItemsAdded = workQueue.totalWorkItemsAdded();
+ totalWorkItemsAdded.setCount(totWorkItemsAdded);
+ return (CountStatistic) totalWorkItemsAdded;
+ }
+
+ @ManagedAttribute
+ @Description("Total number of work items in the queue")
+ public synchronized BoundedRangeStatistic getNumberOfWorkItemsInQueue() {
+ int totWorkItemsInQueue = workQueue.workItemsInQueue();
+ numberOfWorkItemsInQueue.setCurrent(totWorkItemsInQueue);
+ return (BoundedRangeStatistic) numberOfWorkItemsInQueue;
+ }
+
+ @ManagedAttribute
+ @Description("Average time in queue")
+ public synchronized RangeStatistic getAverageTimeInQueue() {
+ long avgTimeInQueue = workQueue.averageTimeInQueue();
+ averageTimeInQueue.setCurrent(avgTimeInQueue);
+
+ return (RangeStatistic) averageTimeInQueue;
+ }
+} //ThreadPoolStatsImpl{ }
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/CreateIiopListener.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/CreateIiopListener.java
new file mode 100644
index 0000000..b05658f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/CreateIiopListener.java
@@ -0,0 +1,184 @@
+/*
+ * 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.orb.admin.cli;
+
+import java.beans.PropertyVetoException;
+import java.util.Properties;
+
+import org.glassfish.api.admin.AdminCommand;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.I18n;
+import org.glassfish.api.Param;
+import org.glassfish.api.ActionReport;
+
+import org.jvnet.hk2.annotations.Service;
+
+import javax.inject.Inject;
+import org.glassfish.hk2.api.PerLookup;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+import org.jvnet.hk2.config.types.Property;
+
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.config.serverbeans.Configs;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+
+import com.sun.enterprise.config.serverbeans.Servers;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import com.sun.enterprise.util.SystemPropertyConstants;
+import org.glassfish.api.admin.ExecuteOn;
+import org.glassfish.api.admin.RuntimeType;
+import org.glassfish.config.support.CommandTarget;
+import org.glassfish.config.support.TargetType;
+import org.glassfish.internal.api.Target;
+import org.glassfish.hk2.api.ServiceLocator;
+
+/**
+ * Create IioP Listener Command
+ *
+ */
+@Service(name="create-iiop-listener")
+@PerLookup
+@I18n("create.iiop.listener")
+@ExecuteOn(value={RuntimeType.DAS,RuntimeType.INSTANCE})
+@TargetType(value={CommandTarget.CLUSTER,CommandTarget.CONFIG,
+ CommandTarget.DAS,CommandTarget.STANDALONE_INSTANCE }
+)
+public class CreateIiopListener implements AdminCommand {
+
+ final private static LocalStringManagerImpl localStrings = new
+ LocalStringManagerImpl(CreateIiopListener.class);
+
+ @Param( name="target", optional=true,
+ defaultValue=SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)
+ String target ;
+
+ @Param(name="listeneraddress", alias="address")
+ String listeneraddress;
+
+ @Param(name="iiopport", optional=true, alias="port", defaultValue="1072")
+ String iiopport;
+
+ @Param(optional=true, defaultValue="true")
+ Boolean enabled;
+
+ @Param(name="securityenabled", optional=true, defaultValue="false", alias="security-enabled")
+ Boolean securityenabled;
+
+ @Param(name="property", optional=true, separator=':')
+ Properties properties;
+
+ @Param(name="listener_id", primary=true, alias="id")
+ String listener_id;
+
+ @Inject
+ Configs configs;
+
+ @Inject
+ Servers servers;
+
+ @Inject
+ ServiceLocator services ;
+
+ /**
+ * 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
+ */
+
+ @Override
+ public void execute(AdminCommandContext context) {
+ final Target targetUtil = services.getService(Target.class ) ;
+ final Config config = targetUtil.getConfig(target ) ;
+ final ActionReport report = context.getActionReport();
+
+ IiopService iiopService = config.getExtensionByType(IiopService.class);
+
+ // ensure we don't already have one of this name
+ // check port uniqueness, only for same address
+ for (IiopListener listener : iiopService.getIiopListener()) {
+ if (listener.getId().equals(listener_id)) {
+ String ls = localStrings.getLocalString(
+ "create.iiop.listener.duplicate",
+ "IIOP Listener named {0} already exists.", listener_id);
+ report.setMessage(ls);
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+
+ if (listener.getAddress().trim().equals(listeneraddress) &&
+ listener.getPort().trim().equals((iiopport))) {
+ String def = "Port [{0}] is already taken by another listener: "
+ + "[{1}] for address [{2}], choose another port.";
+ String ls = localStrings.getLocalString(
+ "create.iiop.listener.port.occupied",
+ def, iiopport, listener.getId(), listeneraddress);
+ report.setMessage(ls);
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ }
+
+ try {
+ ConfigSupport.apply(
+ new SingleConfigCode<IiopService>() {
+ @Override
+ public Object run(IiopService param)
+ throws PropertyVetoException, TransactionFailure {
+
+ IiopListener newListener = param.createChild(
+ IiopListener.class);
+
+ newListener.setId(listener_id);
+ newListener.setAddress(listeneraddress);
+ newListener.setPort(iiopport);
+ newListener.setSecurityEnabled(securityenabled.toString());
+ newListener.setEnabled(enabled.toString());
+
+ //add properties
+ if (properties != null) {
+ for ( java.util.Map.Entry entry : properties.entrySet()) {
+ Property property =
+ newListener.createChild(Property.class);
+ property.setName((String)entry.getKey());
+ property.setValue((String)entry.getValue());
+ newListener.getProperty().add(property);
+ }
+ }
+
+ param.getIiopListener().add(newListener);
+ return newListener;
+ }
+ }, iiopService);
+
+ report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
+ } catch(TransactionFailure e) {
+ String actual = e.getMessage();
+ String def = "Creation of: " + listener_id + "failed because of: "
+ + actual;
+ String msg = localStrings.getLocalString(
+ "create.iiop.listener.fail", def, listener_id, actual);
+ report.setMessage(msg);
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ report.setFailureCause(e);
+ }
+ }
+}
+
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/DeleteIiopListener.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/DeleteIiopListener.java
new file mode 100644
index 0000000..59b057b
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/DeleteIiopListener.java
@@ -0,0 +1,134 @@
+/*
+ * 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
+ */
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.glassfish.orb.admin.cli;
+
+import java.beans.PropertyVetoException;
+
+import org.glassfish.api.admin.AdminCommand;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.I18n;
+import org.glassfish.api.Param;
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.ActionReport.ExitCode;
+
+import org.jvnet.hk2.annotations.Service;
+
+import javax.inject.Inject;
+import org.glassfish.hk2.api.PerLookup;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import com.sun.enterprise.config.serverbeans.Config;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import com.sun.enterprise.util.SystemPropertyConstants;
+
+import java.util.List;
+import org.glassfish.api.admin.ExecuteOn;
+import org.glassfish.api.admin.RuntimeType;
+import org.glassfish.config.support.CommandTarget;
+import org.glassfish.config.support.TargetType;
+import org.glassfish.internal.api.Target;
+import org.glassfish.hk2.api.ServiceLocator;
+
+
+@Service(name="delete-iiop-listener")
+@PerLookup
+@I18n("delete.iiop.listener")
+@ExecuteOn(value={RuntimeType.DAS,RuntimeType.INSTANCE})
+@TargetType(value={CommandTarget.CLUSTER,CommandTarget.CONFIG,
+ CommandTarget.DAS,CommandTarget.STANDALONE_INSTANCE } )
+public class DeleteIiopListener implements AdminCommand {
+
+ final private static LocalStringManagerImpl localStrings =
+ new LocalStringManagerImpl(DeleteIiopListener.class);
+
+ @Param(name="listener_id", primary=true)
+ String listener_id;
+
+ @Param( name="target", optional=true,
+ defaultValue=SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME)
+ String target ;
+
+ @Inject
+ ServiceLocator services ;
+
+ /**
+ * 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
+ */
+ @Override
+ public void execute(AdminCommandContext context) {
+ final Target targetUtil = services.getService(Target.class ) ;
+ final Config config = targetUtil.getConfig(target) ;
+ ActionReport report = context.getActionReport();
+ IiopService iiopService = config.getExtensionByType(IiopService.class);
+
+ if(!isIIOPListenerExists(iiopService)) {
+ report.setMessage(localStrings.getLocalString("delete.iiop.listener" +
+ ".notexists", "IIOP Listener {0} does not exist.", listener_id));
+ report.setActionExitCode(ExitCode.FAILURE);
+ return;
+ }
+
+ try {
+ ConfigSupport.apply(new SingleConfigCode<IiopService>() {
+ @Override
+ public Object run(IiopService param) throws PropertyVetoException,
+ TransactionFailure {
+ List<IiopListener> listenerList = param.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ String currListenerId = listener.getId();
+ if (currListenerId != null && currListenerId.equals
+ (listener_id)) {
+ listenerList.remove(listener);
+ break;
+ }
+ }
+ return listenerList;
+ }
+ }, iiopService);
+ report.setActionExitCode(ExitCode.SUCCESS);
+ } catch(TransactionFailure e) {
+ String actual = e.getMessage();
+ report.setMessage(localStrings.getLocalString(
+ "delete.iiop.listener.fail", "failed", listener_id, actual));
+ report.setActionExitCode(ExitCode.FAILURE);
+ report.setFailureCause(e);
+ }
+ }
+
+ private boolean isIIOPListenerExists(IiopService iiopService) {
+ for (IiopListener listener : iiopService.getIiopListener()) {
+ String currListenerId = listener.getId();
+ if (currListenerId != null && currListenerId.equals(listener_id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/ListIiopListeners.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/ListIiopListeners.java
new file mode 100644
index 0000000..6efe88f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/cli/ListIiopListeners.java
@@ -0,0 +1,107 @@
+/*
+ * 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.orb.admin.cli;
+
+
+import com.sun.enterprise.config.serverbeans.Config;
+import org.glassfish.api.admin.AdminCommand;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.admin.CommandLock;
+
+import org.glassfish.api.I18n;
+import org.glassfish.api.ActionReport;
+
+import org.jvnet.hk2.annotations.Service;
+
+import javax.inject.Inject;
+import org.glassfish.hk2.api.PerLookup;
+
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import com.sun.enterprise.util.SystemPropertyConstants;
+
+import java.util.List;
+import org.glassfish.api.Param;
+import org.glassfish.api.admin.*;
+import org.glassfish.config.support.CommandTarget;
+import org.glassfish.config.support.TargetType;
+import org.glassfish.internal.api.Target;
+import org.glassfish.hk2.api.ServiceLocator;
+
+
+/**
+ * List IIOP Listener command
+ *
+ */
+
+@Service(name="list-iiop-listeners")
+@PerLookup
+@CommandLock(CommandLock.LockType.NONE)
+@I18n("list.iiop.listeners")
+@ExecuteOn(value={RuntimeType.DAS})
+@TargetType(value={CommandTarget.CLUSTER,CommandTarget.CONFIG,
+ CommandTarget.DAS,CommandTarget.STANDALONE_INSTANCE,
+ CommandTarget.CLUSTERED_INSTANCE, CommandTarget.DOMAIN }
+)
+@RestEndpoints({
+ @RestEndpoint(configBean=IiopService.class,
+ opType=RestEndpoint.OpType.GET,
+ path="list-iiop-listeners",
+ description="list-iiop-listeners")
+})
+public class ListIiopListeners implements AdminCommand {
+
+ final private static LocalStringManagerImpl localStrings =
+ new LocalStringManagerImpl(ListIiopListeners.class);
+
+ @Param( primary=true, name="target", optional=true,
+ defaultValue=SystemPropertyConstants.DAS_SERVER_NAME)
+ String target ;
+
+ @Inject
+ ServiceLocator services ;
+
+
+ /**
+ * Executes the command
+ *
+ * @param context information
+ */
+ @Override
+ public void execute(AdminCommandContext context) {
+ final ActionReport report = context.getActionReport();
+ final Target targetUtil = services.getService(Target.class ) ;
+ final Config config = targetUtil.getConfig(target) ;
+ final IiopService iiopService = config.getExtensionByType(IiopService.class);
+
+ try {
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ final ActionReport.MessagePart part = report.getTopMessagePart()
+ .addChild();
+ part.setMessage(listener.getId());
+ }
+ report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
+ } catch (Exception e) {
+ report.setMessage(localStrings.getLocalString("list.iiop.listener" +
+ ".fail", "List IIOP listeners failed."));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ report.setFailureCause(e);
+ }
+ }
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopServiceSslConfigHandler.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopServiceSslConfigHandler.java
new file mode 100644
index 0000000..c457b50
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopServiceSslConfigHandler.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2011, 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.orb.admin.config.handler;
+
+import com.sun.enterprise.admin.commands.CreateSsl;
+import com.sun.enterprise.admin.commands.DeleteSsl;
+import com.sun.enterprise.admin.commands.SslConfigHandler;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.config.serverbeans.SslClientConfig;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import org.glassfish.api.ActionReport;
+import org.glassfish.grizzly.config.dom.Ssl;
+import org.jvnet.hk2.annotations.Service;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import java.beans.PropertyVetoException;
+
+/**
+ * SSL configuration handler for iiop-service.
+ * @author Jerome Dochez
+ */
+@Service(name="iiop-service")
+public class IiopServiceSslConfigHandler implements SslConfigHandler {
+
+ final private static LocalStringManagerImpl localStrings =
+ new LocalStringManagerImpl(CreateSsl.class);
+
+ @Override
+ public void create(final CreateSsl command, ActionReport report) {
+ IiopService iiopSvc = command.config.getExtensionByType(IiopService.class);
+ if (iiopSvc.getSslClientConfig() != null) {
+ report.setMessage(
+ localStrings.getLocalString(
+ "create.ssl.iiopsvc.alreadyExists", "IIOP Service " +
+ "already has been configured with SSL configuration."));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ try {
+ ConfigSupport.apply(new SingleConfigCode<IiopService>() {
+ public Object run(IiopService param)
+ throws PropertyVetoException, TransactionFailure {
+ SslClientConfig newSslClientCfg =
+ param.createChild(SslClientConfig.class);
+ Ssl newSsl = newSslClientCfg.createChild(Ssl.class);
+ command.populateSslElement(newSsl);
+ newSslClientCfg.setSsl(newSsl);
+ param.setSslClientConfig(newSslClientCfg);
+ return newSsl;
+ }
+ }, iiopSvc);
+
+ } catch (TransactionFailure e) {
+ command.reportError(report, e);
+ }
+ command.reportSuccess(report);
+ }
+
+ @Override
+ public void delete(DeleteSsl command, ActionReport report) {
+ if (command.config.getExtensionByType(IiopService.class).getSslClientConfig() == null) {
+ report.setMessage(localStrings.getLocalString(
+ "delete.ssl.element.doesnotexistforiiop",
+ "Ssl element does not exist for IIOP service"));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+
+ try {
+ ConfigSupport.apply(new SingleConfigCode<IiopService>() {
+ public Object run(IiopService param)
+ throws PropertyVetoException {
+ param.setSslClientConfig(null);
+ return null;
+ }
+ }, command.config.getExtensionByType(IiopService.class));
+ } catch (TransactionFailure e) {
+ command.reportError(report, e);
+ }
+ }
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopSslConfigHandler.java b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopSslConfigHandler.java
new file mode 100644
index 0000000..a0990e4
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/IiopSslConfigHandler.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2011, 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.orb.admin.config.handler;
+
+import com.sun.enterprise.admin.commands.CreateSsl;
+import com.sun.enterprise.admin.commands.DeleteSsl;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import org.glassfish.api.ActionReport;
+import org.glassfish.grizzly.config.dom.Ssl;
+import org.jvnet.hk2.annotations.Service;
+import com.sun.enterprise.admin.commands.SslConfigHandler;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import java.beans.PropertyVetoException;
+
+/**
+ * SSL configuration handler for iiop-listener configuration
+ * @author Jerome Dochez
+ *
+ */
+@Service(name="iiop-listener")
+public class IiopSslConfigHandler implements SslConfigHandler {
+
+ final private static LocalStringManagerImpl localStrings =
+ new LocalStringManagerImpl(CreateSsl.class);
+
+
+ @Override
+ public void create(final CreateSsl command, ActionReport report) {
+ IiopService iiopService = command.config.getExtensionByType(IiopService.class);
+ // ensure we have the specified listener
+ IiopListener iiopListener = null;
+ for (IiopListener listener : iiopService.getIiopListener()) {
+ if (listener.getId().equals(command.listenerId)) {
+ iiopListener = listener;
+ }
+ }
+ if (iiopListener == null) {
+ report.setMessage(
+ localStrings.getLocalString("create.ssl.iiop.notfound",
+ "IIOP Listener named {0} to which this ssl element is " +
+ "being added does not exist.", command.listenerId));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ if (iiopListener.getSsl() != null) {
+ report.setMessage(
+ localStrings.getLocalString("create.ssl.iiop.alreadyExists",
+ "IIOP Listener named {0} to which this ssl element is " +
+ "being added already has an ssl element.", command.listenerId));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ try {
+ ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
+ public Object run(IiopListener param)
+ throws PropertyVetoException, TransactionFailure {
+ Ssl newSsl = param.createChild(Ssl.class);
+ command.populateSslElement(newSsl);
+ param.setSsl(newSsl);
+ return newSsl;
+ }
+ }, iiopListener);
+
+ } catch (TransactionFailure e) {
+ command.reportError(report, e);
+ }
+ command.reportSuccess(report);
+ }
+
+ @Override
+ public void delete(DeleteSsl command, ActionReport report) {
+
+ IiopService iiopService = command.config.getExtensionByType(IiopService.class);
+ IiopListener iiopListener = null;
+ for (IiopListener listener : iiopService.getIiopListener()) {
+ if (listener.getId().equals(command.listenerId)) {
+ iiopListener = listener;
+ }
+ }
+
+ if (iiopListener == null) {
+ report.setMessage(localStrings.getLocalString(
+ "delete.ssl.iiop.listener.notfound",
+ "Iiop Listener named {0} not found", command.listenerId));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+
+ if (iiopListener.getSsl() == null) {
+ report.setMessage(localStrings.getLocalString(
+ "delete.ssl.element.doesnotexist", "Ssl element does " +
+ "not exist for Listener named {0}", command.listenerId));
+ report.setActionExitCode(ActionReport.ExitCode.FAILURE);
+ return;
+ }
+ try {
+ ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
+ public Object run(IiopListener param)
+ throws PropertyVetoException {
+ param.setSsl(null);
+ return null;
+ }
+ }, iiopListener);
+ } catch(TransactionFailure e) {
+ command.reportError(report, e);
+ }
+ }
+}
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/LocalStrings.properties b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/LocalStrings.properties
new file mode 100644
index 0000000..7beade6
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/config/handler/LocalStrings.properties
@@ -0,0 +1,29 @@
+#
+# Copyright (c) 2011, 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
+#
+
+create.ssl.iiop.notfound=IIOP Listener named {0} to which this ssl element is being added does not exist.
+create.ssl.iiop.alreadyExists=IIOP Listener named {0} to which this ssl element is being added already has an ssl element.
+
+create.ssl.iiopsvc.alreadyExists=IIOP Service already has been configured with SSL configuration.
+
+delete.ssl.iiop.listener.notfound=IIOP Listener named {0} not found
+delete.ssl.element.doesnotexistforiiop=Ssl element does not exist for IIOP service
+iiop.service.portNumber.title=IIOP service port number
+iiop.service.portNumber.description=Port number that IIOP Service listens on without SSL layer.
+iiop.service.ssl.portNumber.title=IIOP service SSL port number
+iiop.service.ssl.portNumber.description=Port number that IIOP Service listens on with SSL layer.
+iiop.service.mutual.auth.portNumber.title=IIOP service SSL with mutual authentication port number
+iiop.service.mutual.auth.portNumber.description=Port number that IIOP Service listens on with SSL authentication layer.
diff --git a/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/monitor/.gitkeep_empty_dir b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/monitor/.gitkeep_empty_dir
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/java/org/glassfish/orb/admin/monitor/.gitkeep_empty_dir
diff --git a/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/create-iiop-listener.1 b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/create-iiop-listener.1
new file mode 100644
index 0000000..1b11290
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/create-iiop-listener.1
@@ -0,0 +1,92 @@
+create-iiop-listener(1) asadmin Utility Subcommands create-iiop-listener(1)
+
+NAME
+ create-iiop-listener - adds an IIOP listener
+
+SYNOPSIS
+ create-iiop-listener [--help] --listeneraddress address
+ [--iiopport iiop-port-number] [--securityenabled={false|true}] [--enabled={true|false}]
+ [--property (name=value)[:name=value]*]
+ [--target target] listener_id
+
+DESCRIPTION
+ The create-iiop-listener subcommand creates an IIOP listener. This
+ subcommand is supported in remote mode only.
+
+OPTIONS
+ --help, -?
+ Displays the help text for the subcommand.
+
+ --listeneraddress
+ Either the IP address or the hostname (resolvable by DNS).
+
+ --iiopport
+ The IIOP port number. The default value is 1072.
+
+ --securityenabled
+ If set to true, the IIOP listener runs SSL. You can turn SSL2 or
+ SSL3 ON or OFF and set ciphers using an SSL element. The security
+ setting globally enables or disables SSL by making certificates
+ available to the server instance. The default value is false.
+
+ --enabled
+ If set to true, the IIOP listener is enabled at runtime. The
+ default value is true.
+
+ --property
+ Optional attribute name/value pairs for configuring the IIOP
+ listener.
+
+ --target
+ Specifies the target for which you are creating the IIOP listener.
+ Valid values are
+
+ server
+ Creates the listener for the default server instance server and
+ is the default value.
+
+ configuration_name
+ Creates the listener for the named configuration.
+
+ cluster_name
+ Creates the listener for every server instance in the cluster.
+
+ stand-alone_instance_name
+ Creates the listener for a particular standalone server
+ instance.
+
+OPERANDS
+ listener_id
+ A unique identifier for the IIOP listener to be created.
+
+EXAMPLES
+ Example 1, Creating an IIOP Listener
+ The following command creates an IIOP listener named
+ sample_iiop_listener:
+
+ asadmin> create-iiop-listener --listeneraddress 192.168.1.100
+ --iiopport 1400 sample_iiop_listener
+ Command create-iiop-listener executed successfully.
+
+ Example 2, Creating an IIOP Listener with a Target Cluster
+ The following command creates an IIOP listener named
+ iiop_listener_2 for the cluster mycluster. It uses the target
+ option.
+
+ asadmin> create-iiop-listener --listeneraddress 0.0.0.0 --iiopport 1401
+ --target mycluster iiop_listener_2
+ Command create-iiop-listener executed successfully.
+
+EXIT STATUS
+ 0
+ command executed successfully
+
+ 1
+ error in executing the command
+
+SEE ALSO
+ delete-iiop-listener(1), list-iiop-listeners(1), create-ssl(1)
+
+ asadmin(1M)
+
+Java EE 8 18 Aug 2010 create-iiop-listener(1)
diff --git a/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/delete-iiop-listener.1 b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/delete-iiop-listener.1
new file mode 100644
index 0000000..e4dbbdf
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/delete-iiop-listener.1
@@ -0,0 +1,58 @@
+delete-iiop-listener(1) asadmin Utility Subcommands delete-iiop-listener(1)
+
+NAME
+ delete-iiop-listener - removes an IIOP listener
+
+SYNOPSIS
+ delete-iiop-listener [--help] [--target target] listener_id
+
+DESCRIPTION
+ The delete-iiop-listener subcommand removes the specified IIOP
+ listener. This subcommand is supported in remote mode only.
+
+OPTIONS
+ --help, -?
+ Displays the help text for the subcommand.
+
+ --target
+ Specifies the target from which you are deleting the IIOP listener.
+ Valid values are
+
+ server
+ Deletes the listener from the default server instance server
+ and is the default value.
+
+ configuration_name
+ Deletes the listener from the named configuration.
+
+ cluster_name
+ Deletes the listener from every server instance in the cluster.
+
+ instance_name
+ Deletes the listener from a particular server instance.
+
+OPERANDS
+ listener_id
+ The unique identifier for the IIOP listener to be deleted.
+
+EXAMPLES
+ Example 1, Deleting an IIOP Listener
+ The following command deletes the IIOP listener named
+ sample_iiop_listener:
+
+ asadmin> delete-iiop-listener sample_iiop_listener
+ Command delete-iiop-listener executed successfully.
+
+EXIT STATUS
+ 0
+ command executed successfully
+
+ 1
+ error in executing the command
+
+SEE ALSO
+ create-iiop-listener(1), list-iiop-listeners(1)
+
+ asadmin(1M)
+
+Java EE 8 18 Aug 2010 delete-iiop-listener(1)
diff --git a/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/list-iiop-listeners.1 b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/list-iiop-listeners.1
new file mode 100644
index 0000000..7885986
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/manpages/org/glassfish/orb/admin/cli/list-iiop-listeners.1
@@ -0,0 +1,60 @@
+list-iiop-listeners(1) asadmin Utility Subcommands list-iiop-listeners(1)
+
+NAME
+ list-iiop-listeners - lists the existing IIOP listeners
+
+SYNOPSIS
+ list-iiop-listeners [--help]
+ [target]
+
+DESCRIPTION
+ The list-iiop-listeners subcommand lists the existing IIOP listeners.
+ This subcommand is supported in remote mode only.
+
+OPTIONS
+ --help, -?
+ Displays the help text for the subcommand.
+
+OPERANDS
+ target
+ This operand specifies the target for which the IIOP listeners are
+ to be listed. Valid values are:
+
+ server
+ Lists the listeners in the default server instance server and
+ is the default value.
+
+ configuration_name
+ Lists the listeners in the specified configuration.
+
+ cluster_name
+ Lists the listeners in the specified cluster.
+
+ instance_name
+ Lists the listeners in a particular server instance.
+
+EXAMPLES
+ Example 1, Using the list-iiop-listeners subcommand
+ The following command lists all the IIOP listeners for the server
+ instance:
+
+ asadmin> list-iiop-listeners
+ orb-listener-1
+ SSL
+ SSL_MUTUALAUTH
+ sample_iiop_listener
+ Command list-iiop-listeners executed successfully.
+
+EXIT STATUS
+ 0
+ command executed successfully
+
+ 1
+ error in executing the command
+
+SEE ALSO
+ create-iiop-listener(1), delete-iiop-listener(1)
+
+ asadmin(1M)
+
+Java EE 8 18 Aug 2010 list-iiop-listeners(1)
diff --git a/appserver/orb/orb-connector/src/main/resources/META-INF/configuration/iiop-module-conf.xml b/appserver/orb/orb-connector/src/main/resources/META-INF/configuration/iiop-module-conf.xml
new file mode 100644
index 0000000..dfda37f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/resources/META-INF/configuration/iiop-module-conf.xml
@@ -0,0 +1,56 @@
+<!--
+
+ Copyright (c) 2012, 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
+
+-->
+
+<service-config>
+ <config-bundle location="domain/configs/config[$CURRENT_INSTANCE_CONFIG_NAME]" replace-if-exist="true">
+ <customization-tokens>
+
+ <customization-token
+ title="$iiop.service.portNumber.title" name="IIOP_LISTENER_PORT"
+ default-value="3700"
+ description="$iiop.service.portNumber.description"/>
+
+ <customization-token
+ title="$iiop.service.ssl.portNumber.title" name="IIOP_SSL_LISTENER_PORT"
+ default-value="3820"
+ description="$iiop.service.ssl.portNumber.description"/>
+
+
+ <customization-token
+ title="$iiop.service.mutual.auth.portNumber.title" name="IIOP_SSL_MUTUALAUTH_PORT"
+ default-value="3920"
+ description="$iiop.service.mutual.auth.portNumber.description"/>
+ </customization-tokens>
+
+ <configuration-element config-bean-class-name="org.glassfish.orb.admin.config.IiopService">
+ <![CDATA[
+ <iiop-service>
+ <orb use-thread-pool-ids="thread-pool-1"></orb>
+ <iiop-listener port="${IIOP_LISTENER_PORT}" id="orb-listener-1" address="0.0.0.0"></iiop-listener>
+ <iiop-listener port="${IIOP_SSL_LISTENER_PORT}" id="SSL" address="0.0.0.0" security-enabled="true">
+ <ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl" cert-nickname="s1as"></ssl>
+ </iiop-listener>
+ <iiop-listener port="${IIOP_SSL_MUTUALAUTH_PORT}" id="SSL_MUTUALAUTH" address="0.0.0.0" security-enabled="true">
+ <ssl classname="com.sun.enterprise.security.ssl.GlassfishSSLImpl" cert-nickname="s1as" client-auth-enabled="true"></ssl>
+ </iiop-listener>
+ </iiop-service>
+
+ ]]>
+ </configuration-element>
+ </config-bundle>
+</service-config>
diff --git a/appserver/orb/orb-connector/src/main/resources/org/glassfish/orb/admin/cli/LocalStrings.properties b/appserver/orb/orb-connector/src/main/resources/org/glassfish/orb/admin/cli/LocalStrings.properties
new file mode 100644
index 0000000..863775a
--- /dev/null
+++ b/appserver/orb/orb-connector/src/main/resources/org/glassfish/orb/admin/cli/LocalStrings.properties
@@ -0,0 +1,25 @@
+#
+# 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
+#
+
+
+create.iiop.listener.duplicate=IIOP Listener named {0} already exists.
+create.iiop.listener.fail=Listener {0} could not be created, actual reason: {1}
+create.iiop.listener.port.occupied=Port [{0}] is already taken by another listener: [{1}] for address [{2}], choose another port.
+create.iiop.listener.success=IIOP Listener {0} created.
+delete.iiop.listener.notexists=IIOP Listener {0} does not exist.
+delete.iiop.listener.success=IIOP Listener {0} deleted.
+delete.iiop.listener.fail=Listener {0} could not be deleted, actual reason: {1}
+list.iiop.listener.fail=List IIOP listeners failed.
diff --git a/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/CreateIiopListenerTest.java b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/CreateIiopListenerTest.java
new file mode 100644
index 0000000..e44e145
--- /dev/null
+++ b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/CreateIiopListenerTest.java
@@ -0,0 +1,327 @@
+/*
+ * 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.orb.admin.cli;
+
+import org.glassfish.api.admin.AdminCommandContextImpl;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.v3.common.PropsFileActionReporter;
+import com.sun.logging.LogDomains;
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.admin.CommandRunner;
+import org.glassfish.api.admin.ParameterMap;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.junit.After;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.DomDocument;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+import junit.framework.Assert;
+
+
+public class CreateIiopListenerTest extends org.glassfish.tests.utils.ConfigApiTest {
+
+ private ServiceLocator services;
+ private IiopService iiopService;
+ private ParameterMap parameters;
+ private AdminCommandContext context;
+ private CommandRunner cr;
+
+ public static void checkActionReport(ActionReport report) {
+ if (ActionReport.ExitCode.SUCCESS.equals(report.getActionExitCode())) {
+ return;
+ }
+
+ Throwable reason = report.getFailureCause();
+ Assert.assertNotNull("Action failed with exit code " +
+ report.getActionExitCode() + " and message " +
+ report.getMessage(), reason);
+ throw new AssertionError(reason);
+ }
+
+ @Override
+ public String getFileName() {
+ return "DomainTest";
+ }
+
+ public DomDocument getDocument(ServiceLocator services) {
+ return new TestDocument(services);
+ }
+
+ @Before
+ public void setUp() {
+ services = getHabitat();
+ iiopService = services.getService(IiopService.class);
+ parameters = new ParameterMap();
+ context = new AdminCommandContextImpl(
+ LogDomains.getLogger(CreateIiopListenerTest.class, LogDomains.ADMIN_LOGGER),
+ new PropsFileActionReporter());
+ cr = services.getService(CommandRunner.class);
+ }
+
+ @After
+ public void tearDown() throws TransactionFailure {
+ ConfigSupport.apply(new SingleConfigCode<IiopService>() {
+ public Object run(IiopService param) throws PropertyVetoException,
+ TransactionFailure {
+ List<IiopListener> listenerList = param.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ String currListenerId = listener.getId();
+ if (currListenerId != null && currListenerId.equals
+ ("iiop_1")) {
+ listenerList.remove(listener);
+ break;
+ }
+ }
+ return listenerList;
+ }
+ }, iiopService);
+ parameters = new ParameterMap();
+ }
+
+
+
+ /**
+ * Test of execute method, of class CreateIiopListener.
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 --enabled=true --securityenabled=true iiop_1
+ */
+ @Test
+ public void testExecuteSuccess() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ parameters.set("enabled", "true");
+ parameters.set("securityenabled", "true");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("true", listener.getEnabled());
+ assertEquals("4440", listener.getPort());
+ assertEquals("true", listener.getSecurityEnabled());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+
+ /**
+ * Test of execute method, of class CreateIiopListener.
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 iiop_1
+ */
+
+ @Test
+ public void testExecuteSuccessDefaultValues() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("4440", listener.getPort());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+
+
+ /**
+ * Test of execute method, of class CreateIiopListener.
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 iiop_1
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 iiop_1
+ */
+ @Test
+ public void testExecuteFailDuplicateListener() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ CreateIiopListener command1 = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command1);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("4440", listener.getPort());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+
+ CreateIiopListener command2 = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command2);
+ assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
+ int numDupRes = 0;
+ listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ numDupRes = numDupRes + 1;
+ }
+ }
+ assertEquals(1, numDupRes);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+
+ /**
+ * Test of execute method, of class CreateIiopListener with same iiop port number
+ * and listener address.
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 iiop_1
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 iiop_2
+ */
+ @Test
+ public void testExecuteFailForSamePortAndListenerAddress() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("4440", listener.getPort());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+
+ parameters = new ParameterMap();
+ parameters.set("listener_id", "iiop_2");
+ parameters.set("iiopport", "4440");
+ parameters.set("listeneraddress", "localhost");
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
+ logger.fine("msg: " + context.getActionReport().getMessage());
+
+ }
+
+ /**
+ * Test of execute method, of class CreateIiopListener when enabled set to junk
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 --enabled=junk iiop_1
+ */
+ //@Test
+ public void testExecuteFailInvalidOptionEnabled() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ parameters.set("enabled", "junk");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
+ }
+
+ /**
+ * Test of execute method, of class CreateIiopListener when enabled has no value
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 --enable iiop_1
+ */
+ @Test
+ public void testExecuteSuccessNoValueOptionEnabled() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ parameters.set("enabled", "");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("true", listener.getEnabled());
+ assertEquals("4440", listener.getPort());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+
+ /**
+ * Test of execute method, of class CreateIiopListener when enabled has no value
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 --securityenabled iiop_1
+ */
+ @Test
+ public void testExecuteSuccessNoValueOptionSecurityEnabled() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ parameters.set("securityenabled", "");
+ CreateIiopListener command = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
+ checkActionReport(context.getActionReport());
+ boolean isCreated = false;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ assertEquals("localhost", listener.getAddress());
+ assertEquals("true", listener.getSecurityEnabled());
+ assertEquals("4440", listener.getPort());
+ isCreated = true;
+ logger.fine("IIOPListener name iiop_1 is created.");
+ break;
+ }
+ }
+ assertTrue(isCreated);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+}
diff --git a/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/DeleteIiopListenerTest.java b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/DeleteIiopListenerTest.java
new file mode 100644
index 0000000..7f6b0c6
--- /dev/null
+++ b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/DeleteIiopListenerTest.java
@@ -0,0 +1,133 @@
+/*
+ * 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.orb.admin.cli;
+
+import org.glassfish.api.admin.AdminCommandContextImpl;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.v3.common.PropsFileActionReporter;
+import com.sun.logging.LogDomains;
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.admin.CommandRunner;
+import org.glassfish.api.admin.ParameterMap;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.junit.After;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.jvnet.hk2.config.ConfigSupport;
+import org.jvnet.hk2.config.DomDocument;
+import org.jvnet.hk2.config.SingleConfigCode;
+import org.jvnet.hk2.config.TransactionFailure;
+
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+
+public class DeleteIiopListenerTest extends org.glassfish.tests.utils.ConfigApiTest {
+
+ private ServiceLocator services;
+ private IiopService iiopService;
+ private ParameterMap parameters;
+ private CommandRunner cr;
+ private AdminCommandContext context;
+
+ public String getFileName() {
+ return "DomainTest";
+ }
+
+ public DomDocument getDocument(ServiceLocator services) {
+ return new TestDocument(services);
+ }
+
+ @Before
+ public void setUp() {
+ services = getHabitat();
+ iiopService = services.getService(IiopService.class);
+ parameters = new ParameterMap();
+ cr = services.getService(CommandRunner.class);
+ context = new AdminCommandContextImpl(
+ LogDomains.getLogger(DeleteIiopListenerTest.class, LogDomains.ADMIN_LOGGER),
+ new PropsFileActionReporter());
+ }
+
+ @After
+ public void tearDown() throws TransactionFailure {
+ ConfigSupport.apply(new SingleConfigCode<IiopService>() {
+ public Object run(IiopService param) throws PropertyVetoException,
+ TransactionFailure {
+ List<IiopListener> listenerList = param.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ String currListenerId = listener.getId();
+ if (currListenerId != null && currListenerId.equals
+ ("iiop_1")) {
+ listenerList.remove(listener);
+ break;
+ }
+ }
+ return listenerList;
+ }
+ }, iiopService);
+ }
+
+
+ /**
+ * Test of execute method, of class DeleteIiopListener.
+ * delete-iiop-listener iiop_1
+ */
+ @Test
+ public void testExecuteSuccessDefaultTarget() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "iiop_1");
+ CreateIiopListener createCommand = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ parameters = new ParameterMap();
+ parameters.set("listener_id", "iiop_1");
+ DeleteIiopListener deleteCommand = services.getService(DeleteIiopListener.class);
+ cr.getCommandInvocation("delete-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ boolean isDeleted = true;
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ for (IiopListener listener : listenerList) {
+ if (listener.getId().equals("iiop_1")) {
+ isDeleted = false;
+ logger.fine("IIOPListener name iiop_1 is not deleted.");
+ break;
+ }
+ }
+ assertTrue(isDeleted);
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+
+ /**
+ * Test of execute method, of class DeleteIiopListener.
+ * delete-iiop-listener doesnotexist
+ */
+ @Test
+ public void testExecuteFailDoesNotExist() {
+ parameters.set("DEFAULT", "doesnotexist");
+ DeleteIiopListener deleteCommand = services.getService(DeleteIiopListener.class);
+ cr.getCommandInvocation("delete-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ assertEquals(ActionReport.ExitCode.FAILURE, context.getActionReport().getActionExitCode());
+ logger.fine("msg: " + context.getActionReport().getMessage());
+ }
+}
diff --git a/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/ListIiopListenersTest.java b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/ListIiopListenersTest.java
new file mode 100644
index 0000000..64f934b
--- /dev/null
+++ b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/ListIiopListenersTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.orb.admin.cli;
+
+import org.glassfish.api.admin.AdminCommandContextImpl;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.v3.common.PropsFileActionReporter;
+import com.sun.logging.LogDomains;
+import org.glassfish.api.ActionReport;
+import org.glassfish.api.ActionReport.MessagePart;
+import org.glassfish.api.admin.AdminCommandContext;
+import org.glassfish.api.admin.CommandRunner;
+import org.glassfish.api.admin.ParameterMap;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.junit.After;
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.jvnet.hk2.config.DomDocument;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class ListIiopListenersTest extends org.glassfish.tests.utils.ConfigApiTest {
+
+ private ServiceLocator services;
+ private int origNum;
+ private ParameterMap parameters;
+ private CommandRunner cr;
+ private AdminCommandContext context;
+
+ public String getFileName() {
+ return "DomainTest";
+ }
+
+ public DomDocument getDocument(ServiceLocator services) {
+ return new TestDocument(services);
+ }
+
+ @Before
+ public void setUp() {
+ services = getHabitat();
+ IiopService iiopService = services.getService(IiopService.class);
+ parameters = new ParameterMap();
+ cr = services.getService(CommandRunner.class);
+ context = new AdminCommandContextImpl(
+ LogDomains.getLogger(ListIiopListenersTest.class, LogDomains.ADMIN_LOGGER),
+ new PropsFileActionReporter());
+ List<IiopListener> listenerList = iiopService.getIiopListener();
+ origNum = listenerList.size();
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of execute method, of class ListIiopListeners.
+ * list-iiop-listeners
+ */
+ @Test
+ public void testExecuteSuccessListOriginal() {
+ ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
+ cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
+ assertEquals(origNum, list.size());
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ }
+
+ /**
+ * Test of execute method, of class ListIiopListeners.
+ * list-iiop-listeners server
+ */
+ @Test
+ public void testExecuteSuccessValidTargetOperand() {
+ ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
+ parameters.set("DEFAULT", "server");
+ cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
+ assertEquals(origNum, list.size());
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ }
+
+ /**
+ * Test of execute method, of class ListIiopListeners.
+ * asadmin create-iiop-listener --listeneraddress localhost
+ * --iiopport 4440 listener
+ * list-iiop-listeners
+ * delete-iiop-listener listener
+ */
+ @Test
+ public void testExecuteSuccessListListener() {
+ parameters.set("listeneraddress", "localhost");
+ parameters.set("iiopport", "4440");
+ parameters.set("listener_id", "listener");
+ CreateIiopListener createCommand = services.getService(CreateIiopListener.class);
+ cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(createCommand);
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ parameters = new ParameterMap();
+ ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
+ cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
+ assertEquals(origNum + 1, list.size());
+ List<String> listStr = new ArrayList<String>();
+ for (MessagePart mp : list) {
+ listStr.add(mp.getMessage());
+ }
+ assertTrue(listStr.contains("listener"));
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ parameters = new ParameterMap();
+ parameters.set("listener_id", "listener");
+ DeleteIiopListener deleteCommand = services.getService(DeleteIiopListener.class);
+ cr.getCommandInvocation("delete-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(deleteCommand);
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ }
+
+ /**
+ * Test of execute method, of class ListIiopListener.
+ * list-iiop-listeners
+ */
+ @Test
+ public void testExecuteSuccessListNoListener() {
+ parameters = new ParameterMap();
+ ListIiopListeners listCommand = services.getService(ListIiopListeners.class);
+ cr.getCommandInvocation("list-iiop-listeners", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
+ CreateIiopListenerTest.checkActionReport(context.getActionReport());
+ List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
+ assertEquals(origNum, list.size());
+ List<String> listStr = new ArrayList<String>();
+ for (MessagePart mp : list) {
+ listStr.add(mp.getMessage());
+ }
+ assertFalse(listStr.contains("listener"));
+ }
+}
diff --git a/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/TestDocument.java b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/TestDocument.java
new file mode 100644
index 0000000..968ae5f
--- /dev/null
+++ b/appserver/orb/orb-connector/src/test/java/org/glassfish/orb/admin/cli/TestDocument.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2008, 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.orb.admin.cli;
+
+import org.jvnet.hk2.config.DomDocument;
+import org.jvnet.hk2.config.Dom;
+import org.jvnet.hk2.config.ConfigModel;
+import org.glassfish.config.support.GlassFishConfigBean;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.junit.Ignore;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ *
+ * This document will create the appropriate ConfigBean implementation but will
+ * not save the modified config tree.
+ *
+ * User: Jerome Dochez
+ */
+@Ignore
+public class TestDocument extends DomDocument<GlassFishConfigBean> {
+
+ public TestDocument(ServiceLocator habitat) {
+ super(habitat);
+ }
+
+ @Override
+ public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
+ // by default, people get the translated view.
+ return new GlassFishConfigBean(habitat, this, dom, configModel, xmlStreamReader);
+ }
+}
diff --git a/appserver/orb/orb-connector/src/test/resources/DomainTest.xml b/appserver/orb/orb-connector/src/test/resources/DomainTest.xml
new file mode 100644
index 0000000..586a079
--- /dev/null
+++ b/appserver/orb/orb-connector/src/test/resources/DomainTest.xml
@@ -0,0 +1,185 @@
+<!--
+
+ 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
+
+-->
+
+<domain log-root="${com.sun.aas.instanceRoot}/logs" application-root="${com.sun.aas.instanceRoot}/applications" version="10.0">
+ <security-configurations>
+ <authorization-service default="true" name="authorizationService">
+ <security-provider name="simpleAuthorization" type="Simple" provider-name="simpleAuthorizationProvider">
+ <authorization-provider-config support-policy-deploy="false" name="simpleAuthorizationProviderConfig"></authorization-provider-config>
+ </security-provider>
+ </authorization-service>
+ </security-configurations>
+ <system-applications />
+ <applications />
+ <resources/>
+ <servers>
+ <server name="server" config-ref="server-config">
+ <resource-ref ref="jdbc/__TimerPool" />
+ <resource-ref ref="jdbc/__default" />
+ </server>
+ </servers>
+ <configs>
+ <config name="server-config">
+ <http-service>
+ <access-log rotation-suffix="yyyy-MM-dd" rotation-interval-in-minutes="15" />
+ <virtual-server id="server" network-listeners="http-listener-1,http-listener-2">
+ <property name="docroot" value="${com.sun.aas.instanceRoot}/docroot" />
+ <property name="accesslog" value="${com.sun.aas.instanceRoot}/logs/access" />
+ <property name="sso-enabled" value="false" />
+ </virtual-server>
+ <virtual-server id="__asadmin" network-listeners="admin-listener">
+ <property name="docroot" value="${com.sun.aas.instanceRoot}/docroot" />
+ <property name="accesslog" value="${com.sun.aas.instanceRoot}/logs/access" />
+ <property name="sso-enabled" value="false" />
+ </virtual-server>
+ </http-service>
+ <iiop-service>
+ <orb use-thread-pool-ids="thread-pool-1" />
+ <iiop-listener id="orb-listener-1" port="3700" address="0.0.0.0" />
+ <iiop-listener id="SSL" port="3820" address="0.0.0.0" security-enabled="true">
+ <ssl cert-nickname="s1as" />
+ </iiop-listener>
+ <iiop-listener id="SSL_MUTUALAUTH" port="3920" address="0.0.0.0" security-enabled="true">
+ <ssl cert-nickname="s1as" client-auth-enabled="true" />
+ </iiop-listener>
+ </iiop-service>
+ <admin-service system-jmx-connector-name="system" type="das-and-server">
+ <jmx-connector port="8686" address="0.0.0.0" security-enabled="false" name="system" auth-realm-name="admin-realm" />
+ <das-config dynamic-reload-enabled="true" deploy-xml-validation="full" autodeploy-dir="${com.sun.aas.instanceRoot}/autodeploy" autodeploy-enabled="true" />
+ <property name="adminConsoleContextRoot" value="/admin" />
+ <property name="adminConsoleDownloadLocation" value="glassfish/lib/install/applications/admingui.war" />
+ <property name="ipsRoot" value="${com.sun.aas.installRoot}/.." />
+ </admin-service>
+ <log-service log-rotation-limit-in-bytes="2000000" file="${com.sun.aas.instanceRoot}/logs/server.log">
+ <module-log-levels />
+ </log-service>
+ <security-service>
+ <auth-realm name="admin-realm" classname="com.sun.enterprise.security.auth.realm.file.FileRealm">
+ <property name="file" value="${com.sun.aas.instanceRoot}/config/admin-keyfile" />
+ <property name="jaas-context" value="fileRealm" />
+ </auth-realm>
+ <auth-realm name="file" classname="com.sun.enterprise.security.auth.realm.file.FileRealm">
+ <property name="file" value="${com.sun.aas.instanceRoot}/config/keyfile" />
+ <property name="jaas-context" value="fileRealm" />
+ </auth-realm>
+ <auth-realm name="certificate" classname="com.sun.enterprise.security.auth.realm.certificate.CertificateRealm" />
+ <jacc-provider policy-provider="com.sun.enterprise.security.provider.PolicyWrapper" name="default" policy-configuration-factory-provider="com.sun.enterprise.security.provider.PolicyConfigurationFactoryImpl">
+ <property name="repository" value="${com.sun.aas.instanceRoot}/generated/policy" />
+ </jacc-provider>
+ <jacc-provider policy-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyProvider" name="simple" policy-configuration-factory-provider="com.sun.enterprise.security.jacc.provider.SimplePolicyConfigurationFactory" />
+ <audit-module name="default" classname="com.sun.enterprise.security.ee.Audit">
+ <property name="auditOn" value="false" />
+ </audit-module>
+ <message-security-config auth-layer="SOAP">
+ <provider-config provider-type="client" provider-id="XWS_ClientProvider" class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule">
+ <request-policy auth-source="content" />
+ <response-policy auth-source="content" />
+ <property name="encryption.key.alias" value="s1as" />
+ <property name="signature.key.alias" value="s1as" />
+ <property name="dynamic.username.password" value="false" />
+ <property name="debug" value="false" />
+ </provider-config>
+ <provider-config provider-type="client" provider-id="ClientProvider" class-name="com.sun.xml.wss.provider.ClientSecurityAuthModule">
+ <request-policy auth-source="content" />
+ <response-policy auth-source="content" />
+ <property name="encryption.key.alias" value="s1as" />
+ <property name="signature.key.alias" value="s1as" />
+ <property name="dynamic.username.password" value="false" />
+ <property name="debug" value="false" />
+ <property name="security.config" value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml" />
+ </provider-config>
+ <provider-config provider-type="server" provider-id="XWS_ServerProvider" class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule">
+ <request-policy auth-source="content" />
+ <response-policy auth-source="content" />
+ <property name="encryption.key.alias" value="s1as" />
+ <property name="signature.key.alias" value="s1as" />
+ <property name="debug" value="false" />
+ </provider-config>
+ <provider-config provider-type="server" provider-id="ServerProvider" class-name="com.sun.xml.wss.provider.ServerSecurityAuthModule">
+ <request-policy auth-source="content" />
+ <response-policy auth-source="content" />
+ <property name="encryption.key.alias" value="s1as" />
+ <property name="signature.key.alias" value="s1as" />
+ <property name="debug" value="false" />
+ <property name="security.config" value="${com.sun.aas.instanceRoot}/config/wss-server-config-1.0.xml" />
+ </provider-config>
+ </message-security-config>
+ </security-service>
+ <monitoring-service>
+ <module-monitoring-levels />
+ </monitoring-service>
+ <java-config debug-options="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9009" system-classpath="" classpath-suffix="">
+ <jvm-options>-client</jvm-options>
+ <jvm-options>-XX:+UnlockDiagnosticVMOptions</jvm-options>
+ <jvm-options>-XX:+LogVMOutput</jvm-options>
+ <jvm-options>-XX:LogFile=${com.sun.aas.instanceRoot}/logs/jvm.log</jvm-options>
+ <jvm-options>-Djava.endorsed.dirs=${com.sun.aas.installRoot}/lib/endorsed</jvm-options>
+ <jvm-options>-Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy</jvm-options>
+ <jvm-options>-Djava.security.auth.login.config=${com.sun.aas.instanceRoot}/config/login.conf
+ </jvm-options>
+ <jvm-options>-Dsun.rmi.dgc.server.gcInterval=3600000</jvm-options>
+ <jvm-options>-Dsun.rmi.dgc.client.gcInterval=3600000</jvm-options>
+ <jvm-options>-Xmx512m</jvm-options>
+ <jvm-options>-Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks</jvm-options>
+ <jvm-options>-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks</jvm-options>
+ <jvm-options>
+ -Djava.ext.dirs=${com.sun.aas.javaRoot}/lib/ext${path.separator}${com.sun.aas.javaRoot}/jre/lib/ext${path.separator}${com.sun.aas.instanceRoot}/lib/ext${path.separator}${com.sun.aas.derbyRoot}/lib
+ </jvm-options>
+ <jvm-options>-Djdbc.drivers=org.apache.derby.jdbc.ClientDriver</jvm-options>
+ <jvm-options>
+ -Dcom.sun.enterprise.config.config_environment_factory_class=com.sun.enterprise.config.serverbeans.AppserverConfigEnvironmentFactory
+ </jvm-options>
+ <jvm-options>-XX:NewRatio=2</jvm-options>
+ </java-config>
+ <thread-pools>
+ <thread-pool thread-pool-id="thread-pool-1" />
+ </thread-pools>
+ <management-rules enabled="true" />
+ <network-config>
+ <protocols>
+ <protocol name="http-listener-1">
+ <http header-buffer-length="8192" forced-response-type="text/plain; charset=iso-8859-1" default-virtual-server="server" max-connections="250" server-name="" default-response-type="text/plain; charset=iso-8859-1">
+ <file-cache enabled="false" />
+ </http>
+ </protocol>
+ <protocol security-enabled="true" name="http-listener-2">
+ <http header-buffer-length="8192" forced-response-type="text/plain; charset=iso-8859-1" default-virtual-server="server" max-connections="250" server-name="" default-response-type="text/plain; charset=iso-8859-1">
+ <file-cache enabled="false" />
+ </http>
+ <ssl ssl3-enabled="false" cert-nickname="s1as" />
+ </protocol>
+ <protocol name="admin-listener">
+ <http header-buffer-length="8192" forced-response-type="text/plain; charset=iso-8859-1" default-virtual-server="__asadmin" max-connections="250" server-name="" default-response-type="text/plain; charset=iso-8859-1">
+ <file-cache enabled="false" />
+ </http>
+ </protocol>
+ </protocols>
+ <network-listeners>
+ <thread-pool max-thread-pool-size="20" min-thread-pool-size="2" thread-pool-id="http-thread-pool" max-queue-size="4096" />
+ <network-listener port="8080" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool" />
+ <network-listener port="8181" enabled="false" protocol="http-listener-2" transport="tcp" name="http-listener-2" thread-pool="http-thread-pool" />
+ <network-listener port="4848" protocol="admin-listener" transport="tcp" name="admin-listener" thread-pool="http-thread-pool" />
+ </network-listeners>
+ <transports>
+ <transport name="tcp" />
+ </transports>
+ </network-config>
+ </config>
+ </configs>
+ <property name="administrative.domain.name" value="domain1" />
+</domain>
diff --git a/appserver/orb/orb-enabler/osgi.bundle b/appserver/orb/orb-enabler/osgi.bundle
new file mode 100644
index 0000000..519097a
--- /dev/null
+++ b/appserver/orb/orb-enabler/osgi.bundle
@@ -0,0 +1,18 @@
+#
+# 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
+#
+
+-exportcontents: \
+ org.glassfish.orb.admin.config; version=${project.osgi.version}
diff --git a/appserver/orb/orb-enabler/pom.xml b/appserver/orb/orb-enabler/pom.xml
new file mode 100755
index 0000000..884fbf1
--- /dev/null
+++ b/appserver/orb/orb-enabler/pom.xml
@@ -0,0 +1,60 @@
+<!--
+
+ 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.orb</groupId>
+ <artifactId>orb</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>orb-enabler</artifactId>
+ <packaging>glassfish-jar</packaging>
+
+ <name>GlassFish ORB enabler implementation</name>
+
+ <developers>
+ <developer>
+ <id>mk111283</id>
+ <name>Mahesh Kannan</name>
+ <url>http://forum.java.sun.com/profile.jspa?userID=487934</url>
+ <organization>Oracle, Inc.</organization>
+ <roles>
+ <role>lead</role>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.hk2</groupId>
+ <artifactId>hk2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>glassfish-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.core</groupId>
+ <artifactId>kernel</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java b/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java
new file mode 100644
index 0000000..03815d1
--- /dev/null
+++ b/appserver/orb/orb-enabler/src/main/java/org/glassfish/enterprise/api/enabler/ORBConnectorStartup.java
@@ -0,0 +1,159 @@
+/*
+ * 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.enterprise.api.enabler;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.glassfish.api.StartupRunLevel;
+import org.glassfish.api.admin.ServerEnvironment;
+import org.glassfish.grizzly.config.dom.NetworkListener;
+import org.glassfish.hk2.api.PostConstruct;
+import org.glassfish.hk2.runlevel.RunLevel;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import org.jvnet.hk2.annotations.Service;
+
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.v3.services.impl.DummyNetworkListener;
+import com.sun.enterprise.v3.services.impl.GrizzlyService;
+
+/**
+ */
+@Service
+@RunLevel(StartupRunLevel.VAL)
+public class ORBConnectorStartup implements PostConstruct {
+
+ // RMI-IIOP delegate constants
+ private static final String ORB_UTIL_CLASS_PROPERTY =
+ "javax.rmi.CORBA.UtilClass";
+ private static final String RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY =
+ "javax.rmi.CORBA.StubClass";
+ private static final String RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY =
+ "javax.rmi.CORBA.PortableRemoteObjectClass";
+
+ // ORB constants: OMG standard
+ private static final String OMG_ORB_CLASS_PROPERTY =
+ "org.omg.CORBA.ORBClass";
+ private static final String OMG_ORB_SINGLETON_CLASS_PROPERTY =
+ "org.omg.CORBA.ORBSingletonClass";
+
+ private static final String ORB_CLASS =
+ "com.sun.corba.ee.impl.orb.ORBImpl";
+ private static final String ORB_SINGLETON_CLASS =
+ "com.sun.corba.ee.impl.orb.ORBSingleton";
+
+ private static final String ORB_SE_CLASS =
+ "com.sun.corba.se.impl.orb.ORBImpl";
+ private static final String ORB_SE_SINGLETON_CLASS =
+ "com.sun.corba.se.impl.orb.ORBSingleton";
+
+ private static final String RMI_UTIL_CLASS =
+ "com.sun.corba.ee.impl.javax.rmi.CORBA.Util";
+ private static final String RMI_STUB_CLASS =
+ "com.sun.corba.ee.impl.javax.rmi.CORBA.StubDelegateImpl";
+ private static final String RMI_PRO_CLASS =
+ "com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject";
+
+ @Inject @Named(ServerEnvironment.DEFAULT_INSTANCE_NAME)
+ Config config;
+
+ @Inject
+ private GrizzlyService grizzlyService;
+
+ public void postConstruct()
+ {
+ setORBSystemProperties();
+ initializeLazyListener();
+ }
+
+/**
+ * Set ORB-related system properties that are required in case
+ * user code in the app server or app client container creates a
+ * new ORB instance. The default result of calling
+ * ORB.init( String[], Properties ) must be a fully usuable, consistent
+ * ORB. This avoids difficulties with having the ORB class set
+ * to a different ORB than the RMI-IIOP delegates.
+ */
+ private void setORBSystemProperties() {
+
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public java.lang.Object run() {
+ if (System.getProperty(OMG_ORB_CLASS_PROPERTY) == null) {
+ // Assume Sun ee ORB at all times.
+ // set ORB based on JVM vendor
+ //
+ // if (System.getProperty("java.vendor").equals("Sun Microsystems Inc.")) {
+ // System.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_SE_CLASS);
+ // } else {
+ // if not Sun, then set to EE class
+ System.setProperty(OMG_ORB_CLASS_PROPERTY, ORB_CLASS);
+ // }
+ }
+
+ if (System.getProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY) == null) {
+ // Assume Sun ee ORB at all times.
+ //
+ // set ORBSingleton based on JVM vendor
+ // if (System.getProperty("java.vendor").equals("Sun Microsystems Inc.")) {
+ // System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SE_SINGLETON_CLASS);
+ // } else {
+ // if not Sun, then set to EE class
+ System.setProperty(OMG_ORB_SINGLETON_CLASS_PROPERTY, ORB_SINGLETON_CLASS);
+ // }
+ }
+
+ System.setProperty(ORB_UTIL_CLASS_PROPERTY,
+ RMI_UTIL_CLASS);
+
+ System.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY,
+ RMI_STUB_CLASS);
+
+ System.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY,
+ RMI_PRO_CLASS);
+
+ return null;
+ }
+ }
+ );
+ }
+
+ /**
+ * Start Grizzly based ORB lazy listener, which is going to initialize
+ * ORB container on first request.
+ */
+ private void initializeLazyListener() {
+ final IiopService iiopService = config.getExtensionByType(IiopService.class);
+ if (iiopService != null) {
+ List<IiopListener> iiopListenerList = iiopService.getIiopListener();
+ for (IiopListener oneListener : iiopListenerList) {
+ if (Boolean.valueOf(oneListener.getEnabled()) && Boolean.valueOf(oneListener.getLazyInit())) {
+ NetworkListener dummy = new DummyNetworkListener();
+ dummy.setPort(oneListener.getPort());
+ dummy.setAddress(oneListener.getAddress());
+ dummy.setProtocol("light-weight-listener");
+ dummy.setTransport("tcp");
+ dummy.setName("iiop-service");
+ grizzlyService.createNetworkProxy(dummy);
+ }
+ }
+ }
+ }
+}
diff --git a/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopListener.java b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopListener.java
new file mode 100644
index 0000000..a9ed063
--- /dev/null
+++ b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopListener.java
@@ -0,0 +1,213 @@
+/*
+ * 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.orb.admin.config;
+
+import org.jvnet.hk2.config.Attribute;
+import org.jvnet.hk2.config.Element;
+import org.jvnet.hk2.config.Configured;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+import org.glassfish.api.admin.config.PropertiesDesc;
+import org.jvnet.hk2.config.types.Property;
+import org.jvnet.hk2.config.types.PropertyBag;
+import org.glassfish.api.admin.RestRedirects;
+import org.glassfish.api.admin.RestRedirect;
+import org.glassfish.grizzly.config.dom.Ssl;
+import static org.glassfish.config.support.Constants.NAME_REGEX;
+import com.sun.enterprise.util.LocalStringManagerImpl;
+import org.glassfish.quality.ToDo;
+
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.Payload;
+
+/**
+ *
+ */
+
+/* @XmlType(name = "", propOrder = {
+ "ssl",
+ "property"
+}) */
+
+@Configured
+@RestRedirects({
+ @RestRedirect(opType = RestRedirect.OpType.POST, commandName = "create-iiop-listener"),
+ @RestRedirect(opType = RestRedirect.OpType.DELETE, commandName = "delete-iiop-listener")
+})
+public interface IiopListener extends ConfigBeanProxy, PropertyBag, Payload {
+
+ final static String PORT_PATTERN = "\\$\\{[\\p{L}\\p{N}_][\\p{L}\\p{N}\\-_./;#]*\\}"
+ + "|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]"
+ + "|[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]"
+ + "|65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5]";
+
+
+ /**
+ * Gets the value of the id property.
+ *
+ * if false, a configured listener, is disabled
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute(key=true)
+ @NotNull
+ @Pattern(regexp=NAME_REGEX)
+ String getId();
+
+ /**
+ * Sets the value of the id property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ void setId(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the address property.
+ *
+ * ip V6 or V4 address or hostname
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute
+ @NotNull
+ String getAddress();
+
+ /**
+ * Sets the value of the address property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ void setAddress(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the port property.
+ *
+ * Port number
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="1072")
+ @Pattern(regexp=PORT_PATTERN,
+ message="{port-pattern}",
+ payload=IiopListener.class)
+ String getPort();
+
+ /**
+ * Sets the value of the port property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ void setPort(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the securityEnabled property.
+ *
+ * Determines whether the iiop listener runs SSL. You can turn
+ * SSL2 or SSL3 on or off and set ciphers using an ssl element
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="false")
+ String getSecurityEnabled();
+
+ /**
+ * Sets the value of the securityEnabled property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ void setSecurityEnabled(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the enabled property.
+ *
+ * if false, a configured listener, is disabled
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="true",dataType=Boolean.class)
+ String getEnabled();
+
+ /**
+ * Sets the value of the enabled property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ void setEnabled(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the ssl property.
+ *
+ * Specifies optional SSL configuration. Note that the ssl2 ciphers are not
+ * supported for iiop, and therefore must be disabled
+ *
+ * @return possible object is
+ * {@link Ssl }
+ */
+ @Element
+ Ssl getSsl();
+
+ /**
+ * Sets the value of the ssl property.
+ *
+ * @param value allowed object is
+ * {@link Ssl }
+ */
+ void setSsl(Ssl value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of lazyInit property
+ *
+ * if false, this listener is started during server startup
+ *
+ * @return true or false
+ */
+ @Attribute(defaultValue="false", dataType=Boolean.class)
+ String getLazyInit();
+
+ /**
+ * Sets the value of lazyInit property
+ *
+ * Specify is this listener should be started as part of server startup or not
+ *
+ * @param value true if the listener is to be started lazily; false otherwise
+ */
+ void String(boolean value);
+
+ /**
+ Properties as per {@link org.jvnet.hk2.config.types.PropertyBag}
+ */
+ @ToDo(priority=ToDo.Priority.IMPORTANT, details="Provide PropertyDesc for legal props" )
+ @PropertiesDesc(props={})
+ @Element
+ List<Property> getProperty();
+}
diff --git a/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopService.java b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopService.java
new file mode 100644
index 0000000..7d6b287
--- /dev/null
+++ b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/IiopService.java
@@ -0,0 +1,118 @@
+/*
+ * 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.orb.admin.config;
+
+import com.sun.enterprise.config.serverbeans.SslClientConfig;
+import org.glassfish.api.admin.config.ConfigExtension;
+import org.jvnet.hk2.config.Attribute;
+import org.jvnet.hk2.config.Configured;
+import org.jvnet.hk2.config.Element;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+
+/* @XmlType(name = "", propOrder = {
+ "orb",
+ "sslClientConfig",
+ "iiopListener"
+}) */
+
+@Configured
+//@CustomConfiguration(baseConfigurationFileName = "iiop-module-conf.xml")
+//@HasCustomizationTokens
+public interface IiopService extends ConfigBeanProxy, ConfigExtension {
+
+
+ /**
+ * Gets the value of the clientAuthenticationRequired property.
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="false",dataType=Boolean.class)
+ public String getClientAuthenticationRequired();
+
+ /**
+ * Sets the value of the clientAuthenticationRequired property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setClientAuthenticationRequired(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the orb property.
+ *
+ * @return possible object is
+ * {@link Orb }
+ */
+ @Element(required=true)
+ public Orb getOrb();
+
+ /**
+ * Sets the value of the orb property.
+ *
+ * @param value allowed object is
+ * {@link Orb }
+ */
+ public void setOrb(Orb value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the sslClientConfig property.
+ *
+ * @return possible object is
+ * {@link SslClientConfig }
+ */
+ @Element
+ public SslClientConfig getSslClientConfig();
+
+ /**
+ * Sets the value of the sslClientConfig property.
+ *
+ * @param value allowed object is
+ * {@link SslClientConfig }
+ */
+ public void setSslClientConfig(SslClientConfig value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the iiopListener property.
+ * <p/>
+ * <p/>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the iiopListener property.
+ * <p/>
+ * <p/>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getIiopListener().add(newItem);
+ * </pre>
+ * <p/>
+ * <p/>
+ * <p/>
+ * Objects of the following type(s) are allowed in the list
+ * {@link IiopListener }
+ */
+ @Element
+ public List<IiopListener> getIiopListener();
+
+
+
+}
diff --git a/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/Orb.java b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/Orb.java
new file mode 100644
index 0000000..0905b07
--- /dev/null
+++ b/appserver/orb/orb-enabler/src/main/java/org/glassfish/orb/admin/config/Orb.java
@@ -0,0 +1,120 @@
+/*
+ * 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.orb.admin.config;
+
+import org.jvnet.hk2.config.Attribute;
+import org.jvnet.hk2.config.ConfigBeanProxy;
+import org.jvnet.hk2.config.Configured;
+import org.jvnet.hk2.config.Element;
+import org.jvnet.hk2.config.types.Property;
+import org.jvnet.hk2.config.types.PropertyBag;
+
+import java.beans.PropertyVetoException;
+import java.util.List;
+
+import org.glassfish.api.admin.config.PropertiesDesc;
+
+import org.glassfish.quality.ToDo;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Min;
+
+/**
+ * Orb Configuration properties
+ */
+
+/* @XmlType(name = "", propOrder = {
+ "property"
+}) */
+
+@Configured
+public interface Orb extends ConfigBeanProxy, PropertyBag {
+
+ /**
+ * Gets the value of the useThreadPoolIds property.
+ * Specifies a comma-separated list of thread-pool ids.
+ *
+ * This would refer to the thread-pool-id(s) defined in the thread-pool
+ * sub-element of thread-pool-config element in domain.xml. These would be
+ * the threadpool(s) used by the ORB. More than one thread-pool-id(s) could
+ * be specified by using commas to separate the names
+ * e.g. orb-thread-pool-1, orb-thread-pool-2
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute
+ @NotNull
+ public String getUseThreadPoolIds();
+
+ /**
+ * Sets the value of the useThreadPoolIds property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setUseThreadPoolIds(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the messageFragmentSize property.
+ *
+ * GIOPv1.2 messages larger than this will get fragmented.
+ * Minimum value is 128.
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="1024")
+ @Min(value=128)
+ public String getMessageFragmentSize();
+
+ /**
+ * Sets the value of the messageFragmentSize property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setMessageFragmentSize(String value) throws PropertyVetoException;
+
+ /**
+ * Gets the value of the maxConnections property.
+ *
+ * Maximum number of incoming connections, on all listeners
+ *
+ * @return possible object is
+ * {@link String }
+ */
+ @Attribute (defaultValue="1024",dataType=Integer.class)
+ @Min(value=0)
+ public String getMaxConnections();
+
+ /**
+ * Sets the value of the maxConnections property.
+ *
+ * @param value allowed object is
+ * {@link String }
+ */
+ public void setMaxConnections(String value) throws PropertyVetoException;
+
+ /**
+ Properties as per {@link org.jvnet.hk2.config.types.PropertyBag}
+ */
+ @ToDo(priority=ToDo.Priority.IMPORTANT, details="Provide PropertyDesc for legal props" )
+ @PropertiesDesc(props={})
+ @Element
+ List<Property> getProperty();
+}
diff --git a/appserver/orb/orb-iiop/exclude.xml b/appserver/orb/orb-iiop/exclude.xml
new file mode 100644
index 0000000..37be0d4
--- /dev/null
+++ b/appserver/orb/orb-iiop/exclude.xml
@@ -0,0 +1,28 @@
+<!--
+
+ Copyright (c) 2011, 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
+
+-->
+
+<FindBugsFilter>
+ <!--
+ A Servant is always a Tie, but the compiler can't know that.
+ -->
+ <Match>
+ <Class name="org.glassfish.enterprise.iiop.impl.POARemoteReferenceFactory"/>
+ <Method name="postinvoke"/>
+ <Bug pattern="BC_UNCONFIRMED_CAST"/>
+ </Match>
+</FindBugsFilter>
diff --git a/appserver/orb/orb-iiop/osgi.bundle b/appserver/orb/orb-iiop/osgi.bundle
new file mode 100644
index 0000000..0f4e046
--- /dev/null
+++ b/appserver/orb/orb-iiop/osgi.bundle
@@ -0,0 +1,25 @@
+#
+# 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
+#
+
+
+-exportcontents: \
+ org.glassfish.enterprise.iiop.impl; version=${project.osgi.version}
+
+ORB-Class-Provider: org.glassfish.enterprise.iiop.impl.PEORBConfigurator \
+ org.glassfish.enterprise.iiop.impl.GlassFishORBInitializer
+
+
+
diff --git a/appserver/orb/orb-iiop/pom.xml b/appserver/orb/orb-iiop/pom.xml
new file mode 100755
index 0000000..ce66b45
--- /dev/null
+++ b/appserver/orb/orb-iiop/pom.xml
@@ -0,0 +1,127 @@
+<!--
+
+ 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.orb</groupId>
+ <artifactId>orb</artifactId>
+ <version>5.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>orb-iiop</artifactId>
+ <packaging>glassfish-jar</packaging>
+
+ <name>GlassFish ORB interface layer implementation</name>
+ <developers>
+ <developer>
+ <id>mk111283</id>
+ <name>Mahesh Kannan</name>
+ <url>http://forum.java.sun.com/profile.jspa?userID=487934</url>
+ <organization>Oracle, Inc.</organization>
+ <roles>
+ <role>lead</role>
+ <role>developer</role>
+ </roles>
+ </developer>
+ </developers>
+
+ <properties>
+ <findbugs.exclude>${project.basedir}/exclude.xml</findbugs.exclude>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.main.cluster</groupId>
+ <artifactId>gms-bootstrap</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.shoal</groupId>
+ <artifactId>shoal-gms-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.hk2</groupId>
+ <artifactId>hk2-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.deployment</groupId>
+ <artifactId>dol</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.corba</groupId>
+ <artifactId>glassfish-corba-omgapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.corba</groupId>
+ <artifactId>glassfish-corba-internal-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.corba</groupId>
+ <artifactId>glassfish-corba-orb</artifactId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.pfl</groupId>
+ <artifactId>pfl-basic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.pfl</groupId>
+ <artifactId>pfl-dynamic</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.orb</groupId>
+ <artifactId>orb-connector</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.orb</groupId>
+ <artifactId>orb-enabler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>common-util</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.main.common</groupId>
+ <artifactId>internal-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.main.common</groupId>
+ <artifactId>glassfish-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.ejb</groupId>
+ <artifactId>javax.ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.annotations</groupId>
+ <artifactId>logging-annotation-processor</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2Policy.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2Policy.java
new file mode 100644
index 0000000..57628a7
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2Policy.java
@@ -0,0 +1,47 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+//TODO: This class is in an Impl dir, we probably need to create a
+//Contract in the orb-connector module that can be used inside security/ejb.security
+public class CSIv2Policy extends org.omg.CORBA.LocalObject
+ implements org.omg.CORBA.Policy {
+
+ private EjbDescriptor ejbDescriptor;
+
+ public CSIv2Policy(EjbDescriptor ejbDescriptor) {
+ this.ejbDescriptor = ejbDescriptor;
+ }
+
+ public int policy_type() {
+ return POARemoteReferenceFactory.CSIv2_POLICY_TYPE;
+ }
+
+ public org.omg.CORBA.Policy copy() {
+ return new CSIv2Policy(ejbDescriptor);
+ }
+
+ public void destroy() {
+ }
+
+ public EjbDescriptor getEjbDescriptor() {
+ return ejbDescriptor;
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2SSLTaggedComponentHandlerImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2SSLTaggedComponentHandlerImpl.java
new file mode 100644
index 0000000..74c8124
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/CSIv2SSLTaggedComponentHandlerImpl.java
@@ -0,0 +1,186 @@
+/*
+ * 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
+ */
+
+//
+// Created : 2005 Jul 29 (Fri) 08:23:33 by Harold Carr.
+// Last Modified : 2005 Aug 31 (Wed) 19:57:12 by Harold Carr.
+//
+
+package org.glassfish.enterprise.iiop.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.omg.CORBA.ORBPackage.InvalidName;
+import org.omg.IOP.TaggedComponent;
+import org.omg.PortableInterceptor.IORInfo;
+
+import com.sun.corba.ee.spi.folb.ClusterInstanceInfo;
+import com.sun.corba.ee.impl.folb.CSIv2SSLTaggedComponentHandler;
+import com.sun.corba.ee.spi.ior.IOR;
+import com.sun.corba.ee.spi.orb.DataCollector;
+import com.sun.corba.ee.spi.orb.ORB;
+import com.sun.corba.ee.spi.orb.ORBConfigurator;
+import com.sun.corba.ee.spi.transport.SocketInfo;
+
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.corba.ee.spi.ior.iiop.IIOPProfileTemplate ;
+import com.sun.corba.ee.spi.ior.iiop.IIOPAddress ;
+
+// END imports for getSocketInfo code
+
+import com.sun.logging.LogDomains;
+//
+import org.glassfish.enterprise.iiop.api.IIOPSSLUtil;
+import org.glassfish.internal.api.Globals;
+
+/**
+ * @author Harold Carr
+ */
+public class CSIv2SSLTaggedComponentHandlerImpl
+ extends org.omg.CORBA.LocalObject
+ implements CSIv2SSLTaggedComponentHandler,
+ ORBConfigurator
+{
+ private static final Logger _logger = LogDomains.getLogger(
+ CSIv2SSLTaggedComponentHandlerImpl.class, LogDomains.CORBA_LOGGER);
+
+ private final String baseMsg =
+ CSIv2SSLTaggedComponentHandlerImpl.class.getName();
+
+ private ORB orb;
+
+ ////////////////////////////////////////////////////
+ //
+ // CSIv2SSLTaggedComponentHandler
+ //
+
+ @Override
+ public TaggedComponent insert(IORInfo iorInfo,
+ List<ClusterInstanceInfo> clusterInstanceInfo)
+ {
+ try {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "{0}.insert->:", baseMsg);
+ }
+
+ List<com.sun.corba.ee.spi.folb.SocketInfo> socketInfos =
+ new ArrayList<com.sun.corba.ee.spi.folb.SocketInfo>();
+ for(ClusterInstanceInfo clInstInfo : clusterInstanceInfo){
+ for (com.sun.corba.ee.spi.folb.SocketInfo sinfo :
+ clInstInfo.endpoints()) {
+ if (sinfo.type().equals("SSL")
+ || sinfo.type().equals("SSL_MUTUALAUTH")){
+ socketInfos.add(sinfo);
+ }
+ }
+ }
+ IIOPSSLUtil sslUtil = null;
+ if (Globals.getDefaultHabitat() != null) {
+ sslUtil =
+ Globals.getDefaultHabitat().getService(IIOPSSLUtil.class);
+ return sslUtil.createSSLTaggedComponent(iorInfo, socketInfos);
+ } else {
+ return null;
+ }
+
+ } finally {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "{0}.insert<-: {1}",
+ new Object[]{baseMsg, null});
+ }
+ }
+ }
+
+ @Override
+ public List<SocketInfo> extract(IOR ior)
+ {
+ List<SocketInfo> socketInfo = null;
+ try {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "{0}.extract->:", baseMsg);
+ }
+
+ // IIOPProfileTemplate iiopProfileTemplate = (IIOPProfileTemplate)ior.getProfile().getTaggedProfileTemplate();
+ // IIOPAddress primary = iiopProfileTemplate.getPrimaryAddress() ;
+ // String host = primary.getHost().toLowerCase(Locale.ENGLISH);
+
+ IIOPSSLUtil sslUtil = null;
+ if (Globals.getDefaultHabitat() != null) {
+ sslUtil = Globals.getDefaultHabitat().getService(
+ IIOPSSLUtil.class);
+ socketInfo = (List<SocketInfo>)sslUtil.getSSLPortsAsSocketInfo(
+ ior);
+ }
+
+ if (socketInfo == null) {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "{0}.extract: did not find SSL SocketInfo", baseMsg);
+ }
+ } else {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "{0}.extract: found SSL socketInfo", baseMsg);
+ }
+ }
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "{0}.extract: Connection Context", baseMsg);
+ }
+ } catch ( Exception ex ) {
+ _logger.log(Level.WARNING, "Exception getting SocketInfo", ex);
+ } finally {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "{0}.extract<-: {1}", new Object[]{baseMsg, socketInfo});
+ }
+ }
+ return socketInfo;
+ }
+
+ ////////////////////////////////////////////////////
+ //
+ // ORBConfigurator
+ //
+
+ @Override
+ public void configure(DataCollector collector, ORB orb)
+ {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, ".configure->:");
+ }
+
+ this.orb = orb;
+ try {
+ orb.register_initial_reference(
+ ORBConstants.CSI_V2_SSL_TAGGED_COMPONENT_HANDLER,
+ this);
+ } catch (InvalidName e) {
+ _logger.log(Level.WARNING, ".configure: ", e);
+ }
+
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, ".configure<-:");
+ }
+ }
+}
+
+// End of file.
+
+
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBFactoryImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBFactoryImpl.java
new file mode 100644
index 0000000..8686616
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBFactoryImpl.java
@@ -0,0 +1,116 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.enterprise.ee.cms.core.GroupManagementService;
+import org.glassfish.enterprise.iiop.api.GlassFishORBFactory;
+import org.glassfish.enterprise.iiop.util.IIOPUtils;
+import javax.inject.Inject;
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.PostConstruct;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.omg.CORBA.ORB;
+import org.omg.PortableInterceptor.ServerRequestInfo;
+
+import java.util.Properties;
+import org.glassfish.gms.bootstrap.GMSAdapterService;
+
+/**
+ * @author Mahesh Kannan
+ * Date: Jan 15, 2009
+ */
+@Service
+public class GlassFishORBFactoryImpl
+ implements GlassFishORBFactory, PostConstruct {
+
+ @Inject
+ private ServiceLocator habitat;
+
+ @Inject
+ private IIOPUtils iiopUtils;
+
+ private GlassFishORBManager gfORBManager = null;
+
+ @Override
+ public void postConstruct() {
+ gfORBManager = new GlassFishORBManager(habitat);
+
+ IIOPUtils.setInstance(iiopUtils);
+ //iiopUtils.setGlassFishORBManager(gfORBManager);
+ }
+
+ @Override
+ public int getOTSPolicyType() {
+ return POARemoteReferenceFactory.OTS_POLICY_TYPE;
+ }
+
+ @Override
+ public int getCSIv2PolicyType() {
+ return POARemoteReferenceFactory.CSIv2_POLICY_TYPE;
+ }
+
+ @Override
+ public ORB createORB(Properties props) {
+ // TODO change this to a create call
+ return gfORBManager.getORB(props);
+ }
+
+ @Override
+ public Properties getCSIv2Props() {
+ return gfORBManager.getCSIv2Props();
+ }
+
+ @Override
+ public void setCSIv2Prop(String name, String value) {
+ gfORBManager.setCSIv2Prop(name, value);
+ }
+
+ @Override
+ public int getORBInitialPort() {
+ return gfORBManager.getORBInitialPort();
+ }
+
+ @Override
+ public String getORBHost(ORB orb) {
+ return ((com.sun.corba.ee.spi.orb.ORB) orb).getORBData().getORBInitialHost();
+ }
+
+ @Override
+ public int getORBPort(ORB orb) {
+ return ((com.sun.corba.ee.spi.orb.ORB) orb).getORBData().getORBInitialPort();
+ }
+
+ /**
+ * Returns true, if the incoming call is a EJB method call.
+ * This checks for is_a calls and ignores those calls. In callflow analysis
+ * when a component looks up another component, this lookup should be
+ * considered part of the same call coming in.
+ * Since a lookup triggers the iiop codebase, it will fire a new request start.
+ * With this check, we consider the calls that are only new incoming ejb
+ * method calls as new request starts.
+ */
+ @Override
+ public boolean isEjbCall (ServerRequestInfo sri) {
+ return (gfORBManager.isEjbAdapterName(sri.adapter_name()) &&
+ (!gfORBManager.isIsACall(sri.operation())));
+ }
+
+ @Override
+ public String getIIOPEndpoints() {
+ return gfORBManager.getIIOPEndpoints() ;
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java
new file mode 100644
index 0000000..70cc245
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBInitializer.java
@@ -0,0 +1,131 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.logging.LogDomains;
+import org.glassfish.enterprise.iiop.api.IIOPInterceptorFactory;
+import org.glassfish.enterprise.iiop.util.IIOPUtils;
+import org.omg.IOP.Codec;
+import org.omg.IOP.CodecFactory;
+import org.omg.IOP.ENCODING_CDR_ENCAPS;
+import org.omg.IOP.Encoding;
+import org.omg.PortableInterceptor.ClientRequestInterceptor;
+import org.omg.PortableInterceptor.ORBInitializer;
+import org.omg.PortableInterceptor.ServerRequestInterceptor;
+
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This file implements an initializer class for all portable interceptors
+ * used in the J2EE RI (currently security and transactions).
+ * It registers the IOR, client and server request interceptors.
+ *
+ * @author Vivek Nagar
+ * @author Mahesh Kannan
+ *
+ */
+
+public class GlassFishORBInitializer extends org.omg.CORBA.LocalObject
+ implements ORBInitializer {
+ private static final Logger _logger =
+ LogDomains.getLogger(GlassFishORBInitializer.class, LogDomains.CORBA_LOGGER);
+
+ private static void fineLog( String fmt, Object... args ) {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, fmt, args ) ;
+ }
+ }
+
+ public GlassFishORBInitializer() {
+ /*
+ //Ken feels that adding the property to orbInitProperties
+ // is better than setting System properties
+ try {
+ System.setProperty(
+ com.sun.jts.pi.InterceptorImpl.CLIENT_POLICY_CHECKING,
+ String.valueOf(false));
+ } catch (Exception ex) {
+ _logger.log(Level.WARNING, "iiop.readproperty_exception", ex);
+ }
+ */
+ }
+
+ /**
+ * This method is called during ORB initialization.
+ *
+ * @param info object that provides initialization attributes
+ * and operations by which interceptors are registered.
+ */
+ @Override
+ public void pre_init(org.omg.PortableInterceptor.ORBInitInfo info) {
+ }
+
+ /**
+ * This method is called during ORB initialization.
+ *
+ * @param info object that provides initialization attributes
+ * and operations by which interceptors are registered.
+ */
+ @Override
+ public void post_init(org.omg.PortableInterceptor.ORBInitInfo info) {
+ Codec codec = null;
+
+ fineLog( "J2EE Initializer post_init");
+ fineLog( "Creating Codec for CDR encoding");
+
+ CodecFactory cf = info.codec_factory();
+
+ byte major_version = 1;
+ byte minor_version = 2;
+ Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value,
+ major_version, minor_version);
+ try {
+ codec = cf.create_codec(encoding);
+
+ IIOPUtils iiopUtils = IIOPUtils.getInstance();
+ Collection<IIOPInterceptorFactory> interceptorFactories =
+ iiopUtils.getAllIIOPInterceptrFactories();
+
+ for (IIOPInterceptorFactory factory : interceptorFactories) {
+ fineLog( "Processing interceptor factory: {0}", factory);
+
+ ClientRequestInterceptor clientReq =
+ factory.createClientRequestInterceptor(info, codec);
+ ServerRequestInterceptor serverReq =
+ factory.createServerRequestInterceptor(info, codec);
+
+ if (clientReq != null) {
+ fineLog( "Registering client interceptor: {0}", clientReq);
+ info.add_client_request_interceptor(clientReq);
+ }
+ if (serverReq != null) {
+ fineLog( "Registering server interceptor: {0}", serverReq);
+ info.add_server_request_interceptor(serverReq);
+ }
+ }
+
+ } catch (Exception e) {
+ if (_logger.isLoggable(Level.WARNING)) {
+ _logger.log(Level.WARNING, "Exception registering interceptors", e ) ;
+ }
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+}
+
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java
new file mode 100644
index 0000000..c6f38b0
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GlassFishORBManager.java
@@ -0,0 +1,918 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.impl.javax.rmi.CORBA.StubDelegateImpl;
+import com.sun.corba.ee.impl.javax.rmi.CORBA.Util;
+import com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject;
+import com.sun.corba.ee.impl.orb.ORBImpl;
+import com.sun.corba.ee.impl.orb.ORBSingleton;
+import com.sun.corba.ee.spi.oa.rfm.ReferenceFactoryManager;
+import com.sun.corba.ee.spi.osgi.ORBFactory;
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.corba.ee.spi.orb.ORB ;
+import com.sun.corba.ee.impl.folb.InitialGroupInfoService ;
+
+import com.sun.logging.LogDomains;
+
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.Orb;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.config.serverbeans.SslClientConfig;
+
+import org.glassfish.grizzly.config.dom.Ssl;
+import org.glassfish.hk2.api.ServiceLocator;
+
+import java.util.Arrays;
+
+import org.glassfish.api.admin.ProcessEnvironment;
+import org.glassfish.api.admin.ProcessEnvironment.ProcessType;
+import org.glassfish.enterprise.iiop.api.GlassFishORBLifeCycleListener;
+import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
+import org.glassfish.enterprise.iiop.util.IIOPUtils;
+
+import com.sun.enterprise.util.Utility;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.sun.enterprise.module.Module;
+import com.sun.enterprise.module.ModulesRegistry;
+
+import org.jvnet.hk2.config.types.Property;
+
+/**
+ * This class initializes the ORB with a list of (standard) properties
+ * and provides a few convenience methods to get the ORB etc.
+ */
+
+public final class GlassFishORBManager {
+ static final Logger logger = LogDomains.getLogger(
+ GlassFishORBManager.class, LogDomains.CORBA_LOGGER);
+
+ private static void fineLog( String fmt, Object... args ) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, fmt, args ) ;
+ }
+ }
+
+ private static void finestLog( String fmt, Object... args ) {
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.log(Level.FINEST, fmt, args ) ;
+ }
+ }
+
+ private static final Properties EMPTY_PROPERTIES = new Properties();
+
+ // Various pluggable classes defined in the app server that are used
+ // by the ORB.
+ private static final String ORB_CLASS =
+ ORBImpl.class.getName() ;
+ private static final String ORB_SINGLETON_CLASS =
+ ORBSingleton.class.getName() ;
+
+ private static final String ORB_SE_CLASS =
+ "com.sun.corba.se.impl.orb.ORBImpl";
+ private static final String ORB_SE_SINGLETON_CLASS =
+ "com.sun.corba.se.impl.orb.ORBSingleton";
+
+ private static final String PEORB_CONFIG_CLASS =
+ PEORBConfigurator.class.getName() ;
+ private static final String IIOP_SSL_SOCKET_FACTORY_CLASS =
+ IIOPSSLSocketFactory.class.getName() ;
+ private static final String RMI_UTIL_CLASS =
+ Util.class.getName() ;
+ private static final String RMI_STUB_CLASS =
+ StubDelegateImpl.class.getName() ;
+ private static final String RMI_PRO_CLASS =
+ PortableRemoteObject.class.getName() ;
+
+ // JNDI constants
+ public static final String JNDI_PROVIDER_URL_PROPERTY =
+ "java.naming.provider.url";
+ public static final String JNDI_CORBA_ORB_PROPERTY =
+ "java.naming.corba.orb";
+
+ // RMI-IIOP delegate constants
+ public static final String ORB_UTIL_CLASS_PROPERTY =
+ "javax.rmi.CORBA.UtilClass";
+ public static final String RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY =
+ "javax.rmi.CORBA.StubClass";
+ public static final String RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY =
+ "javax.rmi.CORBA.PortableRemoteObjectClass";
+
+ // ORB constants: OMG standard
+ public static final String OMG_ORB_CLASS_PROPERTY =
+ "org.omg.CORBA.ORBClass";
+ public static final String OMG_ORB_SINGLETON_CLASS_PROPERTY =
+ "org.omg.CORBA.ORBSingletonClass";
+
+ // ORB constants: Sun specific
+ public static final String SUN_ORB_SOCKET_FACTORY_CLASS_PROPERTY =
+ ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY;
+
+ // ORB configuration constants
+ private static final String DEFAULT_SERVER_ID = "100";
+ private static final String ACC_DEFAULT_SERVER_ID = "101";
+ private static final String USER_DEFINED_ORB_SERVER_ID_PROPERTY =
+ "org.glassfish.orb.iiop.orbserverid";
+
+ private static final String DEFAULT_MAX_CONNECTIONS = "1024";
+ private static final String GLASSFISH_INITIALIZER =
+ GlassFishORBInitializer.class.getName() ;
+
+ private static final String SUN_GIOP_DEFAULT_FRAGMENT_SIZE = "1024";
+ private static final String SUN_GIOP_DEFAULT_BUFFER_SIZE = "1024";
+
+ public static final String DEFAULT_ORB_INIT_HOST = "localhost";
+
+ // This will only apply for stand-alone java clients, since
+ // in the server the orb port comes from domain.xml, and in an appclient
+ // the port is set from the sun-acc.xml. It's set to the same
+ // value as the default orb port in domain.xml as a convenience.
+ // That way the code only needs to do a "new InitialContext()"
+ // without setting any jvm properties and the naming service will be
+ // found. Of course, if the port was changed in domain.xml for some
+ // reason the code will still have to set org.omg.CORBA.ORBInitialPort.
+ public static final String DEFAULT_ORB_INIT_PORT = "3700";
+
+ private static final String ORB_SSL_STANDALONE_CLIENT_REQUIRED =
+ "com.sun.CSIV2.ssl.standalone.client.required";
+
+ // We need this to get the ORB monitoring set up correctly
+ public static final String S1AS_ORB_ID = "S1AS-ORB";
+
+ // Set in constructor
+ private ServiceLocator services;
+ private IIOPUtils iiopUtils;
+
+ // the ORB instance
+ private ORB orb = null;
+
+ // The ReferenceFactoryManager from the orb.
+ private ReferenceFactoryManager rfm = null;
+
+ private int orbInitialPort = -1;
+
+ private List<IiopListener> iiopListeners = null;
+ private Orb orbBean = null;
+ private IiopService iiopService = null;
+
+ private Properties csiv2Props = new Properties();
+
+ private ProcessType processType;
+
+ private IiopFolbGmsClient gmsClient ;
+
+ /**
+ * Keep this class private to the package. Eventually we need to
+ * move all public statics or change them to package private.
+ * All external orb/iiop access should go through orb-connector module
+ */
+ GlassFishORBManager(ServiceLocator h ) {
+ fineLog( "GlassFishORBManager: Constructing GlassFishORBManager: h {0}",
+ h ) ;
+ services = h;
+
+ iiopUtils = services.getService(IIOPUtils.class);
+
+ ProcessEnvironment processEnv = services.getService(
+ ProcessEnvironment.class);
+
+ processType = processEnv.getProcessType();
+
+ initProperties();
+ }
+
+ /**
+ * Returns whether an adapterName (from ServerRequestInfo.adapter_name)
+ * represents an EJB or not.
+ * @param adapterName The adapter name
+ * @return whether this adapter is an EJB or not
+ */
+ public boolean isEjbAdapterName(String[] adapterName) {
+ boolean result = false;
+ if (rfm != null) {
+ result = rfm.isRfmName(adapterName);
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns whether the operationName corresponds to an "is_a" call
+ * or not (used to implement PortableRemoteObject.narrow.
+ */
+ boolean isIsACall(String operationName) {
+ return operationName.equals("_is_a");
+ }
+
+ /**
+ * Return the shared ORB instance for the app server.
+ * If the ORB is not already initialized, it is created
+ * with the standard server properties, which can be
+ * overridden by Properties passed in the props argument.
+ */
+ synchronized ORB getORB(Properties props) {
+
+ try {
+ finestLog( "GlassFishORBManager.getORB->: {0}", orb);
+
+ if (orb == null) {
+ initORB(props);
+ }
+
+ return orb;
+ } finally {
+ finestLog( "GlassFishORBManager.getORB<-: {0}", orb);
+ }
+ }
+
+ Properties getCSIv2Props() {
+ // Return a copy of the CSIv2Props
+ return new Properties(csiv2Props);
+ }
+
+ void setCSIv2Prop(String name, String value) {
+ csiv2Props.setProperty(name, value);
+ }
+
+ int getORBInitialPort() {
+ return orbInitialPort;
+ }
+
+ private void initProperties() {
+ fineLog( "GlassFishORBManager: initProperties: processType {0}",
+ processType ) ;
+
+ if (processType != ProcessType.ACC) {
+ String sslClientRequired = System.getProperty(
+ ORB_SSL_STANDALONE_CLIENT_REQUIRED);
+ if (sslClientRequired != null
+ && sslClientRequired.equals("true")) {
+ csiv2Props.put(
+ GlassFishORBHelper.ORB_SSL_CLIENT_REQUIRED, "true");
+ }
+ }
+
+ if(!processType.isServer()) {
+ // No access to domain.xml. Just init properties.
+ // In this case iiopListener beans will be null.
+ checkORBInitialPort(EMPTY_PROPERTIES);
+
+
+ } else {
+ iiopService = iiopUtils.getIiopService();
+ iiopListeners = iiopService.getIiopListener() ;
+ assert iiopListeners != null ;
+
+ // checkORBInitialPort looks at iiopListenerBeans, if present
+ checkORBInitialPort(EMPTY_PROPERTIES);
+
+ orbBean = iiopService.getOrb();
+ assert (orbBean != null);
+
+ // Initialize IOR security config for non-EJB CORBA objects
+ //iiopServiceBean.isClientAuthenticationRequired()));
+ csiv2Props.put(GlassFishORBHelper.ORB_CLIENT_AUTH_REQUIRED,
+ String.valueOf(
+ iiopService.getClientAuthenticationRequired()));
+
+ // If there is at least one non-SSL listener, then it means
+ // SSL is not required for CORBA objects.
+ boolean corbaSSLRequired = true;
+ for (IiopListener bean : iiopListeners) {
+ if (bean.getSsl() == null) {
+ corbaSSLRequired = false ;
+ break ;
+ }
+ }
+
+ csiv2Props.put(GlassFishORBHelper.ORB_SSL_SERVER_REQUIRED,
+ String.valueOf( corbaSSLRequired));
+ }
+
+ }
+
+ /**
+ * Set ORB-related system properties that are required in case
+ * user code in the app server or app client container creates a
+ * new ORB instance. The default result of calling
+ * ORB.init( String[], Properties ) must be a fully usuable, consistent
+ * ORB. This avoids difficulties with having the ORB class set
+ * to a different ORB than the RMI-IIOP delegates.
+ */
+ private void setORBSystemProperties() {
+ java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction<Object>() {
+ @Override
+ public java.lang.Object run() {
+ if (System.getProperty(OMG_ORB_CLASS_PROPERTY) == null) {
+ // set ORB based on JVM vendor
+ if (System.getProperty("java.vendor").equals(
+ "Sun Microsystems Inc.")) {
+ System.setProperty(OMG_ORB_CLASS_PROPERTY,
+ ORB_SE_CLASS);
+ } else {
+ // if not Sun, then set to EE class
+ System.setProperty(OMG_ORB_CLASS_PROPERTY,
+ ORB_CLASS);
+ }
+ }
+
+ if (System.getProperty(
+ OMG_ORB_SINGLETON_CLASS_PROPERTY) == null) {
+ // set ORBSingleton based on JVM vendor
+ if (System.getProperty("java.vendor").equals(
+ "Sun Microsystems Inc.")) {
+ System.setProperty(
+ OMG_ORB_SINGLETON_CLASS_PROPERTY,
+ ORB_SE_SINGLETON_CLASS);
+ } else {
+ // if not Sun, then set to EE class
+ System.setProperty(
+ OMG_ORB_SINGLETON_CLASS_PROPERTY,
+ ORB_SINGLETON_CLASS);
+ }
+ }
+
+ System.setProperty(ORB_UTIL_CLASS_PROPERTY,
+ RMI_UTIL_CLASS);
+
+ System.setProperty(RMIIIOP_STUB_DELEGATE_CLASS_PROPERTY,
+ RMI_STUB_CLASS);
+
+ System.setProperty(RMIIIOP_PRO_DELEGATE_CLASS_PROPERTY,
+ RMI_PRO_CLASS);
+
+ return null;
+ }
+ }
+ );
+ }
+
+ /**
+ * Set the ORB properties for IIOP failover and load balancing.
+ */
+ private void setFOLBProperties(Properties orbInitProperties) {
+
+ orbInitProperties.put(ORBConstants.RFM_PROPERTY, "dummy");
+
+ orbInitProperties.put(ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY,
+ IIOP_SSL_SOCKET_FACTORY_CLASS);
+
+ // ClientGroupManager.
+ // Registers itself as
+ // ORBInitializer (that registers ClientRequestInterceptor)
+ // IIOPPrimaryToContactInfo
+ // IORToSocketInfo
+ orbInitProperties.setProperty(
+ ORBConstants.USER_CONFIGURATOR_PREFIX
+ + "com.sun.corba.ee.impl.folb.ClientGroupManager",
+ "dummy");
+
+ // This configurator registers the CSIv2SSLTaggedComponentHandler
+ orbInitProperties.setProperty(
+ ORBConstants.USER_CONFIGURATOR_PREFIX
+ + CSIv2SSLTaggedComponentHandlerImpl.class.getName(),"dummy");
+
+
+ if (processType.isServer()) {
+ gmsClient = new IiopFolbGmsClient( services ) ;
+
+ if (gmsClient.isGMSAvailable()) {
+ fineLog( "GMS available and enabled - doing EE initialization");
+
+ // Register ServerGroupManager.
+ // Causes it to register itself as an ORBInitializer
+ // that then registers it as
+ // IOR and ServerRequest Interceptors.
+ orbInitProperties.setProperty(
+ ORBConstants.USER_CONFIGURATOR_PREFIX
+ + "com.sun.corba.ee.impl.folb.ServerGroupManager",
+ "dummy");
+
+ fineLog( "Did EE property initialization");
+ }
+ }
+ }
+
+ private void initORB(Properties props) {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".initORB->: ");
+ }
+
+ setORBSystemProperties();
+
+ Properties orbInitProperties = new Properties();
+ orbInitProperties.putAll(props);
+
+ orbInitProperties.put(ORBConstants.APPSERVER_MODE, "true");
+
+ // The main configurator.
+ orbInitProperties.put(ORBConstants.USER_CONFIGURATOR_PREFIX
+ + PEORB_CONFIG_CLASS, "dummy");
+
+ setFOLBProperties(orbInitProperties);
+
+ // Standard OMG Properties.
+ String orbDefaultServerId = DEFAULT_SERVER_ID;
+ if (!processType.isServer()) {
+ orbDefaultServerId = ACC_DEFAULT_SERVER_ID;
+ }
+
+ orbDefaultServerId = System.getProperty(
+ USER_DEFINED_ORB_SERVER_ID_PROPERTY, orbDefaultServerId);
+
+ orbInitProperties.put(ORBConstants.ORB_SERVER_ID_PROPERTY,
+ orbDefaultServerId);
+
+ orbInitProperties.put(OMG_ORB_CLASS_PROPERTY, ORB_CLASS);
+
+ orbInitProperties.put( ORBConstants.PI_ORB_INITIALIZER_CLASS_PREFIX
+ + GLASSFISH_INITIALIZER, "");
+
+ orbInitProperties.put(ORBConstants.ALLOW_LOCAL_OPTIMIZATION,
+ "true");
+
+ orbInitProperties.put(
+ ORBConstants.GET_SERVICE_CONTEXT_RETURNS_NULL, "true");
+
+ orbInitProperties.put(ORBConstants.ORB_ID_PROPERTY, S1AS_ORB_ID);
+ orbInitProperties.put(ORBConstants.SHOW_INFO_MESSAGES, "true");
+
+ // Do this even if propertiesInitialized, since props may override
+ // ORBInitialHost and port.
+ String initialPort = checkORBInitialPort(orbInitProperties);
+
+ String orbInitialHost = checkORBInitialHost(orbInitProperties);
+ String[] orbInitRefArgs;
+ if (System.getProperty(IIOP_ENDPOINTS_PROPERTY) != null &&
+ !System.getProperty(IIOP_ENDPOINTS_PROPERTY).isEmpty()) {
+ orbInitRefArgs = getORBInitRef(
+ System.getProperty(IIOP_ENDPOINTS_PROPERTY));
+ } else {
+ // Add -ORBInitRef for INS to work
+ orbInitRefArgs = getORBInitRef(orbInitialHost, initialPort);
+ }
+
+ // In a server, don't configure any default acceptors so that lazy init
+ // can be used. Actual lazy init setup takes place in PEORBConfigurator
+ if (processType.isServer()) {
+ validateIiopListeners();
+ orbInitProperties.put(ORBConstants.NO_DEFAULT_ACCEPTORS, "true");
+ // 14734893 - IIOP ports don't bind to the network address set for the cluster instance
+ // GLASSFISH-17469 IIOP Listener Network Address Setting Ignored
+ checkORBServerHost(orbInitProperties);
+ }
+
+ checkConnectionSettings(orbInitProperties);
+ checkMessageFragmentSize(orbInitProperties);
+ checkServerSSLOutboundSettings(orbInitProperties);
+ checkForOrbPropertyValues(orbInitProperties);
+
+ Collection<GlassFishORBLifeCycleListener> lcListeners =
+ iiopUtils.getGlassFishORBLifeCycleListeners();
+
+ List<String> argsList = new ArrayList<String>();
+ argsList.addAll(Arrays.asList(orbInitRefArgs));
+
+ for (GlassFishORBLifeCycleListener listener : lcListeners) {
+ listener.initializeORBInitProperties(argsList, orbInitProperties);
+ }
+
+ String[] args = argsList.toArray(new String[argsList.size()]);
+
+ // The following is done only on the Server Side to set the
+ // ThreadPoolManager in the ORB. ThreadPoolManager on the server
+ // is initialized based on configuration parameters found in
+ // domain.xml. On the client side this is not done
+
+ if (processType.isServer()) {
+ PEORBConfigurator.setThreadPoolManager();
+ }
+
+ // orb MUST be set before calling getFVDCodeBaseIOR, or we can
+ // recurse back into initORB due to interceptors that run
+ // when the TOA supporting the FVD is created!
+ // DO NOT MODIFY initORB to return ORB!!!
+
+ /**
+ * we can't create object adapters inside the ORB init path,
+ * or else we'll get this same problem in slightly different ways.
+ * (address in use exception) Having an IORInterceptor
+ * (TxSecIORInterceptor) get called during ORB init always
+ * results in a nested ORB.init call because of the call to getORB
+ * in the IORInterceptor.i
+ */
+
+ // TODO Right now we need to explicitly set useOSGI flag. If it's set to
+ // OSGI mode and we're not in OSGI mode, orb initialization fails.
+ boolean useOSGI = false;
+
+ final ClassLoader prevCL = Utility.getClassLoader();
+ try {
+ Utility.setContextClassLoader(GlassFishORBManager.class.getClassLoader());
+
+ if( processType.isServer()) {
+
+ Module corbaOrbModule = null;
+
+ // start glassfish-corba-orb bundle
+ ModulesRegistry modulesRegistry = services.getService(ModulesRegistry.class);
+
+ for(Module m : modulesRegistry.getModules()) {
+ if( m.getName().equals("glassfish-corba-orb") ) {
+ corbaOrbModule = m;
+ break;
+ }
+ }
+
+ if( corbaOrbModule != null) {
+ useOSGI = true;
+ corbaOrbModule.start();
+ }
+ }
+ } finally {
+ Utility.setContextClassLoader(prevCL);
+ }
+
+ // Can't run with GlassFishORBManager.class.getClassLoader() as the context ClassLoader
+ orb = ORBFactory.create() ;
+ ORBFactory.initialize( orb, args, orbInitProperties, useOSGI);
+
+ // Done to indicate this is a server and
+ // needs to create listen ports.
+ try {
+ org.omg.CORBA.Object obj =
+ orb.resolve_initial_references("RootPOA");
+ } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
+ logger.log(Level.SEVERE, "enterprise.orb_reference_exception", in);
+ }
+
+ if (processType.isServer()) {
+ // This MUST happen before new InitialGroupInfoService,
+ // or the ServerGroupManager will get initialized before the
+ // GIS is available.
+ gmsClient.setORB(orb) ;
+
+ // J2EEServer's persistent server port is same as ORBInitialPort.
+ orbInitialPort = getORBInitialPort();
+
+ for (GlassFishORBLifeCycleListener listener : lcListeners) {
+ listener.orbCreated(orb);
+ }
+
+ // TODO: The following statement can be moved to
+ // some GlassFishORBLifeCycleListeners
+
+ rfm = (ReferenceFactoryManager) orb.resolve_initial_references(
+ ORBConstants.REFERENCE_FACTORY_MANAGER);
+
+ new InitialGroupInfoService( orb ) ;
+
+ iiopUtils.setORB(orb);
+ }
+
+ // SeeBeyond fix for 6325988: needs testing.
+ // Still do not know why this might make any difference.
+ // Invoke this for its side-effects: ignore returned IOR.
+ orb.getFVDCodeBaseIOR();
+ } catch (Exception ex) {
+ logger.log(Level.SEVERE, "enterprise_util.excep_in_createorb", ex);
+ throw new RuntimeException(ex);
+ } finally {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".initORB<-: ");
+ }
+ }
+ }
+
+ private String checkForAddrAny(Properties props, String orbInitialHost) {
+ if ((orbInitialHost.equals("0.0.0.0")) || (orbInitialHost.equals("::"))
+ || (orbInitialHost.equals("::ffff:0.0.0.0"))) {
+ try {
+ String localAddress = java.net.InetAddress.getLocalHost().getHostAddress();
+ return localAddress;
+ } catch (java.net.UnknownHostException uhe) {
+ logger.log(Level.WARNING,
+ "Unknown host exception - Setting host to localhost");
+ return DEFAULT_ORB_INIT_HOST;
+ }
+ } else {
+ return orbInitialHost;
+ }
+ }
+
+ // Returns the first IiopListenerBean which represents a clear text endpoint
+ // Note: it is questionable whether the system actually support multiple
+ // endpoints of the same type, or no clear text endpoint at all in the
+ // configuration.
+ private IiopListener getClearTextIiopListener() {
+ if (iiopListeners != null) {
+ for (IiopListener il : iiopListeners) {
+ if (il.getSsl() == null) {
+ return il ;
+ }
+ }
+ }
+
+ return null ;
+ }
+
+ private String checkORBInitialHost(Properties props) {
+ // Host setting in system properties always takes precedence.
+ String initialHost = System.getProperty(
+ ORBConstants.INITIAL_HOST_PROPERTY);
+
+ if (initialHost == null) {
+ initialHost = props.getProperty(
+ ORBConstants.INITIAL_HOST_PROPERTY );
+ }
+
+ if (initialHost == null) {
+ IiopListener il = getClearTextIiopListener() ;
+ if (il != null) {
+ initialHost = il.getAddress();
+ }
+ }
+
+ if (initialHost == null) {
+ initialHost = DEFAULT_ORB_INIT_HOST;
+ }
+
+ initialHost = checkForAddrAny(props, initialHost);
+
+ props.setProperty(ORBConstants.INITIAL_HOST_PROPERTY, initialHost);
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "Setting orb initial host to {0}",
+ initialHost);
+ }
+
+ return initialHost;
+ }
+
+ private String checkORBInitialPort(Properties props) {
+ // Port setting in system properties always takes precedence.
+ String initialPort = System.getProperty(
+ ORBConstants.INITIAL_PORT_PROPERTY );
+
+ if (initialPort == null) {
+ initialPort = props.getProperty(
+ ORBConstants.INITIAL_PORT_PROPERTY);
+ }
+
+ if (initialPort == null) {
+ IiopListener il = getClearTextIiopListener() ;
+ if (il != null) {
+ initialPort = il.getPort();
+ }
+ }
+
+
+ if (initialPort == null) {
+ initialPort = DEFAULT_ORB_INIT_PORT;
+ }
+
+ // Make sure we set initial port in System properties so that
+ // any instantiations of com.sun.jndi.cosnaming.CNCtxFactory
+ // use same port.
+ props.setProperty(ORBConstants.INITIAL_PORT_PROPERTY, initialPort);
+
+
+ // Done to initialize the Persistent Server Port, before any
+ // POAs are created. This was earlier done in POAEJBORB
+ // Do it only in the appserver, not on appclient.
+ if (processType.isServer()) {
+ props.setProperty(ORBConstants.PERSISTENT_SERVER_PORT_PROPERTY,
+ initialPort);
+ }
+
+ fineLog( "Setting orb initial port to {0}", initialPort);
+
+ orbInitialPort = Integer.parseInt(initialPort);
+
+ return initialPort;
+ }
+
+ // Server host property is used only for ORB running in server mode
+ // Return host name (or ip address string) if the SERVER_HOST PROPERTY is set or
+ // network-address attribute is specified in iiop-listener element
+ // Return null otherwise.
+ private String checkORBServerHost(Properties props) {
+ // Host setting in system properties always takes precedence.
+ String serverHost = System.getProperty(ORBConstants.SERVER_HOST_PROPERTY);
+
+ if (serverHost == null) {
+ serverHost = props.getProperty(ORBConstants.SERVER_HOST_PROPERTY );
+ }
+
+
+ if (serverHost == null) {
+ IiopListener il = getClearTextIiopListener() ;
+ if (il != null) {
+ // For this case, use same value as ORBInitialHost,
+ serverHost = il.getAddress();
+ }
+ }
+
+ if (serverHost != null) {
+ // set the property, to be used during ORB initialization
+ // Bug 14734893 - IIOP ports don't bind to the network address set for the cluster instance
+ props.setProperty(ORBConstants.SERVER_HOST_PROPERTY, serverHost);
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "Setting orb server host to {0}", serverHost);
+ }
+ }
+
+ return serverHost;
+ }
+
+ private void validateIiopListeners() {
+ if (iiopListeners != null) {
+ int lazyCount = 0 ;
+ for (IiopListener ilb : iiopListeners) {
+ boolean securityEnabled = Boolean.valueOf( ilb.getSecurityEnabled() ) ;
+ boolean isLazy = Boolean.valueOf( ilb.getLazyInit() ) ;
+ if( isLazy ) {
+ lazyCount++;
+ }
+
+ if (lazyCount > 1) {
+ throw new IllegalStateException(
+ "Invalid iiop-listener " + ilb.getId() +
+ ". Only one iiop-listener can be configured with lazy-init=true");
+ }
+
+ if (securityEnabled || ilb.getSsl() == null) {
+ // no-op
+ } else {
+ if (isLazy) {
+ throw new IllegalStateException("Invalid iiop-listener " + ilb.getId() +
+ ". Lazy-init not supported for SSL iiop-listeners");
+ }
+
+ Ssl sslBean = ilb.getSsl() ;
+ assert sslBean != null ;
+ }
+ }
+ }
+ }
+
+ private void checkConnectionSettings(Properties props) {
+ if (orbBean != null) {
+ String maxConnections;
+
+ try {
+ maxConnections = orbBean.getMaxConnections();
+
+ // Validate number formats
+ Integer.parseInt(maxConnections);
+ } catch (NumberFormatException nfe) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.log(Level.WARNING,
+ "enterprise_util.excep_orbmgr_numfmt", nfe);
+ }
+
+ maxConnections = DEFAULT_MAX_CONNECTIONS;
+ }
+
+ props.setProperty(ORBConstants.HIGH_WATER_MARK_PROPERTY,
+ maxConnections);
+ }
+ return;
+ }
+
+ private void checkMessageFragmentSize(Properties props) {
+ if (orbBean != null) {
+ String fragmentSize, bufferSize;
+ try {
+ int fsize = ((Integer.parseInt(orbBean.getMessageFragmentSize().trim())) / 8) * 8;
+ if (fsize < 32) {
+ fragmentSize = "32";
+ logger.log(Level.INFO,
+ "Setting ORB Message Fragment size to {0}",
+ fragmentSize);
+ } else {
+ fragmentSize = String.valueOf(fsize);
+ }
+ bufferSize = fragmentSize;
+ } catch (NumberFormatException nfe) {
+ // Print stack trace and use default values
+ logger.log(Level.WARNING,
+ "enterprise_util.excep_in_reading_fragment_size", nfe);
+ logger.log(Level.INFO,
+ "Setting ORB Message Fragment size to Default " +
+ SUN_GIOP_DEFAULT_FRAGMENT_SIZE);
+ fragmentSize = SUN_GIOP_DEFAULT_FRAGMENT_SIZE;
+ bufferSize = SUN_GIOP_DEFAULT_BUFFER_SIZE;
+ }
+ props.setProperty(ORBConstants.GIOP_FRAGMENT_SIZE,
+ fragmentSize);
+ props.setProperty(ORBConstants.GIOP_BUFFER_SIZE,
+ bufferSize);
+ }
+ }
+
+ private void checkServerSSLOutboundSettings(Properties props) {
+ if (iiopService != null) {
+ SslClientConfig sslClientConfigBean =
+ iiopService.getSslClientConfig();
+ if (sslClientConfigBean != null) {
+ Ssl ssl = sslClientConfigBean.getSsl();
+ assert (ssl != null);
+ }
+ }
+ }
+
+ private void checkForOrbPropertyValues(Properties props) {
+ if (orbBean != null) {
+ List<Property> orbBeanProps = orbBean.getProperty();
+ if (orbBeanProps != null) {
+ for (int i = 0; i < orbBeanProps.size(); i++) {
+ props.setProperty(orbBeanProps.get(i).getName(),
+ orbBeanProps.get(i).getValue());
+ }
+ }
+ }
+ }
+
+ private String[] getORBInitRef(String orbInitialHost,
+ String initialPort) {
+ // Add -ORBInitRef NameService=....
+ // This ensures that INS will be used to talk with the NameService.
+ String[] newArgs = new String[]{
+ "-ORBInitRef",
+ "NameService=corbaloc:iiop:1.2@"
+ + orbInitialHost + ":"
+ + initialPort + "/NameService"
+ };
+
+ return newArgs;
+ }
+
+ private String[] getORBInitRef(String endpoints) {
+
+ String[] list = endpoints.split(",");
+ String corbalocURL = getCorbalocURL(list);
+ logger.log(Level.FINE, "GlassFishORBManager.getORBInitRef = {0}",
+ corbalocURL);
+
+ // Add -ORBInitRef NameService=....
+ // This ensures that INS will be used to talk with the NameService.
+ String[] newArgs = new String[]{
+ "-ORBInitRef",
+ "NameService=corbaloc:" + corbalocURL + "/NameService"
+ };
+
+ return newArgs;
+ }
+
+ // TODO : Move this to naming NOT needed for V3 FCS
+
+ public static final String IIOP_ENDPOINTS_PROPERTY =
+ "com.sun.appserv.iiop.endpoints";
+
+ private static final String IIOP_URL = "iiop:1.2@";
+
+ private String getCorbalocURL(Object[] list) {
+
+ String corbalocURL = "";
+ //convert list into corbaloc url
+ for (int i = 0; i < list.length; i++) {
+ logger.log(Level.INFO, "list[i] ==> {0}", list[i]);
+ if (corbalocURL.equals("")) {
+ corbalocURL = IIOP_URL + ((String) list[i]).trim();
+ } else {
+ corbalocURL = corbalocURL + "," +
+ IIOP_URL + ((String) list[i]).trim();
+ }
+ }
+ logger.log(Level.INFO, "corbaloc url ==> {0}", corbalocURL);
+ return corbalocURL;
+ }
+
+ String getIIOPEndpoints() {
+ return gmsClient.getIIOPEndpoints() ;
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GroupInfoServiceObserverImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GroupInfoServiceObserverImpl.java
new file mode 100644
index 0000000..74e230c
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/GroupInfoServiceObserverImpl.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2006, 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.spi.folb.ClusterInstanceInfo;
+import com.sun.corba.ee.spi.folb.GroupInfoService;
+import com.sun.corba.ee.spi.folb.GroupInfoServiceObserver;
+import org.glassfish.logging.annotation.LogMessageInfo;
+
+import java.util.List;
+import java.util.logging.Level;
+
+import static org.glassfish.enterprise.iiop.impl.NamingClusterInfoImpl.logger;
+
+/**
+ * Called when the GroupInfoService that you register with
+ * has a change. You should call the GroupInfoService
+ * <code>getClusterInstanceInfo</code> method to get
+ * updated info.
+ * @author Ken Cavanaugh
+ * @author Sheetal Vartak
+ */
+public class GroupInfoServiceObserverImpl implements GroupInfoServiceObserver {
+ @LogMessageInfo(message = "Problem with membership change notification. Exception occurred : {0}",
+ cause = "check server.log for details",
+ action = "check network configuration and cluster setup")
+ public static final String GROUPINFOSERVICE_MEMBERSHIP_NOTIFICATION_PROBLEM = "AS-ORB-00003";
+
+ private GroupInfoService gis;
+ private RoundRobinPolicy rr ;
+
+ public GroupInfoServiceObserverImpl(GroupInfoService gis,
+ RoundRobinPolicy rr ) {
+
+ this.gis = gis;
+ this.rr = rr ;
+ }
+
+ // This method is called for internally forced updates:
+ // see SerialInitContextFactory.getInitialContext.
+ public void forceMembershipChange() {
+ doMembershipChange();
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "GroupInfoServiceObserverImpl.forceMembershipChange called");
+ }
+ }
+
+ @Override
+ // This method is called when the client is informed about a cluster
+ // membership change through ClientGroupManager.receive_star.
+ public void membershipChange() {
+ doMembershipChange();
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "GroupInfoServiceObserverImpl.membershipChange called");
+ }
+ }
+
+ private void doMembershipChange() {
+ try {
+ List<ClusterInstanceInfo> instanceInfoList =
+ gis.getClusterInstanceInfo(null, rr.getHostPortList());
+ if (instanceInfoList != null && instanceInfoList.size() > 0) {
+ rr.setClusterInstanceInfo(instanceInfoList);
+ }
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, GROUPINFOSERVICE_MEMBERSHIP_NOTIFICATION_PROBLEM, e);
+ logger.log(Level.SEVERE, "", e);
+ }
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateClassLoader.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateClassLoader.java
new file mode 100644
index 0000000..ef8d98d
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateClassLoader.java
@@ -0,0 +1,92 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import java.io.*;
+
+public class HandleDelegateClassLoader
+ extends ClassLoader
+{
+
+ public HandleDelegateClassLoader() {
+ super();
+ }
+
+ protected Class findClass(String name)
+ throws ClassNotFoundException
+ {
+ // This is called only if the class could not be loaded by
+ // the parent class loader (see javadoc for loadClass methods).
+ // Load the class from the current thread's context class loader.
+
+ Class c = Thread.currentThread().getContextClassLoader().loadClass(name);
+
+ return c;
+ }
+
+ protected Class loadClass(String name, boolean resolve)
+ throws ClassNotFoundException
+ {
+ if (!name.equals("com.sun.enterprise.iiop.IIOPHandleDelegate")) {
+ return super.loadClass(name, resolve);
+ }
+
+ Class handleDelClass = findLoadedClass(name);
+ if (handleDelClass != null) {
+ return handleDelClass;
+ }
+
+ InputStream is = null;
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+ // read the bytes for IIOPHandleDelegate.class
+ ClassLoader resCl = Thread.currentThread().getContextClassLoader();
+ if (Thread.currentThread().getContextClassLoader() == null) {
+ resCl = getSystemClassLoader();
+ }
+ is = resCl.getResourceAsStream("org/glassfish/enterprise/iiop/impl/IIOPHandleDelegate.class");
+
+ byte[] buf = new byte[4096]; // currently IIOPHandleDelegate is < 4k
+ int nread = 0;
+ while ( (nread = is.read(buf, 0, buf.length)) != -1 ) {
+ baos.write(buf, 0, nread);
+ }
+
+ byte[] buf2 = baos.toByteArray();
+
+ handleDelClass = defineClass(
+ "org.glassfish.enterprise.iiop.impl.IIOPHandleDelegate",
+ buf2, 0, buf2.length);
+
+ } catch ( Exception ex ) {
+ throw (ClassNotFoundException)new ClassNotFoundException(ex.getMessage()).initCause(ex);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ if (resolve) {
+ resolveClass(handleDelClass);
+ }
+
+ return handleDelClass;
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateFacadeImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateFacadeImpl.java
new file mode 100644
index 0000000..adf1ecc
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/HandleDelegateFacadeImpl.java
@@ -0,0 +1,28 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import org.glassfish.enterprise.iiop.api.HandleDelegateFacade;
+import org.jvnet.hk2.annotations.Service;
+import javax.ejb.spi.HandleDelegate;
+
+@Service
+public class HandleDelegateFacadeImpl implements HandleDelegateFacade {
+ public HandleDelegate getHandleDelegate() {
+ return IIOPHandleDelegate.getHandleDelegate();
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPEndpointsInfo.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPEndpointsInfo.java
new file mode 100644
index 0000000..830a0fb
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPEndpointsInfo.java
@@ -0,0 +1,188 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.spi.folb.ClusterInstanceInfo;
+import org.glassfish.orb.admin.config.IiopListener;
+import com.sun.enterprise.config.serverbeans.ServerRef;
+import com.sun.logging.LogDomains;
+import org.glassfish.enterprise.iiop.util.IIOPUtils;
+
+import java.util.List;
+import java.util.Collection;
+import java.util.logging.Logger;
+
+/**
+ * This class is responsible for reading the domain.xml via Config API
+ * and producing a list of instances in the form of ClusterInstanceInfo
+ * objects.
+ * This class is designed for use by both FailoverIORInterceptor
+ * and Java Web Start.
+ * @author Sheetal Vartak
+ * @date 1/12/05
+ */
+
+public class IIOPEndpointsInfo {
+
+ private static final IIOPUtils iiopUtils = IIOPUtils.getInstance();
+
+ private static Logger _logger = LogDomains.getLogger(IIOPEndpointsInfo.class, LogDomains.CORBA_LOGGER);
+
+ private static final String baseMsg = IIOPEndpointsInfo.class.getName();
+
+
+ /**
+ * TODO implement post V3 FCS
+ public static Collection<ServerRef> getServersInCluster() {
+
+ return iiopUtils.getServerRefs();
+ }
+
+ public static List<IiopListener> getListenersInCluster() {
+
+
+ return iiopUtils.getIiopListeners();
+ }
+
+ **/
+
+ /**
+ * This method returns a list of SocketInfo objects for a particular
+ * server. This method is the common code called by
+ * getIIOPEndpoints() and getClusterInstanceInfo()
+ */
+ /*
+ public static List<SocketInfo> getSocketInfoForServer(ServerRef serverRef,
+ IiopListener[] listen) {
+
+ List<SocketInfo> listOfSocketInfo =
+ new LinkedList<SocketInfo>();
+ String serverName = serverRef.getRef();
+ String hostName =
+ getHostNameForServerInstance(serverName);
+ if (hostName == null) {
+ hostName = listen[0].getAddress();
+ }
+ for (int j = 0; j < listen.length; j++) {
+ String id = listen[j].getId();
+ String port =
+ getResolvedPort(listen[j], serverName);
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ baseMsg + ".getSocketInfoForServer:" +
+ " adding address for "+
+ serverName + "/" + id +
+ "/" + hostName + "/" + port);
+ }
+ listOfSocketInfo.add(new SocketInfo(id, hostName, Integer.valueOf(port)));
+ }
+ return listOfSocketInfo;
+ }
+ */
+
+ /**
+ * This method returns the endpoints in host:port,host1:port1,host2:port2,...
+ * format. This is called by Java Web Start
+ */
+ public static String getIIOPEndpoints() {
+ //TODO FIXME
+ String endpoints = null;
+
+ return endpoints;
+
+ }
+
+ /**
+ * This method returns a ClusterInstanceInfo list.
+ */
+ public static List<ClusterInstanceInfo> getClusterInstanceInfo()
+ {
+ //TODO FIXME
+ return null;
+ }
+
+ /**
+ * The following returns the IIOP listener(s) for all the
+ * servers belonging to the current cluster.
+ *
+ * @author satish.viswanatham@sun.com
+ *
+ */
+ /*
+ public static IiopListener[][] getIIOPEndPointsForCurrentCluster() {
+ // For each server instance in a cluster, there are 3 iiop listeners:
+ // one for non ssl, one for ssl and third for ssl mutual auth
+
+ IiopListener[][] listeners = new IiopListener[serverRefs.length][3]; //SHEETAL can there be multiple SSL or
+ //SSL_MUTH_AUTH ports? bug 6321813
+ for (int i = 0; i < serverRefs.length; i++) {
+ Server server =
+ ServerHelper.getServerByName(configCtx, serverRefs[i].getRef());
+ String configRef = server.getConfigRef();
+ Config config =
+ ConfigAPIHelper.getConfigByName(configCtx, configRef);
+ IiopService iiopService = config.getIiopService();
+ listeners[i] = iiopService.getIiopListener();
+ }
+ return listeners;
+ }
+ */
+ /**
+ * Returns ip address from node agent refered from instance
+ * or null if Exception
+ *
+ * @author sridatta.viswanath@sun.com
+ */
+ /*
+ public static String getHostNameForServerInstance(String serverName)
+ {
+ try {
+ JMXConnectorConfig info =
+ ServerHelper.getJMXConnectorInfo(configCtx, serverName);
+ _logger.log(Level.FINE,
+ baseMsg + ".getHostNameForServerInstance: " +
+ "found info: " + info.toString());
+ String host = info.getHost();
+ _logger.log(Level.FINE,
+ baseMsg + ".getHostNameForServerInstance: " +
+ "found host: " + host);
+ return host;
+ } catch (Throwable e){
+ _logger.log(Level.FINE,
+ baseMsg + ".getHostNameForServerInstance: " +
+ "gotException: " + e + " " + e.getMessage() +
+ "; returning null");
+ return null;
+ }
+ }
+ */
+ /**
+ * Gets the correct resolved value for the specific instance
+ * Without this routine, config context resolves the value
+ * to the current running instance
+ *
+ * @author sridatta.viswanath@sun.com
+ */
+ /*
+ public static String getResolvedPort(IiopListener l,
+ String server) {
+ String rawPort = l.getRawAttributeValue("port");
+ PropertyResolver pr = new PropertyResolver(configCtx, server);
+ return pr.resolve(rawPort);
+ }
+ */
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPHandleDelegate.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPHandleDelegate.java
new file mode 100644
index 0000000..fdbd401
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPHandleDelegate.java
@@ -0,0 +1,135 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import java.io.*;
+
+import javax.ejb.*;
+import javax.ejb.spi.HandleDelegate;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import javax.rmi.PortableRemoteObject;
+
+import org.omg.CORBA.portable.Delegate;
+import org.omg.CORBA.ORB;
+import com.sun.corba.ee.spi.presentation.rmi.StubAdapter;
+
+/**
+ * An implementation of HandleDelegate for the IIOP Protocol.
+ *
+ */
+
+public final class IIOPHandleDelegate
+ implements HandleDelegate
+{
+
+ public static HandleDelegate getHandleDelegate() {
+ HandleDelegate handleDelegate =
+ (HandleDelegate) java.security.AccessController.doPrivileged(
+ new java.security.PrivilegedAction() {
+ public Object run() {
+ try {
+ ClassLoader cl = new HandleDelegateClassLoader();
+ Class c = cl.loadClass(
+ "org.glassfish.enterprise.iiop.impl.IIOPHandleDelegate");
+ return c.newInstance();
+ } catch ( Exception ex ) {
+ throw new RuntimeException("Error creating HandleDelegate", ex);
+ }
+ }
+ }
+ );
+ return handleDelegate;
+ }
+
+
+ public void writeEJBObject(javax.ejb.EJBObject ejbObject,
+ java.io.ObjectOutputStream ostream)
+ throws java.io.IOException
+ {
+ ostream.writeObject(ejbObject); // IIOP stubs are Serializable
+ }
+
+ public javax.ejb.EJBObject readEJBObject(java.io.ObjectInputStream istream)
+ throws java.io.IOException, ClassNotFoundException
+ {
+ return (EJBObject)getStub(istream, EJBObject.class);
+ }
+
+ public void writeEJBHome(javax.ejb.EJBHome ejbHome,
+ java.io.ObjectOutputStream ostream)
+ throws java.io.IOException
+ {
+ ostream.writeObject(ejbHome); // IIOP stubs are Serializable
+ }
+
+ public javax.ejb.EJBHome readEJBHome(java.io.ObjectInputStream istream)
+ throws java.io.IOException, ClassNotFoundException
+ {
+ return (EJBHome)getStub(istream, EJBHome.class);
+ }
+
+ private Object getStub(java.io.ObjectInputStream istream, Class stubClass)
+ throws IOException, ClassNotFoundException
+ {
+ // deserialize obj
+ Object obj = istream.readObject();
+
+ if( StubAdapter.isStub(obj) ) {
+
+ try {
+
+ // Check if it is already connected to the ORB by getting
+ // the delegate. If BAD_OPERATION is not thrown, then the
+ // stub is connected. This will happen if istream is an
+ // IIOP input stream.
+ StubAdapter.getDelegate(obj);
+
+ } catch(org.omg.CORBA.BAD_OPERATION bo) {
+
+ // TODO Temporary way to get the ORB. Will need to
+ // replace with an approach that goes through the habitat
+ ORB orb = null;
+ try {
+
+ orb = (ORB) new InitialContext().lookup("java:comp/ORB");
+
+ } catch(NamingException ne) {
+
+ throw new IOException("Error acquiring orb", ne);
+ }
+
+ // Stub is not connected. This can happen if istream is
+ // not an IIOP input stream (e.g. it's a File stream).
+ StubAdapter.connect(obj, (com.sun.corba.ee.spi.orb.ORB) orb);
+ }
+
+ } else {
+ throw new IOException("Unable to create stub for class " +
+ stubClass.getName() +
+ ", object deserialized is not a CORBA object, it's type is " +
+ obj.getClass().getName());
+ }
+
+ // narrow it
+ Object stub = PortableRemoteObject.narrow(obj, stubClass);
+
+ return stub;
+ }
+
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPSSLSocketFactory.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPSSLSocketFactory.java
new file mode 100644
index 0000000..ed514f5
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IIOPSSLSocketFactory.java
@@ -0,0 +1,614 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.impl.misc.ORBUtility;
+import com.sun.corba.ee.spi.transport.Acceptor;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.logging.Logger;
+import javax.net.ssl.SSLContext;
+import com.sun.corba.ee.spi.orb.ORB;
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.corba.ee.spi.transport.ORBSocketFactory;
+import com.sun.enterprise.config.serverbeans.Config;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import org.glassfish.grizzly.config.dom.Ssl;
+import com.sun.logging.LogDomains;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import org.glassfish.api.admin.ProcessEnvironment;
+import org.glassfish.api.admin.ProcessEnvironment.ProcessType;
+import org.glassfish.internal.api.Globals;
+import org.glassfish.security.common.CipherInfo;
+import org.glassfish.enterprise.iiop.api.IIOPSSLUtil;
+import com.sun.enterprise.security.integration.AppClientSSL;
+import org.glassfish.api.admin.ServerEnvironment;
+
+
+/**
+ * This is socket factory used to create either plain sockets or SSL
+ * sockets based on the target's policies and the client policies.
+ * @author Vivek Nagar
+ * @author Shing Wai Chan
+ */
+public class IIOPSSLSocketFactory implements ORBSocketFactory
+{
+ private static final Logger _logger = LogDomains.getLogger(
+ IIOPSSLSocketFactory.class, LogDomains.CORBA_LOGGER);
+
+ private static final String TLS = "TLS";
+ private static final String SSL3 = "SSLv3";
+ private static final String SSL2 = "SSLv2";
+ private static final String SSL = "SSL";
+ private static final String SSL_MUTUALAUTH = "SSL_MUTUALAUTH";
+ private static final String PERSISTENT_SSL = "PERSISTENT_SSL";
+
+ private static final int BACKLOG = 50;
+
+ //private static SecureRandom sr = null;
+
+ /* this is stored for the Server side of SSL Connections.
+ * Note: There will be only a port per iiop listener and a corresponding
+ * ctx for that port
+ */
+ /*
+ * @todo provide an interface to the admin, so that whenever a iiop-listener
+ * is added / removed, we modify the hashtable,
+ */
+ private Map portToSSLInfo = new Hashtable();
+ /* this is stored for the client side of SSL Connections.
+ * Note: There will be only 1 ctx for the client side, as we will reuse the
+ * ctx for all SSL connections
+ */
+ private SSLInfo clientSslInfo = null;
+
+ private ORB orb;
+
+ /**
+ * Constructs an <code>IIOPSSLSocketFactory</code>
+ */
+ public IIOPSSLSocketFactory() {
+ try {
+
+ ProcessEnvironment penv = null;
+ ProcessType processType = null;
+ boolean notServerOrACC = Globals.getDefaultHabitat() == null ? true : false;
+ if (!notServerOrACC) {
+ penv = Globals.get(ProcessEnvironment.class);
+ processType = penv.getProcessType();
+ }
+ //if (Switch.getSwitch().getContainerType() == Switch.EJBWEB_CONTAINER) {
+ if((processType != null) && (processType.isServer())) {
+ //this is the EJB container
+ Config conf = Globals.getDefaultHabitat().getService(Config.class,
+ ServerEnvironment.DEFAULT_INSTANCE_NAME);
+ IiopService iiopBean =conf.getExtensionByType(IiopService.class);
+ List<IiopListener> iiopListeners = iiopBean.getIiopListener();
+ for (IiopListener listener : iiopListeners) {
+ Ssl ssl = listener.getSsl();
+ SSLInfo sslInfo = null;
+ boolean securityEnabled = Boolean.valueOf(listener.getSecurityEnabled());
+
+ if (securityEnabled) {
+ if (ssl != null) {
+ boolean ssl2Enabled = Boolean.valueOf(ssl.getSsl2Enabled());
+ boolean tlsEnabled = Boolean.valueOf(ssl.getTlsEnabled());
+ boolean ssl3Enabled = Boolean.valueOf(ssl.getSsl3Enabled());
+ sslInfo = init(ssl.getCertNickname(),
+ ssl2Enabled, ssl.getSsl2Ciphers(),
+ ssl3Enabled, ssl.getSsl3TlsCiphers(),
+ tlsEnabled);
+ } else {
+ sslInfo = getDefaultSslInfo();
+ }
+ portToSSLInfo.put(
+ new Integer(listener.getPort()), sslInfo);
+ }
+ }
+
+ if (iiopBean.getSslClientConfig() != null &&
+ /*iiopBean.getSslClientConfig().isEnabled()*/
+ iiopBean.getSslClientConfig().getSsl() != null) {
+ Ssl outboundSsl = iiopBean.getSslClientConfig().getSsl();
+ if (outboundSsl != null) {
+ boolean ssl2Enabled = Boolean.valueOf(outboundSsl.getSsl2Enabled());
+ boolean ssl3Enabled = Boolean.valueOf(outboundSsl.getSsl3Enabled());
+ boolean tlsEnabled = Boolean.valueOf(outboundSsl.getTlsEnabled());
+ clientSslInfo = init(outboundSsl.getCertNickname(),
+ ssl2Enabled,
+ outboundSsl.getSsl2Ciphers(),
+ ssl3Enabled,
+ outboundSsl.getSsl3TlsCiphers(),
+ tlsEnabled);
+ }
+ }
+ if (clientSslInfo == null) {
+ clientSslInfo = getDefaultSslInfo();
+ }
+ } else {
+ if ((processType != null) && (processType == ProcessType.ACC)) {
+ IIOPSSLUtil sslUtil = Globals.getDefaultHabitat().getService(IIOPSSLUtil.class);
+ AppClientSSL clientSsl = (AppClientSSL)sslUtil.getAppClientSSL();
+ if (clientSsl != null) {
+ clientSslInfo = init(clientSsl.getCertNickname(),
+ clientSsl.getSsl2Enabled(), clientSsl.getSsl2Ciphers(),
+ clientSsl.getSsl3Enabled(), clientSsl.getSsl3TlsCiphers(),
+ clientSsl.getTlsEnabled());
+ } else { // include case keystore, truststore jvm option
+
+ clientSslInfo = getDefaultSslInfo();
+ }
+ } else {
+ clientSslInfo = getDefaultSslInfo();
+ }
+ }
+ } catch (Exception e) {
+ _logger.log(Level.SEVERE,"iiop.init_exception",e);
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Return a default SSLInfo object.
+ */
+ private SSLInfo getDefaultSslInfo() throws Exception {
+ return init(null, false, null, true, null, true);
+ }
+
+ /**
+ * serveralias/clientalias cannot be set at the same time.
+ * this method encapsulates the common code for both the client side and
+ * server side to create a SSLContext
+ * it is called once for each serveralias and once for each clientalias
+ */
+ private SSLInfo init(String alias,
+ boolean ssl2Enabled, String ssl2Ciphers,
+ boolean ssl3Enabled, String ssl3TlsCiphers,
+ boolean tlsEnabled) throws Exception {
+
+ String protocol;
+ if (tlsEnabled) {
+ protocol = TLS;
+ } else if (ssl3Enabled) {
+ protocol = SSL3;
+ } else if (ssl2Enabled) {
+ protocol = SSL2;
+ } else { // default
+ protocol = "SSL";
+ }
+
+ String[] ssl3TlsCipherArr = null;
+ if (tlsEnabled || ssl3Enabled) {
+ ssl3TlsCipherArr = getEnabledCipherSuites(ssl3TlsCiphers,
+ false, ssl3Enabled, tlsEnabled);
+ }
+
+ String[] ssl2CipherArr = null;
+ if (ssl2Enabled) {
+ ssl2CipherArr = getEnabledCipherSuites(ssl2Ciphers,
+ true, false, false);
+ }
+
+ SSLContext ctx = SSLContext.getInstance(protocol);
+ if (Globals.getDefaultHabitat() != null) {
+ IIOPSSLUtil sslUtil = Globals.getDefaultHabitat().getService(IIOPSSLUtil.class);
+ KeyManager[] mgrs = sslUtil.getKeyManagers(alias);
+ ctx.init(mgrs, sslUtil.getTrustManagers(), sslUtil.getInitializedSecureRandom());
+ } else {
+ //do nothing
+ //ctx.init(mgrs, sslUtil.getTrustManagers(), sslUtil.getInitializedSecureRandom());
+ }
+
+ return new SSLInfo(ctx, ssl3TlsCipherArr, ssl2CipherArr);
+ }
+
+ //----- implements com.sun.corba.ee.spi.transport.ORBSocketFactory -----
+
+ public void setORB(ORB orb) {
+ this.orb = orb;
+ }
+
+ /**
+ * Create a server socket on the specified InetSocketAddress based on the
+ * type of the server socket (SSL, SSL_MUTUALAUTH, PERSISTENT_SSL or CLEAR_TEXT).
+ * @param type type of socket to create.
+ * @param inetSocketAddress the InetSocketAddress
+ * @return the server socket on the specified InetSocketAddress
+ * @exception IOException if an I/O error occurs during server socket
+ * creation
+ */
+ public ServerSocket createServerSocket(String type,
+ InetSocketAddress inetSocketAddress) throws IOException {
+
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "Creating server socket for type =" + type
+ + " inetSocketAddress =" + inetSocketAddress);
+ }
+
+ if(type.equals(SSL_MUTUALAUTH) || type.equals(SSL) ||
+ type.equals(PERSISTENT_SSL)) {
+ return createSSLServerSocket(type, inetSocketAddress);
+ } else {
+ ServerSocket serverSocket = null;
+ if (orb.getORBData().acceptorSocketType().equals(
+ ORBConstants.SOCKETCHANNEL)) {
+ ServerSocketChannel serverSocketChannel =
+ ServerSocketChannel.open();
+ serverSocket = serverSocketChannel.socket();
+ } else {
+ serverSocket = new ServerSocket();
+ }
+
+ serverSocket.bind(inetSocketAddress);
+ return serverSocket;
+
+ }
+ }
+
+ /**
+ * Create a client socket for the specified InetSocketAddress. Creates an SSL
+ * socket if the type specified is SSL or SSL_MUTUALAUTH.
+ * @param type
+ * @param inetSocketAddress
+ * @return the socket.
+ */
+ public Socket createSocket(String type, InetSocketAddress inetSocketAddress)
+ throws IOException {
+
+ try {
+ String host = inetSocketAddress.getHostName();
+ int port = inetSocketAddress.getPort();
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "createSocket(" + type + ", " + host + ", " +port + ")");
+ }
+ if (type.equals(SSL) || type.equals(SSL_MUTUALAUTH)) {
+ return createSSLSocket(host, port);
+ } else {
+ Socket socket = null;
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "Creating CLEAR_TEXT socket for:" +port);
+ }
+
+ if (orb.getORBData().connectionSocketType().equals(
+ ORBConstants.SOCKETCHANNEL)) {
+ SocketChannel socketChannel = ORBUtility.openSocketChannel(inetSocketAddress);
+ socket = socketChannel.socket();
+ } else {
+ socket = new Socket(inetSocketAddress.getHostName(),
+ inetSocketAddress.getPort());
+ }
+
+ // Disable Nagle's algorithm (i.e. always send immediately).
+ socket.setTcpNoDelay(true);
+ return socket;
+ }
+ } catch ( Exception ex ) {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,"Exception creating socket",ex);
+ }
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void setAcceptedSocketOptions(Acceptor acceptor,
+ ServerSocket serverSocket, Socket socket) {
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "setAcceptedSocketOptions: " + acceptor
+ + " " + serverSocket + " " + socket);
+ }
+ // Disable Nagle's algorithm (i.e., always send immediately).
+ try {
+ socket.setTcpNoDelay(true);
+ } catch (SocketException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ //----- END implements com.sun.corba.ee.spi.transport.ORBSocketFactory -----
+
+ /**
+ * Create an SSL server socket at the specified InetSocketAddress. If the type
+ * is SSL_MUTUALAUTH then SSL client authentication is requested.
+ */
+ private ServerSocket createSSLServerSocket(String type,
+ InetSocketAddress inetSocketAddress) throws IOException {
+
+ if (inetSocketAddress == null) {
+ throw new IOException(getFormatMessage(
+ "iiop.invalid_sslserverport",
+ new Object[] { null }));
+ }
+ int port = inetSocketAddress.getPort();
+ Integer iport = Integer.valueOf(port);
+ SSLInfo sslInfo = (SSLInfo)portToSSLInfo.get(iport);
+ if (sslInfo == null) {
+ throw new IOException(getFormatMessage(
+ "iiop.invalid_sslserverport",
+ new Object[] { iport }));
+ }
+ SSLServerSocketFactory ssf = sslInfo.getContext().getServerSocketFactory();
+ String[] ssl3TlsCiphers = sslInfo.getSsl3TlsCiphers();
+ String[] ssl2Ciphers = sslInfo.getSsl2Ciphers();
+ String[] ciphers = null;
+ if (ssl3TlsCiphers != null || ssl2Ciphers != null) {
+ String[] socketCiphers = ssf.getDefaultCipherSuites();
+ ciphers = mergeCiphers(socketCiphers, ssl3TlsCiphers, ssl2Ciphers);
+ }
+
+ String cs[] = null;
+
+ if(_logger.isLoggable(Level.FINE)) {
+ cs = ssf.getSupportedCipherSuites();
+ for(int i=0; i < cs.length; ++i) {
+ _logger.log(Level.FINE,"Cipher Suite: " + cs[i]);
+ }
+ }
+ ServerSocket ss = null;
+ try{
+ // bugfix for 6349541
+ // specify the ip address to bind to, 50 is the default used
+ // by the ssf implementation when only the port is specified
+ ss = ssf.createServerSocket(port, BACKLOG, inetSocketAddress.getAddress());
+ if (ciphers != null) {
+ ((SSLServerSocket)ss).setEnabledCipherSuites(ciphers);
+ }
+ } catch(IOException e) {
+ _logger.log(Level.SEVERE, "iiop.createsocket_exception",
+ new Object[] { type, String.valueOf(port) });
+ _logger.log(Level.SEVERE, "", e);
+ throw e;
+ }
+
+ try {
+ if(type.equals(SSL_MUTUALAUTH)) {
+ _logger.log(Level.FINE,"Setting Mutual auth");
+ ((SSLServerSocket)ss).setNeedClientAuth(true);
+ }
+ } catch(Exception e) {
+ _logger.log(Level.SEVERE,"iiop.cipher_exception",e);
+ throw new IOException(e.getMessage());
+ }
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,"Created server socket:" + ss);
+ }
+ return ss;
+ }
+
+ /**
+ * Create an SSL socket at the specified host and port.
+ * @param host
+ * @param port
+ * @return the socket.
+ */
+ private Socket createSSLSocket(String host, int port)
+ throws IOException {
+ SSLSocket socket = null;
+ SSLSocketFactory factory = null;
+ try{
+ // get socketfactory+sanity check
+ // clientSslInfo is never null
+ factory = clientSslInfo.getContext().getSocketFactory();
+
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,"Creating SSL Socket for host:" + host +" port:" + port);
+ }
+ String[] ssl3TlsCiphers = clientSslInfo.getSsl3TlsCiphers();
+ String[] ssl2Ciphers = clientSslInfo.getSsl2Ciphers();
+ String[] clientCiphers = null;
+ if (ssl3TlsCiphers != null || ssl2Ciphers != null) {
+ String[] socketCiphers = factory.getDefaultCipherSuites();
+ clientCiphers = mergeCiphers(socketCiphers, ssl3TlsCiphers, ssl2Ciphers);
+ }
+
+ socket = (SSLSocket)factory.createSocket(host, port);
+ if (clientCiphers != null) {
+ socket.setEnabledCipherSuites(clientCiphers);
+ }
+ }catch(Exception e) {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "iiop.createsocket_exception",
+ new Object[] { host, String.valueOf(port) });
+ _logger.log(Level.FINE, "", e);
+ }
+ IOException e2 = new IOException(
+ "Error opening SSL socket to host="+host+" port="+port);
+ e2.initCause(e);
+ throw e2;
+ }
+ return socket;
+ }
+
+ /**
+ * This API return an array of String listing the enabled cipher suites.
+ * Input is the cipherSuiteStr from xml which a space separated list
+ * ciphers with a prefix '+' indicating enabled, '-' indicating disabled.
+ * If no cipher is enabled, then it returns an empty array.
+ * If no cipher is specified, then all are enabled and it returns null.
+ * @param cipherSuiteStr cipherSuiteStr from xml
+ * @param ssl2Enabled
+ * @param ssl3Enabled
+ * @param tlsEnabled
+ * @return an array of enabled Ciphers
+ */
+ private String[] getEnabledCipherSuites(String cipherSuiteStr,
+ boolean ssl2Enabled, boolean ssl3Enabled, boolean tlsEnabled) {
+ String[] cipherArr = null;
+ if (cipherSuiteStr != null && cipherSuiteStr.length() > 0) {
+ ArrayList cipherList = new ArrayList();
+ StringTokenizer tokens = new StringTokenizer(cipherSuiteStr, ",");
+ while (tokens.hasMoreTokens()) {
+ String cipherAction = tokens.nextToken();
+ if (cipherAction.startsWith("+")) {
+ String cipher = cipherAction.substring(1);
+ CipherInfo cipherInfo = CipherInfo.getCipherInfo(cipher);
+ if (cipherInfo != null &&
+ isValidProtocolCipher(cipherInfo, ssl2Enabled,
+ ssl3Enabled, tlsEnabled)) {
+ cipherList.add(cipherInfo.getCipherName());
+ } else {
+ throw new IllegalStateException(getFormatMessage(
+ "iiop.unknown_cipher",
+ new Object[] { cipher }));
+ }
+ } else if (cipherAction.startsWith("-")) {
+ String cipher = cipherAction.substring(1);
+ CipherInfo cipherInfo = CipherInfo.getCipherInfo(cipher);
+ if (cipherInfo == null ||
+ !isValidProtocolCipher(cipherInfo, ssl2Enabled,
+ ssl3Enabled, tlsEnabled)) {
+ throw new IllegalStateException(getFormatMessage(
+ "iiop.unknown_cipher",
+ new Object[] { cipher }));
+ }
+ } else if (cipherAction.trim().length() > 0) {
+ throw new IllegalStateException(getFormatMessage(
+ "iiop.invalid_cipheraction",
+ new Object[] { cipherAction }));
+ }
+ }
+
+ cipherArr = (String[])cipherList.toArray(
+ new String[cipherList.size()]);
+ }
+ return cipherArr;
+ }
+
+ /**
+ * Return an array of merged ciphers.
+ * @param enableCiphers ciphers enabled by socket factory
+ * @param ssl3TlsCiphers
+ * @param ssl2Ciphers
+ */
+ private String[] mergeCiphers(String[] enableCiphers,
+ String[] ssl3TlsCiphers, String[] ssl2Ciphers) {
+
+ if (ssl3TlsCiphers == null && ssl2Ciphers == null) {
+ return null;
+ }
+
+ int eSize = (enableCiphers != null)? enableCiphers.length : 0;
+
+ if (_logger.isLoggable(Level.FINE)) {
+ StringBuffer buf = new StringBuffer("Default socket ciphers: ");
+ for (int i = 0; i < eSize; i++) {
+ buf.append(enableCiphers[i] + ", ");
+ }
+ _logger.log(Level.FINE, buf.toString());
+ }
+
+ ArrayList cList = new ArrayList();
+ if (ssl3TlsCiphers != null) {
+ for (int i = 0; i < ssl3TlsCiphers.length; i++) {
+ cList.add(ssl3TlsCiphers[i]);
+ }
+ } else {
+ for (int i = 0; i < eSize; i++) {
+ String cipher = enableCiphers[i];
+ CipherInfo cInfo = CipherInfo.getCipherInfo(cipher);
+ if (cInfo != null && (cInfo.isTLS() || cInfo.isSSL3())) {
+ cList.add(cipher);
+ }
+ }
+ }
+
+ if (ssl2Ciphers != null) {
+ for (int i = 0; i < ssl2Ciphers.length; i++) {
+ cList.add(ssl2Ciphers[i]);
+ }
+ } else {
+ for (int i = 0; i < eSize; i++) {
+ String cipher = enableCiphers[i];
+ CipherInfo cInfo = CipherInfo.getCipherInfo(cipher);
+ if (cInfo != null && cInfo.isSSL2()) {
+ cList.add(cipher);
+ }
+ }
+ }
+
+ if (_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, "Merged socket ciphers: " + cList);
+ }
+
+ return (String[])cList.toArray(new String[cList.size()]);
+ }
+
+ /**
+ * Check whether given cipherInfo belongs to given protocol.
+ * @param cipherInfo
+ * @param ssl2Enabled
+ * @param ssl3Enabled
+ * @param tlsEnabled
+ */
+ private boolean isValidProtocolCipher(CipherInfo cipherInfo,
+ boolean ssl2Enabled, boolean ssl3Enabled, boolean tlsEnabled) {
+ return (tlsEnabled && cipherInfo.isTLS() ||
+ ssl3Enabled && cipherInfo.isSSL3() ||
+ ssl2Enabled && cipherInfo.isSSL2());
+ }
+
+ /**
+ * This API get the format string from resource bundle of _logger.
+ * @param key the key of the message
+ * @param params the parameter array of Object
+ * @return the format String for _logger
+ */
+ private String getFormatMessage(String key, Object[] params) {
+ return MessageFormat.format(
+ _logger.getResourceBundle().getString(key), params);
+ }
+
+ class SSLInfo {
+ private SSLContext ctx;
+ private String[] ssl3TlsCiphers = null;
+ private String[] ssl2Ciphers = null;
+
+ SSLInfo(SSLContext ctx, String[] ssl3TlsCiphers, String[] ssl2Ciphers) {
+ this.ctx = ctx;
+ this.ssl3TlsCiphers = ssl3TlsCiphers;
+ this.ssl2Ciphers = ssl2Ciphers;
+ }
+
+ SSLContext getContext() {
+ return ctx;
+ }
+
+ String[] getSsl3TlsCiphers() {
+ return ssl3TlsCiphers;
+ }
+
+ String[] getSsl2Ciphers() {
+ return ssl2Ciphers;
+ }
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInitializer.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInitializer.java
new file mode 100755
index 0000000..28f6c33
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInitializer.java
@@ -0,0 +1,99 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+
+import com.sun.logging.LogDomains;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.omg.IOP.Codec;
+import org.omg.IOP.CodecFactory;
+import org.omg.IOP.Encoding;
+import org.omg.IOP.ENCODING_CDR_ENCAPS;
+import org.omg.PortableInterceptor.ORBInitializer;
+import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;
+
+/**
+ * This class is used to add IOR interceptors for supporting IN_ADDR_ANY
+ * functionality in the ORB
+ */
+public class IORAddrAnyInitializer extends org.omg.CORBA.LocalObject
+ implements ORBInitializer{
+
+ private static final Logger _logger = LogDomains.getLogger(
+ IORAddrAnyInitializer.class, LogDomains.CORBA_LOGGER);
+
+ public static final String baseMsg = IORAddrAnyInitializer.class.getName();
+
+ /** Creates a new instance of IORAddrAnyInitializer */
+ public IORAddrAnyInitializer() {
+ }
+
+ /**
+ * Called during ORB initialization. If it is expected that initial
+ * services registered by an interceptor will be used by other
+ * interceptors, then those initial services shall be registered at
+ * this point via calls to
+ * <code>ORBInitInfo.register_initial_reference</code>.
+ *
+ * @param info provides initialization attributes and operations by
+ * which Interceptors can be registered.
+ */
+ @Override
+ public void pre_init(org.omg.PortableInterceptor.ORBInitInfo info) {
+ }
+
+ /**
+ * Called during ORB initialization. If a service must resolve initial
+ * references as part of its initialization, it can assume that all
+ * initial references will be available at this point.
+ * <p>
+ * Calling the <code>post_init</code> operations is not the final
+ * task of ORB initialization. The final task, following the
+ * <code>post_init</code> calls, is attaching the lists of registered
+ * interceptors to the ORB. Therefore, the ORB does not contain the
+ * interceptors during calls to <code>post_init</code>. If an
+ * ORB-mediated call is made from within <code>post_init</code>, no
+ * request interceptors will be invoked on that call.
+ * Likewise, if an operation is performed which causes an IOR to be
+ * created, no IOR interceptors will be invoked.
+ *
+ * @param info provides initialization attributes and
+ * operations by which Interceptors can be registered.
+ */
+ @Override
+ public void post_init(org.omg.PortableInterceptor.ORBInitInfo info) {
+ Codec codec = null;
+ CodecFactory cf = info.codec_factory();
+
+ byte major_version = 1;
+ byte minor_version = 2;
+ Encoding encoding = new Encoding(ENCODING_CDR_ENCAPS.value,
+ major_version, minor_version);
+ try {
+ codec = cf.create_codec(encoding);
+ } catch (org.omg.IOP.CodecFactoryPackage.UnknownEncoding e) {
+ _logger.log(Level.WARNING,"UnknownEncoding from " + baseMsg,e);
+ }
+ try {
+ info.add_ior_interceptor(new IORAddrAnyInterceptor(codec));
+ } catch (DuplicateName ex) {
+ _logger.log(Level.WARNING,"DuplicateName from " + baseMsg,ex);
+ }
+ }
+
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInterceptor.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInterceptor.java
new file mode 100755
index 0000000..a3738df
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IORAddrAnyInterceptor.java
@@ -0,0 +1,164 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.logging.LogDomains;
+import org.omg.IOP.Codec;
+
+
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.NetworkInterface;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class IORAddrAnyInterceptor extends org.omg.CORBA.LocalObject
+ implements org.omg.PortableInterceptor.IORInterceptor{
+
+ public static final String baseMsg = IORAddrAnyInterceptor.class.getName();
+ private static final Logger _logger = LogDomains.getLogger(
+ IORAddrAnyInterceptor.class, LogDomains.CORBA_LOGGER);
+
+ private Codec codec;
+
+
+ /** Creates a new instance of IORAddrAnyInterceptor
+ * @param c The codec
+ */
+ public IORAddrAnyInterceptor(Codec c) {
+ codec = c;
+ }
+
+ /**
+ * Provides an opportunity to destroy this interceptor.
+ * The destroy method is called during <code>ORB.destroy</code>. When an
+ * application calls <code>ORB.destroy</code>, the ORB:
+ * <ol>
+ * <li>waits for all requests in progress to complete</li>
+ * <li>calls the <code>Interceptor.destroy</code> operation for each
+ * interceptor</li>
+ * <li>completes destruction of the ORB</li>
+ * </ol>
+ * Method invocations from within <code>Interceptor.destroy</code> on
+ * object references for objects implemented on the ORB being destroyed
+ * result in undefined behavior. However, method invocations on objects
+ * implemented on an ORB other than the one being destroyed are
+ * permitted. (This means that the ORB being destroyed is still capable
+ * of acting as a client, but not as a server.)
+ */
+ @Override
+ public void destroy() {
+ }
+
+ /**
+ * A server side ORB calls the <code>establish_components</code>
+ * operation on all registered <code>IORInterceptor</code> instances
+ * when it is assembling the list of components that will be included
+ * in the profile or profiles of an object reference. This operation
+ * is not necessarily called for each individual object reference.
+ * For example, the POA specifies policies at POA granularity and
+ * therefore, this operation might be called once per POA rather than
+ * once per object. In any case, <code>establish_components</code> is
+ * guaranteed to be called at least once for each distinct set of
+ * server policies.
+ * <p>
+ * An implementation of <code>establish_components</code> must not
+ * throw exceptions. If it does, the ORB shall ignore the exception
+ * and proceed to call the next IOR Interceptor's
+ * <code>establish_components</code> operation.
+ *
+ * @param iorInfo The <code>IORInfo</code> instance used by the ORB
+ * service to query applicable policies and add components to be
+ * included in the generated IORs.
+ */
+ @Override
+ public void establish_components(org.omg.PortableInterceptor.IORInfo iorInfo) {
+ /*
+ try {
+ IORInfoExt iorInfoExt = (IORInfoExt) iorInfo;
+ int port = iorInfoExt.getServerPort(ORBSocketFactory.IIOP_CLEAR_TEXT);
+
+ ArrayList allInetAddress = getAllInetAddresses();
+ addAddressComponents(iorInfo, allInetAddress, port);
+ ORB orb = (ORB)((IORInfoImpl)iorInfo).getORB();
+ Object[] userPorts = orb.getUserSpecifiedListenPorts().toArray();
+ if (userPorts.length > 0) {
+ for (int i = 0; i < userPorts.length; i++) {
+ com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort p =
+ ((com.sun.corba.ee.internal.corba.ORB.UserSpecifiedListenPort)userPorts[i]);
+ // if (p.getType().equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) {
+ addAddressComponents(iorInfo, allInetAddress, p.getPort());
+ // }
+ }
+ }
+ } catch (Exception e) {
+ _logger.log(Level.WARNING,"Exception in " + baseMsg, e);
+ }
+ */
+ }
+
+ /**
+ * Returns the name of the interceptor.
+ * <p>
+ * Each Interceptor may have a name that may be used administratively
+ * to order the lists of Interceptors. Only one Interceptor of a given
+ * name can be registered with the ORB for each Interceptor type. An
+ * Interceptor may be anonymous, i.e., have an empty string as the name
+ * attribute. Any number of anonymous Interceptors may be registered with
+ * the ORB.
+ *
+ * @return the name of the interceptor.
+ */
+ @Override
+ public String name() {
+ return baseMsg;
+ }
+
+ protected short intToShort( int value )
+ {
+ if (value > 32767) {
+ return (short) (value - 65536);
+ }
+ return (short)value ;
+ }
+
+ /*
+ private void addAddressComponents(org.omg.PortableInterceptor.IORInfo iorInfo,
+ ArrayList allInetAddress, int port) {
+ try {
+ for (int i = 0; i < allInetAddress.size(); i++) {
+ String address = ((InetAddress)allInetAddress.get(i)).getHostAddress();
+ AlternateIIOPAddressComponent iiopAddress =
+ new AlternateIIOPAddressComponent(address, intToShort(port));
+ Any any = ORB.init().create_any();
+ AlternateIIOPAddressComponentHelper.insert(any, iiopAddress);
+ byte[] data = codec.encode_value(any);
+ TaggedComponent taggedComponent =
+ new TaggedComponent( org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value,
+ //AlternateIIOPAddressComponent.TAG_ALTERNATE_IIOP_ADDRESS_ID,
+ data);
+ iorInfo.add_ior_component(taggedComponent);
+ }
+ } catch (Exception e) {
+ _logger.log(Level.WARNING,"Exception in " + baseMsg, e);
+ }
+ }
+ */
+
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IiopFolbGmsClient.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IiopFolbGmsClient.java
new file mode 100644
index 0000000..6064ce3
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/IiopFolbGmsClient.java
@@ -0,0 +1,498 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+import com.sun.enterprise.ee.cms.core.FailureNotificationSignal;
+import com.sun.enterprise.ee.cms.core.JoinedAndReadyNotificationSignal;
+import com.sun.enterprise.ee.cms.core.PlannedShutdownSignal;
+import com.sun.enterprise.ee.cms.core.Signal;
+import com.sun.enterprise.ee.cms.core.SignalAcquireException;
+import com.sun.enterprise.ee.cms.core.SignalReleaseException;
+import com.sun.logging.LogDomains;
+
+import com.sun.corba.ee.spi.orb.ORB ;
+import com.sun.corba.ee.spi.folb.ClusterInstanceInfo;
+import com.sun.corba.ee.spi.folb.GroupInfoService;
+import com.sun.corba.ee.impl.folb.GroupInfoServiceBase;
+import com.sun.corba.ee.spi.folb.GroupInfoServiceObserver;
+import com.sun.corba.ee.spi.folb.SocketInfo;
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.enterprise.config.serverbeans.Cluster;
+import com.sun.enterprise.config.serverbeans.Config;
+import com.sun.enterprise.config.serverbeans.Configs;
+import com.sun.enterprise.config.serverbeans.Domain;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.orb.admin.config.IiopService;
+import com.sun.enterprise.config.serverbeans.Server;
+import com.sun.enterprise.config.serverbeans.Servers;
+import com.sun.enterprise.config.serverbeans.Nodes;
+import com.sun.enterprise.config.serverbeans.Node;
+import com.sun.enterprise.ee.cms.core.CallBack;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import org.glassfish.config.support.GlassFishConfigBean;
+import org.glassfish.config.support.PropertyResolver;
+import org.glassfish.gms.bootstrap.GMSAdapter;
+import org.glassfish.gms.bootstrap.GMSAdapterService;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.omg.CORBA.ORBPackage.InvalidName;
+
+// REVISIT impl
+//import com.sun.corba.ee.impl.folb.ServerGroupManager;
+
+/**
+ * @author Harold Carr
+ */
+public class IiopFolbGmsClient implements CallBack {
+ private static final Logger _logger =
+ LogDomains.getLogger(IiopFolbGmsClient.class,
+ LogDomains.CORBA_LOGGER);
+
+ private ServiceLocator services;
+
+ private Domain domain ;
+
+ private Server myServer ;
+
+ private Nodes nodes ;
+
+ private GMSAdapterService gmsAdapterService ;
+
+ private GMSAdapter gmsAdapter ;
+
+ private Map<String, ClusterInstanceInfo> currentMembers;
+
+ private GroupInfoService gis;
+
+ private void fineLog( String fmt, Object... args ) {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE, fmt, args ) ;
+ }
+ }
+
+ public IiopFolbGmsClient( ServiceLocator services ) {
+ fineLog( "IiopFolbGmsClient: constructor: services {0}",
+ services ) ;
+ this.services = services ;
+
+ gmsAdapterService = services.getService(GMSAdapterService.class);
+
+ try {
+ if (gmsAdapterService == null) {
+ return ;
+ }
+
+ gmsAdapter = gmsAdapterService.getGMSAdapter() ;
+ fineLog( "IiopFolbGmsClient: gmsAdapter {0}", gmsAdapter );
+
+ if (gmsAdapter != null) {
+ domain = services.getService( Domain.class );
+ fineLog( "IiopFolbGmsClient: domain {0}", domain) ;
+
+ Servers servers = services.getService(Servers.class );
+ fineLog( "IiopFolbGmsClient: servers {0}", servers );
+
+ nodes = services.getService(Nodes.class);
+ fineLog( "IiopFolbGmsClient: nodes {0}", nodes );
+
+ String instanceName = gmsAdapter.getModule().getInstanceName() ;
+ fineLog( "IiopFolbGmsClient: instanceName {0}", instanceName );
+
+ myServer = servers.getServer(instanceName) ;
+ fineLog( "IiopFolbGmsClient: myServer {0}", myServer );
+
+ gis = new GroupInfoServiceGMSImpl() ;
+ fineLog("IiopFolbGmsClient: IIOP GIS created");
+
+ currentMembers = getAllClusterInstanceInfo() ;
+ fineLog( "IiopFolbGmsClient: currentMembers = ", currentMembers ) ;
+
+ fineLog( "iiop instance info = " + getIIOPEndpoints() ) ;
+
+ gmsAdapter.registerFailureNotificationListener(this);
+ gmsAdapter.registerJoinedAndReadyNotificationListener(this);
+ gmsAdapter.registerPlannedShutdownListener(this);
+
+ fineLog( "IiopFolbGmsClient: GMS action factories added");
+ } else {
+ fineLog( "IiopFolbGmsClient: gmsAdapterService is null") ;
+ gis = new GroupInfoServiceNoGMSImpl() ;
+ }
+
+ } catch (Throwable t) {
+ _logger.log(Level.SEVERE, t.getLocalizedMessage(), t);
+ } finally {
+ fineLog( "IiopFolbGmsClient: gmsAdapter {0}", gmsAdapter ) ;
+ }
+ }
+
+ public void setORB( ORB orb ) {
+ try {
+ orb.register_initial_reference(
+ ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE,
+ (org.omg.CORBA.Object) gis);
+ fineLog( ".initGIS: naming registration complete: {0}", gis);
+
+ // Just for logging
+ GroupInfoService gisRef = (GroupInfoService)orb.resolve_initial_references(
+ ORBConstants.FOLB_SERVER_GROUP_INFO_SERVICE);
+ List<ClusterInstanceInfo> lcii =
+ gisRef.getClusterInstanceInfo(null);
+ fineLog( "Results from getClusterInstanceInfo:");
+ if (lcii != null) {
+ for (ClusterInstanceInfo cii : lcii) {
+ fineLog( cii.toString() );
+ }
+ }
+ } catch (InvalidName e) {
+ fineLog( ".initGIS: registering GIS failed: {0}", e);
+ }
+ }
+
+ public GroupInfoService getGroupInfoService() {
+ return gis ;
+ }
+
+ public boolean isGMSAvailable() {
+ return gmsAdapter != null ;
+ }
+
+ ////////////////////////////////////////////////////
+ //
+ // Action
+ //
+
+ @Override
+ public void processNotification(final Signal signal) {
+ try {
+ fineLog( "processNotification: signal {0}", signal ) ;
+ signal.acquire();
+ handleSignal(signal);
+ } catch (SignalAcquireException e) {
+ _logger.log(Level.SEVERE, e.getLocalizedMessage());
+ } catch (Throwable t) {
+ _logger.log(Level.SEVERE, t.getLocalizedMessage(), t);
+ } finally {
+ try {
+ signal.release();
+ } catch (SignalReleaseException e) {
+ _logger.log(Level.SEVERE, e.getLocalizedMessage());
+ }
+ }
+ }
+
+ ////////////////////////////////////////////////////
+ //
+ // Implementation
+ //
+
+ private void handleSignal(final Signal signal)
+ {
+ fineLog( "IiopFolbGmsClient.handleSignal: signal from: {0}",
+ signal.getMemberToken());
+ fineLog( "IiopFolbGmsClient.handleSignal: map entryset: {0}",
+ signal.getMemberDetails().entrySet());
+
+ if (signal instanceof PlannedShutdownSignal ||
+ signal instanceof FailureNotificationSignal) {
+
+ removeMember(signal);
+
+ } else if (signal instanceof JoinedAndReadyNotificationSignal) {
+
+ addMember(signal);
+
+ } else {
+ _logger.log(Level.SEVERE,
+ "IiopFolbGmsClient.handleSignal: unknown signal: {0}",
+ signal.toString());
+ }
+ }
+
+ private void removeMember(final Signal signal)
+ {
+ String instanceName = signal.getMemberToken();
+ try {
+ fineLog( "IiopFolbGmsClient.removeMember->: {0}",
+ instanceName);
+
+ synchronized (this) {
+ if (currentMembers.get(instanceName) != null) {
+ currentMembers.remove(instanceName);
+
+ fineLog(
+ "IiopFolbGmsClient.removeMember: {0} removed - notifying listeners",
+ instanceName);
+
+ gis.notifyObservers();
+
+ fineLog(
+ "IiopFolbGmsClient.removeMember: {0} - notification complete",
+ instanceName);
+ } else {
+ fineLog(
+ "IiopFolbGmsClient.removeMember: {0} not present: no action",
+ instanceName);
+ }
+ }
+ } finally {
+ fineLog( "IiopFolbGmsClient.removeMember<-: {0}", instanceName);
+ }
+ }
+
+ private void addMember(final Signal signal)
+ {
+ final String instanceName = signal.getMemberToken();
+ try {
+ fineLog( "IiopFolbGmsClient.addMember->: {0}", instanceName);
+
+ synchronized (this) {
+ if (currentMembers.get(instanceName) != null) {
+ fineLog( "IiopFolbGmsClient.addMember: {0} already present: no action",
+ instanceName);
+ } else {
+ ClusterInstanceInfo clusterInstanceInfo =
+ getClusterInstanceInfo(instanceName) ;
+
+ currentMembers.put( clusterInstanceInfo.name(),
+ clusterInstanceInfo);
+
+ fineLog( "IiopFolbGmsClient.addMember: {0} added - notifying listeners",
+ instanceName);
+
+ gis.notifyObservers();
+
+ fineLog( "IiopFolbGmsClient.addMember: {0} - notification complete",
+ instanceName);
+ }
+ }
+ } finally {
+ fineLog( "IiopFolbGmsClient.addMember<-: {0}", instanceName);
+ }
+ }
+
+ private int resolvePort( Server server, IiopListener listener ) {
+ fineLog( "resolvePort: server {0} listener {1}", server, listener ) ;
+
+ IiopListener ilRaw = GlassFishConfigBean.getRawView( listener ) ;
+ fineLog( "resolvePort: ilRaw {0}", ilRaw ) ;
+
+ PropertyResolver pr = new PropertyResolver( domain, server.getName() ) ;
+ fineLog( "resolvePort: pr {0}", pr ) ;
+
+ String port = pr.getPropertyValue( ilRaw.getPort() ) ;
+ fineLog( "resolvePort: port {0}", port ) ;
+
+ return Integer.parseInt(port) ;
+ }
+
+ private ClusterInstanceInfo getClusterInstanceInfo( Server server,
+ Config config, boolean assumeInstanceIsRunning ) {
+ if (server == null) {
+ return null ;
+ }
+
+ if (!assumeInstanceIsRunning) {
+ if (!server.isRunning()) {
+ return null ;
+ }
+ }
+
+ fineLog( "getClusterInstanceInfo: server {0}, config {1}",
+ server, config ) ;
+
+ final String name = server.getName() ;
+ fineLog( "getClusterInstanceInfo: name {0}", name ) ;
+
+ final int weight = Integer.parseInt( server.getLbWeight() ) ;
+ fineLog( "getClusterInstanceInfo: weight {0}", weight ) ;
+
+ final String nodeName = server.getNodeRef() ;
+ String hostName = nodeName ;
+ if (nodes != null) {
+ Node node = nodes.getNode( nodeName ) ;
+ if (node != null) {
+ if (node.isLocal()) {
+ try {
+ hostName = InetAddress.getLocalHost().getHostName() ;
+ } catch (UnknownHostException exc) {
+ fineLog( "getClusterInstanceInfo: caught exception for localhost lookup {0}",
+ exc ) ;
+ }
+ } else {
+ hostName = node.getNodeHost() ;
+ }
+ }
+ }
+
+ fineLog( "getClusterInstanceInfo: host {0}", hostName ) ;
+
+ final IiopService iservice = config.getExtensionByType(IiopService.class) ;
+ fineLog( "getClusterInstanceInfo: iservice {0}", iservice ) ;
+
+ final List<IiopListener> listeners = iservice.getIiopListener() ;
+ fineLog( "getClusterInstanceInfo: listeners {0}", listeners ) ;
+
+ final List<SocketInfo> sinfos = new ArrayList<SocketInfo>() ;
+ for (IiopListener il : listeners) {
+ SocketInfo sinfo = new SocketInfo( il.getId(), hostName,
+ resolvePort( server, il ) ) ;
+ sinfos.add( sinfo ) ;
+ }
+ fineLog( "getClusterInstanceInfo: sinfos {0}", sinfos ) ;
+
+ final ClusterInstanceInfo result = new ClusterInstanceInfo( name, weight,
+ sinfos ) ;
+ fineLog( "getClusterInstanceInfo: result {0}", result ) ;
+
+ return result ;
+ }
+
+ private Config getConfigForServer( Server server ) {
+ fineLog( "getConfigForServer: server {0}", server ) ;
+
+ String configRef = server.getConfigRef() ;
+ fineLog( "getConfigForServer: configRef {0}", configRef ) ;
+
+ Configs configs = services.getService( Configs.class ) ;
+ fineLog( "getConfigForServer: configs {0}", configs ) ;
+
+ Config config = configs.getConfigByName(configRef) ;
+ fineLog( "getConfigForServer: config {0}", config ) ;
+
+ return config ;
+ }
+
+ // For addMember.
+ private ClusterInstanceInfo getClusterInstanceInfo( String instanceName) {
+ fineLog( "getClusterInstanceInfo: instanceName {0}", instanceName ) ;
+
+ final Servers servers = services.getService( Servers.class );
+ fineLog( "getClusterInstanceInfo: servers {0}", servers ) ;
+
+ final Server server = servers.getServer(instanceName) ;
+ fineLog( "getClusterInstanceInfo: server {0}", server ) ;
+
+ final Config config = getConfigForServer( server ) ;
+ fineLog( "getClusterInstanceInfo: servers {0}", servers ) ;
+
+ // assumeInstanceIsRunning is set to true since this is
+ // coming from addMember, because shoal just told us that the instance is up.
+ ClusterInstanceInfo result = getClusterInstanceInfo( server, config,
+ true ) ;
+ fineLog( "getClusterInstanceInfo: result {0}", result ) ;
+
+ return result ;
+ }
+
+ private Map<String,ClusterInstanceInfo> getAllClusterInstanceInfo() {
+ final Cluster myCluster = myServer.getCluster() ;
+ fineLog( "getAllClusterInstanceInfo: myCluster {0}", myCluster ) ;
+
+ final Config myConfig = getConfigForServer( myServer ) ;
+ fineLog( "getAllClusterInstanceInfo: myConfig {0}", myConfig ) ;
+
+ final Map<String,ClusterInstanceInfo> result =
+ new HashMap<String,ClusterInstanceInfo>() ;
+
+ //When myServer is DAS's situation, myCluster is null.
+ //null check is needed.
+ if (myCluster != null) {
+ for (Server server : myCluster.getInstances()) {
+ ClusterInstanceInfo cii = getClusterInstanceInfo(server,
+ myConfig, false);
+ if (cii != null) {
+ result.put(server.getName(), cii);
+ }
+ }
+ }
+
+ fineLog( "getAllClusterInstanceInfo: result {0}", result ) ;
+ return result ;
+ }
+
+ // return host:port,... string for all clear text ports in the cluster
+ // instance info.
+ public final String getIIOPEndpoints() {
+ final Map<String,ClusterInstanceInfo> cinfos = getAllClusterInstanceInfo() ;
+ final StringBuilder result = new StringBuilder() ;
+ boolean first = true ;
+ for (ClusterInstanceInfo cinfo : cinfos.values() ) {
+ for (SocketInfo sinfo : cinfo.endpoints()) {
+ if (!sinfo.type().startsWith( "SSL" )) {
+ if (first) {
+ first = false ;
+ } else {
+ result.append( ',' ) ;
+ }
+
+ result.append( sinfo.host() ).append( ':' )
+ .append( sinfo.port() ) ;
+ }
+ }
+ }
+ return result.toString() ;
+ }
+
+ class GroupInfoServiceGMSImpl extends GroupInfoServiceBase {
+ @Override
+ public List<ClusterInstanceInfo> internalClusterInstanceInfo(
+ List<String> endpoints) {
+
+ fineLog( "internalClusterInstanceInfo: currentMembers {0}",
+ currentMembers ) ;
+
+ if (currentMembers == null) {
+ return new ArrayList<ClusterInstanceInfo>() ;
+ } else {
+ return new ArrayList<ClusterInstanceInfo>(
+ currentMembers.values() ) ;
+ }
+ }
+ }
+
+ class GroupInfoServiceNoGMSImpl extends GroupInfoServiceGMSImpl {
+ @Override
+ public boolean addObserver(GroupInfoServiceObserver x) {
+ throw new RuntimeException("SHOULD NOT BE CALLED");
+ }
+
+ @Override
+ public void notifyObservers() {
+ throw new RuntimeException("SHOULD NOT BE CALLED");
+ }
+
+ @Override
+ public boolean shouldAddAddressesToNonReferenceFactory(String[] x) {
+ throw new RuntimeException("SHOULD NOT BE CALLED");
+ }
+
+ @Override
+ public boolean shouldAddMembershipLabel(String[] adapterName) {
+ throw new RuntimeException("SHOULD NOT BE CALLED");
+ }
+ }
+}
+
+// End of file.
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java
new file mode 100644
index 0000000..e5d1d0d
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/NamingClusterInfoImpl.java
@@ -0,0 +1,199 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.spi.folb.GroupInfoService;
+import org.glassfish.api.naming.NamingClusterInfo;
+import org.glassfish.api.naming.NamingObjectsProvider;
+import org.glassfish.hk2.api.ServiceHandle;
+import org.glassfish.hk2.api.ServiceHandle;
+import org.glassfish.internal.api.ORBLocator;
+import org.glassfish.logging.annotation.LogMessageInfo;
+import org.glassfish.logging.annotation.LoggerInfo;
+import org.glassfish.logging.annotation.LogMessagesResourceBundle;
+
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.ServiceLocator;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.ORBPackage.InvalidName;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.inject.Singleton;
+
+/**
+ * This class is responsible for setting up naming load-balancing including RoundRobinPolicy.
+ */
+
+@Service
+@Singleton
+public class NamingClusterInfoImpl implements NamingClusterInfo {
+ //move up to some class in top orb module
+ @LoggerInfo(subsystem = "orb", description = "logger for GlassFish appserver orb modules", publish = true)
+ public static final String ORB_LOGGER_NAME = "org.glassfish.orb";
+
+ @LogMessagesResourceBundle
+ public static final String ORB_LOGGER_RB = ORB_LOGGER_NAME + ".LogMessages";
+
+ public static final Logger logger = Logger.getLogger(ORB_LOGGER_NAME, ORB_LOGGER_RB);
+
+ @LogMessageInfo(message = "Exception occurred when resolving {0}",
+ cause = "org.omg.CORBA.ORBPackage.InvalidName when trying to resolve GroupInfoService",
+ action = "Check server.log for details")
+ public static final String FAILED_TO_RESOLVE_GROUPINFOSERVICE = "AS-ORB-00001";
+
+ @LogMessageInfo(
+ message = "No Endpoints selected in com.sun.appserv.iiop.endpoints property. Using {0}:{1} instead")
+ public static final String NO_ENDPOINT_SELECTED = "AS-ORB-00002";
+
+ private RoundRobinPolicy rrPolicy;
+
+ private GroupInfoServiceObserverImpl giso;
+
+ @Override
+ public void initGroupInfoService(Hashtable<?, ?> myEnv, String defaultHost, String defaultPort,
+ ORB orb, ServiceLocator services) {
+ // Always create one rrPolicy to be shared, if needed.
+ final List<String> epList = getEndpointList(myEnv, defaultHost, defaultPort);
+ rrPolicy = new RoundRobinPolicy(epList);
+
+ GroupInfoService gis = null ;
+ try {
+ gis = (GroupInfoService) (orb.resolve_initial_references(ORBLocator.FOLB_CLIENT_GROUP_INFO_SERVICE));
+ } catch (InvalidName ex) {
+ logger.log(Level.SEVERE, FAILED_TO_RESOLVE_GROUPINFOSERVICE, ORBLocator.FOLB_CLIENT_GROUP_INFO_SERVICE);
+ logger.log(Level.SEVERE, "", ex);
+ }
+
+ giso = new GroupInfoServiceObserverImpl( gis, rrPolicy );
+
+ gis.addObserver(giso);
+
+ // fineLog( "getInitialContext: rrPolicy = {0}", rrPolicy );
+
+ // this should force the initialization of the resources providers
+ if (services !=null) {
+ for (ServiceHandle<?> provider : services.getAllServiceHandles(NamingObjectsProvider.class)) {
+ provider.getService();
+ // no - op. Do nothing with the provided object
+ }
+// for (NamingObjectsProvider provider :
+// services.getAllByContract(NamingObjectsProvider.class)) {
+// // no-op
+// }
+ }
+
+ // Get the actual content, not just the configured
+ // endpoints.
+ giso.forceMembershipChange();
+
+ if(logger.isLoggable(Level.FINE))
+ logger.log(Level.FINE, "NamingClusterInfoImpl.initGroupInfoService RoundRobinPolicy {0}", rrPolicy);
+ }
+
+ @Override
+ public void setClusterInstanceInfo(Hashtable<?, ?> myEnv, String defaultHost, String defaultPort,
+ boolean membershipChangeForced) {
+ final List<String> list = getEndpointList(myEnv, defaultHost, defaultPort) ;
+ rrPolicy.setClusterInstanceInfoFromString(list);
+ if (!membershipChangeForced) {
+ giso.forceMembershipChange() ;
+ }
+ }
+
+ @Override
+ public List<String> getNextRotation() {
+ return rrPolicy.getNextRotation();
+ }
+
+ private List<String> getEndpointList(Hashtable env, String defaultHost, String defaultPort) {
+ final List<String> list = new ArrayList<String>() ;
+ final String lbpv = getEnvSysProperty( env, LOAD_BALANCING_PROPERTY);
+ final List<String> lbList = splitOnComma(lbpv) ;
+ if (lbList.size() > 0) {
+ final String first = lbList.remove( 0 ) ;
+ if (first.equals(IC_BASED) || first.equals(IC_BASED_WEIGHTED)) {
+ // XXX concurrency issue here: possible race on global
+ System.setProperty(LOAD_BALANCING_PROPERTY, first );
+ }
+ }
+ list.addAll( lbList ) ;
+
+ if (list.isEmpty()) {
+ final String iepv = getEnvSysProperty( env, IIOP_ENDPOINTS_PROPERTY);
+ final List<String> epList = splitOnComma(iepv) ;
+ list.addAll( epList ) ;
+ }
+
+ if (list.isEmpty()) {
+ final String urlValue = (String)env.get(
+ ORBLocator.JNDI_PROVIDER_URL_PROPERTY) ;
+ list.addAll( rrPolicy.getEndpointForProviderURL( urlValue ) ) ;
+ }
+
+ if (list.isEmpty()) {
+ String host = getEnvSysProperty( env,
+ ORBLocator.OMG_ORB_INIT_HOST_PROPERTY) ;
+ String port = getEnvSysProperty( env,
+ ORBLocator.OMG_ORB_INIT_PORT_PROPERTY) ;
+
+ if (host != null && port != null) {
+ list.addAll(rrPolicy.getAddressPortList(host, port) ) ;
+ logger.log(Level.WARNING, NO_ENDPOINT_SELECTED, new Object[]{host, port});
+ }
+ }
+
+ if (list.isEmpty()) {
+ if (defaultHost != null && defaultPort != null) {
+ list.add( defaultHost + ":" + defaultPort ) ;
+ }
+ }
+
+ if (list.isEmpty()) {
+ throw new RuntimeException("Cannot Proceed. No Endpoints specified.");
+ }
+
+ return list ;
+ }
+
+ private List<String> splitOnComma( String arg ) {
+ final List<String> result = new ArrayList<String>() ;
+ if (arg != null) {
+ final String[] splits = arg.split( "," ) ;
+ if (splits != null) {
+ for (String str : splits) {
+ result.add( str.trim() ) ;
+ }
+ }
+ }
+
+ return result ;
+ }
+
+ private String getEnvSysProperty( Hashtable env, String pname ) {
+ String value = (String)env.get( pname ) ;
+ if (value == null) {
+ value = System.getProperty( pname ) ;
+ }
+ return value ;
+ }
+
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/OTSPolicyImpl.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/OTSPolicyImpl.java
new file mode 100644
index 0000000..54420ff
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/OTSPolicyImpl.java
@@ -0,0 +1,75 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+
+import org.omg.CORBA.Policy;
+import org.omg.CORBA.LocalObject;
+
+import org.omg.CosTransactions.ADAPTS;
+import org.omg.CosTransactions.FORBIDS;
+import org.omg.CosTransactions.REQUIRES;
+import org.omg.CosTransactions.OTSPolicy;
+import org.omg.CosTransactions.OTS_POLICY_TYPE;
+import org.omg.PortableInterceptor.AdapterStateHelper;
+
+public class OTSPolicyImpl extends LocalObject implements OTSPolicy {
+
+ // class constants
+
+ public static final OTSPolicyImpl _ADAPTS = new OTSPolicyImpl(ADAPTS.value);
+ public static final OTSPolicyImpl _FORBIDS = new OTSPolicyImpl(FORBIDS.value);
+ public static final OTSPolicyImpl _REQUIRES = new OTSPolicyImpl(REQUIRES.value);
+
+ // instance variables
+
+ private short value = FORBIDS.value;
+
+ // constructor
+
+ public OTSPolicyImpl() {
+ this.value = ADAPTS.value;
+ }
+
+ public OTSPolicyImpl(short value) {
+ this.value = value;
+ }
+
+ // org.omg.CosTransactions.OTSPolicyOperations implementation
+
+ public short value() {
+ return this.value;
+ }
+
+ // org.omg.CORBA.PolicyOperations implementation
+
+ public int policy_type() {
+ return OTS_POLICY_TYPE.value;
+ }
+
+ public Policy copy() {
+ return new OTSPolicyImpl(this.value);
+ }
+
+ public void destroy() {
+ value = FORBIDS.value;
+ }
+
+ public String toString() {
+ return "OTSPolicy[" + this.value + "]";
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/PEORBConfigurator.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/PEORBConfigurator.java
new file mode 100755
index 0000000..deb0187
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/PEORBConfigurator.java
@@ -0,0 +1,305 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+// import org.glassfish.pfl.dynamic.copyobject.spi.CopyobjectDefaults ;
+import com.sun.corba.ee.spi.copyobject.CopyobjectDefaults ;
+import org.glassfish.pfl.dynamic.copyobject.spi.ObjectCopierFactory ;
+import com.sun.corba.ee.spi.copyobject.CopierManager;
+import com.sun.corba.ee.spi.orb.DataCollector;
+import com.sun.corba.ee.spi.orb.ORB;
+import com.sun.corba.ee.spi.orb.ORBConfigurator;
+import com.sun.corba.ee.spi.threadpool.NoSuchWorkQueueException;
+import com.sun.corba.ee.spi.threadpool.ThreadPoolManager;
+import com.sun.corba.ee.spi.presentation.rmi.InvocationInterceptor;
+import com.sun.corba.ee.spi.transport.TransportManager;
+import com.sun.corba.ee.spi.transport.Acceptor;
+import com.sun.corba.ee.spi.transport.TransportDefault;
+import com.sun.logging.LogDomains;
+import org.glassfish.orb.admin.config.IiopListener;
+import org.glassfish.grizzly.config.dom.Ssl;
+import java.util.logging.Logger;
+import org.glassfish.enterprise.iiop.api.IIOPConstants;
+import org.glassfish.enterprise.iiop.util.S1ASThreadPoolManager;
+import org.glassfish.enterprise.iiop.util.IIOPUtils;
+
+import java.nio.channels.SocketChannel;
+import java.net.Socket;
+import java.util.List;
+
+import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
+
+import com.sun.corba.ee.impl.naming.cosnaming.TransientNameService;
+
+// TODO import org.omg.CORBA.TSIdentification;
+
+// TODO import com.sun.corba.ee.impl.txpoa.TSIdentificationImpl;
+
+import com.sun.corba.ee.spi.threadpool.ThreadPool;
+import java.util.logging.Level;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.nio.channels.SelectableChannel;
+import org.glassfish.enterprise.iiop.util.ThreadPoolStats;
+import org.glassfish.enterprise.iiop.util.ThreadPoolStatsImpl;
+import org.glassfish.external.probe.provider.PluginPoint;
+import org.glassfish.external.probe.provider.StatsProviderManager;
+
+public class PEORBConfigurator implements ORBConfigurator {
+ private static final java.util.logging.Logger logger =
+ java.util.logging.Logger.getLogger(LogDomains.CORBA_LOGGER);
+
+ private static final String SSL = "SSL";
+ private static final String SSL_MUTUALAUTH = "SSL_MUTUALAUTH";
+ private static final String IIOP_CLEAR_TEXT_CONNECTION =
+ "IIOP_CLEAR_TEXT";
+ private static final String DEFAULT_ORB_INIT_HOST = "localhost";
+
+ // TODO private static TSIdentification tsIdent;
+ private static ORB theORB;
+ private static ThreadPoolManager threadpoolMgr = null;
+ private static boolean txServiceInitialized = false;
+
+ private Acceptor lazyAcceptor = null;
+
+ static {
+ // TODO tsIdent = new TSIdentificationImpl();
+ }
+
+ private GlassFishORBHelper getHelper() {
+ IIOPUtils iiopUtils = IIOPUtils.getInstance();
+ return iiopUtils.getHabitat().getService(
+ GlassFishORBHelper.class);
+ }
+
+ public void configure(DataCollector dc, ORB orb) {
+ try {
+ //begin temp fix for bug 6320008
+ // this is needed only because we are using transient Name Service
+ //this should be removed once we have the persistent Name Service in place
+ /*TODO
+ orb.setBadServerIdHandler(
+ new BadServerIdHandler() {
+ public void handle(ObjectKey objectkey) {
+ // NO-OP
+ }
+ }
+ );
+ */
+ //end temp fix for bug 6320008
+ if (threadpoolMgr != null) {
+ // This will be the case for the Server Side ORB created
+ // For client side threadpoolMgr will be null, so we will
+ // never come here
+ orb.setThreadPoolManager(threadpoolMgr);
+ }
+
+ // Do the stats for the threadpool
+
+ ThreadPoolManager tpool = orb.getThreadPoolManager();
+ // ORB creates its own threadpool if threadpoolMgr was null above
+ ThreadPool thpool=tpool.getDefaultThreadPool();
+ String ThreadPoolName = thpool.getName();
+ ThreadPoolStats tpStats = new ThreadPoolStatsImpl(
+ thpool.getWorkQueue(0).getThreadPool());
+ StatsProviderManager.register("orb", PluginPoint.SERVER,
+ "thread-pool/orb/threadpool/"+ThreadPoolName, tpStats);
+
+ configureCopiers(orb);
+ configureCallflowInvocationInterceptor(orb);
+
+ // In the server-case, iiop acceptors need to be set up after the
+ // initial part of the orb creation but before any
+ // portable interceptor initialization
+ IIOPUtils iiopUtils = IIOPUtils.getInstance();
+ if (iiopUtils.getProcessType().isServer()) {
+ List<IiopListener> iiop_listener_list = IIOPUtils.getInstance()
+ .getIiopService().getIiopListener() ;
+ IiopListener[] iiopListenerBeans = iiop_listener_list
+ .toArray(new IiopListener [iiop_listener_list.size()]) ;
+ this.createORBListeners(iiopUtils, iiopListenerBeans, orb);
+ }
+ if (orb.getORBData().environmentIsGFServer()) {
+ // Start the transient name service, which publishes NameService
+ // in the ORB's local resolver.
+ new TransientNameService(orb);
+ }
+ // Publish the ORB reference back to GlassFishORBHelper, so that
+ // subsequent calls from interceptor ORBInitializers can call
+ // GlassFishORBHelper.getORB() without problems. This is
+ // especially important for code running in the service initializer
+ // thread.
+ getHelper().setORB(orb);
+ } catch (NoSuchWorkQueueException ex) {
+ Logger.getLogger(PEORBConfigurator.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ private static void configureCopiers(ORB orb) {
+ CopierManager cpm = orb.getCopierManager();
+
+ ObjectCopierFactory stream =
+ CopyobjectDefaults.makeORBStreamObjectCopierFactory(orb) ;
+ ObjectCopierFactory reflect =
+ CopyobjectDefaults.makeReflectObjectCopierFactory(orb) ;
+ ObjectCopierFactory fallback =
+ CopyobjectDefaults.makeFallbackObjectCopierFactory( reflect, stream ) ;
+ ObjectCopierFactory reference =
+ CopyobjectDefaults.getReferenceObjectCopierFactory() ;
+
+ cpm.registerObjectCopierFactory( fallback, IIOPConstants.PASS_BY_VALUE_ID ) ;
+ cpm.registerObjectCopierFactory( reference, IIOPConstants.PASS_BY_REFERENCE_ID ) ;
+ cpm.setDefaultId( IIOPConstants.PASS_BY_VALUE_ID ) ;
+ }
+
+ // Called from GlassFishORBManager only when the ORB is running on server side
+ public static void setThreadPoolManager() {
+ threadpoolMgr = S1ASThreadPoolManager.getThreadPoolManager();
+ }
+
+ private static void configureCallflowInvocationInterceptor(ORB orb) {
+ orb.setInvocationInterceptor(
+ new InvocationInterceptor() {
+ @Override
+ public void preInvoke() {
+ /* TODO
+ Agent agent = Switch.getSwitch().getCallFlowAgent();
+ if (agent != null) {
+ agent.startTime(
+ ContainerTypeOrApplicationType.ORB_CONTAINER);
+ }
+ */
+ }
+
+ @Override
+ public void postInvoke() {
+ /* TODO
+ Agent agent = Switch.getSwitch().getCallFlowAgent();
+ if (agent != null) {
+ agent.endTime();
+ }
+ */
+ }
+ }
+ );
+ }
+
+ private Acceptor addAcceptor( org.omg.CORBA.ORB orb, boolean isLazy,
+ String host, String type, int port ) {
+
+ com.sun.corba.ee.spi.orb.ORB theOrb = (com.sun.corba.ee.spi.orb.ORB) orb;
+ TransportManager ctm = theOrb.getTransportManager() ;
+ Acceptor acceptor ;
+ if (isLazy) {
+ acceptor = TransportDefault.makeLazyCorbaAcceptor(
+ theOrb, port, host, type );
+ } else {
+ acceptor = TransportDefault.makeStandardCorbaAcceptor(
+ theOrb, port, host, type ) ;
+ }
+ ctm.registerAcceptor( acceptor ) ;
+ return acceptor;
+ }
+
+ private static final Set<String> ANY_ADDRS = new HashSet<String>(
+ Arrays.asList( "0.0.0.0", "::", "::ffff:0.0.0.0" ) ) ;
+
+ private String handleAddrAny( String hostAddr ) {
+ if (ANY_ADDRS.contains( hostAddr )) {
+ try {
+ return java.net.InetAddress.getLocalHost().getHostAddress() ;
+ } catch (java.net.UnknownHostException exc) {
+ logger.log( Level.WARNING,
+ "Unknown host exception : Setting host to localhost" ) ;
+ return DEFAULT_ORB_INIT_HOST ;
+ }
+ } else {
+ return hostAddr ;
+ }
+ }
+
+ private void createORBListeners( IIOPUtils iiopUtils,
+ IiopListener[] iiopListenerBeans, org.omg.CORBA.ORB orb ) {
+
+ if (iiopListenerBeans != null) {
+ int lazyCount = 0 ;
+ for (IiopListener ilb : iiopListenerBeans) {
+ boolean securityEnabled = Boolean.valueOf( ilb.getSecurityEnabled() ) ;
+
+ boolean isLazy = Boolean.valueOf( ilb.getLazyInit() ) ;
+ if( isLazy ) {
+ lazyCount++;
+ }
+
+ if (lazyCount > 1) {
+ throw new IllegalStateException( "Invalid iiop-listener "
+ + ilb.getId()
+ + ". Only one iiop-listener can be configured "
+ + "with lazy-init=true");
+ }
+
+ int port = Integer.parseInt( ilb.getPort() ) ;
+ String host = handleAddrAny( ilb.getAddress() ) ;
+
+ if (!securityEnabled || ilb.getSsl() == null) {
+ Acceptor acceptor = addAcceptor( orb, isLazy, host,
+ IIOP_CLEAR_TEXT_CONNECTION, port ) ;
+ if( isLazy ) {
+ lazyAcceptor = acceptor;
+ }
+ } else {
+ if (isLazy) {
+ throw new IllegalStateException( "Invalid iiop-listener "
+ + ilb.getId()
+ + ". Lazy-init not supported for SSL iiop-listeners");
+ }
+
+ Ssl sslBean = ilb.getSsl() ;
+ assert sslBean != null ;
+
+ boolean clientAuth = Boolean.valueOf(
+ sslBean.getClientAuthEnabled() ) ;
+ String type = clientAuth ? SSL_MUTUALAUTH : SSL ;
+ addAcceptor( orb, isLazy, host, type, port ) ;
+ }
+ }
+
+ if( lazyCount == 1 ) {
+ getHelper().setSelectableChannelDelegate(new AcceptorDelegateImpl(
+ lazyAcceptor));
+ }
+ }
+ }
+
+ private static class AcceptorDelegateImpl
+ implements GlassFishORBHelper.SelectableChannelDelegate {
+
+ private Acceptor acceptor;
+
+ AcceptorDelegateImpl(Acceptor lazyAcceptor) {
+ acceptor = lazyAcceptor;
+ }
+
+ @Override
+ public void handleRequest(SelectableChannel channel) {
+ SocketChannel sch = (SocketChannel)channel ;
+ Socket socket = sch.socket() ;
+ acceptor.processSocket( socket ) ;
+ }
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POAProtocolMgr.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POAProtocolMgr.java
new file mode 100644
index 0000000..c1f29fa
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POAProtocolMgr.java
@@ -0,0 +1,400 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.spi.ior.IOR;
+import com.sun.corba.ee.spi.ior.ObjectKey;
+import com.sun.corba.ee.spi.ior.TaggedProfile;
+import com.sun.corba.ee.spi.oa.rfm.ReferenceFactory;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+
+import org.glassfish.enterprise.iiop.api.ProtocolManager;
+import org.glassfish.enterprise.iiop.api.RemoteReferenceFactory;
+
+import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
+import org.glassfish.enterprise.iiop.spi.EjbService;
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+import com.sun.enterprise.util.Utility;
+
+import javax.ejb.NoSuchObjectLocalException;
+import javax.ejb.TransactionRolledbackLocalException;
+import javax.ejb.TransactionRequiredLocalException;
+
+import org.omg.PortableServer.POA;
+import org.omg.PortableServer.Servant;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextHelper;
+import org.omg.CosNaming.NameComponent;
+
+import com.sun.corba.ee.spi.oa.rfm.ReferenceFactoryManager ;
+import com.sun.corba.ee.spi.orb.ORB;
+import com.sun.corba.ee.spi.presentation.rmi.PresentationManager;
+import com.sun.corba.ee.spi.presentation.rmi.StubAdapter;
+
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.logging.LogDomains;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.inject.Provider;
+import javax.rmi.CORBA.Tie;
+
+import org.jvnet.hk2.annotations.Service;
+import org.glassfish.hk2.api.ServiceLocator;
+import javax.inject.Inject;
+import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.INVALID_TRANSACTION;
+import org.omg.CORBA.LocalObject;
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.NO_PERMISSION;
+import org.omg.CORBA.OBJECT_NOT_EXIST;
+import org.omg.CORBA.Policy;
+import org.omg.CORBA.TRANSACTION_REQUIRED;
+import org.omg.CORBA.TRANSACTION_ROLLEDBACK;
+import org.omg.PortableServer.ForwardRequest;
+import org.omg.PortableServer.ServantLocator;
+import org.omg.PortableServer.ServantLocatorPackage.CookieHolder;
+
+/**
+ * This class implements the ProtocolManager interface for the
+ * RMI/IIOP ORB with POA (Portable Object Adapter).
+ * Note that the POA is now accessed only through the
+ * ReferenceFactoryManager for EJB.
+ *
+ * @author Vivek Nagar
+ */
+
+@Service
+public final class POAProtocolMgr extends org.omg.CORBA.LocalObject
+ implements ProtocolManager
+{
+ private static final Logger _logger =
+ LogDomains.getLogger(POAProtocolMgr.class, LogDomains.CORBA_LOGGER);
+
+ private static final int MAPEXCEPTION_CODE = 9998;
+
+ private ORB orb;
+
+ private ReferenceFactoryManager rfm = null ;
+
+ private PresentationManager presentationMgr;
+
+ @Inject
+ private ServiceLocator services;
+
+ public POAProtocolMgr() {}
+
+ @Inject
+ private Provider<EjbService> ejbServiceProvider;
+
+ @Override
+ public void initialize(org.omg.CORBA.ORB o) {
+ this.orb = (ORB)o;
+
+ this.presentationMgr = ORB.getPresentationManager();
+ }
+
+
+ // Called in all VMs, must be called only after InitialNaming is available
+ @Override
+ public void initializePOAs() throws Exception {
+ // NOTE: The RootPOA manager used to be activated here.
+ getRFM() ;
+ _logger.log(Level.FINE,
+ "POAProtocolMgr.initializePOAs: RFM resolved and activated");
+ }
+
+ private static class RemoteNamingServantLocator extends LocalObject
+ implements ServantLocator {
+
+ private final ORB orb ;
+ private final Servant servant ;
+
+ public RemoteNamingServantLocator( ORB orb, Remote impl ) {
+ this.orb = orb ;
+ Tie tie = ORB.getPresentationManager().getTie() ;
+ tie.setTarget( impl ) ;
+ servant = Servant.class.cast( tie ) ;
+ }
+
+ @Override
+ public synchronized Servant preinvoke( byte[] oid, POA adapter,
+ String operation, CookieHolder the_cookie ) throws ForwardRequest {
+ return servant ;
+ }
+
+ @Override
+ public void postinvoke( byte[] oid, POA adapter,
+ String operation, Object the_cookie, Servant the_servant ) {
+ }
+ }
+
+ private synchronized ReferenceFactoryManager getRFM() {
+ if (rfm == null) {
+ try {
+ rfm = ReferenceFactoryManager.class.cast(
+ orb.resolve_initial_references( "ReferenceFactoryManager" )) ;
+ rfm.activate() ;
+ } catch (Exception exc) {
+ // do nothing
+ }
+ }
+
+ return rfm ;
+ }
+
+ private org.omg.CORBA.Object getRemoteNamingReference( Remote remoteNamingProvider ) {
+ final ServantLocator locator = new RemoteNamingServantLocator( orb,
+ remoteNamingProvider ) ;
+
+ final PresentationManager pm = ORB.getPresentationManager() ;
+
+ String repositoryId ;
+ try {
+ repositoryId = pm.getRepositoryId( remoteNamingProvider ) ;
+ } catch (Exception exc) {
+ throw new RuntimeException( exc ) ;
+ }
+
+ final List<Policy> policies = new ArrayList<Policy>() ;
+ final ReferenceFactory rf = getRFM().create( "RemoteSerialContextProvider",
+ repositoryId, policies, locator ) ;
+
+ // arbitrary
+ final byte[] oid = { 0, 3, 5, 7, 2, 37, 42 } ;
+
+ final org.omg.CORBA.Object ref = rf.createReference( oid ) ;
+ return ref ;
+ }
+
+ @Override
+ public void initializeRemoteNaming(Remote remoteNamingProvider)
+ throws Exception {
+
+ try {
+ org.omg.CORBA.Object provider = getRemoteNamingReference( remoteNamingProvider ) ;
+
+ // put object in NameService
+ org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
+ NamingContext ncRef = NamingContextHelper.narrow(objRef);
+ // XXX use constant for SerialContextProvider name
+ NameComponent nc = new NameComponent("SerialContextProvider", "");
+
+ NameComponent path[] = {nc};
+ ncRef.rebind(path, provider);
+ } catch (Exception ex) {
+ _logger.log(Level.SEVERE,
+ "enterprise_naming.excep_in_insertserialcontextprovider",ex);
+
+ RemoteException re = new RemoteException("initSerialCtxProvider error", ex);
+ throw re;
+ }
+
+ }
+
+ // Called only in J2EE Server VM
+ @Override
+ public void initializeNaming() throws Exception {
+ // NOTE: The TransientNameService reference is NOT HA.
+ // new TransientNameService((com.sun.corba.ee.spi.orb.ORB)orb);
+ // _logger.log(Level.FINE, "POAProtocolMgr.initializeNaming: complete");
+ }
+
+
+ /**
+ * Return a factory that can be used to create/destroy remote
+ * references for a particular EJB type.
+ * @param container The container to use
+ * @param remoteHomeView The remote home view
+ * @param id The object id
+ * @return the ref factory
+ */
+ @Override
+ public RemoteReferenceFactory getRemoteReferenceFactory(
+ EjbContainerFacade container, boolean remoteHomeView, String id) {
+
+ RemoteReferenceFactory factory = new POARemoteReferenceFactory
+ (container, this, orb, remoteHomeView, id);
+
+ return factory;
+ }
+
+ /**
+ * Connect the RMI object to the protocol.
+ */
+ @Override
+ public void connectObject(Remote remoteObj) throws RemoteException
+ {
+ StubAdapter.connect(remoteObj, orb);
+ }
+
+
+ @Override
+ public boolean isStub(Object obj) {
+ return StubAdapter.isStub(obj);
+ }
+
+ @Override
+ public boolean isLocal(Object obj) {
+ return StubAdapter.isLocal(obj);
+ }
+
+ @Override
+ public byte[] getObjectID(org.omg.CORBA.Object obj) {
+ IOR ior = ((com.sun.corba.ee.spi.orb.ORB)orb).getIOR(obj, false);
+ java.util.Iterator iter = ior.iterator();
+
+ byte[] oid = null;
+ if (iter.hasNext()) {
+ TaggedProfile profile = (TaggedProfile) iter.next();
+ ObjectKey objKey = profile.getObjectKey();
+ oid = objKey.getId().getId();
+ }
+
+ return oid;
+ }
+
+ /**
+ * Return true if the two object references refer to the same
+ * remote object.
+ */
+ @Override
+ public boolean isIdentical(Remote obj1, Remote obj2) {
+ if (obj1 instanceof org.omg.CORBA.Object && obj2 instanceof org.omg.CORBA.Object) {
+ org.omg.CORBA.Object corbaObj1 = (org.omg.CORBA.Object)obj1;
+ org.omg.CORBA.Object corbaObj2 = (org.omg.CORBA.Object)obj2;
+
+ return corbaObj1._is_equivalent(corbaObj2);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public void validateTargetObjectInterfaces(Remote targetObj) {
+ if( targetObj != null ) {
+ // All Remote interfaces implemented by targetObj will be
+ // validated as a side-effect of calling setTarget().
+ // A runtime exception will be propagated if validation fails.
+ Tie tie = presentationMgr.getTie();
+ tie.setTarget(targetObj);
+ } else {
+ throw new IllegalArgumentException
+ ("null passed to validateTargetObjectInterfaces");
+ }
+
+ }
+
+ /**
+ * Map the EJB/RMI exception to a protocol-specific (e.g. CORBA) exception
+ */
+ @Override
+ public Throwable mapException(Throwable exception) {
+
+ boolean initCause = true;
+ Throwable mappedException = exception;
+
+ if ( exception instanceof java.rmi.NoSuchObjectException
+ || exception instanceof NoSuchObjectLocalException )
+ {
+ mappedException = new OBJECT_NOT_EXIST(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else if ( exception instanceof java.rmi.AccessException
+ || exception instanceof javax.ejb.AccessLocalException )
+ {
+ mappedException = new NO_PERMISSION(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else if ( exception instanceof java.rmi.MarshalException ) {
+ mappedException = new MARSHAL(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else if ( exception instanceof javax.transaction.TransactionRolledbackException
+ || exception instanceof TransactionRolledbackLocalException )
+ {
+ mappedException = new TRANSACTION_ROLLEDBACK(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else if ( exception instanceof javax.transaction.TransactionRequiredException
+ || exception instanceof TransactionRequiredLocalException )
+ {
+ mappedException = new TRANSACTION_REQUIRED(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else if ( exception instanceof javax.transaction.InvalidTransactionException ) {
+ mappedException = new INVALID_TRANSACTION(MAPEXCEPTION_CODE,
+ CompletionStatus.COMPLETED_MAYBE);
+ } else {
+ initCause = false;
+ }
+
+ if( initCause ) {
+ mappedException.initCause(exception);
+ }
+
+ return mappedException;
+ }
+
+
+ /**
+ * Called from SecurityMechanismSelector for each objref creation
+ */
+ @Override
+ public EjbDescriptor getEjbDescriptor(byte[] ejbKey) {
+ EjbDescriptor result = null;
+
+ try {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "POAProtocolMgr.getEjbDescriptor->: {0}", ejbKey);
+ }
+
+ if ( ejbKey.length < POARemoteReferenceFactory.EJBID_OFFSET + 8 ) {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "POAProtocolMgr.getEjbDescriptor: {0}: {1} < {2}{3}",
+ new Object[]{ejbKey, ejbKey.length,
+ POARemoteReferenceFactory.EJBID_OFFSET, 8});
+ }
+
+ return null;
+ }
+
+ long ejbId = Utility.bytesToLong(ejbKey,
+ POARemoteReferenceFactory.EJBID_OFFSET);
+
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "POAProtocolMgr.getEjbDescriptor: {0}: ejbId: {1}",
+ new Object[]{ejbKey, ejbId});
+ }
+
+ EjbService ejbService = ejbServiceProvider.get();
+
+ result = ejbService.ejbIdToDescriptor(ejbId);
+ } finally {
+ if(_logger.isLoggable(Level.FINE)) {
+ _logger.log(Level.FINE,
+ "POAProtocolMgr.getEjbDescriptor<-: {0}: {1}",
+ new Object[]{ejbKey, result});
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POARemoteReferenceFactory.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POARemoteReferenceFactory.java
new file mode 100755
index 0000000..b5a0d9b
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/POARemoteReferenceFactory.java
@@ -0,0 +1,613 @@
+/*
+ * 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.enterprise.iiop.impl;
+
+
+import javax.ejb.NoSuchObjectLocalException;
+
+import java.rmi.Remote;
+
+import java.security.AccessController ;
+import java.security.PrivilegedAction ;
+
+import org.omg.CORBA.portable.Delegate;
+
+import org.glassfish.enterprise.iiop.api.RemoteReferenceFactory;
+
+import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
+import org.glassfish.enterprise.iiop.util.S1ASThreadPoolManager;
+
+import org.omg.PortableServer.POA ;
+import org.omg.PortableServer.Servant ;
+import org.omg.PortableServer.ServantLocator ;
+import org.omg.PortableServer.ServantLocatorPackage.CookieHolder ;
+
+import com.sun.logging.LogDomains;
+
+import com.sun.enterprise.deployment.EjbDescriptor;
+
+// TODO Only needed for checkpointing
+// import com.sun.ejb.base.sfsb.util.EJBServerConfigLookup;
+
+import com.sun.corba.ee.spi.extension.ServantCachingPolicy;
+import com.sun.corba.ee.spi.extension.ZeroPortPolicy;
+import com.sun.corba.ee.spi.extension.CopyObjectPolicy;
+import com.sun.corba.ee.spi.extension.RequestPartitioningPolicy;
+import com.sun.corba.ee.spi.threadpool.ThreadPoolManager;
+
+import com.sun.corba.ee.spi.presentation.rmi.PresentationManager ;
+
+import com.sun.corba.ee.spi.presentation.rmi.StubAdapter;
+import com.sun.corba.ee.spi.oa.rfm.ReferenceFactory ;
+import com.sun.corba.ee.spi.oa.rfm.ReferenceFactoryManager ;
+
+import com.sun.corba.ee.spi.misc.ORBConstants;
+import com.sun.corba.ee.org.omg.CORBA.SUNVMCID;
+import com.sun.corba.ee.spi.ior.IOR;
+import com.sun.corba.ee.spi.ior.ObjectKey;
+import com.sun.corba.ee.spi.ior.TaggedProfile;
+import com.sun.corba.ee.spi.orb.ORB;
+
+import com.sun.enterprise.util.Utility;
+
+import org.glassfish.pfl.dynamic.codegen.spi.Wrapper ;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.IOException;
+import java.io.NotSerializableException;
+import javax.rmi.CORBA.Tie;
+import javax.rmi.CORBA.Util;
+import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.OBJECT_NOT_EXIST;
+import org.omg.CORBA.Policy;
+
+/**
+ * This class implements the RemoteReferenceFactory interface for the
+ * RMI/IIOP ORB with POA (Portable Object Adapter).
+ * There is one instance of the POARemoteReferenceFactory for each
+ * EJB type.
+ *
+ * It also implements the preinvoke/postinvoke APIs in the
+ * POA's ServantLocator interface, which are called before/after
+ * every invocation (local or remote).
+ * It creates a RMI-IIOP-POA object reference (a stub) for every EJBObject
+ * and EJBHome in the EJB container.
+ *
+ * @author Kenneth Saks
+ */
+
+public final class POARemoteReferenceFactory extends org.omg.CORBA.LocalObject
+ implements RemoteReferenceFactory, ServantLocator
+{
+ static final int PASS_BY_VALUE_ID = 0;
+ static final int PASS_BY_REFERENCE_ID = 1;
+
+ static final int OTS_POLICY_TYPE = SUNVMCID.value + 123;
+ static final int CSIv2_POLICY_TYPE = SUNVMCID.value + 124;
+ static final int REQUEST_DISPATCH_POLICY_TYPE = SUNVMCID.value + 125;
+ static final int SFSB_VERSION_POLICY_TYPE = SUNVMCID.value + 126;
+
+ private static final java.util.logging.Logger logger =
+ java.util.logging.Logger.getLogger(LogDomains.CORBA_LOGGER);
+ private static final int GET_TIE_EXCEPTION_CODE = 9999;
+
+ private EjbContainerFacade container;
+ private EjbDescriptor ejbDescriptor;
+ private ClassLoader appClassLoader;
+
+ private ORB orb;
+ private POAProtocolMgr protocolMgr;
+ private PresentationManager presentationMgr;
+
+ private ReferenceFactory ejbHomeReferenceFactory ;
+ private PresentationManager.StubFactory ejbHomeStubFactory;
+ private String ejbHomeRepositoryId;
+
+ private ReferenceFactory ejbObjectReferenceFactory ;
+ private PresentationManager.StubFactory ejbObjectStubFactory;
+ private String ejbObjectRepositoryId;
+
+ private String remoteBusinessIntf;
+
+ // true if remote home view. false if remote business view.
+ // Used when getting target object for an invocation.
+ private boolean isRemoteHomeView;
+
+ private String poaId_EJBHome;
+ private String poaId_EJBObject;
+
+ // The EJB key format with field-name(size in bytes):
+ // -----------------------------------------
+ // | EJB ID(8) | INSTANCEKEY | INSTANCEKEY |
+ // | | LENGTH(4) | (unknown) |
+ // -----------------------------------------
+ // The following are the offsets for the fields in the EJB key.
+ static final int EJBID_OFFSET = 0;
+ private static final int INSTANCEKEYLEN_OFFSET = 8;
+ private static final int INSTANCEKEY_OFFSET = 12;
+
+ POARemoteReferenceFactory(EjbContainerFacade container, POAProtocolMgr protocolMgr,
+ ORB orb, boolean remoteHomeView, String id) {
+
+ this.protocolMgr = protocolMgr;
+ this.orb = orb;
+ this.poaId_EJBHome = id + "-EJBHome";
+ this.poaId_EJBObject = id + "-EJBObject";
+ this.presentationMgr = orb.getPresentationManager();
+ this.container = container;
+ this.ejbDescriptor = container.getEjbDescriptor();
+ this.isRemoteHomeView = remoteHomeView;
+
+ appClassLoader = container.getClassLoader();
+
+ // NOTE: ReferenceFactory creation happens in setRepositoryIds.
+ }
+
+ @Override
+ public int getCSIv2PolicyType() {
+ return CSIv2_POLICY_TYPE;
+ }
+
+ /*
+ private String getRepositoryId(Class c) throws Exception {
+
+ // Using PresentationManager to get repository ID will always work,
+ // independent of whether we have generated static RMI-IIOP stubs.
+
+ PresentationManager.ClassData cData = presentationMgr.getClassData(c);
+ String[] typeIds = cData.getTypeIds();
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".getRepositoryId: {0}", typeIds[0]);
+ }
+
+ // Repository id is always 1st element in array.
+ return typeIds[0];
+ }
+ */
+
+ @Override
+ public void setRepositoryIds(Class homeIntf, Class remoteIntf)
+ {
+ PresentationManager.StubFactoryFactory sff =
+ ORB.getStubFactoryFactory();
+
+ // Home
+ ejbHomeStubFactory =
+ sff.createStubFactory( homeIntf.getName(), false,
+ "", null, appClassLoader);
+ String[] ejbHomeTypeIds = ejbHomeStubFactory.getTypeIds();
+ ejbHomeRepositoryId = ejbHomeTypeIds[0];
+
+ ejbObjectStubFactory = sff.createStubFactory
+ ( remoteIntf.getName(), false, "", null, appClassLoader);
+
+ String[] ejbObjectTypeIds = ejbObjectStubFactory.getTypeIds();
+
+ ejbObjectRepositoryId = ejbObjectTypeIds[0];
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".setRepositoryIds:" + " " + "{0} {1}",
+ new Object[]{ejbHomeRepositoryId, ejbObjectRepositoryId});
+ }
+
+ try {
+
+ ejbHomeReferenceFactory
+ = createReferenceFactory(poaId_EJBHome, ejbHomeRepositoryId);
+ ejbObjectReferenceFactory
+ = createReferenceFactory(poaId_EJBObject, ejbObjectRepositoryId);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if( !isRemoteHomeView ) {
+ remoteBusinessIntf = remoteIntf.getName();
+ }
+
+ }
+
+ @Override
+ public void cleanupClass(Class clazz) {
+
+ try {
+ presentationMgr.flushClass(clazz);
+ } catch(Exception e) {
+ logger.log(Level.FINE, "cleanupClass error", e);
+ }
+ }
+
+ private ReferenceFactory createReferenceFactory(String poaId, String repoid ) throws Exception {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".createReferenceFactory->: {0} {1}",
+ new Object[]{poaId, repoid});
+ }
+
+ ReferenceFactoryManager rfm =
+ (ReferenceFactoryManager) orb.resolve_initial_references(
+ ORBConstants.REFERENCE_FACTORY_MANAGER) ;
+
+ List<Policy> policies = new ArrayList<Policy>();
+
+ // Servant caching for local RMI-IIOP invocation performance
+ policies.add(ServantCachingPolicy.getPolicy());
+
+ // OTS Policy
+ policies.add(new OTSPolicyImpl());
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, ".createReferenceFactory: {0} {1}: {2}",
+ new Object[]{poaId, repoid, ejbDescriptor});
+
+ }
+
+ // CSIv2 Policy
+ policies.add(new CSIv2Policy(ejbDescriptor));
+
+ String threadPoolName = container.getUseThreadPoolId();
+ int threadPoolNumericID = 0;
+ boolean usePassByReference = container.getPassByReference();
+
+ if (usePassByReference) {
+ policies.add(new CopyObjectPolicy(PASS_BY_REFERENCE_ID));
+ }
+
+ if (threadPoolName != null) {
+ ThreadPoolManager threadPoolManager
+ = S1ASThreadPoolManager.getThreadPoolManager();
+ try {
+ threadPoolNumericID = threadPoolManager.getThreadPoolNumericId(
+ threadPoolName);
+ policies.add(new RequestPartitioningPolicy(threadPoolNumericID));
+ } catch (Exception ex) {
+ logger.log(Level.WARNING, "Not using threadpool-request-partitioning...", ex);
+ }
+ }
+
+ /** TODO
+ logger.log(Level.INFO, "POARemoteRefFactory checking if SFSBVersionPolicy need to be added");
+ EJBServerConfigLookup ejbConfigLookup =
+ new EJBServerConfigLookup(ejbDescriptor);
+ boolean addSFSBVersionPolicy = EJBServerConfigLookup.needToAddSFSBVersionInterceptors();
+ logger.log(Level.INFO, "POARemoteRefFactory addSFSBVersionPolicy? " + addSFSBVersionPolicy);
+ if (addSFSBVersionPolicy) {
+ if (container instanceof StatefulSessionContainer) {
+ StatefulSessionContainer sfsbCon = (StatefulSessionContainer) container;
+ if (sfsbCon.isHAEnabled()) {
+ policies.add(new SFSBVersionPolicy(ejbDescriptor.getUniqueId()));
+ }
+ }
+ }
+ **/
+
+ if (logger.isLoggable(Level.FINE)) {
+ String jndiName = ejbDescriptor.getJndiName();
+ logger.log(Level.FINE,
+ "Using Thread-Pool: [{0} ==> {1}] for jndi name: {2}",
+ new Object[]{threadPoolName, threadPoolNumericID, jndiName});
+ logger.log(Level.FINE, "Pass by reference: [{0}] for jndi name: {1}",
+ new Object[]{usePassByReference, usePassByReference});
+ }
+
+ // DisableClearTextIIOP policy which sets IIOP Profile port to 0
+ // if EJB allows only SSL invocations
+ if ( ejbDescriptor.allMechanismsRequireSSL() ) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.WARNING,
+ ".createReferenceFactory: {0} {1}: adding ZeroPortPolicy",
+ new Object[]{poaId, repoid});
+ }
+ policies.add(ZeroPortPolicy.getPolicy());
+ }
+
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE,
+ ".createReferenceFactory: {0} {1}: policies: {2}",
+ new Object[]{poaId, repoid, policies});
+ }
+
+ ReferenceFactory rf = rfm.create( poaId, repoid, policies, this ) ;
+ return rf ;
+ } finally {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.WARNING,
+ ".createReferenceFactory<-: {0} {1}",
+ new Object[]{poaId, repoid});
+ }
+ }
+ }
+
+
+ @Override
+ public java.rmi.Remote createRemoteReference(byte[] instanceKey)
+ {
+ return createRef(instanceKey, ejbObjectReferenceFactory,
+ ejbObjectStubFactory, ejbObjectRepositoryId );
+ }
+
+
+ @Override
+ public Remote createHomeReference(byte[] homeKey)
+ {
+ return createRef(homeKey, ejbHomeReferenceFactory,
+ ejbHomeStubFactory, ejbHomeRepositoryId ) ;
+ }
+
+ private void setClassLoader() {
+ ClassLoader cl ;
+ SecurityManager sman = System.getSecurityManager() ;
+ if (sman == null) {
+ cl = this.getClass().getClassLoader() ;
+ } else {
+ cl = AccessController.doPrivileged(
+ new PrivilegedAction<ClassLoader>() {
+ @Override
+ public ClassLoader run() {
+ return this.getClass().getClassLoader() ;
+ }
+ }
+ ) ;
+ }
+
+ Wrapper._setClassLoader( cl ) ;
+ }
+
+ private Remote createRef(byte[] instanceKey, ReferenceFactory rf,
+ PresentationManager.StubFactory stubFactory, String repoid )
+ {
+ try {
+ PresentationManager.StubFactory stubFact = stubFactory;
+ org.omg.CORBA.Object ref = _createRef(rf, instanceKey,repoid);
+
+ // Set the ClassLoader to the ClassLoader for this class,
+ // which is loaded by the OSGi bundle ClassLoader for the
+ // orb-iiop bundle, which depends on (among others) the
+ // glassfish-corba-codegen bundle, which contains the
+ // CodegenProxyStub class needed inside the makeStub call.
+ setClassLoader() ;
+
+ org.omg.CORBA.Object stub = stubFact.makeStub();
+ Delegate delegate = StubAdapter.getDelegate(ref);
+ StubAdapter.setDelegate(stub, delegate);
+
+ return (Remote) stub;
+
+ } catch(Exception e) {
+ logger.log(Level.SEVERE, "iiop.createreference_exception",
+ e.toString());
+
+ throw new RuntimeException("Unable to create reference ",e);
+ }
+ }
+
+ // NOTE: The repoid is only needed for logging.
+ private org.omg.CORBA.Object _createRef( ReferenceFactory rf,
+ byte[] instanceKey, String repoid ) throws Exception {
+
+ if ( logger.isLoggable(Level.FINE) ) {
+ logger.log(Level.FINE,
+ "\t\tIn POARemoteReferenceFactory._createRef, repositoryId = {0}",
+ repoid);
+ }
+
+ // Create the ejbKey using EJB's unique id + instanceKey
+ byte[] ejbKey = createEJBKey(ejbDescriptor.getUniqueId(),
+ instanceKey);
+
+ org.omg.CORBA.Object obj = rf.createReference( ejbKey ) ;
+
+ return obj;
+ }
+
+ private byte[] createEJBKey(long ejbId, byte[] instanceKey)
+ {
+ byte[] ejbkey = new byte[INSTANCEKEY_OFFSET+instanceKey.length];
+
+ Utility.longToBytes(ejbId, ejbkey, EJBID_OFFSET);
+ Utility.intToBytes(instanceKey.length, ejbkey, INSTANCEKEYLEN_OFFSET);
+ System.arraycopy(instanceKey, 0, ejbkey,
+ INSTANCEKEY_OFFSET, instanceKey.length);
+ return ejbkey;
+ }
+
+ /**
+ * Disconnect an EJBObject or EJBHome from the ORB.
+ */
+ @Override
+ public void destroyReference(Remote remoteRef, Remote remoteObj)
+ {
+ // Note: the POAs have the NON_RETAIN policy so they dont maintain
+ // any state for objects. We only need to unexport the object from
+ // the RMI/IIOP machinery.
+ // The following call also does tie.deactivate() for the remoteObj's tie
+ try {
+ Util.unexportObject(remoteObj);
+ } catch ( RuntimeException ex ) {
+ // A bug in Util.unexportObject causes this exception
+ // Ignore it.
+ } catch ( java.lang.Exception nsoe ){
+ // eat it and ignore it.
+ }
+ }
+
+ /**
+ * This is the implementation of ServantLocator.preinvoke()
+ * It is called from the POA before every remote invocation.
+ * Return a POA Servant (which is the RMI/IIOP Tie for EJBObject/EJBHome).
+ * @param ejbKey
+ * @param cookieHolder
+ */
+ @Override
+ public Servant preinvoke(byte[] ejbKey, POA adapter, String operation,
+ CookieHolder cookieHolder)
+ throws org.omg.PortableServer.ForwardRequest
+ {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "In preinvoke for operation:{0}", operation);
+ }
+
+ // get instance key
+ int keyLen = Utility.bytesToInt(ejbKey, INSTANCEKEYLEN_OFFSET);
+ byte[] instanceKey = new byte[keyLen];
+ System.arraycopy(ejbKey, INSTANCEKEY_OFFSET, instanceKey, 0, keyLen);
+
+ Servant servant = null;
+ try {
+ while ( servant == null ) {
+ // get the EJBObject / EJBHome
+ Remote targetObj =
+ container.getTargetObject(instanceKey,
+ (isRemoteHomeView ? null : remoteBusinessIntf));
+
+ // This could be null in rare cases for sfsbs and entity
+ // beans. It would be preferable to push the retry logic
+ // within the sfsb container and entity container
+ // implementations of getTargetObject, but for now let's keep
+ // the looping logic the same as it has always been.
+ if( targetObj != null ) {
+ // get the Tie which is the POA Servant
+ //fix for bug 6484935
+ @SuppressWarnings("unchecked")
+ Tie tie = (Tie)AccessController.doPrivileged(
+ new PrivilegedAction() {
+ @Override
+ public Tie run() {
+ return presentationMgr.getTie();
+ }
+ });
+
+ tie.setTarget(targetObj);
+ servant = (Servant) tie;
+ }
+ }
+ } catch (NoSuchObjectLocalException e) {
+ logger.log(Level.SEVERE,"iiop.gettie_exception", e);
+ throw new OBJECT_NOT_EXIST( GET_TIE_EXCEPTION_CODE,
+ CompletionStatus.COMPLETED_NO);
+ } catch (RuntimeException e) {
+ logger.log(Level.SEVERE,"iiop.runtime_exception", e);
+ throw e;
+ }
+
+ return servant;
+ }
+
+ @Override
+ public void postinvoke(byte[] ejbKey, POA adapter, String operation,
+ java.lang.Object cookie, Servant servant)
+ {
+ Remote target = null;
+ if ( servant != null ) {
+ target = ((Tie)servant).getTarget();
+ }
+
+ // Always release, since that restores previous context class loader.
+ container.releaseTargetObject(target);
+ }
+
+
+ @Override
+ public void destroy() {
+ try {
+ ejbHomeReferenceFactory.destroy() ;
+ ejbObjectReferenceFactory.destroy() ;
+ ejbHomeReferenceFactory = null ;
+ ejbObjectReferenceFactory = null ;
+
+ container = null;
+ ejbDescriptor = null;
+
+ orb = null;
+ protocolMgr = null;
+
+ } catch (Throwable th) {
+ logger.log(Level.SEVERE, "Exception during "
+ + "POARemoteRefFactory::destroy()", th);
+ }
+ }
+
+ @Override
+ public boolean hasSameContainerID(org.omg.CORBA.Object obj)
+ throws Exception
+ {
+ boolean result = false;
+ try {
+ IOR ior = (orb).getIOR(obj, false);
+ java.util.Iterator iter = ior.iterator();
+
+ byte[] oid = null;
+ if (iter.hasNext()) {
+ TaggedProfile profile = (TaggedProfile) iter.next();
+ ObjectKey objKey = profile.getObjectKey();
+ oid = objKey.getId().getId();
+ }
+
+ if ((oid != null) && (oid.length > INSTANCEKEY_OFFSET)) {
+ long cid = Utility.bytesToLong(oid, EJBID_OFFSET);
+ // To be really sure that is indeed a ref generated
+ // by our container we do the following checks
+ int keyLen = Utility.bytesToInt(oid, INSTANCEKEYLEN_OFFSET);
+ if (oid.length == keyLen + INSTANCEKEY_OFFSET) {
+ result = (cid == ejbDescriptor.getUniqueId() );
+ }
+ if (logger.isLoggable(Level.FINE)) {
+ StringBuilder sbuf = new StringBuilder();
+ sbuf.append("hasSameContainerID() result: ").append(result)
+ .append("; because ==> oid.length: ").append(oid.length)
+ .append("; instance-key-length: ").append(keyLen)
+ .append("; expected oid.length: ")
+ .append(keyLen).append("+").append(INSTANCEKEY_OFFSET)
+ .append("; myContainrID: ")
+ .append(ejbDescriptor.getUniqueId())
+ .append("; obj.containerID: ")
+ .append(cid);
+ logger.log(Level.FINE, sbuf.toString());
+ }
+ } else {
+ if (logger.isLoggable(Level.FINE)) {
+ if (oid == null) {
+ logger.log(Level.FINE,
+ "hasSameContainerID() failed because oid=null");
+ } else {
+ logger.log(Level.FINE,
+ "hasSameContainerID() failed because oid.length= "
+ + "{0}; but INSTANCE_KEY_OFFSET= {1}",
+ new Object[]{oid.length, INSTANCEKEY_OFFSET});
+ }
+ }
+ }
+ } catch (Exception ex) {
+ logger.log(Level.FINE, "Exception while checking for same containerID", ex);
+ throw ex;
+ }
+
+ return result;
+ }
+
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ throw new NotSerializableException();
+ }
+
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ throw new NotSerializableException();
+ }
+}
diff --git a/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/RoundRobinPolicy.java b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/RoundRobinPolicy.java
new file mode 100644
index 0000000..e267a42
--- /dev/null
+++ b/appserver/orb/orb-iiop/src/main/java/org/glassfish/enterprise/iiop/impl/RoundRobinPolicy.java
@@ -0,0 +1,442 @@
+/*
+ * Copyright (c) 2006, 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.enterprise.iiop.impl;
+
+import com.sun.corba.ee.spi.folb.ClusterInstanceInfo;
+import com.sun.corba.ee.spi.folb.SocketInfo;
+import com.sun.jndi.cosnaming.IiopUrl;
+import com.sun.logging.LogDomains;
+import org.glassfish.internal.api.ORBLocator;
+import org.glassfish.logging.annotation.LogMessageInfo;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.glassfish.api.naming.NamingClusterInfo.*;
+import static org.glassfish.enterprise.iiop.impl.NamingClusterInfoImpl.NO_ENDPOINT_SELECTED;
+import static org.glassfish.enterprise.iiop.impl.NamingClusterInfoImpl.logger;
+
+/**
+ * The list of endpoints are randomized the very first time.
+ * This happens only once( when called from the static block
+ * of SerialInitContextFactory class).
+ * Simple RoundRobin is a special case of Weighted Round Robin where the
+ * weight per endpoint is equal.With the dynamic reconfiguration
+ * implementation, the endpoints list willhave the following structure:
+ * - server_identifier (a stringified name for the machine)
+ * - weight- list of SocketInfo {type (type = CLEAR_TEXT or SSL) +
+ * IP address + port }
+ * The above structure supports multi-homed machines
+ * i.e. one machinehosting multiple IP addresses.
+ * The RoundRobinPolicy class can be the class that is also implementing
+ * the Listener interface for listening to events generated whenever there
+ * is a change in the cluster shape. The listener/event design is still
+ * under construction.This list of endpoints will have to be created during
+ * bootstrapping(i.e. when the client first starts up.) This list will comprise
+ * of theendpoints specified by the user in "com.sun.appserv.iiop.endpoints"
+ * property. We can assume a default weight for these endpoints (e.g 10).
+ * This list will be used to make the first lookup call. During the first
+ * lookup call, the actual list of endpoints will beprovided back.
+ * Then on, whenever there is any change in the clustershape,
+ * the listener will get the updated list of endpoints from theserver.
+ * The implementation for choosing the endpoint from the list of endpoints
+ * is as follows:Let's assume 4 endpoints:A(wt=10), B(wt=30), C(wt=40),
+ * D(wt=20).
+ * Using the Random API, generate a random number between 1 and10+30+40+20.
+ * Let's assume that the above list is randomized. Based on the weights, we
+ * have intervals as follows:
+ * 1-----10 (A's weight)
+ * 11----40 (A's weight + B's weight)
+ * 41----80 (A's weight + B's weight + C's weight)
+ * 81----100(A's weight + B's weight + C's weight + C's weight)
+ * Here's the psuedo code for deciding where to send the request:
+ * if (random_number between 1 & 10) {send request to A;}
+ * else if (random_number between 11 & 40) {send request to B;}
+ * else if (random_number between 41 & 80) {send request to C;}
+ * else if (random_number between 81 & 100) {send request to D;}
+ * For simple Round Robin, we can assume the same weight for all endpointsand
+ * perform the above.
+ * @author Sheetal Vartak
+ **/
+
+public class RoundRobinPolicy {
+ @LogMessageInfo(message = "Could not find an endpoint to send request to.")
+ public static final String COULD_NOT_FIND_ENDPOINT = "AS-ORB-00004";
+
+ @LogMessageInfo(message = "Unknown host: {0} Exception thrown : {1}")
+ public static final String UNKNOWN_HOST = "AS-ORB-00005";
+
+ @LogMessageInfo(message = "No Endpoints selected in com.sun.appserv.iiop.endpoints property. Using JNDI Provider URL {0} instead")
+ public static final String NO_ENDPOINTS_SELECTED_PROVIDER = "AS-ORB-00006";
+
+ @LogMessageInfo(message = "Exception : {0} thrown for bad provider URL String: {1}")
+ public static final String PROVIDER_EXCEPTION = "AS-ORB-00007";
+
+ // Each SocketInfo.type() must either start with SSL, or be CLEAR_TEXT
+ private static final String SSL = "SSL" ;
+ private static final String CLEAR_TEXT = "CLEAR_TEXT" ;
+
+ private static java.security.SecureRandom rand = new java.security.SecureRandom();
+
+ private List<ClusterInstanceInfo> endpointsList =
+ new LinkedList<ClusterInstanceInfo>();
+
+ private int totalWeight = 0;
+
+ private List<String> resolvedEndpoints ;
+
+ private static final int default_weight = 10;
+
+ //called during bootstrapping
+ public RoundRobinPolicy(List<String> list) {
+ setClusterInstanceInfoFromString(list);
+ }
+
+ // Copy list, changing any type that does not start with SSL to CLEAR_TEXT.
+ private List<SocketInfo> filterSocketInfos( List<SocketInfo> sis ) {
+ final List<SocketInfo> result = new ArrayList<SocketInfo>() ;
+ for (SocketInfo si : sis) {
+ final String newType = si.type().startsWith(SSL) ?
+ si.type() : CLEAR_TEXT ;
+ final SocketInfo siCopy = new SocketInfo( newType,
+ si.host(), si.port() ) ;
+ result.add( siCopy ) ;
+ }
+ return result ;
+ }
+
+ private boolean isWeighted() {
+ String policy = System.getProperty(LOAD_BALANCING_PROPERTY, IC_BASED);
+ return policy.equals(IC_BASED_WEIGHTED);
+ }
+
+ private List<ClusterInstanceInfo> filterClusterInfo(
+ List<ClusterInstanceInfo> info ) {
+
+ boolean isw = isWeighted() ;
+ ArrayList<ClusterInstanceInfo> newList =
+ new ArrayList<ClusterInstanceInfo>() ;
+ totalWeight = 0 ;
+
+ for (ClusterInstanceInfo clinfo : info) {
+ final int newWeight = isw ? clinfo.weight() : default_weight ;
+
+ final List<SocketInfo> newEndpoints =
+ filterSocketInfos( clinfo.endpoints() ) ;
+ final ClusterInstanceInfo newClinfo = new ClusterInstanceInfo(
+ clinfo.name(), newWeight, newEndpoints ) ;
+ newList.add( newClinfo ) ;
+
+ totalWeight += newWeight ;
+ }
+
+ return newList ;
+ }
+
+ private boolean containsMatchingAddress( List<ClusterInstanceInfo> list,
+ String host, int port ) {
+
+ for (ClusterInstanceInfo info : list) {
+ for (SocketInfo si : info.endpoints()) {
+ if (si.type().equals( CLEAR_TEXT )) {
+ if (si.host().equals( host) && si.port() == port) {
+ return true ;
+ }
+ }
+ }
+ }
+
+ return false ;
+ }
+
+ // Add those elements of the second list that do not contain a clear
+ // text address that appears in the first list.
+ private List<ClusterInstanceInfo> merge( List<ClusterInstanceInfo> first,
+ List<ClusterInstanceInfo> second ) {
+
+ List<ClusterInstanceInfo> result = new ArrayList<ClusterInstanceInfo>() ;
+ result.addAll( first ) ;
+ for (ClusterInstanceInfo info : second) {
+ for (SocketInfo si : info.endpoints()) {
+ if (!containsMatchingAddress(first, si.host(), si.port() )) {
+ result.add( info ) ;
+ }
+ }
+ }
+ return result ;
+ }
+
+ private List<ClusterInstanceInfo> fromHostPortStrings( List<String> list ) {
+ List<ClusterInstanceInfo> result =
+ new LinkedList <ClusterInstanceInfo> ();
+
+ for( String elem : list) {
+ ClusterInstanceInfo info = makeClusterInstanceInfo( elem,
+ default_weight ) ;
+ result.add( info );
+ }
+
+ return result ;
+ }
+
+
+ //will be called after dynamic reconfig
+ // used in GroupInfoServiceObserverImpl
+ synchronized final void setClusterInstanceInfo(List<ClusterInstanceInfo> list) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "setClusterInstanceInfo: list={0}", list);
+ }
+
+ List<ClusterInstanceInfo> filtered = filterClusterInfo(list);
+ List<ClusterInstanceInfo> resolved = fromHostPortStrings(resolvedEndpoints);
+
+ endpointsList = merge(filtered, resolved);
+ }
+
+ // Note: regard any addresses supplied here as a permanent part of the
+ // cluster.
+ synchronized final void setClusterInstanceInfoFromString(List<String> list) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "setClusterInstanceInfoFromString: list={0}", list);
+ }
+
+ List<String> newList = list;
+ if (newList.isEmpty()) {
+ newList = getEndpointForProviderURL(
+ System.getProperty(ORBLocator.JNDI_PROVIDER_URL_PROPERTY));
+ }
+
+ //randomize the list before adding it to linked list
+ if (!newList.isEmpty()) {
+ List<String> newList2 = randomize(newList);
+ resolvedEndpoints = new ArrayList<String>(newList2);
+ endpointsList = fromHostPortStrings(newList2);
+ // Put in a default for total weight; any update will correct this.
+ totalWeight = 10 * endpointsList.size();
+ } else {
+ logger.log(Level.FINE, "no.endpoints");
+ }
+ }
+
+ /**
+ * during bootstrapping, weight is assumed "10" for all endpoints
+ * then on, whenever server sends updates list,
+ * create the list again here with right weights
+ */
+ private ClusterInstanceInfo makeClusterInstanceInfo(String str,
+ int weight) {
+
+ //support IPV6 literal address
+ String[] host_port = new String[2];
+ int i = str.lastIndexOf(':');
+ host_port[0] = str.substring(0,i);
+ host_port[1] = str.substring(i+1);
+
+ String server_identifier = ""; //for bootstrapping, can be ""
+ String type = CLEAR_TEXT; //will be clear_text for bootstrapping
+ SocketInfo socketInfo = new SocketInfo(
+ type, host_port[0], Integer.parseInt( host_port[1]) );
+ List<SocketInfo> sil = new ArrayList<SocketInfo>(1) ;
+ sil.add( socketInfo ) ;
+
+ return new ClusterInstanceInfo(server_identifier, weight, sil);
+ }
+
+ /*
+ * This method checks for other ways of specifying endpoints
+ * namely JNDI provider url
+ * orb host:port is used only if even env passed into
+ * getInitialContext is empty. This check is performed in
+ * SerialInitContextFactory.getInitialContext()
+ */
+ public List<String> getEndpointForProviderURL(String providerURLString) {
+ if (providerURLString != null) {
+ try {
+ final IiopUrl providerURL = new IiopUrl(providerURLString);
+ final List<String> newList = getAddressPortList(providerURL);
+ logger.log(Level.WARNING, NO_ENDPOINTS_SELECTED_PROVIDER, providerURLString);
+ return newList;
+ } catch (MalformedURLException me) {
+ logger.log(Level.WARNING, PROVIDER_EXCEPTION, new Object[]{me, providerURLString});
+ }
+ }
+ return new ArrayList<String>();
+ }
+
+ /**
+ * randomize the list. Note: this empties its argument.
+ */
+ private List<String> randomize( List<String> list ) {
+ List<String> result = new ArrayList<String>( list.size() ) ;
+ while (!list.isEmpty()) {
+ int random = rand.nextInt( list.size() ) ;
+ String elem = list.remove( random ) ;
+ result.add( elem ) ;
+ }
+
+ if(logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "Randomized list {0}", result);
+ }
+ return result ;
+ }
+
+ /*
+ * get a new shape of the endpoints
+ * For e.g. if list contains A,B,C
+ * if the logic below chooses B as the endpoint to send the req to
+ * then return B,C,A.
+ * logic used is as described in Class description comments
+ */
+ public synchronized List<String> getNextRotation() {
+ int lowerLimit = 0; //lowerLimit
+ int random = 0;
+ //make sure that the random # is not 0
+ //Random API gives a number between 0 and sumOfAllWeights
+ //But our range intervals are from 1-upperLimit,
+ //11-upperLimit and so
+ //on. Hence we dont want random # to be 0.
+ // fineLog( "RoundRobinPolicy.getNextRotation -> sumOfAllWeights = {0}",
+ // totalWeight);
+ while( random == 0) {
+ random = rand.nextInt(totalWeight);
+ if (random != 0) {
+ break;
+ }
+ }
+ // fineLog( "getNextRotation : random # = {0} sum of all weights = {1}",
+ // new Object[]{random, totalWeight});
+ int i = 0;
+ for (ClusterInstanceInfo endpoint : endpointsList) {
+ int upperLimit = lowerLimit + endpoint.weight();
+ // fineLog( "upperLimit = {0}", upperLimit);
+ if (random > lowerLimit && random <= upperLimit) {
+ List<ClusterInstanceInfo> instanceInfo =
+ new LinkedList<ClusterInstanceInfo>();
+
+ //add the sublist at index 0
+ instanceInfo.addAll(0,
+ endpointsList.subList(i, endpointsList.size()));
+
+ //add the remaining list
+ instanceInfo.addAll(endpointsList.subList(0, i));
+
+ endpointsList = instanceInfo ;
+
+ if(logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "getNextRotation: result={0}", instanceInfo);
+ }
+
+ return convertIntoCorbaloc(instanceInfo);
+ }
+ lowerLimit = upperLimit;
+ // fineLog( "lowerLimit = {0}", lowerLimit);
+ i++;
+ }
+ logger.log(Level.WARNING, COULD_NOT_FIND_ENDPOINT);
+ return new ArrayList<String>() ;
+ }
+
+ private List<String> convertIntoCorbaloc(List<ClusterInstanceInfo> list) {
+ List<String> host_port = new ArrayList<String>();
+ for (ClusterInstanceInfo endpoint : list) {
+ List<SocketInfo> sinfos = endpoint.endpoints();
+ for (SocketInfo si : sinfos ) {
+ // XXX this needs to be revised if we ever do a secure
+ // bootstrap protocol for the initial corbaloc URL resolution
+ if (si.type().equals( CLEAR_TEXT )) {
+ String element = si.host().trim() + ":" + si.port() ;
+ if (!host_port.contains( element )) {
+ host_port.add( element ) ;
+ }
+ }
+ }
+ }
+ return host_port ;
+ }
+
+ /**
+ * following methods (over-loaded) for getting all IP addresses
+ * corresponding to a particular host.
+ * (multi-homed hosts).
+ */
+
+ private List<String> getAddressPortList(IiopUrl iiopUrl) {
+ // Pull out the host name and port
+ IiopUrl.Address iiopUrlAddress =
+ (IiopUrl.Address)(iiopUrl.getAddresses().elementAt(0));
+ String host = iiopUrlAddress.host;
+ int portNumber = iiopUrlAddress.port;
+ String port = Integer.toString(portNumber);
+ // We return a list of <IP ADDRESS>:<PORT> values
+ return getAddressPortList(host, port);
+ }
+
+ public List<String> getAddressPortList(String host, String port) {
+ // Get the ip addresses corresponding to the host.
+ // XXX this currently does NOT support IPv6.
+ try {
+ InetAddress [] addresses = InetAddress.getAllByName(host);
+ List<InetAddress> addrs = new ArrayList<InetAddress>() ;
+ for (InetAddress addr : addresses) {
+ if (addr instanceof Inet4Address || addr instanceof Inet6Address) {
+ addrs.add( addr ) ;
+ }
+ }
+
+ List<String> ret = new ArrayList<String>() ;
+ for (InetAddress addr : addrs) {
+ ret.add( addr.getHostAddress() + ":" + port ) ;
+ }
+
+ // We return a list of <IP ADDRESS>:<PORT> values
+ return ret;
+ } catch (UnknownHostException ukhe) {
+ logger.log(Level.WARNING, UNKNOWN_HOST, new Object[]{host, ukhe});
+ return new ArrayList<String>() ;
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder() ;
+ sb.append( "RoundRobinPolicy[") ;
+ boolean first = true ;
+ for (ClusterInstanceInfo endpoint : endpointsList ) {
+ if (first) {
+ first = false ;
+ } else {
+ sb.append( ' ' ) ;
+ }
+
+ sb.append( endpoint.toString() ) ;
+ }
+ sb.append( ']' ) ;
+ return sb.toString() ;
+ }
+
+ public synchronized List<String> getHostPortList() {
+ return resolvedEndpoints ;
+ }
+}
diff --git a/appserver/orb/pom.xml b/appserver/orb/pom.xml
new file mode 100755
index 0000000..6ee5c06
--- /dev/null
+++ b/appserver/orb/pom.xml
@@ -0,0 +1,37 @@
+<?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.orb</groupId>
+ <artifactId>orb</artifactId>
+ <packaging>pom</packaging>
+ <name>GlassFish ORB related modules</name>
+ <modules>
+ <module>orb-enabler</module>
+ <module>orb-connector</module>
+ <module>orb-iiop</module>
+ </modules>
+</project>