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 2019/05/24 15:33:16 UTC

[aries-jax-rs-whiteboard] branch master updated (f97bfc6 -> daed160)

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

csierra pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git.


    from f97bfc6  add missing uses contraints
     new 05a965b  Exclude newly detected package
     new daed160  [ARIES-1916] Add test

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 jax-rs.itests/src/main/java/test/JaxrsTest.java    | 31 +++++++++++++++++
 .../{TestFilter.java => PerRequestTestFilter.java} | 33 +++++++++++-------
 .../java/test/types/PerRequestTestResource.java    | 17 +++++----
 .../src/main/java/test/types/TestHelper.java       | 40 ++++++++++++++++++++++
 jax-rs.whiteboard/bnd.bnd                          |  1 +
 5 files changed, 101 insertions(+), 21 deletions(-)
 copy jax-rs.itests/src/main/java/test/types/{TestFilter.java => PerRequestTestFilter.java} (52%)
 copy jax-rs.whiteboard/src/test/java/test/types/PlainResourceSeveralOperationsCommonPath.java => jax-rs.itests/src/main/java/test/types/PerRequestTestResource.java (80%)


[aries-jax-rs-whiteboard] 02/02: [ARIES-1916] Add test

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git

commit daed1608a2118205d9d7f59f3cb66bb131e89051
Author: Carlos Sierra <cs...@apache.org>
AuthorDate: Fri May 24 17:30:35 2019 +0200

    [ARIES-1916] Add test
---
 jax-rs.itests/src/main/java/test/JaxrsTest.java    | 31 ++++++++++++++
 .../main/java/test/types/PerRequestTestFilter.java | 49 ++++++++++++++++++++++
 .../java/test/types/PerRequestTestResource.java    | 36 ++++++++++++++++
 .../src/main/java/test/types/TestHelper.java       | 40 ++++++++++++++++++
 4 files changed, 156 insertions(+)

diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index 1f61953..63db600 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -75,6 +75,8 @@ import test.types.ConfigurationAwareResource;
 import test.types.CxfExtensionTestAddon;
 import test.types.ExtensionA;
 import test.types.ExtensionB;
+import test.types.PerRequestTestFilter;
+import test.types.PerRequestTestResource;
 import test.types.SSEResource;
 import test.types.TestAddon;
 import test.types.TestAddonConflict;
@@ -96,6 +98,7 @@ import javax.ws.rs.HttpMethod;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Feature;
@@ -1909,6 +1912,34 @@ public class JaxrsTest extends TestHelper {
     }
 
     @Test
