Search in sources :

Example 11 with ServiceUnavailableException

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;
}
Also used : EventOutput(org.glassfish.jersey.media.sse.EventOutput) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with ServiceUnavailableException

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());
}
Also used : ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Test(org.junit.jupiter.api.Test)

Example 13 with ServiceUnavailableException

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());
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Test(org.junit.jupiter.api.Test)

Example 14 with ServiceUnavailableException

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);
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException)

Example 15 with ServiceUnavailableException

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);
    }
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) NotAllowedException(javax.ws.rs.NotAllowedException) WebApplicationException(javax.ws.rs.WebApplicationException) Status(javax.ws.rs.core.Response.Status) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) ServiceUnavailableException(javax.ws.rs.ServiceUnavailableException) Response(javax.ws.rs.core.Response) NotAcceptableException(javax.ws.rs.NotAcceptableException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) RedirectionException(javax.ws.rs.RedirectionException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) ServerErrorException(javax.ws.rs.ServerErrorException) NotSupportedException(javax.ws.rs.NotSupportedException)

Aggregations

ServiceUnavailableException (javax.ws.rs.ServiceUnavailableException)38 NotFoundException (javax.ws.rs.NotFoundException)16 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 BadRequestException (javax.ws.rs.BadRequestException)12 Response (javax.ws.rs.core.Response)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 ForbiddenException (javax.ws.rs.ForbiddenException)9 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)8 DataFile (edu.harvard.iq.dataverse.DataFile)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOException (java.io.IOException)7 Test (org.junit.Test)6 ClientErrorException (javax.ws.rs.ClientErrorException)5 ServerErrorException (javax.ws.rs.ServerErrorException)5 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)4 RedirectionException (javax.ws.rs.RedirectionException)4 CircuitBreakerConfiguration (com.oracle.bmc.circuitbreaker.CircuitBreakerConfiguration)3 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)3