You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2020/01/06 01:08:47 UTC

[GitHub] [cxf] andymc12 opened a new pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

andymc12 opened a new pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621
 
 
   This should resolve at least one of the failing SSE tests (specifically, defaultWaiting1s_from_standalone).  The TCK is very picky about the `isOpen` method - and the behavior of the `SseEventSource` is not terribly intuitive.  While the "state" of the SseEventSource might be CLOSED or CONNECTING, the TCK still expects that the `isOpen` method will return true until it has been explicitly closed (via the `close` method).  I adjusted the unit tests to expect this distinction - but also to continue testing for the proper state of the SseEventSource.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r367183976
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   Thanks @andymc12 , LGTM, good changes!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r367076675
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   The community is in agreement that only one of `onError` or `onComplete` should be invoked (depending on if an error occurred or not), so I'm removing the unnecessary call to `onComplete` in the connect method.
   
   @reta, thanks for the help on this.  Please let me know if you see anything else that might need to change.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r363455700
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   The spec is very vague about this, and I don't remember if there was a TCK test that tests this or not...
   
   The notion of invoking both callbacks was discussed in JAX-RS spec issue [606](https://github.com/eclipse-ee4j/jaxrs-api/issues/606).  I have coded up a clarification to resolve that issue (still waiting on one more committer to review it) - and calling both callbacks would satisfy my write-up (and the issue's original request).
   
   I think the main reason for calling both callbacks is to notify the client of two different states:
   1) an error occurred.
   2) this event source will not receive any more events.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r363136965
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -163,38 +174,43 @@ public void open() {
             throw new IllegalStateException("The SseEventSource is already in " + state.get() + " state");
         }
 
-        // Create the executor for scheduling the reconnect tasks 
+        // Create the executor for scheduling the reconnect tasks
         final Configuration configuration = target.getConfiguration();
         if (executor == null) {
             executor = (ScheduledExecutorService)configuration
                 .getProperty("scheduledExecutorService");
-            
+
             if (executor == null) {
                 executor = Executors.newSingleThreadScheduledExecutor();
                 managedExecutor = false; /* we manage lifecycle */
             }
         }
-        
+
         final Object lastEventId = configuration.getProperty(HttpHeaders.LAST_EVENT_ID_HEADER);
         connect(lastEventId != null ? lastEventId.toString() : null);
