public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) { String errorMessage; switch (statusCode) { case 400: errorMessage = "BadRequest"; break; case 403: errorMessage = "Forbidden"; break; case 404: errorMessage = "NotFound"; break; default: errorMessage = "OtherClientError"; } HashMap<String, Object> errorResult = new HashMap<String, Object>() { { put("Message", "Client error occurred."); put("ExceptionMessage", errorMessage); } }; return CompletableFuture.completedFuture( Results.status(statusCode, toJson(errorResult)) ); }
public RaygunPlayJavaRequestHeaderMessage(RequestHeader javaRequestHeader) { try { hostName = javaRequestHeader.host(); url = javaRequestHeader.uri(); httpMethod = javaRequestHeader.method(); ipAddress = javaRequestHeader.remoteAddress(); if (!javaRequestHeader.queryString().isEmpty()) { queryString = flattenMap(javaRequestHeader.queryString()); } headers = flattenMap(javaRequestHeader.headers()); } catch (Throwable t) { Logger.getLogger("Raygun4Java-Play2").info("Couldn't get all request params: " + t.getMessage()); } }
public CompletionStage<Result> onServerError(RequestHeader request, Throwable e) { if (e instanceof CompletionException) { Throwable cause = e.getCause(); if (cause instanceof ResourceNotFoundException) { return CompletableFuture.completedFuture( Results.notFound(getErrorResponse(cause, true)) ); } else if (cause instanceof InvalidConfigurationException) { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(cause, true)) ); } if (cause instanceof ExternalDependencyException) { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(cause, true)) ); } if (cause instanceof InvalidInputException) { return CompletableFuture.completedFuture( Results.badRequest(getErrorResponse(cause, true)) ); } if (cause instanceof ResourceOutOfDateException) { return CompletableFuture.completedFuture( Results.status(Status.CONFLICT, getErrorResponse(cause, true)) ); } else { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(cause, true)) ); } } else { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(e, true)) ); } }
public CompletionStage<Result> onServerError(RequestHeader request, Throwable e) { if (e instanceof CompletionException) { Throwable cause = e.getCause(); if (cause instanceof ResourceNotFoundException) { return CompletableFuture.completedFuture( Results.notFound(getErrorResponse(cause, true)) ); } else if (cause instanceof InvalidConfigurationException) { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(cause, true)) ); } if (cause instanceof ExternalDependencyException) { return CompletableFuture.completedFuture( Results.status(Status.SERVICE_UNAVAILABLE, getErrorResponse(cause, true)) ); } if (cause instanceof InvalidInputException) { return CompletableFuture.completedFuture( Results.badRequest(getErrorResponse(cause, true)) ); } if (cause instanceof ResourceOutOfDateException) { return CompletableFuture.completedFuture( Results.status(Status.PRECONDITION_FAILED, getErrorResponse(cause, true)) ); } else { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(cause, true)) ); } } else { return CompletableFuture.completedFuture( Results.internalServerError(getErrorResponse(e, true)) ); } }
@Override public CompletionStage<Result> apply( Function<RequestHeader, CompletionStage<Result>> next, RequestHeader requestHeader) { return next.apply(requestHeader).thenApplyAsync( result -> result.withHeader("X-ExampleFilter", "foo"), exec ); }
@Override public Promise<Result> onClientError(RequestHeader requestHeader, int statusCode, String error) { injectCommonServicesIncontext(Http.Context.current()); if (statusCode == play.mvc.Http.Status.NOT_FOUND) { return Promise.promise(new Function0<Result>() { public Result apply() throws Throwable { if (requestHeader.path().startsWith(AbstractApiController.STANDARD_API_ROOT_URI)) { return getApiControllerUtilsService().getJsonErrorResponse(new ApiError(404, "Not found"), Controller.ctx().response()); } else { return play.mvc.Results.notFound(views.html.error.not_found.render(requestHeader.uri())); } } }); } if (statusCode == play.mvc.Http.Status.BAD_REQUEST) { injectCommonServicesIncontext(Http.Context.current()); return Promise.promise(new Function0<Result>() { public Result apply() throws Throwable { if (requestHeader.path().startsWith(AbstractApiController.STANDARD_API_ROOT_URI)) { return getApiControllerUtilsService().getJsonErrorResponse(new ApiError(400, error), Controller.ctx().response()); } else { return play.mvc.Results.badRequest(views.html.error.bad_request.render()); } } }); } return Promise.<Result> pure(play.mvc.Results.status(statusCode, "an unexpected error occured: " + error)); }
@Override public Promise<Result> onServerError(RequestHeader requestHeader, Throwable t) { injectCommonServicesIncontext(Http.Context.current()); return Promise.promise(new Function0<Result>() { public Result apply() throws Throwable { return (Result) ControllersUtils.logAndReturnUnexpectedError((Exception) t, getUserMailIfAvailableInContext(), log, getConfiguration(), getMessagesPlugin()); } }); }
@Override public CompletionStage<Result> apply( Function<RequestHeader, CompletionStage<Result>> next, RequestHeader requestHeader) { return next.apply(requestHeader).thenApplyAsync( result -> result.withHeader("X-ExampleFilter", "foo"), exec); }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { Throwable cause = t.getCause(); if (cause instanceof AuthenticationException || cause instanceof ClientAuthenticationException || cause instanceof ClientRegistrationException) { return Promise.pure(Results.unauthorized()); } else { return Promise.pure(Results.internalServerError()); } }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { Throwable cause = t.getCause(); if (OAuth2Plugin.isAuthenticationError(t)) { return Promise.pure(Results.unauthorized()); } else if (cause instanceof OAuth2Exception) { OAuth2Exception oauth2Exception = (OAuth2Exception) cause; return Promise.pure(Results.status(oauth2Exception.getHttpErrorCode(), oauth2Exception.getMessage())); } else { return super.onError(request, t); } }
@Override public F.Promise<Result> onError (final RequestHeader request, final Throwable t) { final Throwable cause = t != null ? t.getCause () : null; if (cause != null && cause instanceof Domain.DomainAccessException) { // Log the exception using toString so that the exception ID is logged. Logger.error (t.toString (), t); // Extract the exception ID. Unfortunately, there is no API available to get the exception ID // so we rely on toString returning the ID in a certain format. final String msg = t.toString (); final String id; if (msg.startsWith ("@")) { final int offset = msg.indexOf (':'); if (offset > 0) { id = msg.substring (0, offset); } else { id = null; } } else { id = null; } return Promise.pure ((Result) Results.internalServerError (domainAccessException.render (id))); } return null; }
@Override public Handler onRouteRequest(RequestHeader arg0) { LOG.trace("onRouteRequest(RequestHeader arg0)"); if(useCustomRouter) { if(router == null) { throw new RuntimeException("Router is not available"); } return router.dispatch(arg0); } return super.onRouteRequest(arg0); }
protected CompletionStage<Result> onForbidden(RequestHeader request, String message) { return CompletableFuture.completedFuture( Results.forbidden("You're not allowed to access this resource.") ); }
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) { return CompletableFuture.completedFuture( Results.status(statusCode, "A client error occurred: " + message) ); }
public CompletionStage<Result> onServerError(RequestHeader request, Throwable e) { String errorMessage; int errorCode; if (e instanceof DocumentClientException) { DocumentClientException ex = (DocumentClientException) e; errorCode = ex.getStatusCode(); switch (errorCode) { case Status.NOT_FOUND: errorMessage = "The resource requested doesn't exist."; break; case Status.CONFLICT: errorMessage = "There is already a key with the Id specified."; break; case Status.PRECONDITION_FAILED: errorMessage = "ETag mismatch: the resource has been updated by another client."; break; default: errorMessage = ex.getMessage(); break; } } else if (e instanceof BadRequestException) { errorCode = Status.BAD_REQUEST; errorMessage = e.getMessage(); } else { errorCode = Status.INTERNAL_SERVER_ERROR; errorMessage = e.getMessage(); } Map<String, Object> errorResult = new HashMap<>(); errorResult.put("Message", "An error has occurred."); errorResult.put("ExceptionType", e.getClass().getName()); errorResult.put("ExceptionMessage", errorMessage); //No StackTrace. if (false) { errorResult.put("StackTrace", e.getStackTrace()); Throwable innerException = e.getCause(); if (innerException != null) { errorResult.put("InnerExceptionMessage", innerException.getMessage()); errorResult.put("InnerExceptionType", innerException.getClass().getName()); errorResult.put("InnerExceptionStackTrace", innerException.getStackTrace()); } } return CompletableFuture.completedFuture( Results.status(errorCode, toJson(errorResult)) ); }
@Override public Promise<play.mvc.Result> onError(RequestHeader request, Throwable t) { return F.Promise.promise(() -> play.mvc.Results.internalServerError(RestController .errorInJson(new APIError(0, t.getMessage())))); }
@Override public Promise<play.mvc.Result> onHandlerNotFound(RequestHeader request) { return F.Promise.promise(() -> play.mvc.Results.badRequest(RestController .errorInJson(new APIError(0, "Handler not found. Invalid route.")))); }
@Override public Promise<play.mvc.Result> onBadRequest(RequestHeader request, String error) { return F.Promise.promise(() -> play.mvc.Results.badRequest(RestController .errorInJson(new APIError(0, error)))); }
@Override public CompletionStage<Result> apply( Function<RequestHeader, CompletionStage<Result>> next, RequestHeader requestHeader) { return next.apply(requestHeader).thenApplyAsync(result -> result.withHeader("X-ExampleFilter", "foo"), exec); }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.error.render(t))); }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t))); }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { return Promise.<Result> pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t))); }
@Override public Promise<Result> onError(RequestHeader request, Throwable t) { return Promise.pure(Results.badRequest()); }
@Override public Promise<Result> onHandlerNotFound(RequestHeader request) { return Promise.<Result> pure(notFound(views.html.paginaNaoEncontrada.render(request.uri()))); }
@Override public Result onBadRequest(RequestHeader arg0, String arg1) { // TODO Auto-generated method stub return super.onBadRequest(arg0, arg1); }
@Override public Result onError(RequestHeader arg0, Throwable arg1) { // TODO Auto-generated method stub return super.onError(arg0, arg1); }
@Override public Result onHandlerNotFound(RequestHeader arg0) { // TODO Auto-generated method stub return super.onHandlerNotFound(arg0); }