+    public void testPerRequestLifecycleAddon() {
+        WebTarget webTarget = createDefaultTarget().path("state");
+
+        assertEquals(0, getRuntimeDTO().applicationDTOs.length);
+        assertEquals(0, getRuntimeDTO().failedApplicationDTOs.length);
+
+        ServiceRegistration<?> serviceRegistration = registerAddon(
+            new PerRequestTestResource());
+
+        assertEquals("original", webTarget.request().get(String.class));
+
+        registerExtension(
+            ContainerRequestFilter.class,
+            new PerRequestTestFilter(), "perrequestfilter");
+
+        assertEquals("original-changed", webTarget.request().get(String.class));
+        assertEquals(
+            "original-changed-changed", webTarget.request().get(String.class));
+
+        serviceRegistration.unregister();
+
+        registerAddonPrototype(PerRequestTestResource::new);
+
+        assertEquals("original-changed", webTarget.request().get(String.class));
+        assertEquals("original-changed", webTarget.request().get(String.class));
+    }
+
+    @Test
     public void testRegisterApplicationWithOnlyExtensions() {
         ServiceRegistration<Application> serviceRegistration =
             registerApplication(new Application() {
diff --git a/jax-rs.itests/src/main/java/test/types/PerRequestTestFilter.java b/jax-rs.itests/src/main/java/test/types/PerRequestTestFilter.java
new file mode 100644
index 0000000..307b3a4
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/PerRequestTestFilter.java
@@ -0,0 +1,49 @@
+/*
+ * 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.ContainerRequestFilter;
+import javax.ws.rs.container.ResourceContext;
+import javax.ws.rs.core.Context;
+import java.io.IOException;
+
+public class PerRequestTestFilter implements ContainerRequestFilter {
+
+    @Override
+    public void filter(ContainerRequestContext requestContext)
+        throws IOException {
+
+        Class<?> matchedResource = (Class<?>)requestContext.
+            getUriInfo().
+            getMatchedResources().
+            get(0);
+
+        Object resource = _resourceContext.getResource(matchedResource);
+
+        if (resource instanceof PerRequestTestResource) {
+            PerRequestTestResource perRequestTestResource =
+                (PerRequestTestResource) resource;
+
+            perRequestTestResource.setState(perRequestTestResource.getState() + "-changed");
+        }
+    }
+
+    @Context
+    private ResourceContext _resourceContext;
+}
diff --git a/jax-rs.itests/src/main/java/test/types/PerRequestTestResource.java b/jax-rs.itests/src/main/java/test/types/PerRequestTestResource.java
new file mode 100644
index 0000000..ac1f5a6
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/PerRequestTestResource.java
@@ -0,0 +1,36 @@
+/*
+ * 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.Path;
+
+public class PerRequestTestResource {
+
+    private String _state = "original";
+
+    @GET
+    @Path("/state")
+    public String getState() {
+        return _state;
+    }
+
+    public void setState(String state) {
+        _state = state;
+    }
+}
diff --git a/jax-rs.itests/src/main/java/test/types/TestHelper.java b/jax-rs.itests/src/main/java/test/types/TestHelper.java
index e4bd084..7dc069f 100644
--- a/jax-rs.itests/src/main/java/test/types/TestHelper.java
+++ b/jax-rs.itests/src/main/java/test/types/TestHelper.java
@@ -53,6 +53,7 @@ import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.function.Function;
 import java.util.function.Predicate;
+import java.util.function.Supplier;
 
 public class TestHelper {
 
@@ -245,6 +246,45 @@ public class TestHelper {
         return serviceRegistration;
     }
 
+    protected ServiceRegistration<?> registerAddonPrototype(
+        Supplier<?> supplier, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_RESOURCE, "true");
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        PrototypeServiceFactory<Object> prototypeServiceFactory =
+            new PrototypeServiceFactory<Object>() {
+                @Override
+                public Object getService(
+                    Bundle bundle,
+                    ServiceRegistration<Object> registration) {
+
+                    return supplier.get();
+                }
+
+                @Override
+                public void ungetService(
+                    Bundle bundle, ServiceRegistration<Object> registration,
+                    Object service) {
+
+                }
+            };
+
+        ServiceRegistration<?> serviceRegistration =
+            bundleContext.registerService(
+                Object.class, (ServiceFactory<?>) prototypeServiceFactory,
+                properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
     protected ServiceRegistration<?> registerAddonLifecycle(
         boolean singleton, Object... keyValues) {
 


[aries-jax-rs-whiteboard] 01/02: Exclude newly detected package

Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git

commit 05a965bbd7d13d945b7c4dfe1ed338883b356941
Author: Carlos Sierra <cs...@apache.org>
AuthorDate: Fri May 24 16:07:11 2019 +0200

    Exclude newly detected package
---
 jax-rs.whiteboard/bnd.bnd | 1 +
 1 file changed, 1 insertion(+)

diff --git a/jax-rs.whiteboard/bnd.bnd b/jax-rs.whiteboard/bnd.bnd
index f38a1d9..26d280e 100644
--- a/jax-rs.whiteboard/bnd.bnd
+++ b/jax-rs.whiteboard/bnd.bnd
@@ -45,6 +45,7 @@ Import-Package:\
     !org.osgi.service.blueprint.*,\
     !org.osgi.service.http,\
     !org.relaxng.datatype.*,\
+    !org.slf4j.impl.*,\
     !org.slf4j.spi.*,\
     !org.springframework.*,\
     !sun.misc,\