/
BaseContainer.java
4564 lines (3698 loc) · 188 KB
/
BaseContainer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2022 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.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.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.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.Vector;
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.EjbApplicationExceptionInfo;
import org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl;
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.deployment.descriptor.ScheduledTimerDescriptor;
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 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<Class> 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<EjbContainerInterceptor> 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<String, RemoteBusinessIntfInfo> 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<Method, InvocationInfo> invocationInfoMap = new HashMap<>();
protected Map<TimerPrimaryKey, Method> scheduleIds = new HashMap<>();
Map<Method, List<ScheduledTimerDescriptor>> 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<Method, InvocationInfo> 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<Class> 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<SimpleJndiName> publishedPortableGlobalJndiNames = new HashSet<>();
private final Set<SimpleJndiName> publishedNonPortableGlobalJndiNames = new HashSet<>();
private final Set<SimpleJndiName> publishedInternalGlobalJndiNames = new HashSet<>();
private final Map<SimpleJndiName, JndiInfo> 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(Level.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");
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) {
EjbBundleDescriptorImpl 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<ScheduledTimerDescriptor> 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(Level.FINE, "Exception creating BaseContainer : [{0}]", containerInfo);
_logger.log(Level.FINE, "", ex);
throw ex;
}
_logger.log(Level.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 {
if (System.getSecurityManager() == null) {
currentThread.setContextClassLoader(myClassLoader);
} else {
AccessController.doPrivileged(new java.security.PrivilegedAction() {
@Override