diff --git a/docs/src/main/asciidoc/application-configuration-guide.adoc b/docs/src/main/asciidoc/application-configuration-guide.adoc index dedcb670f47a6..fcc9688e543ec 100644 --- a/docs/src/main/asciidoc/application-configuration-guide.adoc +++ b/docs/src/main/asciidoc/application-configuration-guide.adoc @@ -123,7 +123,7 @@ public class GreetingResourceTest { @Test public void testHelloEndpoint() { given() - .when().get("/app/greeting") + .when().get("/greeting") .then() .statusCode(200) .body(is("hello shamrock!")); // Modified line @@ -135,7 +135,7 @@ public class GreetingResourceTest { == Package and run the application Run the application with: `mvn compile shamrock:dev`. -Open your browser to http://localhost:8080/app/greeting. +Open your browser to http://localhost:8080/greeting. Changing the configuration file is immediately reflected. You can add the `greeting.suffix`, remove the other properties, change the values, etc. diff --git a/docs/src/main/asciidoc/getting-started-guide.adoc b/docs/src/main/asciidoc/getting-started-guide.adoc index 76f0eca734f69..64a9b54069cfb 100644 --- a/docs/src/main/asciidoc/getting-started-guide.adoc +++ b/docs/src/main/asciidoc/getting-started-guide.adoc @@ -134,23 +134,6 @@ As we are going to create a JAX-RS endpoint, you also need to add the following ArC is a CDI-based dependency injection solution - see also link:cdi-reference.html[Contexts and Dependency Injection]. ==== -== Creating the Application class - -It's now time to create the `Application` class, create the `src/main/java/org/acme/quickstart/MyApplication.java` file with the following content: - -[source,java] ----- -package org.acme.quickstart; - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -@ApplicationPath("/app") -public class MyApplication extends Application { - -} ----- - === Creating the JAX-RS resource Create the `src/main/java/org/acme/quickstart/GreetingResource.java` file with the following content: @@ -175,6 +158,13 @@ public class GreetingResource { } ---- +[TIP] +.Differences with vanilla Jax-RS +==== +With Shamrock no need to create an `Application` class. It's supported but not required. In addition, only one instance +of the resource is created and not one per request. You can configure this using the different `XScoped` annotations. +==== + == Running the application Now we are ready to run our application. @@ -207,7 +197,7 @@ INFO [o.j.shamrock] (main) Shamrock started in 697.982ms Once started, you can request the provided endpoint: ``` -$ curl http://localhost:8080/app/hello +$ curl http://localhost:8080/hello hello ``` @@ -268,7 +258,7 @@ public class GreetingResource { } ---- -Start the application and check that http://localhost:8080/app/hello/greeting/shamrock returns `hello shamrock`. +Start the application and check that http://localhost:8080/hello/greeting/shamrock returns `hello shamrock`. diff --git a/docs/src/main/asciidoc/ide-configuration.adoc b/docs/src/main/asciidoc/ide-configuration.adoc index 77a71c50a14be..58c25da781be0 100644 --- a/docs/src/main/asciidoc/ide-configuration.adoc +++ b/docs/src/main/asciidoc/ide-configuration.adoc @@ -47,10 +47,6 @@ The following table lists the attributes you can pass to the `create` command: | `/hello` | The resource path, only relevant if `className` is set. -| `root` -| `/app` -| The application root prefix, only relevant if `className` is set. - | `extensions` | _[]_ | The list of extensions to add to the project (comma-separated) @@ -58,7 +54,7 @@ The following table lists the attributes you can pass to the `create` command: |=== If you decide to generate a REST resource (using the `className` attribute), the endpoint is exposed at: `http://localhost:8080/$root/$path`. -If you use the default `root` and `path`, the URL is: http://localhost:8080/app/hello. +If you use the default `root` and `path`, the URL is: http://localhost:8080/hello. The project is either generated in the current directory or in a directory named after the passed artifactId. If the current directory is empty, the project is generated in-place. diff --git a/docs/src/main/asciidoc/kubernetes-guide.adoc b/docs/src/main/asciidoc/kubernetes-guide.adoc index 109a10ea06794..bf6c907a36d30 100644 --- a/docs/src/main/asciidoc/kubernetes-guide.adoc +++ b/docs/src/main/asciidoc/kubernetes-guide.adoc @@ -56,7 +56,7 @@ The application is now exposed as an internal service. If you are using `minikub [source, bash] ---- -curl $(minikube service shamrock-quickstart --url)/app/hello/greeting/shamrock +curl $(minikube service shamrock-quickstart --url)/hello/greeting/shamrock ---- == Deploying the application in OpenShift @@ -78,7 +78,7 @@ oc expose service shamrock-quickstart # Get the route URL export URL="http://$(oc get route | grep shamrock-quickstart | awk '{print $2}')" -curl $URL/app/hello/greeting/shamrock +curl $URL/hello/greeting/shamrock ---- Your application is accessible at the printed URL. diff --git a/docs/src/main/asciidoc/scheduled-guide.adoc b/docs/src/main/asciidoc/scheduled-guide.adoc index 616a0281624c7..1fc52175a4158 100644 --- a/docs/src/main/asciidoc/scheduled-guide.adoc +++ b/docs/src/main/asciidoc/scheduled-guide.adoc @@ -139,7 +139,7 @@ public class CountResourceTest { @Test public void testHelloEndpoint() { given() - .when().get("/app/count") + .when().get("/count") .then() .statusCode(200) .body(containsString("count")); // <1> @@ -152,8 +152,8 @@ public class CountResourceTest { == Package and run the application Run the application with: `mvn compile shamrock:dev`. -In another terminal, run `curl localhost:8080/app/count` to check the counter value. -After a few seconds, re-run `curl localhost:8080/app/count` to verify the counter has been incremented. +In another terminal, run `curl localhost:8080/count` to check the counter value. +After a few seconds, re-run `curl localhost:8080/count` to verify the counter has been incremented. As usual, the application can be packaged using `mvn clean package` and executed using the `-runner.jar` file. You can also generate the native executable. \ No newline at end of file diff --git a/maven/src/main/java/org/jboss/shamrock/maven/CreateProjectMojo.java b/maven/src/main/java/org/jboss/shamrock/maven/CreateProjectMojo.java index 326f53417e435..3f22bfbc4fe6a 100644 --- a/maven/src/main/java/org/jboss/shamrock/maven/CreateProjectMojo.java +++ b/maven/src/main/java/org/jboss/shamrock/maven/CreateProjectMojo.java @@ -82,9 +82,6 @@ public class CreateProjectMojo extends AbstractMojo { @Parameter(property = "className") private String className; - @Parameter(property = "root", defaultValue = "/app") - private String root; - @Parameter(property = "extensions") private List extensions; @@ -123,7 +120,7 @@ public void execute() throws MojoExecutionException { model = project.getOriginalModel().clone(); createDirectories(); - templates.generate(project, root, path, className, getLog()); + templates.generate(project, path, className, getLog()); Optional maybe = MojoUtils.hasPlugin(project, PLUGIN_KEY); if (maybe.isPresent()) { printUserInstructions(pomFile); @@ -258,14 +255,6 @@ private File createPomFileFromUserInputs() throws MojoExecutionException { } } - if (root == null) { - root = prompter.promptWithDefaultValue("Set the application root ", - "/app"); - if (!root.startsWith("/")) { - root = "/" + root; - } - } - if (path == null) { path = prompter.promptWithDefaultValue("Set the resource path ", "/hello"); @@ -298,7 +287,6 @@ private File createPomFileFromUserInputs() throws MojoExecutionException { context.put("docRoot", MojoUtils.get("doc-root")); context.put("className", className); - context.put("root", root); context.put("path", path); templates.createNewProjectPomFile(context, pomFile); diff --git a/maven/src/main/java/org/jboss/shamrock/maven/components/SetupTemplates.java b/maven/src/main/java/org/jboss/shamrock/maven/components/SetupTemplates.java index 3b4de1d79286c..8309012ce9fbf 100644 --- a/maven/src/main/java/org/jboss/shamrock/maven/components/SetupTemplates.java +++ b/maven/src/main/java/org/jboss/shamrock/maven/components/SetupTemplates.java @@ -61,7 +61,7 @@ public void createNewProjectPomFile(Map context, File pomFile) t } } - public void generate(MavenProject project, String rootPath, String path, String className, Log log) throws MojoExecutionException { + public void generate(MavenProject project, String path, String className, Log log) throws MojoExecutionException { if (Strings.isNullOrEmpty(className)) { return; } @@ -92,7 +92,6 @@ public void generate(MavenProject project, String rootPath, String path, String File testClassFile = new File(testRoot, className + "Test" + JAVA_EXTENSION); Map context = new HashMap<>(); context.put("classname", className); - context.put("root_prefix", rootPath); context.put("path", path); if (packageName != null) { context.put("packageName", packageName); @@ -113,16 +112,6 @@ public void generate(MavenProject project, String rootPath, String path, String } catch (Exception e) { throw new MojoExecutionException("Unable to generate test code", e); } - - // Generate application. - File appClassFile = new File(root, "ShamrockApplication.java"); - try { - Template temp = cfg.getTemplate("templates/application-template.ftl"); - Writer out = new FileWriter(appClassFile); - temp.process(context, out); - } catch (Exception e) { - throw new MojoExecutionException("Unable to generate Application class", e); - } } public void createIndexPage(Map context, File basedir, Log log) throws MojoExecutionException { diff --git a/maven/src/main/templates/templates/application-template.ftl b/maven/src/main/templates/templates/application-template.ftl deleted file mode 100644 index 09816500361e0..0000000000000 --- a/maven/src/main/templates/templates/application-template.ftl +++ /dev/null @@ -1,11 +0,0 @@ -<#if packageName??> -package ${packageName}; - - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -@ApplicationPath("${root_prefix}") -public class ShamrockApplication extends Application { - -} diff --git a/maven/src/main/templates/templates/test-resource-template.ftl b/maven/src/main/templates/templates/test-resource-template.ftl index d966c20d63d99..b747128eb072f 100644 --- a/maven/src/main/templates/templates/test-resource-template.ftl +++ b/maven/src/main/templates/templates/test-resource-template.ftl @@ -15,7 +15,7 @@ public class ${classname}Test { @Test public void testHelloEndpoint() { given() - .when().get("${root_prefix}${path}") + .when().get("${path}") .then() .statusCode(200) .body(is("hello")); diff --git a/maven/src/test/java/org/jboss/shamrock/maven/it/CreateProjectMojoIT.java b/maven/src/test/java/org/jboss/shamrock/maven/it/CreateProjectMojoIT.java index d9a4002cf1023..64ee01783392d 100644 --- a/maven/src/test/java/org/jboss/shamrock/maven/it/CreateProjectMojoIT.java +++ b/maven/src/test/java/org/jboss/shamrock/maven/it/CreateProjectMojoIT.java @@ -133,7 +133,7 @@ public void testProjectGenerationFromScratchWithResource() throws Exception { assertThat(new File(testDir, "pom.xml")).isFile(); assertThat(new File(testDir, "src/main/java")).isDirectory(); assertThat(new File(testDir, "src/main/java/org/acme/MyResource.java")).isFile(); - assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).isFile(); + assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).doesNotExist(); } @Test @@ -151,7 +151,7 @@ public void testProjectGenerationFromMinimalPomWithResource() throws Exception { .contains("shamrock.version"); assertThat(new File(testDir, "src/main/java")).isDirectory(); assertThat(new File(testDir, "src/main/java/org/acme/MyResource.java")).isFile(); - assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).isFile(); + assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).doesNotExist(); } @Test @@ -169,7 +169,7 @@ public void testProjectGenerationFromScratchWithExtensions() throws Exception { assertThat(new File(testDir, "pom.xml")).isFile(); assertThat(new File(testDir, "src/main/java")).isDirectory(); assertThat(new File(testDir, "src/main/java/org/acme/MyResource.java")).isFile(); - assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).isFile(); + assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).doesNotExist(); assertThat(FileUtils.readFileToString(new File(testDir, "pom.xml"), "UTF-8")) .contains("shamrock-jaxrs-deployment", "shamrock-metrics-deployment").doesNotContain("missing"); @@ -204,7 +204,7 @@ public void testProjectGenerationFromScratchWithCustomDependencies() throws Exce setup(properties); assertThat(new File(testDir, "pom.xml")).isFile(); assertThat(new File(testDir, "src/main/java/org/acme/MyResource.java")).isFile(); - assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).isFile(); + assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).doesNotExist(); assertThat(FileUtils.readFileToString(new File(testDir, "pom.xml"), "UTF-8")) .contains("commons-io"); @@ -238,7 +238,7 @@ public void testProjectGenerationFromMinimalPomWithDependencies() throws Excepti setup(properties); assertThat(new File(testDir, "pom.xml")).isFile(); assertThat(new File(testDir, "src/main/java/org/acme/MyResource.java")).isFile(); - assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).isFile(); + assertThat(new File(testDir, "src/main/java/org/acme/ShamrockApplication.java")).doesNotExist(); assertThat(FileUtils.readFileToString(new File(testDir, "pom.xml"), "UTF-8")) .contains("commons-io"); } @@ -251,7 +251,7 @@ public void cleanup() { } @Test - public void generateNewProjectAndRun() throws MavenInvocationException, FileNotFoundException, InterruptedException { + public void generateNewProjectAndRun() throws MavenInvocationException, FileNotFoundException { testDir = initEmptyProject("projects/project-generation-and-run"); // Scaffold the new project @@ -272,7 +272,7 @@ public void generateNewProjectAndRun() throws MavenInvocationException, FileNotF assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme") .containsIgnoringCase("1.0-SNAPSHOT"); - String greeting = getHttpResponse("/app/hello"); + String greeting = getHttpResponse("/hello"); assertThat(greeting).containsIgnoringCase("hello"); } diff --git a/maven/src/test/java/org/jboss/shamrock/maven/it/DevMojoIT.java b/maven/src/test/java/org/jboss/shamrock/maven/it/DevMojoIT.java index 3b6fe77fa81f5..9b7c1f22ac9ae 100644 --- a/maven/src/test/java/org/jboss/shamrock/maven/it/DevMojoIT.java +++ b/maven/src/test/java/org/jboss/shamrock/maven/it/DevMojoIT.java @@ -57,14 +57,14 @@ public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocatio // Wait until we get "uuid" await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello").contains(uuid)); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/hello").contains(uuid)); sleep(); filter(source, ImmutableMap.of(uuid, "carambar")); // Wait until we get "uuid" await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello").contains("carambar")); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/hello").contains("carambar")); } @Test @@ -95,7 +95,7 @@ public void testThatTheApplicationIsReloadedOnNewResource() throws MavenInvocati // Wait until we get "bar" await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/foo").contains("bar")); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/foo").contains("bar")); } @Test @@ -151,7 +151,7 @@ private void runAndCheck() throws FileNotFoundException, MavenInvocationExceptio assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme") .containsIgnoringCase("1.0-SNAPSHOT"); - String greeting = getHttpResponse("/app/hello"); + String greeting = getHttpResponse("/hello"); assertThat(greeting).containsIgnoringCase("hello"); } @@ -167,7 +167,7 @@ public void testThatTheApplicationIsReloadedOnConfigChange() throws MavenInvocat assertThat(resp).containsIgnoringCase("ready").containsIgnoringCase("application").containsIgnoringCase("org.acme") .containsIgnoringCase("1.0-SNAPSHOT"); - String greeting = getHttpResponse("/app/hello/greeting"); + String greeting = getHttpResponse("/hello/greeting"); assertThat(greeting).containsIgnoringCase("bonjour"); sleep(); @@ -180,7 +180,7 @@ public void testThatTheApplicationIsReloadedOnConfigChange() throws MavenInvocat await() .pollDelay(100, TimeUnit.MILLISECONDS) .atMost(1, TimeUnit.MINUTES) - .until(() -> getHttpResponse("/app/hello/greeting").contains(uuid)); + .until(() -> getHttpResponse("/hello/greeting").contains(uuid)); } @Test @@ -227,7 +227,7 @@ public void testThatApplicationRecoversCompilationIssue() throws MavenInvocation await() .pollDelay(100, TimeUnit.MILLISECONDS) .atMost(1, TimeUnit.MINUTES).until(() -> { - String content = getHttpResponse("/app/hello"); + String content = getHttpResponse("/hello"); last.set(content); return content.contains(uuid); }); @@ -242,7 +242,7 @@ public void testThatApplicationRecoversCompilationIssue() throws MavenInvocation // Wait until we get "uuid" await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello").contains("carambar")); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/hello").contains("carambar")); } @Test @@ -274,7 +274,7 @@ public void testThatNewBeanAreDiscovered() throws IOException, MavenInvocationEx // Wait until we get "uuid" await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello").contains("message")); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/hello").contains("message")); sleep(); @@ -282,11 +282,10 @@ public void testThatNewBeanAreDiscovered() throws IOException, MavenInvocationEx await() .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/app/hello").contains("foobarbaz")); + .atMost(1, TimeUnit.MINUTES).until(() -> getHttpResponse("/hello").contains("foobarbaz")); } - @Test public void testErrorMessageWhenNoJavaSources() throws IOException, MavenInvocationException { testDir = initProject("projects/classic", "projects/project-no-sources"); diff --git a/maven/src/test/resources/projects/classic/src/main/java/org/acme/ShamrockApplication.java b/maven/src/test/resources/projects/classic/src/main/java/org/acme/ShamrockApplication.java deleted file mode 100644 index c79383cbcb16a..0000000000000 --- a/maven/src/test/resources/projects/classic/src/main/java/org/acme/ShamrockApplication.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.acme; - -import javax.ws.rs.ApplicationPath; -import javax.ws.rs.core.Application; - -@ApplicationPath("/app") -public class ShamrockApplication extends Application { - -} diff --git a/maven/src/test/resources/projects/classic/src/test/java/org/acme/HelloResourceTest.java b/maven/src/test/resources/projects/classic/src/test/java/org/acme/HelloResourceTest.java index bd0ace6c11400..ae172a1ad4bf2 100644 --- a/maven/src/test/resources/projects/classic/src/test/java/org/acme/HelloResourceTest.java +++ b/maven/src/test/resources/projects/classic/src/test/java/org/acme/HelloResourceTest.java @@ -13,7 +13,7 @@ public class HelloResourceTest { @Test public void testHelloEndpoint() { given() - .when().get("/app/hello") + .when().get("/hello") .then() .statusCode(200) .body(is("hello"));