aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [04/11] aries-jax-rs-whiteboard git commit: Adapt to new specification
Date Mon, 19 Jun 2017 15:34:08 GMT
Adapt to new specification


Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/faa76367
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/faa76367
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/faa76367

Branch: refs/heads/master
Commit: faa7636792c558cb4ce6af241679fc56e0458d9a
Parents: 9826878
Author: Carlos Sierra <csierra@apache.org>
Authored: Mon Jun 5 15:55:08 2017 +0200
Committer: Carlos Sierra <csierra@apache.org>
Committed: Mon Jun 19 17:31:55 2017 +0200

----------------------------------------------------------------------
 jax-rs.example/pom.xml                          |  5 +++
 jax-rs.itests/itest.bndrun                      |  2 +-
 jax-rs.itests/pom.xml                           | 20 +++++++++
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 32 ++++++---------
 .../java/test/types/TestAddonLifecycle.java     |  1 +
 .../activator/CXFJaxRsBundleActivator.java      | 21 ++++------
 .../internal/CXFJaxRsServiceRegistrator.java    | 43 ++------------------
 .../aries/jax/rs/whiteboard/internal/Utils.java |  7 +---
 8 files changed, 52 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.example/pom.xml
----------------------------------------------------------------------
diff --git a/jax-rs.example/pom.xml b/jax-rs.example/pom.xml
index 4a71297..21eef6d 100644
--- a/jax-rs.example/pom.xml
+++ b/jax-rs.example/pom.xml
@@ -152,5 +152,10 @@
             <artifactId>org.osgi.service.metatype</artifactId>
             <version>1.3.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jax.rs</groupId>
+            <artifactId>javax.ws.rs_2.0</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.itests/itest.bndrun
----------------------------------------------------------------------
diff --git a/jax-rs.itests/itest.bndrun b/jax-rs.itests/itest.bndrun
index ed73734..135caf0 100644
--- a/jax-rs.itests/itest.bndrun
+++ b/jax-rs.itests/itest.bndrun
@@ -23,7 +23,7 @@
 	osgi.identity;filter:='(osgi.identity=osgi.cmpn)'
 -runbundles: \
 	javax.annotation-api;version='[1.2.0,1.2.1)',\
-	javax.ws.rs-api;version='[2.0.1,2.0.2)',\
+	org.apache.aries.jax.rs.javax.ws.rs_2.0;version='[0.0.1,0.0.2)',\
 	log4j;version='[1.2.17,1.2.18)',\
 	org.apache.aries.jax.rs.itests;version='[0.0.1,0.0.2)',\
 	org.apache.cxf.cxf-core;version='[3.1.7,3.1.8)',\

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.itests/pom.xml
----------------------------------------------------------------------
diff --git a/jax-rs.itests/pom.xml b/jax-rs.itests/pom.xml
index 06729b7..83817ed 100644
--- a/jax-rs.itests/pom.xml
+++ b/jax-rs.itests/pom.xml
@@ -132,6 +132,16 @@
         </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.util.promise</artifactId>
+            <version>LATEST</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.util.function</artifactId>
+            <version>LATEST</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
             <artifactId>osgi.enroute.junit.wrapper</artifactId>
             <version>4.12.0</version>
         </dependency>
@@ -140,5 +150,15 @@
             <artifactId>osgi.enroute.hamcrest.wrapper</artifactId>
             <version>1.3.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.jaxrs</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jax.rs</groupId>
+            <artifactId>javax.ws.rs_2.0</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+        </dependency>
     </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.itests/src/main/java/test/JaxrsTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index 646f427..7472f35 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -18,7 +18,6 @@
 package test;
 
 import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*;
-import static org.apache.aries.jax.rs.whiteboard.AriesJaxRSWhiteboardConstants.*;
 
 import java.util.Dictionary;
 import java.util.Hashtable;
@@ -292,14 +291,12 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
-            serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE_BASE, "/test-addon");
+            serviceRegistration = registerAddon(JAX_RS_RESOURCE, "true");
 
             Response response = webTarget.request().get();
 
