-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can configure @ExposedApplication for a package
Reading https://jersey.java.net/documentation/latest/deployment.html we found that one can deploy an application without an Application subclass. In this case we expect @ExposedApplication (with a servletName) to be set on a package in package-info.java.
- Loading branch information
Showing
12 changed files
with
231 additions
and
5 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
jax-rs-linker-integration-tests/no-configuration-webapp/pom.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,72 @@ | ||
<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>fr.vidal.oss</groupId> | ||
<artifactId>jax-rs-linker-integration-tests</artifactId> | ||
<version>0.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>no-configuration-webapp</artifactId> | ||
<packaging>war</packaging> | ||
|
||
<name>JAX RS Linker: webapp without JAXRS Configuration</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.sonatype.plugins</groupId> | ||
<artifactId>port-allocator-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>jax-rs-linker</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-servlet</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okhttp</groupId> | ||
<artifactId>okhttp</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
...ts/no-configuration-webapp/src/main/java/fr/vidal/oss/jax_rs_linker/it/BrandResource.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,23 @@ | ||
package fr.vidal.oss.jax_rs_linker.it; | ||
|
||
|
||
import fr.vidal.oss.jax_rs_linker.Linkers; | ||
import fr.vidal.oss.jax_rs_linker.api.Self; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
@Path("/brand") | ||
public class BrandResource { | ||
|
||
@Self | ||
@Path("/{id}") | ||
@GET | ||
public String getById(@PathParam("id") int id) { | ||
return Linkers.brandResourceLinker() | ||
.self() | ||
.replace(BrandResourcePathParameters.ID, String.valueOf(id)) | ||
.value(); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...sts/no-configuration-webapp/src/main/java/fr/vidal/oss/jax_rs_linker/it/package-info.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,2 @@ | ||
@fr.vidal.oss.jax_rs_linker.api.ExposedApplication(servletName = "javax.ws.rs.core.Application") | ||
package fr.vidal.oss.jax_rs_linker.it; |
14 changes: 14 additions & 0 deletions
14
jax-rs-linker-integration-tests/no-configuration-webapp/src/main/webapp/WEB-INF/web.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,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app xmlns="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
version="3.1" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> | ||
|
||
<servlet> | ||
<servlet-name>javax.ws.rs.core.Application</servlet-name> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>javax.ws.rs.core.Application</servlet-name> | ||
<url-pattern>/rest/*</url-pattern> | ||
</servlet-mapping> | ||
</web-app> |
35 changes: 35 additions & 0 deletions
35
...on-tests/no-configuration-webapp/src/test/java/fr/vidal/oss/jax_rs_linker/it/BrandIT.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,35 @@ | ||
package fr.vidal.oss.jax_rs_linker.it; | ||
|
||
import com.squareup.okhttp.OkHttpClient; | ||
import com.squareup.okhttp.Request; | ||
import com.squareup.okhttp.Response; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class BrandIT { | ||
|
||
@Test | ||
public void self_link_with_context_path_and_servlet_name() throws Exception { | ||
Response response = request("brand/23"); | ||
|
||
assertThat(response.body().string()) | ||
.isEqualTo("/it-tests/rest/brand/23"); | ||
} | ||
|
||
private static Response request(String resource) throws IOException { | ||
OkHttpClient client = new OkHttpClient(); | ||
|
||
Request request = new Request.Builder() | ||
.url("http://localhost:" + port() + "/it-tests/rest/" + resource) | ||
.build(); | ||
|
||
return client.newCall(request).execute(); | ||
} | ||
|
||
private static String port() { | ||
return System.getProperty("jetty.port", "8080"); | ||
} | ||
} |
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
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
32 changes: 32 additions & 0 deletions
32
jax-rs-linker/src/test/resources/linkers/LinkersPackageInfo.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,32 @@ | ||
|
||
package fr.vidal.oss.jax_rs_linker; | ||
|
||
import fr.vidal.oss.jax_rs_linker.servlet.ContextPaths; | ||
import javax.annotation.Generated; | ||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import javax.servlet.annotation.WebListener; | ||
import fr.vidal.oss.jax_rs_linker.parser.BrandResourceLinker; | ||
|
||
@WebListener | ||
@Generated("fr.vidal.oss.jax_rs_linker.LinkerAnnotationProcessor") | ||
public class Linkers | ||
implements ServletContextListener { | ||
|
||
private static String contextPath = ""; | ||
|
||
private static String applicationName = "my-super-application"; | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent sce) { | ||
contextPath = ContextPaths.contextPath(sce.getServletContext(), applicationName); | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent sce) { | ||
} | ||
|
||
public static BrandResourceLinker brandResourceLinker() { | ||
return new BrandResourceLinker(contextPath); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
jax-rs-linker/src/test/resources/mispackage/package-info.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,2 @@ | ||
@fr.vidal.oss.jax_rs_linker.api.ExposedApplication | ||
package mispackage; |
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,2 @@ | ||
@fr.vidal.oss.jax_rs_linker.api.ExposedApplication(servletName = "my-super-application") | ||
package fr.vidal.oss.jax_rs_linker; |
1 comment
on commit 520ecc3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nickel sinon.
va quand même falloir trouver un moyen de dégraisser LinkerAnnotationProcessor :/
Il vaut mieux utiliser un visiteur du type http://docs.oracle.com/javase/7/docs/api/javax/lang/model/util/ElementKindVisitor7.html
On les a peu utilisé jusqu'ici.