aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [01/12] aries-jax-rs-whiteboard git commit: [ARIES-JAXRS] use constants, general cleanup
Date Fri, 24 Feb 2017 16:41:48 GMT
Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master 1463182b8 -> 576f7e395


[ARIES-JAXRS] use constants, general cleanup

Signed-off-by: Raymond Auge <raymond.auge@liferay.com>


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

Branch: refs/heads/master
Commit: 5b7b1eb899e977519dfec112257685247ff8d68c
Parents: f8a7138
Author: Raymond Auge <raymond.auge@liferay.com>
Authored: Fri Feb 24 10:10:21 2017 -0500
Committer: Raymond Auge <raymond.auge@liferay.com>
Committed: Fri Feb 24 10:11:03 2017 -0500

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 48 ++++++++++----------
 jax-rs.whiteboard/bnd.bnd                       |  1 +
 .../AriesJaxRSWhiteboardConstants.java          | 35 ++++++++++++++
 .../activator/CXFJaxRsBundleActivator.java      | 29 ++++++------
 .../internal/CXFJaxRsServiceRegistrator.java    | 12 +++--
 .../aries/jax/rs/whiteboard/package-info.java   | 21 +++++++++
 6 files changed, 106 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5b7b1eb8/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 20f8910..646f427 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -17,6 +17,9 @@
 
 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;
 
