当前位置: 首页>>代码示例>>Java>>正文


Java Http.RequestHeader方法代码示例

本文整理汇总了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;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:19,代码来源:SystemRequestHandler.java

示例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)));
    });
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:17,代码来源:SystemErrorHandler.java

示例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)));
    });
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:22,代码来源:SystemErrorHandler.java

示例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;
    });

}
 
开发者ID:reljicd,项目名称:play-framework-blog,代码行数:19,代码来源:LoggingFilter.java

示例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));
}
 
开发者ID:lagom,项目名称:activator-lagom-cargotracker,代码行数:24,代码来源:ErrorHandler.java

示例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());
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:8,代码来源:SystemRequestHandler.java

示例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());
}
 
开发者ID:vangav,项目名称:vos_backend,代码行数:8,代码来源:Global.java

示例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)));
}
 
开发者ID:peerdavid,项目名称:ComeAndGo,代码行数:11,代码来源:Global.java

示例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"));
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:7,代码来源:GlobalConfig.java

示例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"));
}
 
开发者ID:webinerds,项目名称:s3-proxy-chunk-upload,代码行数:6,代码来源:GlobalConfig.java

示例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);
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:4,代码来源:BaseController.java

示例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);
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:7,代码来源:SystemRequestHandler.java

示例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();
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:7,代码来源:SystemRequestHandler.java

示例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;
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:45,代码来源:SystemRequestHandler.java

示例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);
    }
}
 
开发者ID:CSCfi,项目名称:exam,代码行数:7,代码来源:SystemRequestHandler.java


注:本文中的play.mvc.Http.RequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。