Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CDI annotations to the annotations that need them. Updated the si… #1221

Open
wants to merge 1 commit into
base: release-5.0
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/ApplicationPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Stereotype;

/**
* Identifies the application path that serves as the base URI for all resource URIs provided by
* {@link jakarta.ws.rs.Path}. May only be applied to a subclass of {@link jakarta.ws.rs.core.Application}.
Expand All @@ -40,6 +43,8 @@
@Documented
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Stereotype
@ApplicationScoped
public @interface ApplicationPath {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/BeanParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* The annotation that may be used to inject custom JAX-RS "parameter aggregator" value object into a resource class
* field, property or resource method parameter.
Expand Down Expand Up @@ -68,5 +70,6 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface BeanParam {
}
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/CookieParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value of a HTTP cookie to a resource method parameter, resource class field, or resource class bean
* property. A default value can be specified using the {@link DefaultValue} annotation.
Expand Down Expand Up @@ -55,6 +57,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface CookieParam {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/FormParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value(s) of a form parameter contained within a request entity body to a resource method parameter. Values
* are URL decoded unless this is disabled using the {@link Encoded} annotation. A default value can be specified using
Expand Down Expand Up @@ -66,6 +68,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface FormParam {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/HeaderParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value(s) of a HTTP header to a resource method parameter, resource class field, or resource class bean
* property. A default value can be specified using the {@link DefaultValue} annotation.
Expand Down Expand Up @@ -58,6 +60,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface HeaderParam {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/MatrixParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value(s) of a URI matrix parameter to a resource method parameter, resource class field, or resource class
* bean property. Values are URL decoded unless this is disabled using the {@link Encoded} annotation. A default value
Expand Down Expand Up @@ -66,6 +68,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface MatrixParam {

/**
Expand Down
5 changes: 5 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Stereotype;

/**
* Identifies the URI path that a resource class or class method will serve requests for.
*
Expand Down Expand Up @@ -65,6 +68,8 @@
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Stereotype
@RequestScoped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it possibly clash with @singleton?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I don't know how that works since @Singleton is not part of CDI. However, resources should be @RequestScoped per the specification documentation. I don't see anything in the CDI specification that clears this up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDI says @Singleton is the pseudoscope. Which I am not sure how it is handled by Weld. Would need to do some testing.

However, the REST spec supports the @jakarta.inject.Singleton resource classes, for instance in Section 9.4.

It also mandates:

In a product that supports EJBs, an implementation MUST support the use of stateless and singleton session beans as root resource classes

Though it is jakarta.ejb.Singleton, I still feel some potential clash with @RequestScoped.

Copy link
Contributor

@jansupol jansupol Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what Weld throws (3.1 @Path - Not modified, yet) :

org.jboss.weld.exceptions.DefinitionException: WELD-000046: At most one scope may be specified on [EnhancedAnnotatedTypeImpl] public @RequestScoped @Singleton @Path class AnnotatedTestResource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only happens if you add both @RequestScoped and @Singleton to the resource though. If you only add @Singleton and @Path it will work. A stereotypes scope can be overridden as it's just the default scope. From the end of https://jakarta.ee/specifications/cdi/4.0/jakarta-cdi-spec-4.0#stereotype_default_scope

For example, the following stereotype might be used to identify action classes in a web application:

@RequestScoped
@Stereotype
@Target(TYPE)
@Retention(RUNTIME)
public @interface Action {}

Then actions would have scope @RequestScoped unless the scope is explicitly specified by the bean.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I was not aware of it, that resolves my concerns. Keeping unresolved for others should they have the same doubts.

public @interface Path {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/PathParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value of a URI template parameter or a path segment containing the template parameter to a resource method
* parameter, resource class field, or resource class bean property. The value is URL decoded unless this is disabled
Expand Down Expand Up @@ -67,6 +69,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface PathParam {

/**
Expand Down
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/QueryParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.inject.Qualifier;

/**
* Binds the value(s) of a HTTP query parameter to a resource method parameter, resource class field, or resource class
* bean property. Values are URL decoded unless this is disabled using the {@link Encoded} annotation. A default value
Expand Down Expand Up @@ -60,6 +62,7 @@
@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Qualifier
public @interface QueryParam {

/**
Expand Down
5 changes: 5 additions & 0 deletions jaxrs-api/src/main/java/jakarta/ws/rs/ext/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Stereotype;

/**
* Marks an implementation of an extension interface that should be discoverable by JAX-RS runtime during a provider
* scanning phase.
Expand All @@ -33,5 +36,7 @@
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Stereotype
@ApplicationScoped
public @interface Provider {
}
3 changes: 3 additions & 0 deletions jaxrs-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
module jakarta.ws.rs {

requires static jakarta.xml.bind;
// These two modules are not required on the client side
requires static jakarta.cdi;
requires static jakarta.inject;

requires java.logging;

Expand Down
32 changes: 21 additions & 11 deletions jaxrs-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${project.version}</version>
<!-- Used so the TCK version can be changed without needing to change the API version -->
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
jansupol marked this conversation as resolved.
Show resolved Hide resolved
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -97,12 +107,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.netbeans.tools</groupId>
<artifactId>sigtest-maven-plugin</artifactId>
<version>1.4</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -147,9 +151,9 @@
<build>
<plugins>
<plugin>
<groupId>org.netbeans.tools</groupId>
<groupId>jakarta.tck</groupId>
<artifactId>sigtest-maven-plugin</artifactId>
<version>1.4</version>
<version>2.1</version>
<executions>
<execution>
<goals>
Expand All @@ -158,10 +162,16 @@
</execution>
</executions>
<configuration>
<FileName>${project.build.directory}/jakarta.ws.rs.sig_${project.parent.version}</FileName>
<packages>
jakarta.ws.rs,jakarta.ws.rs.client,jakarta.ws.rs.core,jakarta.ws.rs.container,jakarta.ws.rs.ext,jakarta.ws.rs.sse
jakarta.ws.rs,
jakarta.ws.rs.client,
jakarta.ws.rs.core,
jakarta.ws.rs.container,
jakarta.ws.rs.ext,
jakarta.ws.rs.sse
</packages>
<attach>false</attach>
<sigfile>${project.build.directory}/jakarta.ws.rs.sig_${project.parent.version}</sigfile>
</configuration>
</plugin>
</plugins>
Expand Down
Loading