aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [01/11] aries-jax-rs-whiteboard git commit: Revert "Adapt to new specification"
Date Mon, 19 Jun 2017 15:34:05 GMT
Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master a012f18ef -> 1a1c2b708


Revert "Adapt to new specification"

This reverts commit a012f18efc7afbad47778c879597dc39b3985b49.


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/f420f976
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/f420f976
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/f420f976

Branch: refs/heads/master
Commit: f420f976a042c074bdefbcd8f2e803de9d87070f
Parents: a012f18
Author: Carlos Sierra <csierra@apache.org>
Authored: Mon Jun 19 17:30:16 2017 +0200
Committer: Carlos Sierra <csierra@apache.org>
Committed: Mon Jun 19 17:30:16 2017 +0200

----------------------------------------------------------------------
 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 +++-
 5 files changed, 78 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/f420f976/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 7472f35..646f427 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -18,6 +18,7 @@
 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;
@@ -291,12 +292,14 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
+            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
-            serviceRegistration = registerAddon(JAX_RS_RESOURCE, "true");
+            serviceRegistration = registerAddon(
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             Response response = webTarget.request().get();
 
@@ -317,6 +320,7 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
+            path("/test-addon").
             path("test");
 
         Runnable testCase = () -> {
@@ -325,7 +329,8 @@ public class JaxrsTest {
             ServiceRegistration<?> serviceRegistration = null;
 
             try {
-                serviceRegistration = registerAddon(JAX_RS_RESOURCE, "true");
+                serviceRegistration = registerAddon(
+                    JAX_RS_RESOURCE_BASE, "/test-addon");
 
                 assertEquals(
                     "Hello test",
@@ -349,13 +354,13 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon-lifecycle");
+            path("/test-addon");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                true, JAX_RS_RESOURCE, "true");
+                true, JAX_RS_RESOURCE_BASE, "/test-addon");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -376,13 +381,13 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
-            path("/test-addon-lifecycle");
+            path("/test-addon");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                false, JAX_RS_RESOURCE, "true");
+                false, JAX_RS_RESOURCE_BASE, "/test-addon");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -403,6 +408,7 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
+            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> filterRegistration = null;
@@ -411,10 +417,10 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE, true);
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             filterRegistration = registerFilter(
-                JAX_RS_EXTENSION, "test-filter");
+                JAX_RS_EXTENSION_NAME, "test-filter");
 
             Response response = webTarget.request().get();
 
@@ -440,13 +446,14 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
+            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE, "true");
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             assertEquals("Hello test",
                 webTarget.request().get().readEntity(String.class));
@@ -460,7 +467,7 @@ public class JaxrsTest {
                     assertNull(response.getHeaders().getFirst("Filtered"));
 
                     filterRegistration = registerFilter(
-                        JAX_RS_EXTENSION, "test-filter");
+                        JAX_RS_EXTENSION_NAME, "test-filter");
 
                     response = webTarget.request().get();
 
@@ -495,6 +502,7 @@ public class JaxrsTest {
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
+            path("/test-addon").
             path("test");
 
         ServiceRegistration<?> serviceRegistration = null;
@@ -503,7 +511,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                JAX_RS_RESOURCE, "true",
+                JAX_RS_RESOURCE_BASE, "/test-addon",
                 JAX_RS_EXTENSION_SELECT, new String[]{
                     "(property one=one)",
                     "(property two=two)",
@@ -648,7 +656,7 @@ public class JaxrsTest {
 
         Dictionary<String, Object> properties = new Hashtable<>();
 
-        properties.put(JAX_RS_EXTENSION, name);
+        properties.put(JAX_RS_EXTENSION_NAME, 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/f420f976/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 059a74d..f271dc7 100644
--- a/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
+++ b/jax-rs.itests/src/main/java/test/types/TestAddonLifecycle.java
@@ -20,7 +20,6 @@ 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/f420f976/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 0f05902..ab06853 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,6 +40,7 @@ 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;
@@ -49,7 +50,6 @@ 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,9 +114,14 @@ 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);
@@ -155,11 +160,11 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     }
 
     private static String getExtensionFilter() {
-        return format("(%s=*)", JAX_RS_EXTENSION);
+        return format("(%s=*)", JAX_RS_EXTENSION_NAME);
     }
 
     private static String getSingletonsFilter() {
-        return format("(%s=true)", JAX_RS_RESOURCE);
+        return format("(%s=*)", JAX_RS_RESOURCE_BASE);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/f420f976/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 886847f..e1e6a25 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,6 +21,7 @@ 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;
 
@@ -30,11 +31,15 @@ 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 {
 
@@ -66,6 +71,9 @@ 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));
         }
 
@@ -162,9 +170,30 @@ public class CXFJaxRsServiceRegistrator {
             jaxRsServerFactoryBean.setProvider(provider);
         }
 
+        JAXRSServiceFactoryBean serviceFactory =
+            jaxRsServerFactoryBean.getServiceFactory();
+
         for (ResourceInformation resourceInformation : _services) {
-            jaxRsServerFactoryBean.setResourceProvider(
-                resourceInformation.getResourceProvider());
+
+            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()));
+                }
+            }
         }
 
         String address = safeToString(_properties.get(CXF_ENDPOINT_ADDRESS));
@@ -179,23 +208,29 @@ 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, ResourceProvider resourceProvider) {
+            T comparable, String prefixPath,
+            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/f420f976/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 4a7aa0c..0836ac0 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,6 +36,7 @@ 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
@@ -124,10 +125,14 @@ 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, resourceProvider);
+                new ResourceInformation<>(
+                    serviceReference, resourceBase, resourceProvider);
             registrator.add(resourceInformation);
             return just(resourceInformation);
         }


Mime
View raw message