本文整理匯總了Java中play.mvc.Http.RequestHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.RequestHeader方法的具體用法?Java Http.RequestHeader怎麽用?Java Http.RequestHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類play.mvc.Http
的用法示例。
在下文中一共展示了Http.RequestHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getReservationHeaders
import play.mvc.Http; //導入方法依賴的package包/類
private Map<String, String> getReservationHeaders(Http.RequestHeader request, User user) {
Map<String, String> headers = new HashMap<>();
Optional<ExamEnrolment> ongoingEnrolment = getNextEnrolment(user.getId(), 0);
if (ongoingEnrolment.isPresent()) {
handleOngoingEnrolment(ongoingEnrolment.get(), request, headers);
} else {
DateTime now = new DateTime();
int lookAheadMinutes = Minutes.minutesBetween(now, now.plusDays(1).withMillisOfDay(0)).getMinutes();
Optional<ExamEnrolment> upcomingEnrolment = getNextEnrolment(user.getId(), lookAheadMinutes);
if (upcomingEnrolment.isPresent()) {
handleUpcomingEnrolment(upcomingEnrolment.get(), request, headers);
} else if (isOnExamMachine(request)) {
// User is logged on an exam machine but has no exams for today
headers.put("x-exam-upcoming-exam", "none");
}
}
return headers;
}
示例2: onClientError
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> onClientError(Http.RequestHeader request, int statusCode, String message) {
return CompletableFuture.supplyAsync(() -> {
Logger.warn("onClientError: URL: {}, status: {}, msg: {}", request.uri(), statusCode, message);
if (statusCode == play.mvc.Http.Status.BAD_REQUEST) {
return Results.badRequest(Json.toJson(new ApiError(message)));
}
if (statusCode == play.mvc.Http.Status.NOT_FOUND) {
return Results.notFound(Json.toJson(new ApiError(message)));
}
if (statusCode == Http.Status.UNAUTHORIZED || statusCode == Http.Status.FORBIDDEN) {
return Results.unauthorized(Json.toJson(new ApiError(message)));
}
return Results.internalServerError(Json.toJson(new ApiError(message)));
});
}
示例3: onServerError
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> onServerError(Http.RequestHeader request, Throwable exception) {
return CompletableFuture.supplyAsync(() -> {
Throwable cause = exception.getCause();
String errorMessage = cause == null ? exception.getMessage() : cause.getMessage();
Logger.error("onServerError: URL: {}, msg: {}", request.uri(), errorMessage);
exception.printStackTrace();
if (cause != null) {
if (cause instanceof MalformedDataException) {
return Results.badRequest(Json.toJson(errorMessage));
}
if (cause instanceof IllegalArgumentException) {
return Results.badRequest(Json.toJson(new ApiError(errorMessage)));
}
if (cause instanceof OptimisticLockException) {
return Results.badRequest("sitnet_error_data_has_changed");
}
}
return Results.internalServerError(Json.toJson(new ApiError(errorMessage)));
});
}
示例4: apply
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> apply(
Function<Http.RequestHeader, CompletionStage<Result>> nextFilter,
Http.RequestHeader requestHeader) {
long startTime = System.currentTimeMillis();
return nextFilter.apply(requestHeader).thenApply(result -> {
long endTime = System.currentTimeMillis();
long requestTime = endTime - startTime;
if (!requestHeader.uri().contains("assets")) {
Logger.info("{} {} from {} took {}ms and returned {}",
requestHeader.method(), requestHeader.uri(), requestHeader.remoteAddress(), requestTime, result.status());
}
return result;
});
}
示例5: onDevServerError
import play.mvc.Http; //導入方法依賴的package包/類
/**
* Invoked in dev mode when a server error occurs.
*
* @param request The request that triggered the error.
* @param exception The exception.
*/
protected CompletionStage<Result> onDevServerError(Http.RequestHeader request, UsefulException exception) {
ObjectNode jsonError = Json.newObject();
final Throwable cause = exception.cause;
final String description = exception.description;
final String id = exception.id;
final String title = exception.title;
jsonError.put("description", description);
jsonError.put("title", title);
jsonError.put("id", id);
jsonError.put("message", exception.getMessage());
jsonError.set("cause", causesToJson(cause));
return CompletableFuture.completedFuture(Results.internalServerError(jsonError));
}
示例6: handleUpcomingEnrolment
import play.mvc.Http; //導入方法依賴的package包/類
private void handleUpcomingEnrolment(ExamEnrolment enrolment, Http.RequestHeader request, Map<String, String> headers) {
if (isMachineOk(enrolment, request, headers)) {
String hash = getExamHash(enrolment);
headers.put("x-exam-start-exam", hash);
headers.put("x-exam-upcoming-exam", enrolment.getId().toString());
}
}
示例7: onHandlerNotFound
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public F.Promise<SimpleResult> onHandlerNotFound(Http.RequestHeader requestHeader) {
// This is here to make sure that the context is set, there is a test that asserts
// that this is true
Http.Context.current().session().put("onHandlerNotFound", "true");
return F.Promise.<SimpleResult>pure(Results.notFound());
}
示例8: onError
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public F.Promise<Result> onError(Http.RequestHeader request, Throwable throwable) {
if (throwable instanceof UserException) {
// ToDo: Message box
return F.Promise.<Result>pure(internalServerError(views.html.error.render(throwable)));
}
return F.Promise.<Result>pure(internalServerError(views.html.error.render(throwable)));
}
示例9: onError
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public F.Promise<Result> onError(Http.RequestHeader requestHeader, Throwable throwable)
{
Logger.error("Error: " + throwable.getMessage());
return F.Promise.<Result>pure(Response.internalError("InternalError", "error"));
}
示例10: onBadRequest
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public F.Promise<Result> onBadRequest(Http.RequestHeader uri, String typeError) {
Logger.error("Bad request: " + typeError);
return F.Promise.<Result>pure(Response.invalidPart("Invalid part", "bad"));
}
示例11: getToken
import play.mvc.Http; //導入方法依賴的package包/類
public static Optional<String> getToken(Http.RequestHeader request) {
return request.header(LOGIN_TYPE.equals("HAKA") ? "Shib-Session-ID" : SITNET_TOKEN_HEADER_KEY);
}
示例12: updateSession
import play.mvc.Http; //導入方法依賴的package包/類
private void updateSession(Http.RequestHeader request, Session session, String token) {
if (!request.path().contains("checkSession")) {
session.setSince(DateTime.now());
cache.set(BaseController.SITNET_CACHE_KEY + token, session);
}
}
示例13: isOnExamMachine
import play.mvc.Http; //導入方法依賴的package包/類
private boolean isOnExamMachine(Http.RequestHeader request) {
return Ebean.find(ExamMachine.class).where()
.eq("ipAddress", request.remoteAddress())
.findOneOrEmpty()
.isPresent();
}
示例14: isMachineOk
import play.mvc.Http; //導入方法依賴的package包/類
private boolean isMachineOk(ExamEnrolment enrolment, Http.RequestHeader request, Map<String,
String> headers) {
// Loose the checks for dev usage to facilitate for easier testing
if (environment.isDev()) {
return true;
}
ExamMachine examMachine = enrolment.getReservation().getMachine();
ExamRoom room = examMachine.getRoom();
String machineIp = examMachine.getIpAddress();
String remoteIp = request.remoteAddress();
Logger.debug("User is on IP: {} <-> Should be on IP: {}", remoteIp, machineIp);
if (!remoteIp.equals(machineIp)) {
String message;
String header;
// Is this a known machine?
ExamMachine lookedUp = Ebean.find(ExamMachine.class).where().eq("ipAddress", remoteIp).findUnique();
if (lookedUp == null) {
// IP not known
header = "x-exam-unknown-machine";
message = room.getCampus() + ":::" +
room.getBuildingName() + ":::" +
room.getRoomCode() + ":::" +
examMachine.getName() + ":::" +
ISODateTimeFormat.dateTime().print(new DateTime(enrolment.getReservation().getStartAt()));
} else if (lookedUp.getRoom().getId().equals(room.getId())) {
// Right room, wrong machine
header = "x-exam-wrong-machine";
message = enrolment.getId() + ":::" + lookedUp.getId();
} else {
// Wrong room
header = "x-exam-wrong-room";
message = enrolment.getId() + ":::" + lookedUp.getId();
}
headers.put(header, DatatypeConverter.printBase64Binary(message.getBytes()));
Logger.debug("room and machine not ok. " + message);
return false;
}
Logger.debug("room and machine ok");
return true;
}
示例15: handleOngoingEnrolment
import play.mvc.Http; //導入方法依賴的package包/類
private void handleOngoingEnrolment(ExamEnrolment enrolment, Http.RequestHeader request, Map<String, String> headers) {
if (isMachineOk(enrolment, request, headers)) {
String hash = getExamHash(enrolment);
headers.put("x-exam-start-exam", hash);
}
}