-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jersey-3992 CDI Bean created (but fails) when interface has @path ann…
…otation Signed-off-by: Gaurav Gupta <gaurav.gupta.jc@gmail.com>
- Loading branch information
1 parent
6f425d9
commit 310db2c
Showing
10 changed files
with
386 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. | ||
Copyright (c) 2018 Payara Foundation 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 | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.glassfish.jersey.tests.integration</groupId> | ||
<artifactId>project</artifactId> | ||
<version>2.28-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>jersey-3992</artifactId> | ||
<packaging>war</packaging> | ||
<name>jersey-3992</name> | ||
|
||
<description>Jersey CDI Inheritance test web application</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.annotation</groupId> | ||
<artifactId>javax.annotation-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.enterprise</groupId> | ||
<artifactId>cdi-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-bundle</artifactId> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.ext.cdi</groupId> | ||
<artifactId>jersey-weld2-se</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>run-external-tests</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory> | ||
<jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<!-- External test container configuration is done via properties to allow overriding via command line. --> | ||
<external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory> | ||
<external.container.port>8080</external.container.port> | ||
<maven.test.skip>false</maven.test.skip> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
76 changes: 76 additions & 0 deletions
76
...n/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/MainApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2010, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.cdi.resources; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.logging.Logger; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
import javax.inject.Inject; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
/** | ||
* JAX-RS application to configure resources. | ||
* | ||
* @author Jonathan Benoit (jonathan.benoit at oracle.com) | ||
*/ | ||
@ApplicationPath("main") | ||
@ApplicationScoped | ||
public class MainApplication extends Application { | ||
|
||
static AtomicInteger postConstructCounter = new AtomicInteger(); | ||
|
||
@Inject BeanManager bm; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(MainApplication.class.getName()); | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
final Set<Class<?>> classes = new HashSet<Class<?>>(); | ||
classes.add(UserResource.class); | ||
classes.add(UserResourceImpl.class); | ||
return classes; | ||
} | ||
|
||
// JERSEY-2531: make sure this type gets managed by CDI | ||
@PostConstruct | ||
public void postConstruct() { | ||
LOGGER.info(String.format("%s: POST CONSTRUCT.", this.getClass().getName())); | ||
postConstructCounter.incrementAndGet(); | ||
if (bm == null) { | ||
throw new IllegalStateException("BeanManager should have been injected into a CDI managed bean."); | ||
} | ||
if (postConstructCounter.intValue() > 1) { | ||
throw new IllegalStateException("postConstruct should have been invoked only once on app scoped bean."); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy() { | ||
LOGGER.info(String.format("%s: PRE DESTROY.", this.getClass().getName())); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...tion/jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2018 Payara Foundation 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.cdi.resources; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
/** | ||
* | ||
* @author Gaurav Gupta (gaurav.gupta@payara.fish) | ||
*/ | ||
public interface UserResource { | ||
|
||
/** | ||
* Gets the user count | ||
* | ||
* @return user count. | ||
*/ | ||
@GET | ||
@Path("/count") | ||
public int getCount(); | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
.../jersey-3992/src/main/java/org/glassfish/jersey/tests/cdi/resources/UserResourceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2018 Payara Foundation 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.cdi.resources; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
/** | ||
* | ||
* @author Gaurav Gupta (gaurav.gupta@payara.fish) | ||
*/ | ||
@Path("user") | ||
public class UserResourceImpl implements UserResource { | ||
|
||
/** | ||
* Gets the user count | ||
* | ||
* @return user count. | ||
*/ | ||
@GET | ||
@Path("/count") | ||
@Override | ||
public int getCount() { | ||
return 0; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/integration/jersey-3992/src/main/resources/META-INF/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2018 Payara Foundation 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 | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
|
||
<beans | ||
xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee | ||
http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" | ||
bean-discovery-mode="annotated"> | ||
</beans> |
64 changes: 64 additions & 0 deletions
64
...tegration/jersey-3992/src/test/java/org/glassfish/jersey/tests/cdi/resources/CdiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2013, 2017 Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018 Payara Foundation 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 | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.cdi.resources; | ||
|
||
import java.net.URI; | ||
|
||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.UriBuilder; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.jboss.weld.environment.se.Weld; | ||
|
||
/** | ||
* Test for CDI web application resources. | ||
* Run with: | ||
* <pre> | ||
* mvn clean package | ||
* $AS_HOME/bin/asadmin deploy target/cdi-test-webapp | ||
* mvn -DskipTests=false test</pre> | ||
* | ||
* @author Jakub Podlesak (jakub.podlesak at oracle.com) | ||
*/ | ||
public class CdiTest extends JerseyTest { | ||
|
||
Weld weld; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
weld = new Weld(); | ||
weld.initialize(); | ||
super.setUp(); | ||
} | ||
|
||
@Override | ||
public void tearDown() throws Exception { | ||
weld.shutdown(); | ||
super.tearDown(); | ||
} | ||
|
||
@Override | ||
protected Application configure() { | ||
return new MainApplication(); | ||
} | ||
|
||
@Override | ||
protected URI getBaseUri() { | ||
return UriBuilder.fromUri(super.getBaseUri()).path("cdi-test-webapp/main").build(); | ||
} | ||
} | ||
|
Oops, something went wrong.