Skip to content

Commit

Permalink
[WFLY-16545] Register the @Provider, @path and @ApplicationPath annot…
Browse files Browse the repository at this point in the history
…ations as bean defining annotations.

https://issues.redhat.com/browse/WFLY-16545
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Jul 11, 2022
1 parent 67bf29c commit 08e6fec
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 22 deletions.
Expand Up @@ -31,7 +31,7 @@
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -52,7 +52,7 @@ public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class,"jaxrsapp.war");
war.addPackage(HttpRequest.class.getPackage());
war.addClasses(CDIApplicationPathIntegrationTestCase.class, CDIBean.class, CDIPathApplication.class, CDIResource.class);
war.add(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "WEB-INF/beans.xml");
war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
return war;
}

Expand Down
Expand Up @@ -21,9 +21,12 @@
*/
package org.jboss.as.test.integration.jaxrs.integration.cdi;

import javax.enterprise.context.ApplicationScoped;

/**
* @author Stuart Douglas
*/
@ApplicationScoped
public class CDIBean {

public String message() {
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
Expand All @@ -58,7 +58,7 @@ public static Archive<?> deploy() {

WebArchive war = ShrinkWrap.create(WebArchive.class,"jaxrsnoap.war");
war.addPackage(HttpRequest.class.getPackage());
war.add(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "WEB-INF/beans.xml");
war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
war.addClasses(CDIResourceInjectionEarTestCase.class, CDIResource.class, CDIBean.class);
war.addAsWebInfResource(WebXml.get("<servlet-mapping>\n" +
" <servlet-name>javax.ws.rs.core.Application</servlet-name>\n" +
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -52,7 +52,7 @@ public class CDIResourceInjectionTestCase {
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class,"jaxrsnoap.war");
war.addPackage(HttpRequest.class.getPackage());
war.add(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "WEB-INF/beans.xml");
war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
war.addClasses(CDIResourceInjectionTestCase.class, CDIResource.class, CDIBean.class);
war.addAsWebInfResource(WebXml.get("<servlet-mapping>\n" +
" <servlet-name>javax.ws.rs.core.Application</servlet-name>\n" +
Expand Down
@@ -0,0 +1,103 @@
/*
* Copyright 2022 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.as.test.integration.jaxrs.integration.cdi;

import java.net.URISyntaxException;
import java.net.URL;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class CdiInjectionTestCase {

@Deployment(testable = false)
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, CdiInjectionTestCase.class.getSimpleName() + ".war")
.add(new StringAsset("<beans bean-discovery-mode=\"annotated\"></beans>"), "WEB-INF/beans.xml")
.addClasses(CDIApplication.class, CDIProvider.class, CDIResource.class, CDIBean.class, InjectionResource.class);
}


private static Client CLIENT;

@ArquillianResource
private URL url;

@BeforeClass
public static void createClient() {
CLIENT = ClientBuilder.newClient();
}

@AfterClass
public static void closeClient() {
if (CLIENT != null) {
CLIENT.close();
}
}

@Test
public void checkApplication() throws Exception {
checkResponse("app", CDIApplication.class);
}

@Test
public void checkProvider() throws Exception {
checkResponse("provider", CDIProvider.class);
}

@Test
public void checkResource() throws Exception {
checkResponse("resource", CDIResource.class);
}

private void checkResponse(final String path, final Class<?> expectedType) throws Exception {
try (
Response response = CLIENT.target(createUri(path))
.request()
.get()
) {
final String text = response.readEntity(String.class);
Assert.assertEquals(text, Response.Status.OK, response.getStatusInfo());
Assert.assertTrue(String.format("Expected type %s, but found %s", expectedType.getName(), text), text.startsWith(expectedType.getName()));
}
}

private UriBuilder createUri(final String path) throws URISyntaxException {
return UriBuilder.fromUri(url.toURI())
.path("rest/inject/" + path);
}
}
@@ -0,0 +1,67 @@
/*
* Copyright 2022 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jboss.as.test.integration.jaxrs.integration.cdi;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Path("/inject")
@Produces(MediaType.TEXT_PLAIN)
public class InjectionResource {

@Inject
private Application app;
@Inject
private CDIProvider provider;
@Inject
private CDIResource resource;

@GET
@Path("/app")
public Response app() {
if (app == null) {
return Response.serverError().entity("Application was null").build();
}
return Response.ok(app.getClass().getName()).build();
}

@GET
@Path("/provider")
public Response provider() {
if (provider == null) {
return Response.serverError().entity("Provider was null").build();
}
return Response.ok(provider.getClass().getName()).build();
}

@GET
@Path("/resource")
public Response resource() {
if (resource == null) {
return Response.serverError().entity("Resource was null").build();
}
return Response.ok(resource.getClass().getName()).build();
}
}
Expand Up @@ -35,7 +35,7 @@
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -50,7 +50,7 @@ public class JaxrsComponentBeanDefinitionTestCase {
@Deployment
public static Archive<?> deploy() {
WebArchive war = ShrinkWrap.create(WebArchive.class);
war.add(new StringAsset("<beans bean-discovery-mode=\"all\"></beans>"), "WEB-INF/beans.xml");
war.add(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
war.addClasses(JaxrsComponentBeanDefinitionTestCase.class, CDIBean.class, CDIResource.class, CDIApplication.class, CDIProvider.class);
return war;
}
Expand Down
Expand Up @@ -21,6 +21,8 @@
*/
package org.jboss.as.test.integration.jaxrs.validator;

import static org.jboss.as.test.shared.PermissionUtils.createPermissionsXmlAsset;

import java.net.URL;

import javax.ws.rs.ApplicationPath;
Expand All @@ -31,6 +33,7 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.hibernate.validator.HibernateValidatorPermission;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
Expand Down Expand Up @@ -67,7 +70,9 @@ public static Archive<?> deploy() {
ValidatorResource.class,
AnotherValidatorResource.class,
YetAnotherValidatorResource.class
);
).addAsManifestResource(createPermissionsXmlAsset(
HibernateValidatorPermission.ACCESS_PRIVATE_MEMBERS
), "permissions.xml");
}

@ArquillianResource
Expand Down
Expand Up @@ -41,15 +41,14 @@
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.test.integration.microprofile.openapi.service.TestApplication;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestEjb;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestBean;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestRequest;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestResource;
import org.wildfly.test.integration.microprofile.openapi.service.multimodule.TestResponse;
Expand All @@ -73,16 +72,13 @@ public static Archive<?> deploy() throws Exception {
.addAsResource(TestResource.class.getResource("beans.xml"), "WEB-INF/beans.xml")
.addClasses(TestApplication.class, TestResource.class);
JavaArchive core = ShrinkWrap.create(JavaArchive.class, "core.jar")
.addClasses(TestEjb.class, TestRequest.class)
.addAsResource(new StringAsset(
"<ejb-jar version=\"3.0\" "
+ "metadata-complete=\"true\"></ejb-jar>"),
"META-INF/ejb-jar.xml");
.addClasses(TestBean.class, TestRequest.class)
.addAsResource(TestResource.class.getResource("beans.xml"), "WEB-INF/beans.xml");
JavaArchive common = ShrinkWrap.create(JavaArchive.class, "common.jar").addClass(TestResponse.class);
return ShrinkWrap.create(EnterpriseArchive.class, PARENT_DEPLOYMENT_NAME)
.addAsModules(jaxrs, core)
.addAsManifestResource(
TestEjb.class.getResource("application.xml"),
TestBean.class.getResource("application.xml"),
"application.xml")
.addAsLibraries(common);
}
Expand Down
Expand Up @@ -16,13 +16,13 @@

package org.wildfly.test.integration.microprofile.openapi.service.multimodule;

import javax.ejb.Stateless;
import javax.enterprise.context.ApplicationScoped;

/**
* @author Joachim Grimm
*/
@Stateless
public class TestEjb {
@ApplicationScoped
public class TestBean {

public TestResponse hello(TestRequest request) {
TestResponse testResponse = new TestResponse();
Expand Down
Expand Up @@ -43,7 +43,7 @@
public class TestResource {

@Inject
private TestEjb testEjb;
private TestBean testEjb;

@POST
@Operation(summary = "Test the indexing of multi module deployments")
Expand Down
Expand Up @@ -49,7 +49,7 @@
import org.jboss.jbossts.star.util.TxSupport;

@Path(WorkRestATResource.PATH_SEGMENT)
public final class WorkRestATResource {
public class WorkRestATResource {

public static final String PATH_SEGMENT = "txresource";

Expand Down
Expand Up @@ -34,6 +34,10 @@ public class BeanDefiningAnnotationProcessor implements DeploymentUnitProcessor

private static final DotName VIEW_SCOPED_NAME = DotName.createSimple("javax.faces.view.ViewScoped");
private static final DotName FLOW_SCOPED_NAME = DotName.createSimple("javax.faces.flow.FlowScoped");
// Jakarta REST annotations
private static final DotName PROVIDER = DotName.createSimple("javax.ws.rs.ext.Provider");
private static final DotName APPLICATION_PATH = DotName.createSimple("javax.ws.rs.ApplicationPath");
private static final DotName PATH = DotName.createSimple("javax.ws.rs.Path");

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
Expand All @@ -52,6 +56,15 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
addAnnotation(deploymentUnit, new AnnotationType(TransactionScoped.class));
addAnnotation(deploymentUnit, new AnnotationType(VIEW_SCOPED_NAME, true));
addAnnotation(deploymentUnit, new AnnotationType(FLOW_SCOPED_NAME, true));
// Per section 11.2.3 of the Jakarta REST 3.1 specification:
// In a product that supports CDI, implementations MUST support the use of CDI-style Beans as root resource
// classes, providers and Application subclasses. Providers and Application subclasses MUST be singletons or
// use application scope.
// Currently, these are not specified as @Stereotype annotations with a default scope. In a later spec this may
// happen, in which case these can be removed.
addAnnotation(deploymentUnit, new AnnotationType(PROVIDER, false));
addAnnotation(deploymentUnit, new AnnotationType(APPLICATION_PATH, false));
addAnnotation(deploymentUnit, new AnnotationType(PATH, false));

for (AnnotationType annotationType : CdiAnnotations.BEAN_DEFINING_META_ANNOTATIONS) {
addAnnotations(deploymentUnit, getAnnotationsAnnotatedWith(index, annotationType.getName()));
Expand Down

0 comments on commit 08e6fec

Please sign in to comment.