@@ -320,7 +317,6 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon").
             path("test");
 
         Runnable testCase = () -> {
@@ -329,8 +325,7 @@ public class JaxrsTest {
             ServiceRegistration<?> serviceRegistration = null;
 
             try {
-                serviceRegistration = registerAddon(
-                    JAX_RS_RESOURCE_BASE, "/test-addon");
+                serviceRegistration = registerAddon(JAX_RS_RESOURCE, "true");
 
                 assertEquals(
                     "Hello test",
@@ -354,13 +349,13 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon");
+            path("/test-addon-lifecycle");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                true, JAX_RS_RESOURCE_BASE, "/test-addon");
+                true, JAX_RS_RESOURCE, "true");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -381,13 +376,13 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon");
+            path("/test-addon-lifecycle");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                false, JAX_RS_RESOURCE_BASE, "/test-addon");
+                false, JAX_RS_RESOURCE, "true");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -408,7 +403,6 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> filterRegistration = null;
@@ -417,10 +411,10 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE_BASE, "/test-addon");
+                JAX_RS_RESOURCE, true);
 
             filterRegistration = registerFilter(
-                JAX_RS_EXTENSION_NAME, "test-filter");
+                JAX_RS_EXTENSION, "test-filter");
 
             Response response = webTarget.request().get();
 
@@ -446,14 +440,13 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE_BASE, "/test-addon");
+                JAX_RS_RESOURCE, "true");
 
             assertEquals("Hello test",
                 webTarget.request().get().readEntity(String.class));
@@ -467,7 +460,7 @@ public class JaxrsTest {
                     assertNull(response.getHeaders().getFirst("Filtered"));
 
                     filterRegistration = registerFilter(
-                        JAX_RS_EXTENSION_NAME, "test-filter");
+                        JAX_RS_EXTENSION, "test-filter");
 
                     response = webTarget.request().get();
 
