Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4f4383c
bugfix: EAR deployment bugs found
lprimak Mar 7, 2025
2555d00
exclude RAR and EJB-JAR modules from WAR/EAR-lib wiring to comply wit…
lprimak Mar 22, 2025
e4d1c05
added fish.payara.war-beans-visible-in-ear-libs system / app property
lprimak Mar 26, 2025
fa3923f
bugfix: dis-ambiguate by class loader if bean IDs are the same
lprimak Mar 31, 2025
ce9c62a
fixed RAR injection bug
lprimak Apr 1, 2025
6e76b70
another RAR fix
lprimak Apr 3, 2025
8c83f60
another stab at RAR fix
lprimak Apr 3, 2025
e111c58
another stab at RAR fix
lprimak Apr 3, 2025
af91b86
RAR issue - fixed based on the reproducer
lprimak Apr 4, 2025
a07e85c
RAR code cleanup
lprimak Apr 4, 2025
95592f8
fixed Jakarta Rest TCK test that uses custom serializer
lprimak Apr 7, 2025
5d11d02
JSON-B code cleanup
lprimak Apr 7, 2025
a571ceb
Json-B: instroduce lambda
lprimak Apr 7, 2025
42a85d1
Jakarta Web Service: update tester servlet to supported arguments
lprimak Apr 7, 2025
4e2d97d
Web Services: restore deployment context after wstx service startup
lprimak Apr 8, 2025
81d5381
Revert "Web Services: restore deployment context after wstx service s…
lprimak Apr 9, 2025
daed1b9
more generic fix for recursive deployments (ex: WebServices/WSTX depl…
lprimak Apr 9, 2025
3565710
bugfix: only apply Jax-RS resolver type for CDI if it's not a class w…
lprimak Apr 15, 2025
5bae52c
one more guess at Rest integratino issues
lprimak Apr 15, 2025
46a6d0a
add context providers registered via @Provider annotation
lprimak Apr 23, 2025
bdb0398
working interceptor
lprimak Apr 24, 2025
f8f05f7
refactor
lprimak Apr 24, 2025
2f261bb
review comment - fixed confusing line
lprimak Apr 24, 2025
f9cde87
fallback to any type from the proper BDA if the registered type is a …
lprimak Apr 24, 2025
86704b9
fixed class loader check
lprimak Apr 24, 2025
0cb1b80
added backup find of Weld manager instance in case none of the ClassL…
lprimak Apr 25, 2025
8494928
cleanup
lprimak Apr 25, 2025
0cf55b0
reworked and simplified CDI BeanManager find algorithm
lprimak Apr 29, 2025
ea3ee83
fixed circular reference to current deployment context
lprimak May 1, 2025
f00b096
refactor assymetric equals() code into multimap
lprimak May 5, 2025
6bebd5d
cleanup: removed code and associated `fish.payara.war-beans-visible-i…
lprimak May 5, 2025
3f57431
cleanup: remove unused `recursivelyAdd()` method
lprimak May 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2018-2021] [Payara Foundation and/or its affiliates]
// Portions Copyright [2018-2025] [Payara Foundation and/or its affiliates]

package org.glassfish.enterprise.iiop.impl;


import jakarta.ejb.NoSuchObjectLocalException;

import java.lang.ref.WeakReference;
import java.rmi.Remote;

import java.security.AccessController ;
Expand Down Expand Up @@ -135,7 +136,7 @@ public final class POARemoteReferenceFactory extends org.omg.CORBA.LocalObject

private EjbContainerFacade container;
private EjbDescriptor ejbDescriptor;
private ClassLoader appClassLoader;
private WeakReference<ClassLoader> appClassLoader;

private ORB orb;
private POAProtocolMgr protocolMgr;
Expand Down Expand Up @@ -180,7 +181,7 @@ public final class POARemoteReferenceFactory extends org.omg.CORBA.LocalObject
this.ejbDescriptor = container.getEjbDescriptor();
this.isRemoteHomeView = remoteHomeView;

appClassLoader = container.getClassLoader();
appClassLoader = new WeakReference<>(container.getClassLoader());

// NOTE: ReferenceFactory creation happens in setRepositoryIds.
}
Expand Down Expand Up @@ -217,12 +218,12 @@ public void setRepositoryIds(Class homeIntf, Class remoteIntf)
// Home
ejbHomeStubFactory =
sff.createStubFactory( homeIntf.getName(), false,
"", null, appClassLoader);
"", null, appClassLoader.get());
String[] ejbHomeTypeIds = ejbHomeStubFactory.getTypeIds();
ejbHomeRepositoryId = ejbHomeTypeIds[0];

ejbObjectStubFactory = sff.createStubFactory
( remoteIntf.getName(), false, "", null, appClassLoader);
( remoteIntf.getName(), false, "", null, appClassLoader.get());

String[] ejbObjectTypeIds = ejbObjectStubFactory.getTypeIds();

Expand Down
5 changes: 5 additions & 0 deletions appserver/web/weld-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<include>**/faces-config.xml</include>
<include>**/com.sun.faces.spi.FacesConfigResourceProvider</include>
<include>**/jakarta.enterprise.inject.spi.Extension</include>
<include>**/org.glassfish.jersey.internal.spi.*</include>
</includes>
</resource>
</resources>
Expand Down Expand Up @@ -200,6 +201,10 @@
<groupId>fish.payara.server.internal.transaction</groupId>
<artifactId>jta</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,28 @@
* only if the new code is made subject to such option by the copyright
* holder.
*
* Portions Copyright [2017-2024] Payara Foundation and/or affiliates
* Portions Copyright [2017-2025] Payara Foundation and/or affiliates
*/

package org.glassfish.weld;

import org.glassfish.internal.deployment.Deployment;
import org.glassfish.web.loader.WebappClassLoader;
import org.jboss.weld.bootstrap.api.SingletonProvider;
import org.jboss.weld.bootstrap.api.Singleton;
import org.glassfish.internal.api.Globals;
import org.glassfish.internal.api.ClassLoaderHierarchy;
import org.jboss.weld.util.collections.Multimap;
import org.jboss.weld.util.collections.SetMultimap;

import java.util.Collection;
import java.util.Map;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import static org.glassfish.weld.ACLSingletonProvider.ACLSingleton.ValueAndClassLoaders.findByClassLoader;
import static org.glassfish.weld.ACLSingletonProvider.ACLSingleton.ValueAndClassLoaders.findByIdOnly;

/**
* Singleton provider that uses Application ClassLoader to differentiate
Expand Down Expand Up @@ -83,11 +90,39 @@ public <T> ACLSingleton<T> create(Class<? extends T> expectedType) {
return new ACLSingleton<T>();
}

private static class ACLSingleton<T> implements Singleton<T> {
static class ACLSingleton<T> implements Singleton<T> {

private final Map<ClassLoader, T> store = new ConcurrentHashMap<>();
private final Map<String, T> storeById = new ConcurrentHashMap<>();
private final Multimap<String, ValueAndClassLoaders<T>> storeById = SetMultimap.newConcurrentSetMultimap();
private ClassLoader ccl = Globals.get(ClassLoaderHierarchy.class).getCommonClassLoader();
private final Deployment deployment = Globals.getDefaultHabitat().getService(Deployment.class);
static final class ValueAndClassLoaders<TT> {
final TT value;
final ClassLoader classLoader;
final ClassLoader backupClassLoader;

public ValueAndClassLoaders(TT value, ClassLoader classLoader, ClassLoader backupClassLoader) {
this.value = value;
this.classLoader = classLoader;
this.backupClassLoader = backupClassLoader;
}

public static <T> T findByClassLoader(Collection<ValueAndClassLoaders<T>> values, ClassLoader classLoader) {
return values.stream()
.filter(v -> Objects.equals(v.classLoader, classLoader)
|| Objects.equals(v.backupClassLoader, classLoader))
.findAny()
.map(v -> v.value)
.orElse(null);
}

public static <T> T findByIdOnly(Collection<ValueAndClassLoaders<T>> values) {
return values.stream()
.findAny()
.map(v -> v.value)
.orElse(null);
}
}

// Can't assume bootstrap loader as null. That's more of a convention.
// I think either android or IBM JVM does not use null for bootstap loader
Expand All @@ -108,9 +143,11 @@ public ClassLoader run()
@Override
public T get( String id )
{
T instance = storeById.get(id);
if (instance == null)
{
T instance = findByClassLoader(storeById.get(id), getDeploymentOrContextClassLoader());
if (instance == null) {
instance = findByIdOnly(storeById.get(id));
}
if (instance == null) {
ClassLoader acl = getClassLoader();
instance = store.get(acl);
if (instance == null) {
Expand All @@ -120,6 +157,14 @@ public T get( String id )
return instance;
}

private ClassLoader getDeploymentOrContextClassLoader() {
if (deployment.getCurrentDeploymentContext() != null) {
return deployment.getCurrentDeploymentContext().getClassLoader();
} else {
return Thread.currentThread().getContextClassLoader();
}
}

/**
* This is the most significant method of this class. This is what
* distingushes it from TCCLSIngleton. It tries to obtain a class loader
Expand Down Expand Up @@ -196,13 +241,16 @@ public boolean isSet(String id) {
@Override
public void set(String id, T object) {
store.put(getClassLoader(), object);
storeById.put(id, object);
storeById.put(id, new ValueAndClassLoaders<>(object, getDeploymentOrContextClassLoader(),
Thread.currentThread().getContextClassLoader()));
}

@Override
public void clear(String id) {
store.remove(getClassLoader());
storeById.remove(id);
storeById.get(id).removeIf(v ->
Objects.equals(v.classLoader, getDeploymentOrContextClassLoader())
|| Objects.equals(v.classLoader, Thread.currentThread().getContextClassLoader()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public DeploymentImpl(ReadableArchive archive,
this.archiveFactory = archiveFactory;
this.context = context;
this.injectionManager = injectionManager;
this.contextId = moduleName != null? moduleName : archive.getName();

// Collect /lib Jar BDAs (if any) from the parent module.
// If we've produced BDA(s) from any /lib jars, <code>return</code> as
Expand All @@ -177,7 +178,6 @@ public DeploymentImpl(ReadableArchive archive,
this.appName = "CDIApp";
}

this.contextId = moduleName != null? moduleName : archive.getName();
createModuleBda(archive, ejbs, context, contextId);
}

Expand Down Expand Up @@ -274,7 +274,9 @@ private <TT extends BeanDeploymentArchive> Set<TT> filterBDAs(Set<TT> bdas, List
}

private void addBeanDeploymentArchives(RootBeanDeploymentArchive bda) {
rootBDAs(bda).add(bda);
if (bda.getModuleBDAType() != BDAType.UNKNOWN) {
rootBDAs(bda).add(bda);
}
}

private Set<RootBeanDeploymentArchive> rootBDAs(RootBeanDeploymentArchive bda) {
Expand Down Expand Up @@ -313,12 +315,16 @@ public void scanArchive(ReadableArchive archive, Collection<EjbDescriptor> ejbs,
* <code>Deployment</code>.
*/
public void buildDeploymentGraph() {
Set<BeanDeploymentArchive> ejbModuleAndRarBDAs = new HashSet<>();

// Make jars accessible to each other - Example:
// /ejb1.jar <----> /ejb2.jar
// If there are any application (/lib) jars, make them accessible

for (RootBeanDeploymentArchive ejbRootBda : ejbRootBdas) {
BeanDeploymentArchive ejbModuleBda = ejbRootBda.getModuleBda();
ejbModuleAndRarBDAs.add(ejbRootBda);
ejbModuleAndRarBDAs.add(ejbModuleBda);

boolean modifiedArchive = false;
for (RootBeanDeploymentArchive otherEjbRootBda : ejbRootBdas) {
Expand All @@ -345,6 +351,8 @@ public void buildDeploymentGraph() {
// Make rars accessible to ejbs
for (RootBeanDeploymentArchive rarRootBda : rarRootBdas) {
BeanDeploymentArchive rarModuleBda = rarRootBda.getModuleBda();
ejbModuleAndRarBDAs.add(rarRootBda);
ejbModuleAndRarBDAs.add(rarModuleBda);
ejbRootBda.getBeanDeploymentArchives().add(rarRootBda);
ejbRootBda.getBeanDeploymentArchives().add(rarModuleBda);
ejbModuleBda.getBeanDeploymentArchives().add(rarRootBda);
Expand Down Expand Up @@ -391,18 +399,6 @@ public void buildDeploymentGraph() {
warModuleBda.getBeanDeploymentArchives().add(libJarRootBda);
warModuleBda.getBeanDeploymentArchives().add(libJarModuleBda);

// make WAR's BDAs accessible to libJar BDAs
Set<BeanDeploymentArchive> seen = Collections.newSetFromMap(new IdentityHashMap<>());
beanDeploymentArchives.stream()
.filter(RootBeanDeploymentArchive.class::isInstance)
.map(RootBeanDeploymentArchive.class::cast)
.forEach(bda -> recursivelyAdd(bda.getBeanDeploymentArchives(), warModuleBda, seen));
recursivelyAdd(beanDeploymentArchives, warModuleBda, seen);
libJarRootBda.getBeanDeploymentArchives().add(warRootBda);
libJarModuleBda.getBeanDeploymentArchives().add(warRootBda);
libJarRootBda.getBeanDeploymentArchives().add(warModuleBda);
libJarModuleBda.getBeanDeploymentArchives().add(warModuleBda);

for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) {
oneBda.getBeanDeploymentArchives().add( libJarRootBda );
oneBda.getBeanDeploymentArchives().add( libJarModuleBda );
Expand Down Expand Up @@ -458,15 +454,6 @@ private void addDependentBdas() {
}
}

private void recursivelyAdd(Collection<BeanDeploymentArchive> bdas, BeanDeploymentArchive bda, Set<BeanDeploymentArchive> seen) {
for (BeanDeploymentArchive subBda : new LinkedHashSet<>(bdas)) {
if (seen.add(subBda)) {
subBda.getBeanDeploymentArchives().add(bda);
recursivelyAdd(subBda.getBeanDeploymentArchives(), bda, seen);
}
}
}

@Override
public Set<BeanDeploymentArchive> getBeanDeploymentArchives() {
if ( logger.isLoggable( FINE ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2024] [Payara Foundation and/or its affiliates]
// Portions Copyright [2024-2025] [Payara Foundation and/or its affiliates]

package org.glassfish.weld;

Expand All @@ -49,26 +49,36 @@
import org.jboss.weld.Container;
import org.jboss.weld.SimpleCDI;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.jboss.weld.logging.BeanManagerLogger;
import org.jboss.weld.manager.BeanManagerImpl;

import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.inject.spi.CDIProvider;
import java.lang.StackWalker.StackFrame;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static java.lang.StackWalker.Option.RETAIN_CLASS_REFERENCE;

/**
* @author <a href="mailto:[email protected]">JJ Snyder</a>
*/
public class GlassFishWeldProvider implements CDIProvider {
private static final WeldDeployer weldDeployer = Globals.get(WeldDeployer.class);
private static final InvocationManager invocationManager = Globals.get(InvocationManager.class);
private static final StackWalker stackWalker = StackWalker.getInstance(RETAIN_CLASS_REFERENCE);

private static class GlassFishEnhancedWeld extends SimpleCDI {
private final Set<String> knownClassNames;

GlassFishEnhancedWeld() {
knownClassNames = new HashSet<>(super.knownClassNames);
}

GlassFishEnhancedWeld(String contextId) {
super(contextId == null ? Container.instance() : Container.instance(contextId));
knownClassNames = new HashSet<>(super.knownClassNames);
}

@Override
Expand Down Expand Up @@ -103,23 +113,40 @@ protected BeanManagerImpl unsatisfiedBeanManager(String callerClassName) {

return super.unsatisfiedBeanManager(callerClassName);
}

@Override
protected String getCallingClassName() {
boolean outerSubclassReached = false;
BundleDescriptor bundleDescriptor = getBundleDescriptor();
for (StackFrame element : stackWalker.walk(sf -> sf.collect(Collectors.toList()))) {
// the method call that leads to the first invocation of this class or its subclass is considered the caller
if (!knownClassNames.contains(element.getClassName())) {
Class<?> declaringClass = element.getDeclaringClass();
if (outerSubclassReached && declaringClass.getClassLoader() != null) {
if (bundleDescriptor != null && declaringClass.getClassLoader() == bundleDescriptor.getClassLoader()) {
// we are in the same class loader, so this is the caller
return declaringClass.getName();
} else {
return getAnyClassFromBundleDescriptor(declaringClass.getName());
}
}
} else {
outerSubclassReached = true;
}
}
throw BeanManagerLogger.LOG.unableToIdentifyBeanManager();
}

private static String getAnyClassFromBundleDescriptor(String backupClassName) {
BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(getBundleDescriptor());
return bda != null ? bda.getBeanClasses().stream().findAny().orElse(backupClassName) : backupClassName;
}
}

@Override
public CDI<Object> getCDI() {
try {
BundleDescriptor bundle = null;
Object componentEnv = invocationManager.getCurrentInvocation().getJNDIEnvironment();
if( componentEnv instanceof EjbDescriptor) {
bundle = (BundleDescriptor)
((EjbDescriptor) componentEnv).getEjbBundleDescriptor().
getModuleDescriptor().getDescriptor();

} else if( componentEnv instanceof WebBundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
}

BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle);
BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(getBundleDescriptor());
if (bda == null) {
return new GlassFishEnhancedWeld();
} else {
Expand All @@ -133,4 +160,18 @@ public CDI<Object> getCDI() {
throw throwable;
}
}

private static BundleDescriptor getBundleDescriptor() {
BundleDescriptor bundle = null;
Object componentEnv = invocationManager.getCurrentInvocation().getJNDIEnvironment();
if( componentEnv instanceof EjbDescriptor) {
bundle = (BundleDescriptor)
((EjbDescriptor) componentEnv).getEjbBundleDescriptor().
getModuleDescriptor().getDescriptor();

} else if( componentEnv instanceof WebBundleDescriptor) {
bundle = (BundleDescriptor) componentEnv;
}
return bundle;
}
}
Loading