Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions core-client/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
exports org.glassfish.jersey.client.inject;
exports org.glassfish.jersey.client.spi;
exports org.glassfish.jersey.client.internal;
exports org.glassfish.jersey.client.internal.inject to org.glassfish.jersey.incubator.cdi.inject.weld;

exports org.glassfish.jersey.client.innate to
org.glassfish.jersey.apache5.connector,
Expand Down
6 changes: 4 additions & 2 deletions core-common/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
org.glassfish.jersey.container.servlet,
org.glassfish.jersey.container.jetty.http,
org.glassfish.jersey.netty.connector,
org.glassfish.jersey.ext.mp.rest.client;
org.glassfish.jersey.ext.mp.rest.client,
org.glassfish.jersey.incubator.cdi.inject.weld;

exports org.glassfish.jersey.innate.inject to org.glassfish.jersey.inject.hk2,
org.glassfish.jersey.inject.cdi2.se,
Expand All @@ -80,6 +81,7 @@
org.glassfish.jersey.ext.entity.filtering,
org.glassfish.jersey.ext.metainf.services,
org.glassfish.jersey.ext.mvc,
org.glassfish.jersey.incubator.cdi.inject.weld,
org.glassfish.jersey.gf.ejb,
org.glassfish.jersey.security.oauth1.signature;
exports org.glassfish.jersey.innate.virtual to org.glassfish.jersey.container.grizzly2.http,
Expand All @@ -104,14 +106,14 @@

opens org.glassfish.jersey.innate.spi to org.glassfish.jersey.media.multipart;
opens org.glassfish.jersey.internal;
opens org.glassfish.jersey.internal.util.collection;
opens org.glassfish.jersey.message.internal;
opens org.glassfish.jersey.spi;

uses jakarta.ws.rs.core.Feature;
uses jakarta.ws.rs.container.DynamicFeature;
uses jakarta.ws.rs.ext.RuntimeDelegate;

uses org.glassfish.jersey.innate.BootstrapPreinitialization;
uses org.glassfish.jersey.innate.spi.EntityPartBuilderProvider;
uses org.glassfish.jersey.internal.ServiceFinder;
uses org.glassfish.jersey.internal.inject.InjectionManagerFactory;
Expand Down
16 changes: 13 additions & 3 deletions core-server/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
exports org.glassfish.jersey.server.wadl.internal.generators.resourcedoc;
exports org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model;
exports org.glassfish.jersey.server.filter;
exports org.glassfish.jersey.server.filter.internal to org.glassfish.hk2.locator, org.glassfish.hk2.utilities;
exports org.glassfish.jersey.server.filter.internal to
org.glassfish.hk2.locator,
org.glassfish.hk2.utilities,
org.glassfish.jersey.incubator.cdi.inject.weld;

exports org.glassfish.jersey.server.monitoring;
exports org.glassfish.jersey.server.internal;
Expand Down Expand Up @@ -76,11 +79,18 @@

opens org.glassfish.jersey.server;
opens org.glassfish.jersey.server.filter;
opens org.glassfish.jersey.server.internal to org.glassfish.hk2.utilities;
opens org.glassfish.jersey.server.filter.internal to
org.glassfish.hk2.locator,
org.glassfish.hk2.utilities,
weld.core.impl;
opens org.glassfish.jersey.server.internal to org.glassfish.hk2.utilities, weld.core.impl;
opens org.glassfish.jersey.server.internal.inject;
opens org.glassfish.jersey.server.internal.monitoring to org.glassfish.hk2.utilities;
opens org.glassfish.jersey.server.internal.monitoring.jmx to org.glassfish.hk2.utilities;
opens org.glassfish.jersey.server.internal.process to org.glassfish.hk2.locator, org.glassfish.hk2.utilities;
opens org.glassfish.jersey.server.internal.process to
org.glassfish.hk2.locator,
org.glassfish.hk2.utilities,
weld.core.impl;
opens org.glassfish.jersey.server.internal.routing to org.glassfish.hk2.utilities;
opens org.glassfish.jersey.server.model;
opens org.glassfish.jersey.server.wadl.processor;
Expand Down
33 changes: 29 additions & 4 deletions incubator/cdi-inject-weld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@