@@ -126,8 +129,8 @@ public class JaxrsTest {
             applicationRegistration = registerApplication();
 
             serviceRegistration = registerAddon(
-                "osgi.jaxrs.application.select",
-                "(osgi.jaxrs.application.base=/test-application)");
+                JAX_RS_APPLICATION_SELECT,
+                "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
             assertEquals(
                 "Hello extended",
@@ -164,8 +167,8 @@ public class JaxrsTest {
 
                 try {
                     serviceRegistration = registerAddon(
-                        "osgi.jaxrs.application.select",
-                        "(osgi.jaxrs.application.base=/test-application)");
+                        JAX_RS_APPLICATION_SELECT,
+                        "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
                     assertEquals(
                         "Hello extended",
@@ -206,8 +209,8 @@ public class JaxrsTest {
             applicationRegistration = registerApplication();
 
             filterRegistration = registerFilter(
-                "osgi.jaxrs.application.select",
-                "(osgi.jaxrs.application.base=/test-application)");
+                JAX_RS_APPLICATION_SELECT,
+                "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
             Response response = webTarget.request().get();
 
@@ -255,8 +258,8 @@ public class JaxrsTest {
 
                 try {
                     filterRegistration = registerFilter(
-                        "osgi.jaxrs.application.select",
-                        "(osgi.jaxrs.application.base=/test-application)");
+                        JAX_RS_APPLICATION_SELECT,
+                        "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
                     response = webTarget.request().get();
 
@@ -296,7 +299,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                "osgi.jaxrs.resource.base", "/test-addon");
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             Response response = webTarget.request().get();
 
@@ -327,7 +330,7 @@ public class JaxrsTest {
 
             try {
                 serviceRegistration = registerAddon(
-                    "osgi.jaxrs.resource.base", "/test-addon");
+                    JAX_RS_RESOURCE_BASE, "/test-addon");
 
                 assertEquals(
                     "Hello test",
@@ -357,7 +360,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                true, "osgi.jaxrs.resource.base", "/test-addon");
+                true, JAX_RS_RESOURCE_BASE, "/test-addon");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -384,7 +387,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddonLifecycle(
-                false, "osgi.jaxrs.resource.base", "/test-addon");
+                false, JAX_RS_RESOURCE_BASE, "/test-addon");
 
             String first = webTarget.request().get().readEntity(String.class);
 
@@ -414,10 +417,10 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                "osgi.jaxrs.resource.base", "/test-addon");
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             filterRegistration = registerFilter(
-                "osgi.jaxrs.extension.name", "test-filter");
+                JAX_RS_EXTENSION_NAME, "test-filter");
 
             Response response = webTarget.request().get();
 
@@ -450,7 +453,7 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                "osgi.jaxrs.resource.base", "/test-addon");
+                JAX_RS_RESOURCE_BASE, "/test-addon");
 
             assertEquals("Hello test",
                 webTarget.request().get().readEntity(String.class));
@@ -464,7 +467,7 @@ public class JaxrsTest {
                     assertNull(response.getHeaders().getFirst("Filtered"));
 
                     filterRegistration = registerFilter(
-                        "osgi.jaxrs.extension.name", "test-filter");
+                        JAX_RS_EXTENSION_NAME, "test-filter");
 
                     response = webTarget.request().get();
 
@@ -508,8 +511,8 @@ public class JaxrsTest {
 
         try {
             serviceRegistration = registerAddon(
-                "osgi.jaxrs.resource.base", "/test-addon",
-                "osgi.jaxrs.extension.select", new String[]{
+                JAX_RS_RESOURCE_BASE, "/test-addon",
+                JAX_RS_EXTENSION_SELECT, new String[]{
                     "(property one=one)",
                     "(property two=two)",
                 });
@@ -601,14 +604,14 @@ public class JaxrsTest {
                 new PrototypeServiceFactory<Object>() {
                     @Override
                     public Object getService(
-                        Bundle bundle, ServiceRegistration registration) {
+                        Bundle bundle, ServiceRegistration<Object> registration) {
 
                         return new TestAddonLifecycle();
                     }
 
                     @Override
                     public void ungetService(
-                        Bundle bundle, ServiceRegistration registration,
+                        Bundle bundle, ServiceRegistration<Object> registration,
                         Object service) {
 
                     }
@@ -626,8 +629,7 @@ public class JaxrsTest {
 
         Dictionary<String, Object> properties = new Hashtable<>();
 
-        properties.put(
-            "osgi.jaxrs.application.base", "/test-application");
+        properties.put(JAX_RS_APPLICATION_BASE, "/test-application");
 
         return bundleContext.registerService(
             Application.class, testApplication, properties);
@@ -654,7 +656,7 @@ public class JaxrsTest {
 
         Dictionary<String, Object> properties = new Hashtable<>();
 
-        properties.put("osgi.jaxrs.extension.name", 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/5b7b1eb8/jax-rs.whiteboard/bnd.bnd
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/bnd.bnd b/jax-rs.whiteboard/bnd.bnd
index f37aab4..2abfe41 100644
--- a/jax-rs.whiteboard/bnd.bnd
+++ b/jax-rs.whiteboard/bnd.bnd
@@ -48,6 +48,7 @@ Import-Package:\
 #            version:Version=1
 
 -exportcontents:\
+    org.apache.aries.jax.rs.whiteboard,\
     org.apache.cxf.jaxrs.ext.*
 
 -includeresource:\

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5b7b1eb8/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/AriesJaxRSWhiteboardConstants.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/AriesJaxRSWhiteboardConstants.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/AriesJaxRSWhiteboardConstants.java
new file mode 100644
index 0000000..615f49f
--- /dev/null
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/AriesJaxRSWhiteboardConstants.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.aries.jax.rs.whiteboard;
+
+import java.nio.file.DirectoryStream.Filter;
+
+public class AriesJaxRSWhiteboardConstants {
+
+    /**
+     * A Service property specifying a target filter used to select
+     * an Application onto which to bind the service.
+     * <p>
+     * If this service property is not specified, the service is ignored.
+     * <p>
+     * The value of this service property must be of type {@code String} and be
+     * a valid {@link Filter filter string}.
+     */
+    public static final String JAX_RS_APPLICATION_SELECT = "org.apache.aries.jaxrs.extension.select";
+
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5b7b1eb8/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 23d0427..d369b47 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
@@ -45,12 +45,15 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
+import static java.lang.String.format;
+import static org.apache.aries.jax.rs.whiteboard.AriesJaxRSWhiteboardConstants.*;
 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.apache.aries.osgi.functional.OSGi.serviceReferences;
 import static org.apache.aries.osgi.functional.OSGi.services;
+import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME;
 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;
@@ -109,7 +112,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
                 flatMap(ref ->
             just(
                 CXFJaxRsServiceRegistrator.getProperties(
-                    ref, "osgi.jaxrs.application.base")).
+                    ref, JAX_RS_APPLICATION_BASE)).
                 flatMap(properties ->
             service(ref).flatMap(application ->
             cxfRegistrator(bus, application, properties)
@@ -129,7 +132,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
             waitForExtensionDependencies(serviceReference,
                 just(
                     CXFJaxRsServiceRegistrator.getProperties(
-                        serviceReference, "osgi.jaxrs.resource.base")).
+                        serviceReference, JAX_RS_RESOURCE_BASE)).
                     flatMap(properties ->
                 service(serviceReference).flatMap(service ->
                 safeRegisterEndpoint(
@@ -149,9 +152,9 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
         _extensionsResult = extensions.run(bundleContext);
 
         OSGi<?> applicationSingletons =
-            serviceReferences("(osgi.jaxrs.application.select=*)").
+            serviceReferences(format("(%s=*)", JAX_RS_APPLICATION_SELECT)).
                 flatMap(ref ->
-            just(ref.getProperty("osgi.jaxrs.application.select").toString()).
+            just(ref.getProperty(JAX_RS_APPLICATION_SELECT).toString()).
                 flatMap(applicationFilter ->
             services(CXFJaxRsServiceRegistrator.class, applicationFilter).
                 flatMap(registrator ->
@@ -222,14 +225,14 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     }
 
     private String buildExtensionFilter(String filter) {
-        return "(&(osgi.jaxrs.extension.name=*)" + filter + ")";
+        return format("(&%s%s)", getExtensionFilter(), filter);
     }
 
     private OSGi<?> waitForExtensionDependencies(
         ServiceReference<?> serviceReference, OSGi<?> program) {
 
         String[] extensionDependencies = canonicalize(
-            serviceReference.getProperty("osgi.jaxrs.extension.select"));
+            serviceReference.getProperty(JAX_RS_EXTENSION_SELECT));
 
         for (String extensionDependency : extensionDependencies) {
             program =
@@ -261,7 +264,7 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
         ClassLoader contextClassLoader = thread.getContextClassLoader();
         ClassLoader classLoader = ref.getBundle().adapt(BundleWiring.class).
             getClassLoader();
-        Object resourceBaseObject = ref.getProperty("osgi.jaxrs.resource.base");
+        Object resourceBaseObject = ref.getProperty(JAX_RS_RESOURCE_BASE);
 
         ResourceProvider resourceProvider = getResourceProvider(serviceObjects);
 
@@ -329,8 +332,8 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     private ServiceRegistration<Servlet> registerCXFServletService(Bus bus) {
         Dictionary<String, Object> properties = new Hashtable<>();
         properties.put(HTTP_WHITEBOARD_CONTEXT_SELECT,
-            "(" + HTTP_WHITEBOARD_CONTEXT_NAME + "=" + 
-                HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME + ")");
+            format("(%s=%s)", HTTP_WHITEBOARD_CONTEXT_NAME,
+                HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME));
         properties.put(HTTP_WHITEBOARD_SERVLET_PATTERN, "/*");
         properties.put(Constants.SERVICE_RANKING, -1);
         CXFNonSpringServlet cxfNonSpringServlet = createCXFServlet(bus);
@@ -345,17 +348,17 @@ public class CXFJaxRsBundleActivator implements BundleActivator {
     }
 
     private String getExtensionFilter() {
-        return "(osgi.jaxrs.extension.name=*)";
+        return format("(%s=*)", JAX_RS_EXTENSION_NAME);
     }
 
     private String getApplicationFilter() {
-        return "(osgi.jaxrs.application.base=*)";
+        return format("(%s=*)", JAX_RS_APPLICATION_BASE);
     }
 
     private String getSingletonsFilter() {
-        return "(osgi.jaxrs.resource.base=*)";
+        return format("(%s=*)", JAX_RS_RESOURCE_BASE);
     }
-    
+
     @Override
     public void stop(BundleContext context) throws Exception {
         _applicationSingletonsResult.close();

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5b7b1eb8/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 e6170cb..1ac45ee 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
@@ -36,6 +36,8 @@ import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.json.JSONProvider;
 import org.osgi.framework.ServiceReference;
 
+import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*;
+
 public class CXFJaxRsServiceRegistrator {
     private volatile boolean _closed = false;
     private final Application _application;
@@ -45,6 +47,8 @@ public class CXFJaxRsServiceRegistrator {
     private Server _server;
     private final Collection<ServiceInformation> _services = new ArrayList<>();
 
+    private static final String CXF_ENDPOINT_ADDRESS = "CXF_ENDPOINT_ADDRESS";
+
     public CXFJaxRsServiceRegistrator(
         Bus bus, Application application, Map<String, Object> properties) {
 
@@ -54,19 +58,19 @@ public class CXFJaxRsServiceRegistrator {
 
         rewire();
     }
-    
+
     public static Map<String, Object> getProperties(ServiceReference<?> sref,
String addressKey) {
         String[] propertyKeys = sref.getPropertyKeys();
         Map<String, Object> properties = new HashMap<String, Object>(propertyKeys.length);
 
         for (String key : propertyKeys) {
-            if (key.equals("osgi.jaxrs.resource.base")) {
+            if (key.equals(JAX_RS_RESOURCE_BASE)) {
                 continue;
             }
             properties.put(key, sref.getProperty(key));
         }
 
-        properties.put("CXF_ENDPOINT_ADDRESS", sref.getProperty(addressKey).toString());
+        properties.put(CXF_ENDPOINT_ADDRESS, sref.getProperty(addressKey).toString());
         return properties;
     }
 
@@ -181,7 +185,7 @@ public class CXFJaxRsServiceRegistrator {
         }
 
         Object cxfEndpointAddressObject = _properties.get(
-            "CXF_ENDPOINT_ADDRESS");
+            CXF_ENDPOINT_ADDRESS);
 
         String address;
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5b7b1eb8/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/package-info.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/package-info.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/package-info.java
new file mode 100644
index 0000000..ac5149e
--- /dev/null
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+@Version("1.0.0")
+package org.apache.aries.jax.rs.whiteboard;
+
+import org.osgi.annotation.versioning.Version;
\ No newline at end of file


Mime
View raw message