Refine search
private WebApplicationException createExceptionForFamily(final Response response, final Response.Status.Family statusFamily) { final WebApplicationException webAppException; switch (statusFamily) { case REDIRECTION: webAppException = new RedirectionException(response); break; case CLIENT_ERROR: webAppException = new ClientErrorException(response); break; case SERVER_ERROR: webAppException = new ServerErrorException(response); break; default: webAppException = new WebApplicationException(response); } return webAppException; }
/** * Construct a new server error exception. * * @param status server error status. Must be a {@code 5xx} status code. * @param cause the underlying cause of the exception. * @throws IllegalArgumentException in case the status code is not a valid HTTP status code or * if it is not from the {@link javax.ws.rs.core.Response.Status.Family#SERVER_ERROR} * status code family. */ public ServerErrorException(int status, Throwable cause) { super(cause, validate(Response.status(status).build(), Response.Status.Family.SERVER_ERROR)); }
@GET @Path("/api/logs/{attempt_id}/upload_handle") public DirectUploadHandle getFileHandles( @PathParam("attempt_id") long attemptId, @QueryParam("task") String taskName, @QueryParam("file_time") long unixFileTime, @QueryParam("node_id") String nodeId) throws ResourceNotFoundException { return tm.begin(() -> { // TODO null check taskName // TODO null check nodeId LogFilePrefix prefix = getPrefix(attemptId); Optional<DirectUploadHandle> handle = logServer.getDirectUploadHandle(prefix, taskName, Instant.ofEpochSecond(unixFileTime), nodeId); if (handle.isPresent()) { return handle.get(); } else { throw new ServerErrorException( Response.status(Response.Status.NOT_IMPLEMENTED) .type("application/json") .entity("{\"message\":\"Direct upload handle is not available for this log server implementation\",\"status\":501}") .build()); } }, ResourceNotFoundException.class); }
final int status = response.getStatus(); switch (status) throw new ClientErrorException(response); if (status >= 500) throw new ServerErrorException(response);
private Message getMessageFromHttpResponse(Response response) throws Exception { if (response.getStatus() != Status.OK.getStatusCode()) { if (response.getStatus() >= 500) { throw new ServerErrorException(response); } else if (response.getStatus() >= 400) { throw new ClientErrorException(response); } else {
@Test public void testServerWebApplicationExceptionWithProxy() throws Exception { BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); try { store.throwException(); fail("Exception expected"); } catch (ServerErrorException ex) { assertEquals(500, ex.getResponse().getStatus()); assertEquals("This is a WebApplicationException", ex.getResponse().readEntity(String.class)); } }
public <T> void read(Response response, Callback<T> callback, TypeReference<T> type) throws IOException { try { final int sc = response.getStatus(); switch(sc) { case 201: case 204: LOG.debug("Return code is {}, finishing.", response.getStatus()); return; case 200: try (final JsonParser jp = mapper.getFactory().createParser(response.readEntity(InputStream.class))) { doRead(callback, type, jp); } return; default: if (sc >= 400 && sc < 500) { throw new ClientErrorException(response); } throw new ServerErrorException(response); } } finally { response.close(); } }
public PulsarAdminException(ServerErrorException e, String message) { super(message, e); this.httpError = e.getMessage(); this.statusCode = e.getResponse().getStatus(); }
public PulsarAdminException(ServerErrorException e, String message) { super(message, e); this.httpError = getReasonFromServer(e); this.statusCode = e.getResponse().getStatus(); }
Response response = ((ServerErrorException) e.getCause()).getResponse(); String readEntity = response.readEntity(String.class); ExceptionMessage serverException = JsonUtil.fromJson(readEntity.replace("\r", "").replace("\n", ""), ExceptionMessage.class);
throw new ServerErrorException("Destination was not a valid resource path", BAD_GATEWAY); } else if (nodeService.exists(session.getFedoraSession(), destination)) { throw new ClientErrorException("Destination resource already exists", PRECONDITION_FAILED); session.commit(); return created(new URI(destinationUri)).build(); } catch (final RepositoryRuntimeException e) { final Throwable cause = e.getCause();
@Override public Response toResponse(final ServerErrorException e) { debugException(this, e, LOGGER); return fromResponse(e.getResponse()).entity(e.getMessage()).type(TEXT_PLAIN_WITH_CHARSET).build(); } }
/** * Construct a new server error exception. * * @param response server error response. Must have a status code set to a {@code 5xx} * status code. * @param cause the underlying cause of the exception. * @throws IllegalArgumentException in case the response status code is not from the * {@link javax.ws.rs.core.Response.Status.Family#SERVER_ERROR} status code family. */ public ServerErrorException(Response response, Throwable cause) { super(cause, validate(response, Response.Status.Family.SERVER_ERROR)); }
@Test public void shouldTimeoutGetIfNoResponseIsFound() { final Client client = ClientBuilder.newClient(); //Start the rest interface rest = new OrdersService("localhost"); rest.start(CLUSTER.bootstrapServers(), TestUtils.tempDirectory().getPath()); Paths paths = new Paths("localhost", rest.port()); //Then GET order should timeout try { client.target(paths.urlGet(1)) .queryParam("timeout", 100) //Lower the request timeout .request(APPLICATION_JSON_TYPE) .get(new GenericType<OrderBean>() { }); fail("Request should have failed as materialized view has not been updated"); } catch (ServerErrorException e) { assertThat(e.getMessage()).isEqualTo("HTTP 504 Gateway Timeout"); } }
/** * Construct a new server error exception. * * @param status server error status. Must be a {@code 5xx} status code. * @throws IllegalArgumentException in case the status code is not a valid HTTP status code or * if it is not from the {@link javax.ws.rs.core.Response.Status.Family#SERVER_ERROR} * status code family. */ public ServerErrorException(int status) { super((Throwable) null, validate(Response.status(status).build(), Response.Status.Family.SERVER_ERROR)); }
String msg = what + " vertex ID " + id + " in execution " + executionID + "; " + ex.getMessage(); final String body = RestUtil.formatErrorJson(msg); final Response response = Response.status(Response.Status.BAD_REQUEST).entity(body).header("X-Windup-Error", msg).build(); throw new BadRequestException(msg, response, ex); if (cause instanceof PermanentBackendException) msg = "Backend database permanent error: "; throw new ServerErrorException(msg + ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR, ex);
public static WebApplicationException toHttpException(Throwable cause, Response response) { if (response == null) { throw new WebApplicationException(cause); } throw response.getStatus() >= 500 ? new ServerErrorException(response, cause) : new ClientErrorException(response, cause); }
private List<Message<byte[]>> getMessageFromHttpResponse(String topic, Response response) throws Exception { if (response.getStatus() != Status.OK.getStatusCode()) { if (response.getStatus() >= 500) { throw new ServerErrorException(response); } else if (response.getStatus() >= 400) { throw new ClientErrorException(response); } else {
@Test public void testServerWebApplicationException() throws Exception { WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception"); wc.accept("application/xml"); try { wc.get(Book.class); fail("Exception expected"); } catch (ServerErrorException ex) { assertEquals(500, ex.getResponse().getStatus()); assertEquals("This is a WebApplicationException", ex.getResponse().readEntity(String.class)); } }
public PulsarAdminException(ServerErrorException e) { super(getReasonFromServer(e), e); this.httpError = e.getMessage(); this.statusCode = e.getResponse().getStatus(); }