Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2021 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 com.sun.ejb.containers;
import com.sun.ejb.ComponentContext;
import com.sun.ejb.Container;
import com.sun.ejb.EJBUtils;
import com.sun.ejb.EjbInvocation;
import com.sun.ejb.EjbInvocationFactory;
import com.sun.ejb.InvocationInfo;
import com.sun.ejb.MethodLockInfo;
import com.sun.ejb.codegen.EjbOptionalIntfGenerator;
import com.sun.ejb.containers.interceptors.InterceptorManager;
import com.sun.ejb.containers.interceptors.SystemInterceptorProxy;
import com.sun.ejb.containers.util.MethodMap;
import com.sun.ejb.monitoring.probes.EjbCacheProbeProvider;
import com.sun.ejb.monitoring.probes.EjbMonitoringProbeProvider;
import com.sun.ejb.monitoring.probes.EjbTimedObjectProbeProvider;
import com.sun.ejb.monitoring.stats.EjbCacheStatsProvider;
import com.sun.ejb.monitoring.stats.EjbMonitoringStatsProvider;
import com.sun.ejb.monitoring.stats.EjbMonitoringUtils;
import com.sun.ejb.monitoring.stats.EjbPoolStatsProvider;
import com.sun.ejb.monitoring.stats.EjbTimedObjectStatsProvider;
import com.sun.ejb.portable.EJBMetaDataImpl;
import com.sun.ejb.spi.container.OptionalLocalInterfaceProvider;
import com.sun.enterprise.admin.monitor.callflow.CallFlowInfo;
import com.sun.enterprise.admin.monitor.callflow.ComponentType;
import com.sun.enterprise.container.common.spi.CDIService;
import com.sun.enterprise.container.common.spi.JavaEEContainer;
import com.sun.enterprise.container.common.spi.util.ComponentEnvManager;
import com.sun.enterprise.container.common.spi.util.IndirectlySerializable;
import com.sun.enterprise.container.common.spi.util.InjectionManager;
import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.EjbApplicationExceptionInfo;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.EnvironmentProperty;
import com.sun.enterprise.deployment.InterceptorDescriptor;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
import com.sun.enterprise.deployment.LifecycleCallbackDescriptor.CallbackType;
import com.sun.enterprise.deployment.MethodDescriptor;
import com.sun.enterprise.deployment.ScheduledTimerDescriptor;
import com.sun.enterprise.deployment.WebServiceEndpoint;
import com.sun.enterprise.deployment.WebServicesDescriptor;
import com.sun.enterprise.deployment.util.TypeUtil;
import com.sun.enterprise.deployment.xml.RuntimeTagNames;
import com.sun.enterprise.security.SecurityManager;
import com.sun.enterprise.transaction.api.JavaEETransaction;
import com.sun.enterprise.transaction.api.JavaEETransactionManager;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.enterprise.util.Utility;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.ejb.AccessLocalException;
import jakarta.ejb.CreateException;
import jakarta.ejb.EJBAccessException;
import jakarta.ejb.EJBContext;
import jakarta.ejb.EJBException;
import jakarta.ejb.EJBHome;
import jakarta.ejb.EJBLocalHome;
import jakarta.ejb.EJBLocalObject;
import jakarta.ejb.EJBMetaData;
import jakarta.ejb.EJBObject;
import jakarta.ejb.EJBTransactionRequiredException;
import jakarta.ejb.EJBTransactionRolledbackException;
import jakarta.ejb.FinderException;
import jakarta.ejb.LockType;
import jakarta.ejb.NoSuchEJBException;
import jakarta.ejb.NoSuchObjectLocalException;
import jakarta.ejb.PostActivate;
import jakarta.ejb.PrePassivate;
import jakarta.ejb.RemoveException;
import jakarta.ejb.TransactionRequiredLocalException;
import jakarta.ejb.TransactionRolledbackLocalException;
import jakarta.interceptor.AroundConstruct;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.transaction.RollbackException;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.Transaction;
import jakarta.transaction.UserTransaction;
import java.io.Serializable;
import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.rmi.AccessException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.text.MessageFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.StringRefAddr;
import org.glassfish.api.invocation.ComponentInvocation;
import org.glassfish.api.invocation.InvocationManager;
import org.glassfish.api.naming.GlassfishNamingManager;
import org.glassfish.api.naming.SimpleJndiName;
import org.glassfish.deployment.common.DeploymentException;
import org.glassfish.deployment.common.Descriptor;
import org.glassfish.ejb.LogFacade;
import org.glassfish.ejb.api.EjbEndpointFacade;
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
import org.glassfish.ejb.deployment.descriptor.EjbInitInfo;
import org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor;
import org.glassfish.ejb.spi.EjbContainerInterceptor;
import org.glassfish.ejb.spi.WSEjbEndpointRegistry;
import org.glassfish.enterprise.iiop.api.GlassFishORBHelper;
import org.glassfish.enterprise.iiop.api.ProtocolManager;
import org.glassfish.enterprise.iiop.api.RemoteReferenceFactory;
import org.glassfish.enterprise.iiop.spi.EjbContainerFacade;
import org.glassfish.flashlight.provider.ProbeProviderFactory;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.internal.api.Globals;
import org.glassfish.logging.annotation.LogMessageInfo;
import static com.sun.enterprise.deployment.EjbDescriptor.BEAN_TRANSACTION_TYPE;
import static com.sun.enterprise.deployment.MethodDescriptor.EJB_LOCAL;
import static com.sun.enterprise.deployment.MethodDescriptor.EJB_REMOTE;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.FINEST;
import static java.util.logging.Level.SEVERE;
import static org.glassfish.api.naming.SimpleJndiName.JNDI_CTX_JAVA_GLOBAL;
/**
* This class implements part of the com.sun.ejb.Container interface. It implements the container's side of the
* EJB-to-Container contract definweed by the EJB 2.0 spec. It contains code shared by SessionBeans, EntityBeans and
* MessageDrivenBeans. Its subclasses provide the remaining implementation of the container functionality.
*
*/
public abstract class BaseContainer implements Container, EjbContainerFacade, JavaEEContainer {
public enum ContainerType {
STATELESS, STATEFUL, SINGLETON, MESSAGE_DRIVEN, ENTITY, READ_ONLY
}
protected static final Logger _logger = LogFacade.getLogger();
@LogMessageInfo(message = "The feature {0} requires Full Jakarta EE Profile to be supported", level = "WARNING")
private static final String WARN_FEATURE_REQUIRES_FULL_PROFILE = "AS-EJB-00053";
@LogMessageInfo(message = "Portable JNDI names for EJB {0}: {1}", level = "INFO")
private static final String PORTABLE_JNDI_NAMES = "AS-EJB-00054";
@LogMessageInfo(message = "Glassfish-specific (Non-portable) JNDI names for EJB {0}: {1}", level = "INFO")
private static final String GLASSFISH_SPECIFIC_JNDI_NAMES = "AS-EJB-00055";
@LogMessageInfo(message = "A system exception occurred during an invocation on EJB {0}, method: {1}", level = "WARNING")
private static final String SYSTEM_EXCEPTION = "AS-EJB-00056";
@LogMessageInfo(message = "Error while creating enterprise bean context for {0} during jacc callback", level = "WARNING")
private static final String CONTEXT_FAILURE_JACC = "AS-EJB-00057";
@LogMessageInfo(message = "Attempt to override reserved ejb interface method [{0}] in [{1}]. Override will be ignored.", level = "WARNING")
private static final String ILLEGAL_EJB_INTERFACE_OVERRIDE = "AS-EJB-00058";
@LogMessageInfo(message = "Bean class for ejb [{0}] does not define a method corresponding to [{1}] interface method [{2}]", level = "WARNING")
private static final String BEAN_CLASS_METHOD_NOT_FOUND = "AS-EJB-00059";
@LogMessageInfo(message = "keepstate is true and will not create new auto timers during deployment.", level = "INFO")
private static final String KEEPSTATE_IS_TRUE = "AS-EJB-00060";
@LogMessageInfo(message = "Failed to initialize the interceptor", level = "SEVERE", cause = "Error during initializing the interceptor", action = "Try to restart the server")
private static final String FAILED_TO_INITIALIZE_INTERCEPTOR = "AS-EJB-00061";
@LogMessageInfo(message = "[**BaseContainer**] Could not create MonitorRegistryMediator. [{0}]", level = "SEVERE", cause = "Fail to create MonitorRegistryMediator", action = "Check the exception stack")
private static final String COULD_NOT_CREATE_MONITORREGISTRYMEDIATOR = "AS-EJB-00062";
@LogMessageInfo(message = "Internal Error", level = "WARNING", cause = "Error during invoke the ejb application", action = "Trying to invoke the ejb application")
private static final String INTERNAL_ERROR = "AS-EJB-00052";
protected static final Class[] NO_PARAMS = new Class[] {};
protected final ContainerInfo containerInfo;
// constants for EJB(Local)Home/EJB(Local)Object methods,
// used in authorizeRemoteMethod and authorizeLocalMethod
private static final int EJB_INTF_METHODS_LENGTH = 16;
static final int EJBHome_remove_Handle = 0;
static final int EJBHome_remove_Pkey = 1;
static final int EJBHome_getEJBMetaData = 2;
static final int EJBHome_getHomeHandle = 3;
static final int EJBLocalHome_remove_Pkey = 4;
static final int EJBObject_getEJBHome = 5;
protected static final int EJBObject_getPrimaryKey = 6; // TODO - move related to entity-container
static final int EJBObject_remove = 7;
static final int EJBObject_getHandle = 8;
static final int EJBObject_isIdentical = 9;
static final int EJBLocalObject_getEJBLocalHome = 10;
protected static final int EJBLocalObject_getPrimaryKey = 11; // TODO - move related to entity-container
static final int EJBLocalObject_remove = 12;
static final int EJBLocalObject_isIdentical = 13;
static final int EJBHome_create = 14;
static final int EJBLocalHome_create = 15;
// true if home method, false if component intf method.
// Used for setting info on invocation object during authorization.
private static final boolean[] EJB_INTF_METHODS_INFO =
{ true, true, true, true, true, false, false, false, false, false, false, false, false, false, true, true };
private static final byte HOME_KEY = (byte) 0xff;
private static final byte[] homeInstanceKey = { HOME_KEY };
protected static final String SINGLETON_BEAN_POOL_PROP = "singleton-bean-pool";
protected final ClassLoader loader;
protected Class> ejbClass;
protected Class> sfsbSerializedClass;
protected Method ejbPassivateMethod;
protected Method ejbActivateMethod;
protected Method ejbRemoveMethod;
private Method ejbTimeoutMethod;
protected Class> webServiceEndpointIntf;
// true if exposed as a web service endpoint.
protected boolean isWebServiceEndpoint;
private boolean isTimedObject_;
/*****************************************
* Data members for Local views *
*****************************************/
// True if bean has a LocalHome/Local view
// OR a Local business view OR both.
protected boolean isLocal;
// True if bean exposes a local home view
protected boolean hasLocalHomeView;
// True if bean exposes a local business view
protected boolean hasLocalBusinessView;
protected boolean hasOptionalLocalBusinessView;
protected Class> ejbGeneratedOptionalLocalBusinessIntfClass;
//
// Data members for LocalHome/Local view
//
// LocalHome interface written by developer
protected Class> localHomeIntf;
// Local interface written by developer
private Class> localIntf;
// Client reference to ejb local home
protected EJBLocalHome ejbLocalHome;
// Implementation of ejb local home. May or may not be the same
// object as ejbLocalHome, for example in the case of dynamic proxies.
protected EJBLocalHomeImpl ejbLocalHomeImpl;
//
// Data members for 3.x Local business view
//
// Internal interface describing operation used to create an
// instance of a local business object. (GenericEJBLocalHome)
protected Class localBusinessHomeIntf;
protected Class ejbOptionalLocalBusinessHomeIntf;
// Local business interface written by developer
protected Set localBusinessIntfs = new HashSet();
// Client reference to internal local business home interface.
// This is only seen by internal ejb code that instantiates local
// business objects during lookups.
protected GenericEJBLocalHome ejbLocalBusinessHome;
protected GenericEJBLocalHome ejbOptionalLocalBusinessHome;
// Implementation of internal local business home interface.
protected EJBLocalHomeImpl ejbLocalBusinessHomeImpl;
// Implementation of internal local business home interface.
protected EJBLocalHomeImpl ejbOptionalLocalBusinessHomeImpl;
private Collection interceptors;
/*****************************************
* Data members for Remote views *
*****************************************/
// True if bean has a RemoteHome/Remote view
// OR a Remote business view OR both.
protected boolean isRemote;
// True if bean exposes a RemoteHome view
protected boolean hasRemoteHomeView;
// True if bean exposes a Remote Business view.
protected boolean hasRemoteBusinessView;
//
// Data members for RemoteHome/Remote view
//
// Home interface written by developer.
protected Class homeIntf;
// Remote interface written by developer.
protected Class remoteIntf;
// Container implementation of EJB Home. May or may not be the same
// object as ejbHome, for example in the case of dynamic proxies.
protected EJBHomeImpl ejbHomeImpl;
// EJB Home reference used by ORB Tie within server to deliver
// invocation.
protected EJBHome ejbHome;
// Client reference to EJB Home.
protected EJBHome ejbHomeStub;
// Remote interface proxy class
private Class ejbObjectProxyClass;
// RemoteReference Factory for RemoteHome view
protected RemoteReferenceFactory remoteHomeRefFactory;
//
// Data members for 3.x Remote business view
//
// Internal interface describing operation used to create an
// instance of a remote business object.
protected Class remoteBusinessHomeIntf;
// Container implementation of internal EJB Business Home. May or may
// not be same object as ejbRemoteBusinessHome, for example in the
// case of dynamic proxies.
protected EJBHomeImpl ejbRemoteBusinessHomeImpl;
// EJB Remote Business Home reference used by ORB Tie within server
// to deliver invocation.
protected EJBHome ejbRemoteBusinessHome;
// Client reference to internal Remote EJB Business Home. This is
// only seen by internal EJB code that instantiates remote business
// objects during lookups.
protected EJBHome ejbRemoteBusinessHomeStub;
// Holds information such as remote reference factory that are associated
// with a particular remote business interface
protected Map remoteBusinessIntfInfo = new HashMap<>();
//
// END -- Data members for Remote views
//
protected EJBMetaData metadata;
protected final SecurityManager securityManager;
protected boolean isSession;
protected boolean isStatelessSession;
protected boolean isStatefulSession;
protected boolean isMessageDriven;
protected boolean isSingleton;
protected EjbDescriptor ejbDescriptor;
protected String componentId; // unique id for java:comp namespace lookup
protected Map invocationInfoMap = new HashMap<>();
protected Map scheduleIds = new HashMap<>();
Map> schedules = new HashMap<>();
// Need a separate map for web service methods since it's possible for
// an EJB Remote interface to be a subtype of the Service Endpoint
// Interface. In that case, it's ambiguous to do a lookup based only
// on a java.lang.reflect.Method
protected Map webServiceInvocationInfoMap = new HashMap<>();
// optimized method map for proxies to resolve invocation info
private MethodMap proxyInvocationInfoMap;
protected Method[] ejbIntfMethods;
protected InvocationInfo[] ejbIntfMethodInfo;
protected Properties envProps;
protected boolean isBeanManagedTran;
protected boolean debugMonitorFlag;
private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(BaseContainer.class);
private final ThreadLocal threadLocalContext = new ThreadLocal();
protected static final int CONTAINER_INITIALIZING = -1;
protected static final int CONTAINER_STARTED = 0;
protected static final int CONTAINER_STOPPED = 1;
protected static final int CONTAINER_UNDEPLOYED = 3;
protected static final int CONTAINER_ON_HOLD = 4;
protected int containerState = CONTAINER_INITIALIZING;
protected HashMap methodMonitorMap;
protected boolean monitorOn;
protected EjbMonitoringStatsProvider ejbProbeListener;
protected EjbMonitoringProbeProvider ejbProbeNotifier;
protected EjbTimedObjectStatsProvider timerProbeListener;
protected EjbTimedObjectProbeProvider timerProbeNotifier;
protected EjbPoolStatsProvider poolProbeListener;
protected EjbCacheProbeProvider cacheProbeNotifier;
protected EjbCacheStatsProvider cacheProbeListener;
private final String debugDescription;
protected CallFlowInfo callFlowInfo;
protected InterceptorManager interceptorManager;
// the order must be the same as CallbackType and getPre30LifecycleMethodNames
private static final Class[] lifecycleCallbackAnnotationClasses = {
AroundConstruct.class,
PostConstruct.class,
PreDestroy.class,
PrePassivate.class,
PostActivate.class };
private final Set monitoredGeneratedClasses = new HashSet<>();
protected InvocationManager invocationManager;
protected InjectionManager injectionManager;
protected GlassfishNamingManager namingManager;
protected JavaEETransactionManager transactionManager;
private EjbInvocationFactory invFactory;
private ProtocolManager protocolMgr;
protected EjbContainerUtil ejbContainerUtilImpl = EjbContainerUtilImpl.getInstance();
protected EjbOptionalIntfGenerator optIntfClassLoader;
private final Set publishedPortableGlobalJndiNames = new HashSet<>();
private final Set publishedNonPortableGlobalJndiNames = new HashSet<>();
private final Set publishedInternalGlobalJndiNames = new HashSet<>();
private final Map jndiInfoMap = new HashMap<>();
private String optIntfClassName;
// Used to track whether we've done the base container cleanup (JNDI entries, etc.)
// Only. Not applicable to concrete containers.
private boolean baseContainerCleanupDone;
// True if there is at least one asynchronous method exposed from the bean.
private boolean hasAsynchronousInvocations;
// Information about a web service ejb endpoint. Used as a conduit
// between webservice runtime and ejb container. Contains a Remote
// servant used by jaxrpc to call web service business method.
private WebServiceEndpoint webServiceEndpoint;
// The Webservices Ejb Endpoint Registry contract
// used to register and unregister ejb webservices endpoints
private WSEjbEndpointRegistry wsejbEndpointRegistry;
protected EJBContainerStateManager containerStateManager;
protected EJBContainerTransactionManager containerTransactionManager;
private final CDIService cdiService;
private Class[] ejbLocalBusinessProxyInterfaces;
private Class[] ejbOptionalLocalBusinessHomeProxyInterfaces;
/**
* This constructor is called from ContainerFactoryImpl when an EJB Jar is deployed.
*/
protected BaseContainer(final ContainerType type, final EjbDescriptor ejbDesc, final ClassLoader loader, final SecurityManager sm) throws Exception {
this.ejbDescriptor = ejbDesc;
this.loader = loader;
this.securityManager = sm;
this.containerInfo = createContainerInfo(type, ejbDesc);
this.debugDescription = super.toString() + "[ejbName=" + ejbDescriptor.getName() + ", containerId="
+ ejbDescriptor.getUniqueId() + ']';
_logger.log(FINE, "Initializing {0} ...", this.debugDescription);
try {
invocationManager = ejbContainerUtilImpl.getInvocationManager();
injectionManager = ejbContainerUtilImpl.getInjectionManager();
namingManager = ejbContainerUtilImpl.getGlassfishNamingManager();
transactionManager = ejbContainerUtilImpl.getTransactionManager();
// get Class objects for creating new EJBs
ejbClass = loader.loadClass(ejbDescriptor.getEjbImplClassName());
containerStateManager = new EJBContainerStateManager(this);
containerTransactionManager = new EJBContainerTransactionManager(this, ejbDesc);
isBeanManagedTran = ejbDescriptor.getTransactionType().equals(BEAN_TRANSACTION_TYPE);
if (ejbDescriptor instanceof EjbSessionDescriptor) {
isSession = true;
EjbSessionDescriptor sd = (EjbSessionDescriptor) ejbDescriptor;
if (!sd.isSessionTypeSet()) {
throw new RuntimeException(localStrings.getLocalString("ejb.session_type_not_set",
"Invalid ejb Descriptor. Session type not set for {0}: {1}", sd.getName(), sd));
}
if (sd.isSingleton()) {
isSingleton = true;
} else {
isStatelessSession = sd.isStateless();
isStatefulSession = !isStatelessSession;
if (isStatefulSession) {
/**
* If bean class isn't explicitly marked Serializable, generate a subclass that is. We do this with a generator that
* uses ASM directly instead of the CORBA codegen library since none of the corba .jars are part of the Web Profile.
*/
if (!Serializable.class.isAssignableFrom(ejbClass)) {
sfsbSerializedClass = EJBUtils.loadGeneratedSerializableClass(loader, ejbClass);
}
}
}
hasAsynchronousInvocations = sd.hasAsynchronousMethods();
}
if (ejbDescriptor.isRemoteInterfacesSupported() || ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
assertFullProfile("exposes a Remote client view");
initializeProtocolManager();
}
if (ejbDescriptor.isRemoteInterfacesSupported()) {
isRemote = true;
hasRemoteHomeView = true;
String homeClassName = ejbDescriptor.getHomeClassName();
homeIntf = loader.loadClass(homeClassName);
remoteIntf = loader.loadClass(ejbDescriptor.getRemoteClassName());
String id = Long.toString(ejbDescriptor.getUniqueId()) + "_RHome";
remoteHomeRefFactory = getProtocolManager().getRemoteReferenceFactory(this, true, id);
}
if (ejbDescriptor.isRemoteBusinessInterfacesSupported()) {
isRemote = true;
hasRemoteBusinessView = true;
remoteBusinessHomeIntf = EJBUtils.loadGeneratedGenericEJBHomeClass(loader, ejbClass);
for (String next : ejbDescriptor.getRemoteBusinessClassNames()) {
Class> genRemoteIntf = EJBUtils.loadGeneratedRemoteBusinessClasses(loader, next);
RemoteBusinessIntfInfo info = new RemoteBusinessIntfInfo();
info.generatedRemoteIntf = genRemoteIntf;
info.remoteBusinessIntf = loader.loadClass(next);
// One remote reference factory for each remote
// business interface. Id must be unique across
// all ejb containers.
String id = Long.toString(ejbDescriptor.getUniqueId()) + "_RBusiness" + "_" + genRemoteIntf.getName();
info.referenceFactory = getProtocolManager().getRemoteReferenceFactory(this, false, id);
remoteBusinessIntfInfo.put(genRemoteIntf.getName(), info);
addToGeneratedMonitoredMethodInfo(genRemoteIntf);
}
}
if (ejbDescriptor.isLocalInterfacesSupported()) {
// initialize class objects for LocalHome/LocalIntf etc.
isLocal = true;
hasLocalHomeView = true;
String localHomeClassName = ejbDescriptor.getLocalHomeClassName();
localHomeIntf = loader.loadClass(localHomeClassName);
localIntf = loader.loadClass(ejbDescriptor.getLocalClassName());
}
if (ejbDescriptor.isLocalBusinessInterfacesSupported()) {
isLocal = true;
hasLocalBusinessView = true;
localBusinessHomeIntf = GenericEJBLocalHome.class;
for (String next : ejbDescriptor.getLocalBusinessClassNames()) {
Class clz = loader.loadClass(next);
localBusinessIntfs.add(clz);
addToGeneratedMonitoredMethodInfo(clz);
}
}
if (ejbDescriptor.isLocalBean()) {
isLocal = true;
hasOptionalLocalBusinessView = true;
ejbOptionalLocalBusinessHomeIntf = GenericEJBLocalHome.class;
Class clz = loader.loadClass(ejbDescriptor.getEjbClassName());
addToGeneratedMonitoredMethodInfo(clz);
this.optIntfClassName = EJBUtils.getGeneratedOptionalInterfaceName(ejbClass.getName());
optIntfClassLoader = new EjbOptionalIntfGenerator(loader);
optIntfClassLoader.generateOptionalLocalInterface(ejbClass, optIntfClassName);
ejbGeneratedOptionalLocalBusinessIntfClass = optIntfClassLoader.loadClass(optIntfClassName);
}
if (isStatelessSession || isSingleton) {
EjbBundleDescriptor bundle = ejbDescriptor.getEjbBundleDescriptor();
WebServicesDescriptor webServices = bundle.getWebServices();
Collection> endpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);
// JSR 109 doesn't require support for a single ejb
// implementing multiple port ex.
if (endpoints.size() == 1) {
assertFullProfile("is a Web Service Endpoint");
webServiceEndpointIntf = loader.loadClass(ejbDescriptor.getWebServiceEndpointInterfaceName());
isWebServiceEndpoint = true;
}
}
try {
// get Method objects for ejbPassivate/Activate/ejbRemove
ejbPassivateMethod = ejbClass.getMethod("ejbPassivate", NO_PARAMS);
ejbActivateMethod = ejbClass.getMethod("ejbActivate", NO_PARAMS);
ejbRemoveMethod = ejbClass.getMethod("ejbRemove", NO_PARAMS);
} catch (NoSuchMethodException nsme) {
// ignore. Will happen for EJB 3.0 session beans
}
if (ejbDescriptor.isTimedObject()) {
warnIfNotFullProfile("use of persistent EJB Timer Service");
MethodDescriptor ejbTimeoutMethodDesc = ejbDescriptor.getEjbTimeoutMethod();
// Can be a @Timeout or @Schedule or TimedObject
if (ejbTimeoutMethodDesc != null) {
Method method = ejbTimeoutMethodDesc.getMethod(ejbDescriptor);
processEjbTimeoutMethod(method);
ejbTimeoutMethod = method;
}
for (ScheduledTimerDescriptor schd : ejbDescriptor.getScheduledTimerDescriptors()) {
Method method = schd.getTimeoutMethod().getMethod(ejbDescriptor);
if (method == null) {
// This should've been caught in EjbBundleValidator
throw new EJBException(
localStrings.getLocalString("ejb.no_timeout_method", "Class {0} does not define timeout method {1}",
ejbClass.getName(), schd.getTimeoutMethod().getFormattedString()));
}
processEjbTimeoutMethod(method);
List list = schedules.get(method);
if (list == null) {
list = new ArrayList<>();
schedules.put(method, list);
}
list.add(schd);
}
}
if (isTimedObject_) {
if (!isStatefulSession) {
// EJBTimerService should be accessed only if needed
// not to cause it to be loaded if it's not used.
EJBTimerService timerService = EJBTimerService.getEJBTimerService();
if (timerService != null) {
timerService.timedObjectCount();
}
} else {
isTimedObject_ = false;
throw new EJBException(localStrings.getLocalString("ejb.stateful_cannot_be_timed_object",
"EJB {0} is invalid. Stateful session ejbs cannot be Timed Objects", ejbDescriptor.getName()));
}
}
preInitialize(ejbDesc, loader);
initializeEjbInterfaceMethods();
if (needSystemInterceptorProxy()) {
addSystemInterceptorProxy();
}
// NOTE : InterceptorManager initialization delayed until transition to START state.
addLocalRemoteInvocationInfo();
addWSOrTimedObjectInvocationInfo();
initializeInvocationInfo();
setupEnvironment();
ServiceLocator services = ejbContainerUtilImpl.getServices();
cdiService = services.getService(CDIService.class);
initEjbInterceptors();
} catch (Exception ex) {
_logger.log(FINE, "Exception creating BaseContainer : [{0}]", containerInfo);
_logger.log(FINE, "", ex);
throw ex;
}
_logger.log(FINE, "Successfuly initialized: {0}", debugDescription);
}
protected ProtocolManager getProtocolManager() {
return protocolMgr;
}
public ContainerInfo getContainerInfo() {
return this.containerInfo;
}
protected void doEJBHomeRemove(Object pk, Method m, boolean isLocal) throws RemoteException, RemoveException {
throw new UnsupportedOperationException(
localStrings.getLocalString("ejb.ejbhome_remove_on_nonentity", "EJBHome.remove() called on non entity container"));
}
private void addToGeneratedMonitoredMethodInfo(Class generatedClass) {
monitoredGeneratedClasses.add(generatedClass);
}
protected void initializeProtocolManager() {
try {
GlassFishORBHelper orbHelper = ejbContainerUtilImpl.getORBHelper();
protocolMgr = orbHelper.getProtocolManager();
} catch (Throwable t) {
throw new RuntimeException(
"IIOP Protocol Manager initialization failed. " + "Possible cause is that ORB is not available in this "
+ ((ejbContainerUtilImpl.isEmbeddedServer())
? "embedded container, or server instance is running and required ports are in use"
: "container"),
t);
}
}
protected void preInitialize(EjbDescriptor ejbDesc, ClassLoader loader) {
// Overridden in sub classes
}
public void checkUserTransactionLookup(ComponentInvocation inv) throws javax.naming.NameNotFoundException {
if (!this.isBeanManagedTran) {
throw new javax.naming.NameNotFoundException(localStrings.getLocalString("ejb.ut_lookup_not_allowed",
"Lookup of java:comp/UserTransaction not allowed for Container managed Transaction beans"));
}
}
protected final void createCallFlowAgent(ComponentType compType) {
this.callFlowInfo = new CallFlowInfoImpl(this, ejbDescriptor, compType);
}
@Override
public String toString() {
return debugDescription;
}
@Override
public final void setStartedState() {
if (containerState == CONTAINER_STARTED) {
return;
}
// NOTE : we used to initialize interceptor manager in the ctor but we need to delay
// the initialization to account for the possiblity of a CDI-enabled app. In
// that case, the CDI-defined ejb interceptors are not added until the
// deployment load() phase. That's ok, as long as everything is initialized
// before any bean instances are created or any ejb invocations take place.
// Therefore, moving the initialization to the point that we transition into the
// ejb container START state.
try {
initializeInterceptorManager();
for (InvocationInfo invocationInfo : invocationInfoMap.values()) {
setInterceptorChain(invocationInfo);
}
for (InvocationInfo invocationInfo : this.webServiceInvocationInfoMap.values()) {
setInterceptorChain(invocationInfo);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
containerState = CONTAINER_STARTED;
}
private void setInterceptorChain(InvocationInfo info) {
if (info.aroundMethod != null) {
if (info.isEjbTimeout) {
MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.TIMER_METHOD);
info.interceptorChain = interceptorManager.getAroundTimeoutChain(md, info.aroundMethod);
} else {
MethodDescriptor md = new MethodDescriptor(info.aroundMethod, MethodDescriptor.EJB_BEAN);
info.interceptorChain = interceptorManager.getAroundInvokeChain(md, info.aroundMethod);
}
}
}
@Override
public final void setStoppedState() {
containerState = CONTAINER_STOPPED;
}
public final boolean isStopped() {
return containerState == CONTAINER_STOPPED;
}
@Override
public final void setUndeployedState() {
containerState = CONTAINER_UNDEPLOYED;
}
public final boolean isUndeployed() {
return (containerState == CONTAINER_UNDEPLOYED);
}
@Override
public final boolean isTimedObject() {
return isTimedObject_;
}
@Override
public final boolean isLocalObject() {
return isLocal;
}
@Override
public final boolean isRemoteObject() {
return isRemote;
}
@Override
public final ClassLoader getContainerClassLoader() {
return loader;
}
@Override
public final ClassLoader getClassLoader() {
return loader;
}
@Override
public final String getUseThreadPoolId() {
return ejbDescriptor.getIASEjbExtraDescriptors().getUseThreadPoolId();
}
@Override
public final boolean getPassByReference() {
return ejbDescriptor.getIASEjbExtraDescriptors().getPassByReference();
}
protected final long getContainerId() {
return ejbDescriptor.getUniqueId();
}
public final long getApplicationId() {
return ejbDescriptor.getApplication().getUniqueId();
}
@Override
public final EjbDescriptor getEjbDescriptor() {
return ejbDescriptor;
}
/**
* Method defined on JavaEEContainer
*/
@Override
public final Descriptor getDescriptor() {
return getEjbDescriptor();
}
@Override
public final EJBMetaData getEJBMetaData() {
return metadata;
}
public final UserTransaction getUserTransaction() {
return containerTransactionManager.getUserTransaction();
}
public boolean isHAEnabled() {
return false;
}
/**
* EJB spec makes a distinction between access to the UserTransaction object itself and access to its methods.
* getUserTransaction covers the first check and this method covers the second. It is called by the UserTransaction
* implementation to verify access.
*/
@Override
public boolean userTransactionMethodsAllowed(ComponentInvocation inv) {
// Overridden by containers that allowed BMT;
return false;
}
public final EJBHome getEJBHomeStub() {
return ejbHomeStub;
}
@Override
public final EJBHome getEJBHome() {
return ejbHome;
}
/**
* Return an object that implements ejb's local home interface. If dynamic proxies are being used, this is the proxy
* itself, it can't be directly cast to an EJBLocalHomeImpl.
*/
public final EJBLocalHome getEJBLocalHome() {
return ejbLocalHome;
}
/**
* Return an object that implements ejb's local business home interface.
*/
public final GenericEJBLocalHome getEJBLocalBusinessHome(String clientViewClassName) {
return isLocalBeanClass(clientViewClassName) ? ejbOptionalLocalBusinessHome : ejbLocalBusinessHome;
}
boolean isLocalBeanClass(String className) {
return hasOptionalLocalBusinessView
&& (className.equals(ejbClass.getName()) || className.equals(ejbGeneratedOptionalLocalBusinessIntfClass.getName()));
}
public final Class getEJBClass() {
return ejbClass;
}
@Override
public final SecurityManager getSecurityManager() {
return securityManager;
}
final Properties getEnvironmentProperties() {
return envProps;
}
/**
* Create an EJBObject reference from the instanceKey Called from EJBObjectOutputStream.SerializableRemoteRef during
* deserialization of a remote-ref
*
* @param instanceKey instanceKey of the ejbobject
* @param generatedRemoteBusinessIntf non-null, this is a remote business view and the param is the name of the
* generated remote business interface. Otherwise, this is for the RemoteHome view
*/
public Remote createRemoteReferenceWithId(byte[] instanceKey, String generatedRemoteBusinessIntf) {
final Thread currentThread = Thread.currentThread();
final ClassLoader previousClassLoader = currentThread.getContextClassLoader();
final ClassLoader myClassLoader = loader;
try {
currentThread.setContextClassLoader(myClassLoader);
final Remote remoteRef;
if (generatedRemoteBusinessIntf == null) {
remoteRef = remoteHomeRefFactory.createRemoteReference(instanceKey);
} else {
RemoteReferenceFactory remoteBusinessRefFactory = remoteBusinessIntfInfo.get(generatedRemoteBusinessIntf).referenceFactory;
remoteRef = remoteBusinessRefFactory.createRemoteReference(instanceKey);
}
return remoteRef;
} finally {
currentThread.setContextClassLoader(previousClassLoader);
}
}
private void assertFullProfile(String description) {
if (ejbContainerUtilImpl.isEJBLite()) {
throw new RuntimeException(localStrings.getLocalString("ejb.assert_full_profile",
"Invalid application. EJB {0} {1}. This feature is not part of the EJB 3.1 Lite API", ejbDescriptor.getName(),
description));
}
}
private void warnIfNotFullProfile(String description) {
if (ejbContainerUtilImpl.isEJBLite()) {
_logger.log(Level.WARNING, WARN_FEATURE_REQUIRES_FULL_PROFILE, description);
}
}
/**
* Called from the ContainerFactory during initialization.
*/
protected void initializeHome() throws Exception {
if (isWebServiceEndpoint) {
final EjbBundleDescriptor bundle = ejbDescriptor.getEjbBundleDescriptor();
final WebServicesDescriptor webServices = bundle.getWebServices();
final Collection myEndpoints = webServices.getEndpointsImplementedBy(ejbDescriptor);
// An ejb can only be exposed through 1 web service endpoint
webServiceEndpoint = myEndpoints.iterator().next();
final Class> seiClass;
final Class> declaredSEIClass = loader.loadClass(webServiceEndpoint.getServiceEndpointInterface());
if (declaredSEIClass.isInterface()) {
seiClass = declaredSEIClass;
} else {
seiClass = EJBUtils.generateSEI(loader, ejbClass);
if (seiClass == null) {
throw new RuntimeException(localStrings.getLocalString("ejb.error_generating_sei",
"Error in generating service endpoint interface class for EJB class {0}", this.ejbClass));
}
}
final WebServiceInvocationHandler invocationHandler = new WebServiceInvocationHandler(ejbClass,
webServiceEndpoint, seiClass, ejbContainerUtilImpl, webServiceInvocationInfoMap);
invocationHandler.setContainer(this);
final Object servant = Proxy.newProxyInstance(loader, new Class[] {seiClass}, invocationHandler);
// starting in 2.0, there is no more generated Ties
final Class> tieClass;
if (webServiceEndpoint.getTieClassName() == null) {
tieClass = null;
} else {
tieClass = loader.loadClass(webServiceEndpoint.getTieClassName());
}
wsejbEndpointRegistry = Globals.getDefaultHabitat().getService(WSEjbEndpointRegistry.class);
if (wsejbEndpointRegistry == null) {
throw new DeploymentException(localStrings.getLocalString("ejb.no_webservices_module",
"EJB-based Webservice endpoint is detected but there is no webservices module installed to handle it"));
}
EjbEndpointFacade endpointFacade = new EjbEndpointFacadeImpl(this, ejbContainerUtilImpl);
wsejbEndpointRegistry.registerEndpoint(webServiceEndpoint, endpointFacade, servant, tieClass);
}
final Map intfsForPortableJndi = new HashMap<>();
// Root of portable global JNDI name for this bean
final SimpleJndiName javaGlobalName = getJavaGlobalJndiNamePrefix();
_logger.log(FINEST, "javaGlobalName={0}", javaGlobalName);
if (isRemote) {
boolean disableNonPortableJndiName = false;
Boolean disableInDD = ejbDescriptor.getEjbBundleDescriptor().getDisableNonportableJndiNames();
if (disableInDD != null) { // explicitly set in glassfish-ejb-jar.xml
disableNonPortableJndiName = disableInDD;
} else {
String disableInServer = ejbContainerUtilImpl.getEjbContainer()
.getPropertyValue(RuntimeTagNames.DISABLE_NONPORTABLE_JNDI_NAMES);
disableNonPortableJndiName = Boolean.parseBoolean(disableInServer);
}
final SimpleJndiName glassfishSpecificJndiName;
if (disableNonPortableJndiName) {
glassfishSpecificJndiName = null;
} else {
// This is either the default glassfish-specific (non-portable)
// global JNDI name or the one specified via mappedName(), glassfish-ejb-jar.xml, etc.
final SimpleJndiName jndiName = ejbDescriptor.getJndiName();
// If the explicitly specified name is the same as the portable name,
// don't register any of the glassfish-specific names to prevent clashes.
if (jndiName == null || jndiName.isEmpty() || jndiName.equals(javaGlobalName)) {
glassfishSpecificJndiName = null;
} else {
glassfishSpecificJndiName = jndiName;
}
}
_logger.log(FINEST, "glassfishSpecificJndiName={0}", glassfishSpecificJndiName);
if (hasRemoteHomeView) {
this.ejbHomeImpl = instantiateEJBHomeImpl();
this.ejbHome = ejbHomeImpl.getEJBHome();
// Make sure all Home/Remote interfaces conform to RMI-IIOP
// rules. Checking for conformance here keeps the exposed
// deployment/startup error behavior consistent since when
// rmic is used during codegen it makes equivalent checks and
// treats any validation problems as fatal errors.
//
// These same checks will be made when setTarget is called
// in POARemoteReferenceFactory.preinvoke, but that happens
// only when the actual invocation is made, so it's better to
// know at container initialization time if there is a problem.
getProtocolManager().validateTargetObjectInterfaces(this.ejbHome);
// Unlike the Home, each of the concrete containers are
// responsible for creating the EJBObjects, so just create
// a dummy EJBObjectImpl for validation purposes.
final EJBObjectImpl dummyEJBObjectImpl = instantiateEJBObjectImpl();
final EJBObject dummyEJBObject = (EJBObject) dummyEJBObjectImpl.getEJBObject();
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it doesn't have
// stubs and ties. This must be done before any Home or Remote
// references are created.
remoteHomeRefFactory.setRepositoryIds(homeIntf, remoteIntf);
// Get a remote ref for the EJBHome
ejbHomeStub = (EJBHome) remoteHomeRefFactory.createHomeReference(homeInstanceKey);
// Add 2.x Home for later portable JNDI name processing.
intfsForPortableJndi.put(ejbDescriptor.getHomeClassName(), ejbHomeStub);
// If there's a glassfish-specific JNDI name, any 2.x Home object is always
// regsitered under that name. This preserves backward compatibility since
// this was the original use of the jndi name.
if (glassfishSpecificJndiName != null) {
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(glassfishSpecificJndiName, ejbHomeStub);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
}
if (hasRemoteBusinessView) {
this.ejbRemoteBusinessHomeImpl = instantiateEJBRemoteBusinessHomeImpl();
this.ejbRemoteBusinessHome = ejbRemoteBusinessHomeImpl.getEJBHome();
// RMI-IIOP validation
getProtocolManager().validateTargetObjectInterfaces(this.ejbRemoteBusinessHome);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
// Remotereference factory needs instances of
// Home and Remote to get repository Ids since it
// doesn't have stubs and ties. This must be done before
// any Home or Remote references are created.
next.referenceFactory.setRepositoryIds(remoteBusinessHomeIntf, next.generatedRemoteIntf);
// Create home stub from the remote reference factory
// associated with one of the remote business interfaces.
// It doesn't matter which remote reference factory is
// selected, so just do it the first time through the loop.
if (ejbRemoteBusinessHomeStub == null) {
ejbRemoteBusinessHomeStub = (EJBHome) next.referenceFactory.createHomeReference(homeInstanceKey);
}
}
// Internal jndi name under which remote business home is registered for
// glassfish-specific remote business JNDI names
final SimpleJndiName remoteBusinessHomeJndiName;
if (glassfishSpecificJndiName == null) {
remoteBusinessHomeJndiName = null;
} else {
remoteBusinessHomeJndiName = EJBUtils.getRemote30HomeJndiName(glassfishSpecificJndiName);
}
_logger.log(FINEST, "remoteBusinessHomeJndiName={0}", remoteBusinessHomeJndiName);
// Convenience location for common case of 3.0 session bean with only
// 1 remote business interface and no adapted remote home. Allows a
// stand-alone client to access 3.0 business interface by using simple
// jndi name. Each remote business interface is also always available
// at #. This is needed for the
// case where the bean has an adapted remote home and/or multiple business
// interfaces.
final SimpleJndiName simpleRemoteBusinessJndiName;
if (glassfishSpecificJndiName == null || hasRemoteHomeView || remoteBusinessIntfInfo.size() != 1) {
simpleRemoteBusinessJndiName = null;
} else {
simpleRemoteBusinessJndiName = glassfishSpecificJndiName;
}
// We need a separate name for the internal generated home object to
// support the portable global JNDI names for business interfaces.
// There won't necessarily be a glassfish-specific name specified so
// it's cleaner to just always use a separate ones.
final SimpleJndiName internalHomeJndiNameForPortableRemoteNames = EJBUtils.getRemote30HomeJndiName(javaGlobalName);
_logger.log(FINEST, "internalHomeJndiNameForPortableRemoteNames={0}", internalHomeJndiNameForPortableRemoteNames);
final EJBObjectImpl dummyEJBObjectImpl = instantiateRemoteBusinessObjectImpl();
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
Remote dummyEJBObject = dummyEJBObjectImpl.getEJBObject(next.generatedRemoteIntf.getName());
getProtocolManager().validateTargetObjectInterfaces(dummyEJBObject);
if (glassfishSpecificJndiName != null) {
next.jndiName = EJBUtils.getRemoteEjbJndiName(true, next.remoteBusinessIntf.getName(), glassfishSpecificJndiName);
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", remoteBusinessHomeJndiName == null ? null : remoteBusinessHomeJndiName.toString()),
RemoteBusinessObjectFactory.class.getName(), null);
// Glassfish-specific JNDI name for fully-qualified 3.0 Remote business interface.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(next.jndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
if (simpleRemoteBusinessJndiName != null) {
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", remoteBusinessHomeJndiName == null ? null : remoteBusinessHomeJndiName.toString()),
RemoteBusinessObjectFactory.class.getName(), null);
// Glassfish-specific JNDI name for simple 3.0 Remote business interface lookup.
// Applicable when the bean exposes only a single Remote 3.x client view.
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(simpleRemoteBusinessJndiName, remoteBusRef);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
Reference remoteBusRef = new Reference(next.remoteBusinessIntf.getName(),
new StringRefAddr("url", internalHomeJndiNameForPortableRemoteNames.toString()),
RemoteBusinessObjectFactory.class.getName(), null);
// Always register portable JNDI name for each remote business view
intfsForPortableJndi.put(next.remoteBusinessIntf.getName(), remoteBusRef);
}
if (remoteBusinessHomeJndiName != null) {
// Glassfish-specific JNDI name for internal generated
// home object used by container
JndiInfo jndiInfo = JndiInfo.newNonPortableRemote(remoteBusinessHomeJndiName, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
// Always registeer internal name for home in support of portable global
// remote business JNDI names.
JndiInfo jndiInfo = JndiInfo.newPortableRemote(internalHomeJndiNameForPortableRemoteNames, ejbRemoteBusinessHomeStub);
jndiInfo.setInternal(true);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
// If there isn't any jndi name from the descriptor, set one so the
// lookup logic that depends on ejbDescriptor.getJndiName() will work.
if (glassfishSpecificJndiName == null) {
ejbDescriptor.setJndiName(javaGlobalName);
}
}
}
if (isLocal) {
if (hasLocalHomeView) {
this.ejbLocalHomeImpl = instantiateEJBLocalHomeImpl();
this.ejbLocalHome = ejbLocalHomeImpl.getEJBLocalHome();
// Portable JNDI name for EJB 2.x LocalHome. We don't provide a
// glassfish-specific way of accessing Local EJBs.
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, localHomeIntf.getName());
intfsForPortableJndi.put(localHomeIntf.getName(), namingProxy);
}
if (hasLocalBusinessView) {
ejbLocalBusinessHomeImpl = instantiateEJBLocalBusinessHomeImpl();
ejbLocalBusinessHome = (GenericEJBLocalHome) ejbLocalBusinessHomeImpl.getEJBLocalHome();
ejbLocalBusinessProxyInterfaces = new Class[localBusinessIntfs.size() + 1];
ejbLocalBusinessProxyInterfaces[0] = IndirectlySerializable.class;
int index = 1;
for (Class next : localBusinessIntfs) {
ejbLocalBusinessProxyInterfaces[index] = next;
index++;
}
for (Class next : localBusinessIntfs) {
// Portable JNDI name for EJB 3.x Local business interface.
// We don't provide a glassfish-specific way of accessing Local EJBs.
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, next.getName());
intfsForPortableJndi.put(next.getName(), namingProxy);
}
}
if (hasOptionalLocalBusinessView) {
EJBLocalHomeImpl obj = instantiateEJBOptionalLocalBusinessHomeImpl();
ejbOptionalLocalBusinessHomeImpl = obj;
ejbOptionalLocalBusinessHome = (GenericEJBLocalHome) ejbOptionalLocalBusinessHomeImpl.getEJBLocalHome();
ejbOptionalLocalBusinessHomeProxyInterfaces = new Class[2];
ejbOptionalLocalBusinessHomeProxyInterfaces[0] = IndirectlySerializable.class;
String optionalIntfName = EJBUtils.getGeneratedOptionalInterfaceName(ejbClass.getName());
ejbGeneratedOptionalLocalBusinessIntfClass = optIntfClassLoader.loadClass(optionalIntfName);
ejbOptionalLocalBusinessHomeProxyInterfaces[1] = ejbGeneratedOptionalLocalBusinessIntfClass;
// Portable JNDI name for no-interface view.
// We don't provide a glassfish-specific way of accessing the
// no-interface view of a session bean.
JavaGlobalJndiNamingObjectProxy namingProxy = new JavaGlobalJndiNamingObjectProxy(this, ejbClass.getName());
intfsForPortableJndi.put(ejbClass.getName(), namingProxy);
}
}
for (Map.Entry entry : intfsForPortableJndi.entrySet()) {
String intf = entry.getKey();
SimpleJndiName fullyQualifiedJavaGlobalName = new SimpleJndiName(javaGlobalName + "!" + intf);
Object namingProxy = entry.getValue();
boolean local = (namingProxy instanceof JavaGlobalJndiNamingObjectProxy);
if (intfsForPortableJndi.size() == 1) {
JndiInfo jndiInfo = local ? JndiInfo.newPortableLocal(javaGlobalName, namingProxy)
: JndiInfo.newPortableRemote(javaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
JndiInfo jndiInfo = local ? JndiInfo.newPortableLocal(fullyQualifiedJavaGlobalName, namingProxy)
: JndiInfo.newPortableRemote(fullyQualifiedJavaGlobalName, namingProxy);
jndiInfoMap.put(jndiInfo.name, jndiInfo);
}
for (Entry entry : jndiInfoMap.entrySet()) {
JndiInfo jndiInfo = entry.getValue();
try {
jndiInfo.publish(this.namingManager);
if (jndiInfo.internal) {
publishedInternalGlobalJndiNames.add(jndiInfo.name);
} else {
if (jndiInfo.portable) {
publishedPortableGlobalJndiNames.add(jndiInfo.name);
} else {
publishedNonPortableGlobalJndiNames.add(jndiInfo.name);
}
}
} catch (Exception e) {
throw new RuntimeException(localStrings.getLocalString("ejb.error_binding_jndi_name",
"Error while binding JNDI name {0} for EJB {1}", jndiInfo.name, this.ejbDescriptor.getName()), e);
}
}
if (!publishedPortableGlobalJndiNames.isEmpty()) {
_logger.log(Level.INFO, PORTABLE_JNDI_NAMES,
new Object[] {this.ejbDescriptor.getName(), publishedPortableGlobalJndiNames});
}
if (!publishedNonPortableGlobalJndiNames.isEmpty()) {
_logger.log(Level.INFO, GLASSFISH_SPECIFIC_JNDI_NAMES,
new Object[] { this.ejbDescriptor.getName(), publishedNonPortableGlobalJndiNames });
}
if (!publishedInternalGlobalJndiNames.isEmpty()) {
_logger.log(FINE, "Internal container JNDI names for EJB {0}: {1}",
new Object[] { this.ejbDescriptor.getName(), publishedInternalGlobalJndiNames });
}
// set EJBMetaData
setEJBMetaData();
}
// default impl
protected void setEJBMetaData() throws Exception {
metadata = new EJBMetaDataImpl(ejbHomeStub, homeIntf, remoteIntf, isSession, isStatelessSession);
}
protected SimpleJndiName getJavaGlobalJndiNamePrefix() {
final Application app = ejbDescriptor.getApplication();
final String appName = app.isVirtual() ? null : app.getAppName();
StringBuilder javaGlobalPrefix = new StringBuilder().append(JNDI_CTX_JAVA_GLOBAL);
if (appName != null) {
javaGlobalPrefix.append(appName);
javaGlobalPrefix.append('/');
}
javaGlobalPrefix.append(ejbDescriptor.getEjbBundleDescriptor().getModuleDescriptor().getModuleName());
javaGlobalPrefix.append('/');
javaGlobalPrefix.append(ejbDescriptor.getName());
return new SimpleJndiName(javaGlobalPrefix.toString());
}
// This method is used to create the ejb after the around_construct interceptor chain has completed.
public void createEjbInstanceForInterceptors(Object[] params, EJBContextImpl ctx) throws Exception {
final Object instance;
final EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
if (cdiService != null && cdiService.isCDIEnabled(ejbBundle)) {
// EJB creation for CDI is handled in CDIServiceImpl not here.
instance = ctx.getCDIInjectionContext().createEjbAfterAroundConstruct();
} else {
// This is only for non-cdi case.
instance = _constructEJBInstance();
}
ctx.setEJB(instance);
}
protected EJBContextImpl createEjbInstanceAndContext() throws Exception {
if (containerState != CONTAINER_STARTED) {
throw new IllegalStateException(localStrings.getLocalString("ejb.container_not_started",
"Attempt to invoke when container is in {0}", containerStateToString(containerState)));
}
EjbBundleDescriptor ejbBundle = ejbDescriptor.getEjbBundleDescriptor();
Object instance = null;
EJBContextImpl ctx = _constructEJBContextImpl(null);
EjbInvocation ejbInv = null;
boolean success = false;
CDIService.CDIInjectionContext