Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 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
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 @@ -42,6 +42,7 @@

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;
Expand All @@ -51,6 +52,7 @@
import java.util.Map;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
Expand Down Expand Up @@ -86,8 +88,45 @@ public <T> ACLSingleton<T> create(Class<? extends T> expectedType) {
private 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 Map<ClassLoaderAndId, T> storeById = new ConcurrentHashMap<>();
private ClassLoader ccl = Globals.get(ClassLoaderHierarchy.class).getCommonClassLoader();
private final Deployment deployment = Globals.getDefaultHabitat().getService(Deployment.class);

private static class ClassLoaderAndId {
private final ClassLoader cl;
private final ClassLoader backupClassLoader;
private final String id;

ClassLoaderAndId(ClassLoader cl, String id) {
this.cl = cl;
this.backupClassLoader = cl;
this.id = id;
}

ClassLoaderAndId(ClassLoader cl, ClassLoader backupClassLoader, String id) {
this.cl = cl;
this.backupClassLoader = backupClassLoader;
this.id = id;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof ClassLoaderAndId)) return false;
ClassLoaderAndId that = (ClassLoaderAndId) o;
if (Objects.equals(id, that.id)) {
if (Objects.equals(cl, that.cl)) {
return true;
}
return Objects.equals(cl, that.backupClassLoader);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(id);
}
}

// 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,7 +147,7 @@ public ClassLoader run()
@Override
public T get( String id )
{
T instance = storeById.get(id);
T instance = storeById.get(new ClassLoaderAndId(getDeploymentOrContextClassLoader(), id));
if (instance == null)
{
ClassLoader acl = getClassLoader();
Expand All @@ -120,6 +159,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 @@ -190,19 +237,20 @@ public ClassLoader run()

@Override
public boolean isSet(String id) {
return store.containsKey(getClassLoader()) || storeById.containsKey(id);
return store.containsKey(getClassLoader()) || storeById.containsKey(
new ClassLoaderAndId(getDeploymentOrContextClassLoader(), id));
}

@Override
public void set(String id, T object) {
store.put(getClassLoader(), object);
storeById.put(id, object);
storeById.put(new ClassLoaderAndId(getDeploymentOrContextClassLoader(), Thread.currentThread().getContextClassLoader(), id), object);
}

@Override
public void clear(String id) {
store.remove(getClassLoader());
storeById.remove(id);
storeById.remove(new ClassLoaderAndId(getDeploymentOrContextClassLoader(), Thread.currentThread().getContextClassLoader(), id));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import static java.util.logging.Level.WARNING;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.glassfish.weld.WeldDeployer.MAKE_WARS_VISIBLE_IN_EAR_LIBS;
import static org.glassfish.weld.connector.WeldUtils.*;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -159,6 +160,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 +179,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 +275,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 +316,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 +352,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 @@ -392,16 +401,21 @@ public void buildDeploymentGraph() {
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);
boolean makeWarBDAsAccessibleToEARLibs = Boolean.parseBoolean(context.getAppProps()
.getProperty(MAKE_WARS_VISIBLE_IN_EAR_LIBS)) || Boolean.getBoolean(MAKE_WARS_VISIBLE_IN_EAR_LIBS);
if (makeWarBDAsAccessibleToEARLibs) {
Set<BeanDeploymentArchive> seen = Collections.newSetFromMap(new IdentityHashMap<>());
beanDeploymentArchives.stream()
.filter(RootBeanDeploymentArchive.class::isInstance)
.map(RootBeanDeploymentArchive.class::cast)
.forEach(bda ->
recursivelyAdd(bda.getBeanDeploymentArchives(), warModuleBda, seen, ejbModuleAndRarBDAs));
recursivelyAdd(beanDeploymentArchives, warModuleBda, seen, ejbModuleAndRarBDAs);
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 );
Expand Down Expand Up @@ -458,11 +472,12 @@ private void addDependentBdas() {
}
}

private void recursivelyAdd(Collection<BeanDeploymentArchive> bdas, BeanDeploymentArchive bda, Set<BeanDeploymentArchive> seen) {
private void recursivelyAdd(Collection<BeanDeploymentArchive> bdas, BeanDeploymentArchive bda, Set<BeanDeploymentArchive> seen,
Set<BeanDeploymentArchive> excluded) {
for (BeanDeploymentArchive subBda : new LinkedHashSet<>(bdas)) {
if (seen.add(subBda)) {
if (seen.add(subBda) && !excluded.contains(subBda)) {
subBda.getBeanDeploymentArchives().add(bda);
recursivelyAdd(subBda.getBeanDeploymentArchives(), bda, seen);
recursivelyAdd(subBda.getBeanDeploymentArchives(), bda, seen, excluded);
}
}
}
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 @@ -55,6 +55,7 @@
import jakarta.enterprise.inject.spi.CDIProvider;
import java.util.Map;
import java.util.Set;
import static org.glassfish.weld.JaxRSJsonContextResolver.currentType;

/**
* @author <a href="mailto:[email protected]">JJ Snyder</a>
Expand Down Expand Up @@ -103,6 +104,15 @@ protected BeanManagerImpl unsatisfiedBeanManager(String callerClassName) {

return super.unsatisfiedBeanManager(callerClassName);
}

@Override
protected String getCallingClassName() {
if (currentType.get() != null) {
return currentType.get().getName();
} else {
return super.getCallingClassName();
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2025] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/main/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.weld;

import jakarta.annotation.Priority;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.ws.rs.ConstrainedTo;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.FeatureContext;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.ContextResolver;
import org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import static jakarta.ws.rs.RuntimeType.SERVER;
import static org.glassfish.jersey.internal.spi.AutoDiscoverable.DEFAULT_PRIORITY;

/**
* Works in conjunction with {@link org.glassfish.weld.GlassFishWeldProvider} to provide the
* correct {@link Jsonb} instance based on the type of Jax-RS resource class being processed.
*
* This includes creating {@link Jsonb} instances that contains correct {@link jakarta.enterprise.inject.spi.BeanManager}
*/
@ConstrainedTo(SERVER)
@Priority(DEFAULT_PRIORITY)
@Produces(MediaType.APPLICATION_JSON)
public class JaxRSJsonContextResolver implements ContextResolver<Jsonb>, ForcedAutoDiscoverable {
private final Map<Class<?>, Jsonb> jsonbMap = new ConcurrentHashMap<>();
static final ThreadLocal<Class<?>> currentType = new ThreadLocal<>();
private final List<ContextResolver<?>> existingResolvers;

public JaxRSJsonContextResolver() {
this.existingResolvers = Collections.emptyList();
}

private JaxRSJsonContextResolver(List<ContextResolver<?>> existingResolvers) {
this.existingResolvers = existingResolvers;
}

@Override
public void configure(FeatureContext context) {
List<ContextResolver<?>> resolvers = context.getConfiguration().getInstances().stream()
.filter(ContextResolver.class::isInstance)
.map(resolver -> (ContextResolver<?>) resolver)
.collect(Collectors.toList());
context.register(new JaxRSJsonContextResolver(resolvers));
}

@Override
public Jsonb getContext(Class<?> type) {
return jsonbMap.computeIfAbsent(type, unused -> {
currentType.set(type);
try {
for (ContextResolver<?> resolver : existingResolvers) {
Object result = resolver.getContext(type);
if (result instanceof Jsonb) {
return (Jsonb) result;
}
}
return JsonbBuilder.create();
} finally {
currentType.remove();
}
});
}
}
Loading