You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2019/09/27 00:27:49 UTC

[cxf] branch 3.2.x-fixes updated (10515e7 -> 9532ab1)

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

reta pushed a change to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from 10515e7  Recording .gitmergeinfo Changes
     new aa81997  CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException
     new 85e4e85  Recording .gitmergeinfo Changes
     new 9532ab1  CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException. Fixing test cases

The 3 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:
 .gitmergeinfo                                      |  5 ++++
 .../org/apache/cxf/jaxrs/utils/ExceptionUtils.java | 12 ++++++++
 .../apache/cxf/jaxrs/client/AbstractClient.java    | 10 +------
 .../cxf/jaxrs/sse/client/SseEventSourceImpl.java   | 10 ++++++-
 .../jaxrs/sse/client/SseEventSourceImplTest.java   | 32 ++++++++++++++++++++++
 5 files changed, 59 insertions(+), 10 deletions(-)


[cxf] 01/03: CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit aa81997eb1403418b6a174b1c8410370512e3ac1
Author: reta <dr...@gmail.com>
AuthorDate: Sun Sep 22 12:26:32 2019 -0400

    CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException
    
    (cherry picked from commit 88e3eb24de7ee6498240aac557ccf3d75a1be9af)
    (cherry picked from commit 1a4505c09fa403262a54e0fa745edf78a8c3ba0c)
    
    # Conflicts:
    #	rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
---
 .../org/apache/cxf/jaxrs/utils/ExceptionUtils.java | 12 ++++++++
 .../apache/cxf/jaxrs/client/AbstractClient.java    | 10 +------
 .../cxf/jaxrs/sse/client/SseEventSourceImpl.java   | 10 ++++++-
 .../jaxrs/sse/client/SseEventSourceImplTest.java   | 32 ++++++++++++++++++++++
 4 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
index 5e8b014..a8c607a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ExceptionUtils.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.utils;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.reflect.Constructor;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
@@ -169,4 +170,15 @@ public final class ExceptionUtils {
             return toWebApplicationException(ex, response);
         }
     }
