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/10/02 13:11:02 UTC

[1/2] aries-jax-rs-whiteboard git commit: Enable async support

Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master f0dcc9ae5 -> 5629d40f0


Enable async support


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

Branch: refs/heads/master
Commit: 9d1d0617d146a44d996dd033c699a8ae2361e3c8
Parents: f0dcc9a
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Oct 2 15:06:01 2017 +0200
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Oct 2 15:07:12 2017 +0200

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 77 +++++++++++++++-----
 .../main/java/test/types/TestAsyncResource.java | 61 ++++++++++++++++
 .../jax/rs/whiteboard/internal/Whiteboard.java  |  2 +
 3 files changed, 121 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/9d1d0617/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 0e25089..94226d8 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -26,6 +26,9 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.junit.After;
 import org.junit.Test;
@@ -45,10 +48,12 @@ import test.types.TestAddonLifecycle;
 import test.types.TestApplication;
 import test.types.TestApplicationConflict;
 import test.types.TestApplicationWithException;
+import test.types.TestAsyncResource;
 import test.types.TestFilter;
 import test.types.TestFilterAndExceptionMapper;
 import test.types.TestHelper;
 
+import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Application;
@@ -103,25 +108,6 @@ public class JaxrsTest extends TestHelper {
     }
 
     @Test
-    public void testApplicationWithoutStartingSlash()
-        throws InterruptedException {
-
-        assertEquals(0, getRuntimeDTO().applicationDTOs.length);
-
-        registerApplication(
-            new TestApplication(), JAX_RS_APPLICATION_BASE, "test-application");
-
-        assertEquals(1, getRuntimeDTO().applicationDTOs.length);
-
-        WebTarget webTarget = createDefaultTarget().path("/test-application");
-
-        Response response = webTarget.request().get();
-
-        assertEquals("Hello application",
-            response.readEntity(String.class));
-    }
-
-    @Test
     public void testApplicationChangeCount() throws Exception {
         Long changeCount = (Long)_runtimeServiceReference.getProperty(
             "service.changecount");
@@ -641,6 +627,59 @@ public class JaxrsTest extends TestHelper {
     }
 
     @Test
+    public void testApplicationWithoutStartingSlash()
+        throws InterruptedException {
+
+        assertEquals(0, getRuntimeDTO().applicationDTOs.length);
+
+        registerApplication(
+            new TestApplication(), JAX_RS_APPLICATION_BASE, "test-application");
+
+        assertEquals(1, getRuntimeDTO().applicationDTOs.length);
+
+        WebTarget webTarget = createDefaultTarget().path("/test-application");
+
+        Response response = webTarget.request().get();
+
+        assertEquals("Hello application",
+            response.readEntity(String.class));
+    }
+
+    @Test
+    public void testAsyncResource()
+        throws ExecutionException, InterruptedException {
+
+        WebTarget webTarget =
+            createDefaultTarget().path("whiteboard").path("async").
+                path("HelloAsync");
+
+        AtomicBoolean pre = new AtomicBoolean();
+        AtomicBoolean post = new AtomicBoolean();
+
+        registerAddon(
+            new TestAsyncResource(() -> pre.set(true), () -> post.set(true)));
+
+        Future<String> future = webTarget.request().async().get(
+            new InvocationCallback<String>() {
+                @Override
+                public void completed(String s) {
+                    assertTrue(pre.get());
+                }
+
+                @Override
+                public void failed(Throwable throwable) {
+
+                }
+            });
+
+        String result = future.get();
+
+        assertTrue(post.get());
+
+        assertEquals("This should say HelloAsync", "HelloAsync", result);
+    }
+
+    @Test
     public void testEndpointsOverride() {
         WebTarget webTarget = createDefaultTarget().path("conflict");
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/9d1d0617/jax-rs.itests/src/main/java/test/types/TestAsyncResource.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestAsyncResource.java b/jax-rs.itests/src/main/java/test/types/TestAsyncResource.java
new file mode 100644
index 0000000..4297aee
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/TestAsyncResource.java
@@ -0,0 +1,61 @@
+/*
+ * 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;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.container.AsyncResponse;
+import javax.ws.rs.container.Suspended;
+import javax.ws.rs.core.MediaType;
+
+@Path("whiteboard/async")
+public class TestAsyncResource {
+
+    private final Runnable	preResume;
+    private final Runnable postResume;
+
+    public TestAsyncResource(Runnable preResume, Runnable postResume) {
+        this.preResume = preResume;
+        this.postResume = postResume;
+    }
+
+    @GET
+    @Path("{name}")
+    @Produces(MediaType.TEXT_PLAIN)
+    public void echo(@Suspended AsyncResponse async,
+                     @PathParam("name") String value) {
+
+        new Thread(() -> {
+            try {
+                try {
+                    Thread.sleep(1000);
+                } catch (Exception e) {
+                    preResume.run();
+                    async.resume(e);
+                    return;
+                }
+                preResume.run();
+                async.resume(value);
+            } finally {
+                postResume.run();
+            }
+        }).start();
+    }
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/9d1d0617/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 48af331..7af9ec2 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
@@ -89,6 +89,7 @@ import static org.osgi.service.http.runtime.HttpServiceRuntimeConstants.HTTP_SER
 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;
+import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET;
 import static org.osgi.service.jaxrs.runtime.JaxRSServiceRuntimeConstants.JAX_RS_SERVICE_ENDPOINT;
@@ -741,6 +742,7 @@ public class Whiteboard {
         }
 
         properties.putIfAbsent(HTTP_WHITEBOARD_SERVLET_PATTERN, address + "/*");
+        properties.putIfAbsent(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true);
 
         CXFNonSpringServlet cxfNonSpringServlet = createCXFServlet(bus);
 


[2/2] aries-jax-rs-whiteboard git commit: Source cleaning

Posted by cs...@apache.org.
Source cleaning


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

Branch: refs/heads/master
Commit: 5629d40f024de4133cbcf67b995f0181af0c7d51
Parents: 9d1d061
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Oct 2 15:07:32 2017 +0200
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Oct 2 15:07:32 2017 +0200

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5629d40f/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java b/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
index c4388e7..de23987 100644
--- a/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
+++ b/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
@@ -104,8 +104,6 @@ public class WhiteboardFactoryTest extends TestHelper {
         }
     }
 
-
-
     private BundleContext bundleContext =
         FrameworkUtil.getBundle(getClass()).getBundleContext();