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:
[email protected]


With regards,
Apache Git Services

Reply via email to