use of javax.ws.rs.ServiceUnavailableException in project jersey by eclipse-ee4j.
the class ItemStoreResource method itemEvents.
/**
* Connect or re-connect to SSE event stream.
*
* @param lastEventId Value of custom SSE HTTP <tt>{@value SseFeature#LAST_EVENT_ID_HEADER}</tt> header.
* Defaults to {@code -1} if not set.
* @return new SSE event output stream representing the (re-)established SSE client connection.
* @throws InternalServerErrorException in case replaying missed events to the reconnected output stream fails.
* @throws ServiceUnavailableException in case the reconnect delay is set to a positive value.
*/
@GET
@Path("events")
@Produces(SseFeature.SERVER_SENT_EVENTS)
public EventOutput itemEvents(@HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) @DefaultValue("-1") int lastEventId) {
final EventOutput eventOutput = new EventOutput();
if (lastEventId >= 0) {
LOGGER.info("Received last event id :" + lastEventId);
// decide the reconnect handling strategy based on current reconnect delay value.
final long delay = reconnectDelay;
if (delay > 0) {
LOGGER.info("Non-zero reconnect delay [" + delay + "] - responding with HTTP 503.");
throw new ServiceUnavailableException(delay);
} else {
LOGGER.info("Zero reconnect delay - reconnecting.");
replayMissedEvents(lastEventId, eventOutput);
}
}
if (!broadcaster.add(eventOutput)) {
LOGGER.severe("!!! Unable to add new event output to the broadcaster !!!");
// let's try to force a 5s delayed client reconnect attempt
throw new ServiceUnavailableException(5L);
}
return eventOutput;
}
use of javax.ws.rs.ServiceUnavailableException in project cloudbreak by hortonworks.
the class FreeipaServiceTest method testCheckFreeipaRunningWhenFreeIpaIsNullThenThrowsException.
@Test
void testCheckFreeipaRunningWhenFreeIpaIsNullThenThrowsException() {
when(underTest.describe(ENV_CRN)).thenReturn(null);
ServiceUnavailableException exception = Assertions.assertThrows(ServiceUnavailableException.class, () -> underTest.checkFreeipaRunning(ENV_CRN));
assertEquals("Freeipa availability cannot be determined currently.", exception.getMessage());
}
use of javax.ws.rs.ServiceUnavailableException in project cloudbreak by hortonworks.
the class FreeipaServiceTest method testCheckFreeipaRunningWhenFreeIpaStatusIsNullThenThrowsException.
@Test
void testCheckFreeipaRunningWhenFreeIpaStatusIsNullThenThrowsException() {
DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
when(underTest.describe(ENV_CRN)).thenReturn(freeipa);
ServiceUnavailableException exception = Assertions.assertThrows(ServiceUnavailableException.class, () -> underTest.checkFreeipaRunning(ENV_CRN));
assertEquals("Freeipa availability cannot be determined currently.", exception.getMessage());
}
use of javax.ws.rs.ServiceUnavailableException in project cloudbreak by hortonworks.
the class FreeipaService method checkFreeipaRunning.
public void checkFreeipaRunning(String envCrn) {
DescribeFreeIpaResponse freeipa = describe(envCrn);
if (freeipa != null && freeipa.getAvailabilityStatus() != null) {
if (!freeipa.getAvailabilityStatus().isAvailable()) {
String message = "Freeipa should be in Available state but currently is " + freeipa.getStatus().name();
LOGGER.info(message);
throw new BadRequestException(message);
}
} else {
String message = "Freeipa availability cannot be determined currently.";
LOGGER.warn(message);
throw new ServiceUnavailableException(message);
}
}
use of javax.ws.rs.ServiceUnavailableException in project scout.rt by eclipse-scout.
the class RestClientProxyFactory method convertToWebAppException.
protected WebApplicationException convertToWebAppException(Response response) {
if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
return null;
}
// Buffer and close input stream to release any resources (i.e. memory and connections)
response.bufferEntity();
final Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status != null) {
switch(status) {
case BAD_REQUEST:
return new BadRequestException(response);
case UNAUTHORIZED:
return new NotAuthorizedException(response);
case FORBIDDEN:
return new ForbiddenException(response);
case NOT_FOUND:
return new NotFoundException(response);
case METHOD_NOT_ALLOWED:
return new NotAllowedException(response);
case NOT_ACCEPTABLE:
return new NotAcceptableException(response);
case UNSUPPORTED_MEDIA_TYPE:
return new NotSupportedException(response);
case INTERNAL_SERVER_ERROR:
return new InternalServerErrorException(response);
case SERVICE_UNAVAILABLE:
return new ServiceUnavailableException(response);
}
}
switch(response.getStatusInfo().getFamily()) {
case REDIRECTION:
return new RedirectionException(response);
case CLIENT_ERROR:
return new ClientErrorException(response);
case SERVER_ERROR:
return new ServerErrorException(response);
default:
return new WebApplicationException(response);
}
}
Aggregations