You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2017/08/25 15:25:49 UTC

[8/8] aries-jax-rs-whiteboard git commit: Register only advertised interfaces

Register only advertised interfaces


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

Branch: refs/heads/master
Commit: 432486ac7993fe0e7605dd265cefcf75e98abfbd
Parents: 08db7b1
Author: Carlos Sierra <cs...@apache.org>
Authored: Fri Aug 25 17:23:12 2017 +0200
Committer: Carlos Sierra <cs...@apache.org>
Committed: Fri Aug 25 17:23:12 2017 +0200

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 51 +++++++++++++++++++
 .../types/TestApplicationWithException.java     | 39 ++++++++++++++
 .../src/main/java/test/types/TestFilter.java    |  1 -
 .../types/TestFilterAndExceptionMapper.java     | 53 ++++++++++++++++++++
 .../jax/rs/whiteboard/internal/Whiteboard.java  |  2 +-
 5 files changed, 144 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/432486ac/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 9857ae4..7f364ce 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -41,7 +41,9 @@ import test.types.TestAddonConflict2;
 import test.types.TestAddonLifecycle;
 import test.types.TestApplication;
 import test.types.TestApplicationConflict;
+import test.types.TestApplicationWithException;
 import test.types.TestFilter;
+import test.types.TestFilterAndExceptionMapper;
 import test.types.TestHelper;
 
 import javax.ws.rs.client.Client;
@@ -49,6 +51,7 @@ import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
@@ -982,6 +985,42 @@ public class JaxrsTest extends TestHelper {
     }
 
     @Test
+    public void testExtensionRegisterOnlySignalledInterfaces()
+        throws InterruptedException {
+
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("test-application");
+
+        ServiceRegistration<?> serviceRegistration = null;
+
+        try {
+            serviceRegistration = registerApplication(
+                new TestApplicationWithException());
+
+            ServiceRegistration<?> filterRegistration =
+                registerMultiExtension(
+                    "Filter",
+                    ExceptionMapper.class.getName());
+
+            Response response = webTarget.request().get();
+
+            assertEquals(200, response.getStatus());
+
+            assertNull(response.getHeaders().getFirst("Filtered"));
+
+            filterRegistration.unregister();
+        }
+        finally {
+            if (serviceRegistration != null) {
+                serviceRegistration.unregister();
+            }
+        }
+    }
+
+    @Test
     public void testUngettableExtension() throws InterruptedException {
         Client client = createClient();
 
@@ -1201,6 +1240,18 @@ public class JaxrsTest extends TestHelper {
             ContainerResponseFilter.class, testFilter, properties);
     }
 
+    private ServiceRegistration<?> registerMultiExtension(
+        String name, String... classes) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        return bundleContext.registerService(
+            classes, new TestFilterAndExceptionMapper(), properties);
+    }
+
     private ServiceRegistration<?> registerInvalidExtension(
         String name, Object... keyValues) {
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/432486ac/jax-rs.itests/src/main/java/test/types/TestApplicationWithException.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestApplicationWithException.java b/jax-rs.itests/src/main/java/test/types/TestApplicationWithException.java
new file mode 100644
index 0000000..05eb000
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/TestApplicationWithException.java
@@ -0,0 +1,39 @@
+/*
+ * 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 test.types;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
+import java.util.Collections;
+import java.util.Set;
+
+public class TestApplicationWithException extends Application {
+
+    @Override
+    public Set<Object> getSingletons() {
+        return Collections.<Object>singleton(this);
+    }
+
+    @GET
+    @Produces("text/plain")
+    public String sayHello() {
+        throw new TestFilterAndExceptionMapper.MyException();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/432486ac/jax-rs.itests/src/main/java/test/types/TestFilter.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestFilter.java b/jax-rs.itests/src/main/java/test/types/TestFilter.java
index 1757ca3..79e4726 100644
--- a/jax-rs.itests/src/main/java/test/types/TestFilter.java
+++ b/jax-rs.itests/src/main/java/test/types/TestFilter.java
@@ -26,7 +26,6 @@ import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
 
-@Provider
 public class TestFilter implements ContainerResponseFilter {
 
     @Override

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/432486ac/jax-rs.itests/src/main/java/test/types/TestFilterAndExceptionMapper.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestFilterAndExceptionMapper.java b/jax-rs.itests/src/main/java/test/types/TestFilterAndExceptionMapper.java
new file mode 100644
index 0000000..89cf88c
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/TestFilterAndExceptionMapper.java
@@ -0,0 +1,53 @@
+/*
+ * 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 test.types;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.util.Collections;
+
+public class TestFilterAndExceptionMapper implements
+    ContainerResponseFilter,
+    ExceptionMapper<TestFilterAndExceptionMapper.MyException> {
+
+    @Override
+    public void filter(
+        ContainerRequestContext requestContext,
+        ContainerResponseContext responseContext) throws IOException {
+
+        MultivaluedMap<String, Object> headers = responseContext.getHeaders();
+
+        headers.put("Filtered", Collections.singletonList("true"));
+    }
+
+    @Override
+    public Response toResponse(MyException e) {
+        return Response.ok().entity("This is fine").build();
+    }
+
+    public static class MyException extends RuntimeException {
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/432486ac/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
index 02e1b73..a2f5b25 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
@@ -149,7 +149,7 @@ public class Whiteboard {
     }
 
     private static OSGi<Void> ignore(OSGi<?> program) {
-        return program.map(t -> { return null;});
+        return program.map(t -> null);
     }
 
     private static OSGi<Collection<String>> bestEffortCalculationOfEnpoints(Filter filter) {