<description>CDI InjectionManager implementation</description>

<properties>
<!-- test packages -->
<surefire.security.argline>
--add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=org.glassfish.jersey.core.common
--add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=weld.core.impl
--add-exports org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld=weld.core.impl
--add-opens org.glassfish.jersey.incubator.cdi.inject.weld/org.glassfish.jersey.inject.weld.binder.client=weld.core.impl
</surefire.security.argline>
</properties>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
Expand Down Expand Up @@ -73,20 +83,36 @@
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<scope>test</scope>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-spi</artifactId>
<version>${weld.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core-impl</artifactId>
<version>${weld.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<scope>provided</scope>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down Expand Up @@ -140,7 +166,6 @@
org.glassfish.jersey.inject.weld.managed.*;version=${project.version}
</Export-Package>
<Import-Package>
jakarta.servlet.*;version="[6.0,7.0)",
sun.misc.*;resolution:=optional,
${jakarta.annotation.osgi.version},
${cdi.osgi.version},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,33 @@
requires jakarta.cdi;
requires jakarta.inject;
requires jakarta.interceptor;
requires jakarta.servlet;
// requires jakarta.persistence;
requires jakarta.ws.rs;

requires java.logging;

requires weld.api;
requires weld.spi;
requires weld.core.impl;
requires weld.se.core;
requires weld.probe.core;
requires org.glassfish.grizzly.http.server;
requires weld.spi;

requires org.glassfish.jersey.core.common;
requires org.glassfish.jersey.core.client;
requires org.glassfish.jersey.core.server;
requires org.glassfish.jersey.container.servlet;

opens org.glassfish.jersey.inject.weld.internal.data;
opens org.glassfish.jersey.inject.weld.internal.bean;
opens org.glassfish.jersey.inject.weld.internal.inject;
opens org.glassfish.jersey.inject.weld.internal.managed;
opens org.glassfish.jersey.inject.weld.internal.scope;
opens org.glassfish.jersey.inject.weld.internal.type;
opens org.glassfish.jersey.inject.weld.spi;
opens org.glassfish.jersey.inject.weld.managed;

exports org.glassfish.jersey.inject.weld.internal.data;
exports org.glassfish.jersey.inject.weld.internal.bean;
exports org.glassfish.jersey.inject.weld.internal.inject;
exports org.glassfish.jersey.inject.weld.internal.managed;
exports org.glassfish.jersey.inject.weld.internal.scope;
exports org.glassfish.jersey.inject.weld.internal.type;
exports org.glassfish.jersey.inject.weld.spi;
exports org.glassfish.jersey.inject.weld.managed;

exports org.glassfish.jersey.inject.weld.internal.managed to
org.glassfish.jersey.core.common,
weld.core.impl;
exports org.glassfish.jersey.inject.weld.managed to org.glassfish.jersey.core.common;

opens org.glassfish.jersey.inject.weld.internal.managed to weld.core.impl;
opens org.glassfish.jersey.inject.weld.internal.scope to weld.core.impl;
opens org.glassfish.jersey.inject.weld.managed to weld.core.impl;
opens org.glassfish.jersey.inject.weld.internal.injector to weld.core.impl;

uses org.glassfish.jersey.innate.BootstrapPreinitialization;

provides jakarta.enterprise.inject.spi.Extension with
org.glassfish.jersey.inject.weld.internal.managed.BinderRegisterExtension;

provides org.glassfish.jersey.internal.inject.InjectionManagerFactory with
org.glassfish.jersey.inject.weld.managed.CdiInjectionManagerFactory;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025 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
Expand Down Expand Up @@ -41,7 +41,7 @@
import org.glassfish.jersey.internal.inject.PerLookup;
import org.glassfish.jersey.internal.inject.PerThread;

import org.jboss.weld.environment.se.contexts.ThreadScoped;
//import org.jboss.weld.environment.se.contexts.ThreadScoped;

/**
* Jersey-specific abstract class which implements {@link Bean} interface. Class particularly contains default implementations
Expand Down Expand Up @@ -88,7 +88,7 @@ protected static Class<? extends Annotation> transformScope(Class<? extends Anno
if (scope == PerLookup.class) {
return Dependent.class;
} else if (scope == PerThread.class) {
return ThreadScoped.class;
return RequestScoped.class; // ThreadScoped.class;
} else if (scope == org.glassfish.jersey.process.internal.RequestScoped.class) {
return RequestScoped.class;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025 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
Expand All @@ -19,8 +19,10 @@
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.List;
import java.util.logging.Logger;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.spi.DeploymentException;
import jakarta.ws.rs.WebApplicationException;

import jakarta.enterprise.context.spi.CreationalContext;
Expand All @@ -32,9 +34,9 @@

import org.glassfish.jersey.inject.weld.internal.bean.BeanHelper;
import org.glassfish.jersey.inject.weld.internal.bean.JerseyBean;
import org.glassfish.jersey.inject.weld.internal.l10n.LocalizationMessages;
import org.glassfish.jersey.inject.weld.managed.CdiInjectionManagerFactory;
import org.glassfish.jersey.internal.inject.InjectionManager;
import org.glassfish.jersey.internal.inject.InjectionManagerFactory;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.collection.LazyValue;
import org.glassfish.jersey.internal.util.collection.Value;
Expand All @@ -56,7 +58,6 @@
import org.jboss.weld.injection.producer.SubclassDecoratorApplyingInstantiator;
import org.jboss.weld.injection.producer.SubclassedComponentInstantiator;
import org.jboss.weld.interceptor.spi.model.InterceptionModel;
import org.jboss.weld.logging.BeanLogger;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.reflection.Formats;

Expand All @@ -70,6 +71,8 @@
*/
public class JerseyInjectionTarget<T> extends BasicInjectionTarget<T> {

private static final Logger LOGGER = Logger.getLogger(JerseyInjectionTarget.class.getName());

private final Bean<T> bean;
private final Class<T> clazz;
private final LazyValue<JerseyInstanceInjector<T>> injector;
Expand All @@ -78,6 +81,7 @@ public class JerseyInjectionTarget<T> extends BasicInjectionTarget<T> {
private BasicInjectionTarget delegate; // for managed beans the initializeAfterBeanDiscovery is called for it
private final Instantiator<T> instantiator;


/**
* Creates a new injection target which is able to delegate an injection to {@code delegate injection target} and inject
* the fields that are Jersey-specific. The resolvers must be set later on. CDI will select its own constructor.
Expand Down Expand Up @@ -156,8 +160,7 @@ public void inject(T instance, CreationalContext<T> ctx) {
} catch (WebApplicationException wae) {
throw wae;
} catch (Throwable cause) {
throw new InjectionException(
"Exception occurred during Jersey/JAX-RS annotations processing in the class: " + clazz, cause);
throw injectionException(LocalizationMessages.IT_PROCESSING_ANNOTATION_EXCEPTION(clazz.getName()), cause);
}

/*
Expand Down Expand Up @@ -194,7 +197,7 @@ public void initializeAfterBeanDiscovery(EnhancedAnnotatedType<T> annotatedType)

if (hasNonConstructorInterceptors || hasDecorators) {
if (!(getInstantiator() instanceof DefaultInstantiator<?>)) {
throw new IllegalStateException("Unexpected instantiator " + getInstantiator());
throw illegalStateException(LocalizationMessages.IT_UNEXPECTED_INSTANTIATOR(getInstantiator()));
}

/*
Expand Down Expand Up @@ -232,16 +235,16 @@ private void checkNoArgsConstructor(EnhancedAnnotatedType<T> type) {
}
EnhancedAnnotatedConstructor<T> constructor = type.getNoArgsEnhancedConstructor();
if (constructor == null) {
throw BeanLogger.LOG.decoratedHasNoNoargsConstructor(this);
throw deploymentException(LocalizationMessages.IT_DECORATED_HAS_NO_NOARGS_CONSTRUCTOR(type));
} else if (constructor.isPrivate()) {
throw BeanLogger.LOG
.decoratedNoargsConstructorIsPrivate(this, Formats.formatAsStackTraceElement(constructor.getJavaMember()));
String stackTraceElement = Formats.formatAsStackTraceElement(constructor.getJavaMember());
throw deploymentException(LocalizationMessages.IT_DECORATED_NOARGS_CONSTRUCTOR_PRIVATE(type, stackTraceElement));
}
}

private void checkDecoratedMethods(EnhancedAnnotatedType<T> type, List<Decorator<?>> decorators) {
if (type.isFinal()) {
throw BeanLogger.LOG.finalBeanClassWithDecoratorsNotAllowed(this);
throw deploymentException(LocalizationMessages.IT_FINAL_BEAN_CLASS_WITH_DECORATORS_NOT_ALLOWED(type));
}
checkNoArgsConstructor(type);
for (Decorator<?> decorator : decorators) {
Expand All @@ -253,13 +256,13 @@ private void checkDecoratedMethods(EnhancedAnnotatedType<T> type, List<Decorator
} else if (decorator instanceof CustomDecoratorWrapper<?>) {
decoratorClass = ((CustomDecoratorWrapper<?>) decorator).getEnhancedAnnotated();
} else {
throw BeanLogger.LOG.nonContainerDecorator(decorator);
throw illegalStateException(LocalizationMessages.IT_NON_CONTAINER_DECORATOR(decorator));
}

for (EnhancedAnnotatedMethod<?, ?> decoratorMethod : decoratorClass.getEnhancedMethods()) {
EnhancedAnnotatedMethod<?, ?> method = type.getEnhancedMethod(decoratorMethod.getSignature());
if (method != null && !method.isStatic() && !method.isPrivate() && method.isFinal()) {
throw BeanLogger.LOG.finalBeanClassWithInterceptorsNotAllowed(this);
throw deploymentException(LocalizationMessages.IT_FINAL_BEAN_CLASS_WITH_INTERCEPTORS_NOT_ALLOWED(type));
}
}
}
Expand Down Expand Up @@ -292,6 +295,21 @@ private boolean isInterceptionCandidate() {
return !isInterceptor() && !isDecorator() && !Modifier.isAbstract(getType().getJavaClass().getModifiers());
}

private static IllegalStateException illegalStateException(String message) {
LOGGER.warning(message);
return new IllegalStateException(message);
}

private static DeploymentException deploymentException(String message) {
LOGGER.warning(message);
return new DeploymentException(message);
}

private static InjectionException injectionException(String message, Throwable cause) {
LOGGER.warning(message);
return new InjectionException(message, cause);
}

@Override
public T produce(CreationalContext<T> ctx) {
T instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025 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
Expand Down Expand Up @@ -33,6 +33,7 @@
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import jakarta.annotation.Priority;
Expand Down Expand Up @@ -105,7 +106,9 @@
* CDI extension that handles CDI bootstrap events and registers Jersey's internally used components and components registered
* using {@link Application}.
*/
class BinderRegisterExtension implements Extension {
public class BinderRegisterExtension implements Extension {

private static final Logger LOGGER = Logger.getLogger(BinderRegisterExtension.class.getName());

private final AtomicBoolean registrationDone = new AtomicBoolean(false);
private Supplier<BeanManager> beanManagerSupplier;
Expand Down Expand Up @@ -679,6 +682,7 @@ public <T> T createAndInitialize(Class<T> createMe) {
Constructor<T> constructor = createMe.getConstructor();
return constructor.newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
LOGGER.warning(e.getMessage());
return null;
}
}
Expand Down
Loading
Loading