+    
+    public static WebApplicationException toWebApplicationException(Response response) {
+        try {
+            final Class<?> exceptionClass = ExceptionUtils.getWebApplicationExceptionClass(response, 
+                WebApplicationException.class);
+            final Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
+            return (WebApplicationException)ctr.newInstance(response);
+        } catch (Throwable ex) {
+            return new WebApplicationException(response);
+        }
+    }
 }
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index 01d448c..4090293 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -23,7 +23,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
@@ -537,14 +536,7 @@ public abstract class AbstractClient implements Client {
     }
 
     protected WebApplicationException convertToWebApplicationException(Response r) {
-        try {
-            Class<?> exceptionClass = ExceptionUtils.getWebApplicationExceptionClass(r,
-                                       WebApplicationException.class);
-            Constructor<?> ctr = exceptionClass.getConstructor(Response.class);
-            return (WebApplicationException)ctr.newInstance(r);
-        } catch (Throwable ex2) {
-            return new WebApplicationException(r);
-        }
+        return ExceptionUtils.toWebApplicationException(r);
     }
 
     protected <T> T readBody(Response r, Message outMessage, Class<T> cls,
diff --git a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
index 3a7f78e..f0c2acf 100644
--- a/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
+++ b/rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
@@ -41,6 +41,7 @@ import javax.ws.rs.sse.SseEventSource;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 
 /**
  * SSE Event Source implementation 
@@ -191,13 +192,20 @@ public class SseEventSourceImpl implements SseEventSource {
 
             // A client can be told to stop reconnecting using the HTTP 204 No Content 
             // response code. In this case, we should give up.
-            if (response.getStatus() == 204) {
+            final int status = response.getStatus();
+            if (status == 204) {
                 LOG.fine("SSE endpoint " + target.getUri() + " returns no data, disconnecting");
                 state.set(SseSourceState.CLOSED);
                 response.close();
                 return;
             }
 
+            // Convert unsuccessful responses to instances of WebApplicationException
+            if (status != 304 && status >= 300) {
+                LOG.fine("SSE connection to " + target.getUri() + " returns " + status);
+                throw ExceptionUtils.toWebApplicationException(response);
+            }
+
             // Should not happen but if close() was called from another thread, we could
             // end up there.
             if (state.get() == SseSourceState.CLOSED) {
diff --git a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
index 176dc14..635f432 100644
--- a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
+++ b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
@@ -389,6 +389,38 @@ public class SseEventSourceImplTest extends Assert {
     }
     
     @Test
+    public void testReconnectAndNotAuthorized() throws InterruptedException, IOException {
+        when(response.getStatus()).thenReturn(401);
+        
+        try (SseEventSource eventSource = withReconnect()) {
+            eventSource.open();
+            assertThat(eventSource.isOpen(), equalTo(false));
+            verify(response, times(1)).getStatus();
+
+            // Allow the event processor to pull for events (150ms)
+            Thread.sleep(150L);
+        }
+        
+        verify(response, times(2)).getStatus();
+    }
+
+    @Test
+    public void testNoReconnectAndNotAuthorized() throws InterruptedException, IOException {
+        when(response.getStatus()).thenReturn(401);
+        
+        try (SseEventSource eventSource = withNoReconnect()) {
+            eventSource.open();
+            assertThat(eventSource.isOpen(), equalTo(false));
+            verify(response, times(1)).getStatus();
+
+            // Allow the event processor to pull for events (150ms)
+            Thread.sleep(150L);
+        }
+        
+        verify(response, times(1)).getStatus();
+    }
+
+    @Test
     public void testNoReconnectAndCloseTheStreamWhileEventIsBeingReceived() throws InterruptedException, IOException {
         when(response.getStatus()).thenReturn(200);
         when(response.readEntity(InputStream.class)).then(invocation -> {


[cxf] 03/03: CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException. Fixing test cases

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 9532ab1108e996ffb113a6d79f6e6e8d1a08b377
Author: reta <dr...@gmail.com>
AuthorDate: Thu Sep 26 20:27:30 2019 -0400

    CXF-8120: JAX-RS 2.1 SSE client: forbidden response without WebApplicationException. Fixing test cases
---
 .../org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
index 635f432..a06c650 100644
--- a/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
+++ b/rt/rs/sse/src/test/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImplTest.java
@@ -395,13 +395,13 @@ public class SseEventSourceImplTest extends Assert {
         try (SseEventSource eventSource = withReconnect()) {
             eventSource.open();
             assertThat(eventSource.isOpen(), equalTo(false));
-            verify(response, times(1)).getStatus();
+            verify(response, times(3)).getStatus();
 
             // Allow the event processor to pull for events (150ms)
             Thread.sleep(150L);
         }
         
-        verify(response, times(2)).getStatus();
+        verify(response, times(6)).getStatus();
     }
 
     @Test
@@ -411,13 +411,13 @@ public class SseEventSourceImplTest extends Assert {
         try (SseEventSource eventSource = withNoReconnect()) {
             eventSource.open();
             assertThat(eventSource.isOpen(), equalTo(false));
-            verify(response, times(1)).getStatus();
+            verify(response, times(3)).getStatus();
 
             // Allow the event processor to pull for events (150ms)
             Thread.sleep(150L);
         }
         
-        verify(response, times(1)).getStatus();
+        verify(response, times(3)).getStatus();
     }
 
     @Test


[cxf] 02/03: Recording .gitmergeinfo Changes

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 85e4e855b7b4b90c6a246d28398cc8dd4bc77b5b
Author: reta <dr...@gmail.com>
AuthorDate: Wed Sep 25 22:22:36 2019 -0400

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 8c86ede..bbc4327 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -673,9 +673,12 @@ M 13772a327098239e468c6b04b24afc92afd4cebd
 M 1449f125586deaf6f5d87e282f0e1502eef4b6b4
 M 15982b9496d0909ffa37e895a48c8428464196c9
 M 182d5c91002425fd79c6c62c0318a554fb8cecac
+M 1a4505c09fa403262a54e0fa745edf78a8c3ba0c
 M 1cc03b9b70bc509d8f8c631563c3964e56e30621
 M 1cdf673a8ce2fc5c57318d1a102ca0923cb1d945
 M 1f0468398ddb21ecaf6b6eda370e3464e402ef8a
+M 26f3e944a56b79ac2e30286c61b3fab6d4bab638
+M 2dd0450422b5952b15ddab15b7f40dee499bc1a5
 M 34473b533d14ca0c4e5ba24e3d92b0d5f402973a
 M 37537350f8c56635902b6566dc94bec19a4e19c3
 M 3904a477e70fe6385777120bfe4820ff9a7713f3
@@ -701,6 +704,7 @@ M 58cc0cd69c4274cb1bbff531107ff2db6f434d67
 M 5cef96612ccae5cce36e0b7802c1c866aa7226f5
 M 5cfbdfeb59581514f3b2773abdca57728e19fdad
 M 6b8b33acde5eb94ca84121591c68eb3e5e7b294f
+M 7233ba20684c3e8f20bf363647c028b2f406f08c
 M 74e7684b76dfa03310f30a0dc520f61b4a6fa1b3
 M 77b0819893e6c18806c8c6b7c07313d29e75e7eb
 M 7808ae48865df413346f523ca6e8df7bcedb2091
@@ -727,6 +731,7 @@ M ac561c4a2b27bd8b427ff1f91d19c7929a8222ab
 M ad5c6ad246f9155fec7096de7701de02d757c0f2
 M af6a95f5b7efc141cc55792e10d05d471905cf32
 M b9300944381ebe10f7c5fe86d55b25b8292372fd
+M ba4896378eeb0c01152ea09ae0bdd3e123207736
 M c13381d891b56fe5a2b56f6f9f6f6b2cc8a10d5d
 M c3adee999d4464d740f0740e2d5bd497b2b24af2
 M c453a20f958b49119029b229a908f94848fb7f2d