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:
[email protected]
With regards,
Apache Git Services