Java 类play.mvc.Http.RequestHeader 实例源码

项目:pcs-storage-adapter-java    文件:ErrorHandler.java   
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))
    );
}
项目:raygun4java    文件:RaygunPlayJavaRequestHeaderMessage.java   
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());
    }
}
项目:device-telemetry-java    文件:ErrorHandler.java   
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))
        );
    }
}
项目:iothub-manager-java    文件:ErrorHandler.java   
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))
        );
    }
}
项目:play-java-spring-data-jpa    文件:ExampleFilter.java   
@Override
public CompletionStage<Result> apply(
    Function<RequestHeader, CompletionStage<Result>> next,
    RequestHeader requestHeader) {

    return next.apply(requestHeader).thenApplyAsync(
        result -> result.withHeader("X-ExampleFilter", "foo"),
        exec
    );
}
项目:maf-desktop-app    文件:MafHttpErrorHandler.java   
@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));
}
项目:maf-desktop-app    文件:MafHttpErrorHandler.java   
@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());
        }
    });
}
项目:play2-maven-test-projects    文件:ExampleFilter.java   
@Override
public CompletionStage<Result> apply(
    Function<RequestHeader, CompletionStage<Result>> next,
    RequestHeader requestHeader) {

    return next.apply(requestHeader).thenApplyAsync(
        result -> result.withHeader("X-ExampleFilter", "foo"),
        exec
    );
}
项目:glowroot    文件:ExampleFilter.java   
@Override
public CompletionStage<Result> apply(
        Function<RequestHeader, CompletionStage<Result>> next,
        RequestHeader requestHeader) {

    return next.apply(requestHeader).thenApplyAsync(
            result -> result.withHeader("X-ExampleFilter", "foo"),
            exec);
}
项目:play-oauth2    文件:Global.java   
@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());
  }
}
项目:play-plugins    文件:OAuth2GlobalSettings.java   
@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);
  }
}
项目:geo-publisher    文件:Global.java   
@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;
  }
项目:playnorm    文件:GlobalSettings.java   
@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);
}
项目:device-telemetry-java    文件:ErrorHandler.java   
protected CompletionStage<Result> onForbidden(RequestHeader request, String message) {
    return CompletableFuture.completedFuture(
        Results.forbidden("You're not allowed to access this resource.")
    );
}
项目:device-telemetry-java    文件:ErrorHandler.java   
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
    return CompletableFuture.completedFuture(
        Results.status(statusCode, "A client error occurred: " + message)
    );
}
项目:pcs-storage-adapter-java    文件:ErrorHandler.java   
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))
    );
}
项目:iothub-manager-java    文件:ErrorHandler.java   
protected CompletionStage<Result> onForbidden(RequestHeader request, String message) {
    return CompletableFuture.completedFuture(
        Results.forbidden("You're not allowed to access this resource.")
    );
}
项目:iothub-manager-java    文件:ErrorHandler.java   
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
    return CompletableFuture.completedFuture(
        Results.status(statusCode, "A client error occurred: " + message)
    );
}
项目:assistance-platform-server    文件:Global.java   
@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()))));
}
项目:assistance-platform-server    文件:Global.java   
@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."))));
}
项目:assistance-platform-server    文件:Global.java   
@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))));
}
项目:ground    文件:GroundFilter.java   
@Override
public CompletionStage<Result> apply(
                                      Function<RequestHeader, CompletionStage<Result>> next, RequestHeader requestHeader) {

  return next.apply(requestHeader).thenApplyAsync(result -> result.withHeader("X-ExampleFilter", "foo"), exec);
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result> pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.error.render(t)));
}
项目:PlayTraining    文件:Global.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
    return Promise.<Result>pure(play.mvc.Results.internalServerError(views.html.bo.error.render(t)));
}
项目:play-plugins    文件:SpringGlobalSettings.java   
@Override
public Promise<Result> onError(RequestHeader request, Throwable t) {
  return Promise.pure(Results.badRequest());
}
项目:play2-casadocodigo    文件:Global.java   
@Override
public Promise<Result> onHandlerNotFound(RequestHeader request) {
    return Promise.<Result> pure(notFound(views.html.paginaNaoEncontrada.render(request.uri())));
}
项目:playnorm    文件:GlobalSettings.java   
@Override
public Result onBadRequest(RequestHeader arg0, String arg1) {
           // TODO Auto-generated method stub
           return super.onBadRequest(arg0, arg1);
}
项目:playnorm    文件:GlobalSettings.java   
@Override
public Result onError(RequestHeader arg0, Throwable arg1) {
           // TODO Auto-generated method stub
           return super.onError(arg0, arg1);
}
项目:playnorm    文件:GlobalSettings.java   
@Override
public Result onHandlerNotFound(RequestHeader arg0) {
           // TODO Auto-generated method stub
           return super.onHandlerNotFound(arg0);
}