@@ -502,7 +495,6 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
@@ -511,7 +503,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE_BASE, "/test-addon",
+                JAX_RS_RESOURCE, "true",
                 JAX_RS_EXTENSION_SELECT, new String[]{
                     "(property one=one)",
                     "(property two=two)",
@@ -656,7 +648,7 @@ public class JaxrsTest {
 
         Dictionary<String, Object> properties = new Hashtable<>();
 
-        properties.put(JAX_RS_EXTENSION_NAME, name);
+        properties.put(JAX_RS_EXTENSION, name);
 
         for (int i = 0; i < keyValues.length; i = i + 2) {
             properties.put(keyValues[i].toString(), keyValues[i + 1]);

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java b/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
index f271dc7..059a74d 100644
--- a/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
+++ b/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
@@ -20,6 +20,7 @@ package test.types;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 
+@Path("/test-addon-lifecycle")
 public class TestAddonLifecycle {
 
     @GET

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
index ab06853..0f05902 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CXFJaxRsBundleActivator.java
@@ -40,7 +40,6 @@ import java.util.HashMap;
 import java.util.Hashtable;
 
 import static java.lang.String.format;
-import static org.apache.aries.jax.rs.whiteboard.AriesJaxRSWhiteboardConstants.*;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.*;
 import static org.apache.aries.osgi.functional.OSGi.just;
 import static org.apache.aries.osgi.functional.OSGi.serviceReferences;
@@ -50,6 +49,7 @@ import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHIT
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN;
+import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_APPLICATION_SELECT;
 
 public class CXFJaxRsBundleActivator implements BundleActivator {
 
@@ -103,10 +103,10 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
 
         OSGi<?> extensions =
             serviceReferences(getExtensionFilter()).flatMap(ref ->
-                waitForExtensionDependencies(ref,
-                    safeRegisterExtension(ref, defaultServiceRegistrator)
-                )
-            );
+            waitForExtensionDependencies(ref,
+                safeRegisterExtension(ref, defaultServiceRegistrator)
+            )
+        );
 
         _extensionsResult = extensions.run(bundleContext);
 
@@ -114,14 +114,9 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
             serviceReferences(getSingletonsFilter()).
                 flatMap(serviceReference ->
             waitForExtensionDependencies(serviceReference,
-                just(
-                    CXFJaxRsServiceRegistrator.getProperties(
-                        serviceReference, JAX_RS_RESOURCE_BASE)).
-                    flatMap(properties ->
-                service(serviceReference).flatMap(service ->
                 safeRegisterEndpoint(
                     serviceReference, defaultServiceRegistrator)
-            )))
+            )
         );
 
         _singletonsResult = singletons.run(bundleContext);
@@ -160,11 +155,11 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     }
 
     private static String getExtensionFilter() {
-        return format("(%s=*)", JAX_RS_EXTENSION_NAME);
+        return format("(%s=*)", JAX_RS_EXTENSION);
     }
 
     private static String getSingletonsFilter() {
-        return format("(%s=*)", JAX_RS_RESOURCE_BASE);
+        return format("(%s=true)", JAX_RS_RESOURCE);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
index e1e6a25..886847f 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
 
@@ -31,15 +30,11 @@ import javax.ws.rs.ext.RuntimeDelegate;
 import org.apache.cxf.Bus;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.json.JSONProvider;
 import org.osgi.framework.ServiceReference;
 
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.safeToString;
-import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*;
 
 public class CXFJaxRsServiceRegistrator {
 
@@ -71,9 +66,6 @@ public class CXFJaxRsServiceRegistrator {
         Map<String, Object> properties = new HashMap<>(propertyKeys.length);
 
         for (String key : propertyKeys) {
-            if (key.equals(JAX_RS_RESOURCE_BASE)) {
-                continue;
-            }
             properties.put(key, sref.getProperty(key));
         }
 
@@ -170,30 +162,9 @@ public class CXFJaxRsServiceRegistrator {
             jaxRsServerFactoryBean.setProvider(provider);
         }
 
-        JAXRSServiceFactoryBean serviceFactory =
-            jaxRsServerFactoryBean.getServiceFactory();
-
         for (ResourceInformation resourceInformation : _services) {
-
-            ResourceProvider resourceProvider =
-                resourceInformation.getResourceProvider();
-
-            jaxRsServerFactoryBean.setResourceProvider(resourceProvider);
-
-            //FIXME: this is hack to programmatically prefix only resource path
-            List<ClassResourceInfo> classResourceInfo =
-                serviceFactory.getClassResourceInfo();
-
-            for (ClassResourceInfo resourceInfo : classResourceInfo) {
-                if (resourceInfo.getServiceClass() ==
-                        resourceProvider.getResourceClass()) {
-                    URITemplate uriTemplate = resourceInfo.getURITemplate();
-                    resourceInfo.setURITemplate(
-                        new URITemplate(
-                            resourceInformation.getPrefixPath() +
-                                uriTemplate.getValue()));
-                }
-            }
+            jaxRsServerFactoryBean.setResourceProvider(
+                resourceInformation.getResourceProvider());
         }
 
         String address = safeToString(_properties.get(CXF_ENDPOINT_ADDRESS));
@@ -208,29 +179,23 @@ public class CXFJaxRsServiceRegistrator {
     public static class ResourceInformation<T extends Comparable<? super T>>
         implements Comparable<ResourceInformation<T>> {
 
-        private final String _prefixPath;
         private final T _comparable;
         private final ResourceProvider _resourceProvider;
 
         public ResourceInformation(
-            T comparable, String prefixPath,
-            ResourceProvider resourceProvider) {
-
+            T comparable, ResourceProvider resourceProvider) {
             _comparable = comparable;
 
             _resourceProvider = resourceProvider;
         }
 
-        public String getPrefixPath() {
-            return _prefixPath;
-        }
-
         public ResourceProvider getResourceProvider() {
             return _resourceProvider;
         }
 
         @Override
         public int compareTo(ResourceInformation<T> resourceInformation) {
+
             if (resourceInformation == null) {
                 return 1;
             }

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/faa76367/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
index 0836ac0..4a7aa0c 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
@@ -36,7 +36,6 @@ import static org.apache.aries.osgi.functional.OSGi.bundleContext;
 import static org.apache.aries.osgi.functional.OSGi.just;
 import static org.apache.aries.osgi.functional.OSGi.onClose;
 import static org.apache.aries.osgi.functional.OSGi.register;
-import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_RESOURCE_BASE;
 
 /**
  * @author Carlos Sierra Andrés
@@ -125,14 +124,10 @@ public class Utils {
         BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
         ClassLoader classLoader = bundleWiring.getClassLoader();
         ResourceProvider resourceProvider = getResourceProvider(serviceObjects);
-        String resourceBase = safeToString(
-            serviceReference.getProperty(JAX_RS_RESOURCE_BASE));
-
         try {
             thread.setContextClassLoader(classLoader);
             ResourceInformation<ServiceReference<?>> resourceInformation =
-                new ResourceInformation<>(
-                    serviceReference, resourceBase, resourceProvider);
+                new ResourceInformation<>(serviceReference, resourceProvider);
             registrator.add(resourceInformation);
             return just(resourceInformation);
         }


Mime
View raw message