本文整理汇总了Java中play.mvc.Http.RequestHeader类的典型用法代码示例。如果您正苦于以下问题:Java RequestHeader类的具体用法?Java RequestHeader怎么用?Java RequestHeader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestHeader类属于play.mvc.Http包,在下文中一共展示了RequestHeader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClientError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
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))
);
}
示例2: RaygunPlayJavaRequestHeaderMessage
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
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());
}
}
示例3: onServerError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
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))
);
}
}
示例4: onServerError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
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))
);
}
}
示例5: apply
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@Override
public CompletionStage<Result> apply(
Function<RequestHeader, CompletionStage<Result>> next,
RequestHeader requestHeader) {
return next.apply(requestHeader).thenApplyAsync(
result -> result.withHeader("X-ExampleFilter", "foo"),
exec
);
}
示例6: onClientError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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));
}
示例7: onServerError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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());
}
});
}
示例8: apply
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@Override
public CompletionStage<Result> apply(
Function<RequestHeader, CompletionStage<Result>> next,
RequestHeader requestHeader) {
return next.apply(requestHeader).thenApplyAsync(
result -> result.withHeader("X-ExampleFilter", "foo"),
exec);
}
示例9: onError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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());
}
}
示例10: onError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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);
}
}
示例11: onError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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;
}
示例12: onRouteRequest
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
@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);
}
示例13: onForbidden
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
protected CompletionStage<Result> onForbidden(RequestHeader request, String message) {
return CompletableFuture.completedFuture(
Results.forbidden("You're not allowed to access this resource.")
);
}
示例14: onClientError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
return CompletableFuture.completedFuture(
Results.status(statusCode, "A client error occurred: " + message)
);
}
示例15: onServerError
import play.mvc.Http.RequestHeader; //导入依赖的package包/类
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))
);
}