+        // If a 503 was receieved during connect we might be in the "Connecting" state,  however
+        // the isOpened flag will need to be set indicating that the eventsource has been opened
+        // and not yet closed.
+        isOpened = true;
     }
 
     private void connect(String lastEventId) {
         final InboundSseEventListenerDelegate delegate = new InboundSseEventListenerDelegate();
         Response response = null;
-        
+
         try {
             Invocation.Builder builder = target.request(MediaType.SERVER_SENT_EVENTS);
             if (lastEventId != null) {
                 builder.header(HttpHeaders.LAST_EVENT_ID_HEADER, lastEventId);
             }
             response = builder.get();
 
-            // A client can be told to stop reconnecting using the HTTP 204 No Content 
+            // A client can be told to stop reconnecting using the HTTP 204 No Content
             // response code. In this case, we should give up.
             final int status = response.getStatus();
             if (status == 204) {
                 LOG.fine("SSE endpoint " + target.getUri() + " returns no data, disconnecting");
+                delegate.onComplete();
 
 Review comment:
   :+1: 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r363455918
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -44,65 +52,69 @@
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 
 /**
- * SSE Event Source implementation 
+ * SSE Event Source implementation
  */
 public class SseEventSourceImpl implements SseEventSource {
     private static final Logger LOG = LogUtils.getL7dLogger(SseEventSourceImpl.class);
-    
+
     private final WebTarget target;
     private final Collection<InboundSseEventListener> listeners = new CopyOnWriteArrayList<>();
     private final AtomicReference<SseSourceState> state = new AtomicReference<>(SseSourceState.CLOSED);
-    
+
     // It may happen that open() and close() could be called on separate threads
     private volatile ScheduledExecutorService executor;
     private volatile boolean managedExecutor = true;
-    private volatile InboundSseEventProcessor processor; 
-    private volatile TimeUnit unit;
+    private volatile InboundSseEventProcessor processor;
+    // delay here is always in Milliseconds - conversion takes place in the ctor
     private volatile long delay;
+    // Indicates the this SseEventSource has been opened. It will remain true even if this is moved back to the
+    // connecting state due to a scheduled reconnect.
+    private volatile boolean isOpened;
 
 Review comment:
   Sure, I can change that.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r363136925
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   Calling 2 callbacks at the same time seems to be a problem, either success (onComplete) or failure (onError) is expected, right?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r364500050
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   Sorry for the delay @andymc12 , just went over the discussion threads, indeed the JAX-RS spec is not very clear regarding the callback. As far as I remember, the initial SSE spec draft was based on Reactive Streams (basically by copy/pasting Java 9's Flow & family). The Reactive Streams specs is very clear:
    - onError: unrecoverable error & no more events (failed terminal state)
    - onComplete: normal completion & no more events (successful terminal state)
   
   Projecting it to SSE:
    - onError: consumer is invoked invoked upon a unrecoverable error encountered  (failed terminal state)
    - onComplete callback is invoked when there are no further events to be received (successful terminal state)
   
   I have checked Jersey, the reference implementation, and it strictly follows this semantics, so does the CXF's current implementation. I would strongly advocate for sticking to the same semantics: it is widely accepted and understood. 
   
   But you are very right by raising https://github.com/eclipse-ee4j/jaxrs-api/issues/606 and https://github.com/eclipse-ee4j/jaxrs-api/pull/670, the spec is not clear and leaves the space for different interpretations. 
   
   For me as a developer, the expectation would be to receive either `onError` or `onComplete`, but not both. 
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r365067085
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   Thanks a lot @andymc12. Yes, I would personally prefer to stick with the more Flow-like behavior (we actually do have one of the SSE examples using RxJava 2 under the hood), it's semantics is well understood (now part of JDK even), thank you. 
   
   To be honest, I would be happy to join JAX-RS spec community and be more informed of what is coming (unfortunately that only fits into my spare time), thank you! 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
reta commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r363137022
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -44,65 +52,69 @@
 import org.apache.cxf.jaxrs.utils.ExceptionUtils;
 
 /**
- * SSE Event Source implementation 
+ * SSE Event Source implementation
  */
 public class SseEventSourceImpl implements SseEventSource {
     private static final Logger LOG = LogUtils.getL7dLogger(SseEventSourceImpl.class);
-    
+
     private final WebTarget target;
     private final Collection<InboundSseEventListener> listeners = new CopyOnWriteArrayList<>();
     private final AtomicReference<SseSourceState> state = new AtomicReference<>(SseSourceState.CLOSED);
-    
+
     // It may happen that open() and close() could be called on separate threads
     private volatile ScheduledExecutorService executor;
     private volatile boolean managedExecutor = true;
-    private volatile InboundSseEventProcessor processor; 
-    private volatile TimeUnit unit;
+    private volatile InboundSseEventProcessor processor;
+    // delay here is always in Milliseconds - conversion takes place in the ctor
     private volatile long delay;
+    // Indicates the this SseEventSource has been opened. It will remain true even if this is moved back to the
+    // connecting state due to a scheduled reconnect.
+    private volatile boolean isOpened;
 
 Review comment:
   Minor, may be just `opened` would be OK?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] andymc12 commented on issue #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
andymc12 commented on issue #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#issuecomment-574937769
 
 
   Thanks for the approval - it looks like these changes may be causing some systest failures - some of them seem unrelated, but others are in the SSE bucket - I'll investigate a little more - it's possible I may need to tweak the tests.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [cxf] andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests

Posted by GitBox <gi...@apache.org>.
andymc12 commented on a change in pull request #621: CXF-7996: TCK Fixes for SSE reconnect state tests
URL: https://github.com/apache/cxf/pull/621#discussion_r364996230
 
 

 ##########
 File path: rt/rs/sse/src/main/java/org/apache/cxf/jaxrs/sse/client/SseEventSourceImpl.java
 ##########
 @@ -206,36 +222,86 @@ private void connect(String lastEventId) {
                 throw ExceptionUtils.toWebApplicationException(response);
             }
 
+            // A client can be told to trigger a reconnect delay via a HTTP 503 Service Unavailable response code.
+            if (status == 503) {
+                LOG.fine("SSE endpoint " + target.getUri() + " returns 503");
+                MultivaluedMap<String, Object> headerMap = response.getHeaders();
+                // There should only be one header entry
+                Object retryAfter = headerMap.getFirst(HttpHeaders.RETRY_AFTER);
+                if (retryAfter != null) {
+                    long retryAfterDelay = handleRetry((String) retryAfter);
+                    delay = retryAfterDelay;
+                    if (retryAfterDelay > -1) {
+                        scheduleReconnect(retryAfterDelay, lastEventId);
+                        response.close();
+                        return;
+                    }
+
+                }
+            }
+
+            String contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
+            if (status != 200 || !MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                if (LOG.isLoggable(Level.FINEST)) {
+                    LOG.log(Level.FINEST, "Received " + status + " Content-Type=" + contentType);
+                }
+                final Response fResponse = response;
+                Throwable t;
+                if (!MediaType.SERVER_SENT_EVENTS.equals(contentType)) {
+                    t = new WebApplicationException("Unexpected Content-Type in response", response);
+                } else {
+                    t = AccessController.doPrivileged((PrivilegedExceptionAction<Throwable>) () -> {
+                        @SuppressWarnings("unchecked")
+                        Class<? extends Throwable> throwableClass = (Class<? extends Throwable>) ExceptionUtils
+                                .getWebApplicationExceptionClass(fResponse, WebApplicationException.class);
+                        Constructor<? extends Throwable> ctor;
+                        try {
+                            ctor = throwableClass.getConstructor(Response.class);
+                        } catch (NoSuchMethodException ex) {
+                            ctor = null;
+                        }
+                        return ctor == null ? throwableClass.newInstance() : ctor.newInstance(fResponse);
+                    });
+                }
+
+                delegate.onError(t);
+                delegate.onComplete();
 
 Review comment:
   No problem @reta - I think this is a good discussion, and I don't have any urgent need to merge it (my comments in the mail list were just to call attention that this change might not be included in 3.3.5, but that should be fine).
   
   It would be nice if the JAX-RS spec was consistent with the Flow APIs.  The clarification that I put in with https://github.com/eclipse-ee4j/jaxrs-api/pull/670 came about from recommendations from the RestEasy folks - so I assume that they already call both callbacks.  I can see value in both approaches.
   
   Since neither approach is specified in the existing JAX-RS (2.X) specs, would you prefer to stick with the more Flow-like behavior, and then try to change the JAX-RS 3.X API clarification to indicate only one callback should be called?  The risk with that is that if the JAX-RS spec community wants to leave it as is with 670 then CXF will need to have different behavior for JAX-RS 3.X as it would in JAX-RS 2.1.  I'm fine either way.
   
   Thanks again for the thorough review!  On a related note - do you have any interest in joining the JAX-RS spec community?  I think it would definitely help to have more Apache representation there.  

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services