You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2021/09/15 08:48:00 UTC

[sling-whiteboard] branch master updated: Sling engine activated, path conflicts fixed

This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 56b552d  Sling engine activated, path conflicts fixed
56b552d is described below

commit 56b552d5c86c9e29b58979b1535b75f595abba6b
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Wed Sep 15 10:47:21 2021 +0200

    Sling engine activated, path conflicts fixed
---
 aries-jax-rs-whiteboard/README.md                   | 14 +++++++++++++-
 .../java/org/apache/sling/jaxrs/TestService.java    | 21 ++++++++++++++++++---
 .../features/feature-aries-jars-sample.json         | 14 +++++++++++++-
 .../test/resources/features/feature-sling12.json    |  2 +-
 4 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/aries-jax-rs-whiteboard/README.md b/aries-jax-rs-whiteboard/README.md
index 7d9a690..39de350 100644
--- a/aries-jax-rs-whiteboard/README.md
+++ b/aries-jax-rs-whiteboard/README.md
@@ -2,7 +2,7 @@
 
 This repository implements a minimal Sling application using the
 [Aries JAX-RS Whiteboard](https://github.com/apache/aries-jax-rs-whiteboard)
-modules to implement a HTTPs that can be documented with OpenAPI.
+modules to implement HTTP APIs that can be documented with [OpenAPI](https://www.openapis.org/).
 
 The [org.fipro.modifier.jaxrs](https://github.com/fipro78/access_osgi_services/tree/master/org.fipro.modifier.jaxrs)
 example was useful in setting this up.
@@ -14,3 +14,15 @@ To start this, run
 Then open http://localhost:8080 - which might require logging in
 at http://localhost:8080/system/console first.
 
+http://localhost:8080/api/jaxrs/test/testing.this (for example) should
+then address the JAX-RS [`TestService`](./src/main/java/org/apache/sling/jaxrs/TestService.java) resource, while
+http://localhost:8080/api/sling.json is served by Sling as usual.
+
+A POST can increment the test counter, such as:
+
+    curl -XPOST http://localhost:8080/api/jaxrs/test/increment/42
+
+## TODO
+
+The JAX-RS servlet should use Sling authentication, mounting it on
+a resource type might be interesting.
diff --git a/aries-jax-rs-whiteboard/src/main/java/org/apache/sling/jaxrs/TestService.java b/aries-jax-rs-whiteboard/src/main/java/org/apache/sling/jaxrs/TestService.java
index 5942ed2..e862041 100644
--- a/aries-jax-rs-whiteboard/src/main/java/org/apache/sling/jaxrs/TestService.java
+++ b/aries-jax-rs-whiteboard/src/main/java/org/apache/sling/jaxrs/TestService.java
@@ -19,6 +19,7 @@
 package org.apache.sling.jaxrs;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
@@ -27,22 +28,36 @@ import javax.ws.rs.core.MediaType;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.jaxrs.whiteboard.propertytypes.JaxrsResource;
 
-@Path("/jaxrs")
+@Path("/test")
 @Produces(MediaType.TEXT_PLAIN)
 @Component(service=TestService.class)
 @JaxrsResource
 public class TestService {
+
+	static int counter;
 	 
 	@GET
 	@Path("/{one}")
 	public String getOne(@PathParam("one") String one) {
-		return String.format("The single input was %s (%d characters)", one, one.length());
+		return String.format(
+			"The single input was %s (%d characters) and the counter is %d", 
+			one, one.length(), counter);
 	}
 
 	@GET
 	@Path("/{one}/{two}")
 	public String getTwo(@PathParam("one") String one, @PathParam("two") String two) {
-		return String.format("The dual input was %s and %s", one, two);
+		return String.format(
+			"The dual input was %s and %s and the counter is %d",
+			one, two, counter);
 	}
 
+	@POST
+	@Path("/increment/{howMuch}")
+	public static String incrementCounter(@PathParam("howMuch") int howMuch) {
+		counter += howMuch;
+		return String.format(
+			"The counter has been incremented by %d and is now %d",
+			howMuch, counter);
+	}
 }
\ No newline at end of file
diff --git a/aries-jax-rs-whiteboard/src/test/resources/features/feature-aries-jars-sample.json b/aries-jax-rs-whiteboard/src/test/resources/features/feature-aries-jars-sample.json
index 311b92e..6910373 100644
--- a/aries-jax-rs-whiteboard/src/test/resources/features/feature-aries-jars-sample.json
+++ b/aries-jax-rs-whiteboard/src/test/resources/features/feature-aries-jars-sample.json
@@ -29,6 +29,9 @@
     "com.adobe.aem.guides:aem-guides-wknd.ui.content.sample:zip:0.0.4"
   ],
   "configurations":{
+    "org.apache.aries.jax.rs.whiteboard.default":{
+      "default.application.base":"/api/jaxrs"
+    },
     "org.apache.sling.jcr.base.internal.LoginAdminWhitelist.fragment~installer-packages":{
       "whitelist.bundles":[
         "org.apache.sling.installer.factory.packages"
@@ -56,5 +59,14 @@
         ],
       "org.apache.sling.commons.log.pattern": "%-5level [%-50logger{50}] %message ## %mdc{sling.InternalRequest} %n"
     }
-  }
+  },
+  "repoinit:TEXT|true":[
+    "create path /api/sling",
+    "set ACL on /api",
+    "allow jcr:read for everyone",
+    "end",
+    "set properties on /api/sling",
+    "set info to \"This resource is served by Sling\"",
+    "end"
+  ]
 }
\ No newline at end of file
diff --git a/aries-jax-rs-whiteboard/src/test/resources/features/feature-sling12.json b/aries-jax-rs-whiteboard/src/test/resources/features/feature-sling12.json
index 5afede1..84c82ac 100644
--- a/aries-jax-rs-whiteboard/src/test/resources/features/feature-sling12.json
+++ b/aries-jax-rs-whiteboard/src/test/resources/features/feature-sling12.json
@@ -495,7 +495,7 @@
     },
     {
       "id":"org.apache.sling:org.apache.sling.engine:2.7.2",
-      "start-order":"99",
+      "start-order":"20",
       "feature-origins":"org.apache.sling:org.apache.sling.kickstart.conversion:slingfeature:sling:0.0.1-SNAPSHOT"
     },
     {