當前位置: 首頁>>代碼示例>>Java>>正文


Java Http.Request方法代碼示例

本文整理匯總了Java中play.mvc.Http.Request方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.Request方法的具體用法?Java Http.Request怎麽用?Java Http.Request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在play.mvc.Http的用法示例。


在下文中一共展示了Http.Request方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createAction

import play.mvc.Http; //導入方法依賴的package包/類
@Override
public Action createAction(Http.Request request, Method actionMethod) {
    String token = BaseController.getToken(request).orElse("");
    Session session = cache.get(BaseController.SITNET_CACHE_KEY + token);
    boolean temporalStudent = session != null && session.isTemporalStudent();
    User user = session == null ? null : Ebean.find(User.class, session.getUserId());
    AuditLogger.log(request, user);

    // logout, no further processing
    if (request.path().equals("/app/logout")) {
        return propagateAction();
    }

    return validateSession(session, token).orElseGet(() -> {
        updateSession(request, session, token);
        if ((user == null || !user.hasRole("STUDENT", session)) && !temporalStudent) {
            // propagate further right away
            return propagateAction();
        } else {
            // requests are candidates for extra processing
            return propagateAction(getReservationHeaders(request, user));
        }
    });
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:25,代碼來源:SystemRequestHandler.java

示例2: setUp

import play.mvc.Http; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    Map<String, String> flashData = Collections.emptyMap();
    Map<String, Object> argData = Collections.emptyMap();
    Long id = 2L;
    play.api.mvc.RequestHeader header = new FakeRequest("GET", "/").getWrappedRequest();
    Http.Request request = mock(Http.Request.class);
    Http.Context ctx = new Http.Context(id, header, request, flashData, flashData, argData);
    Http.Context.current.set(ctx);

    when(request.body()).thenReturn(new Http.RequestBody());
    keyResponse = IOUtils.toString(SelfAssessmentConnectorTest.class.getResourceAsStream("/keystoreResponse.json"));
    calculatorResponse = IOUtils.toString(SelfAssessmentConnectorTest.class.getResourceAsStream("/calculatorResponse.json"));

    timestamp = LocalTime.now().toString();
    uuid = "1";

    ObjectMapper mapper = new ObjectMapper();
    tree = mapper.readTree(keyResponse);
    calculatorResponseTree = mapper.readTree(calculatorResponse);
}
 
開發者ID:hmrc,項目名稱:self-service-time-to-pay-frontend-java,代碼行數:22,代碼來源:BaseControllerTest.java

示例3: rawInvocation

import play.mvc.Http; //導入方法依賴的package包/類
@Override
public boolean rawInvocation(Http.Request request, Http.Response response) throws Exception {

    // Mark an evolution as resolved
    if (Play.mode.isDev() && request.method.equals("POST") && request.url.matches("^/@evolutions/force/[0-9]+$")) {
        int revision = Integer.parseInt(request.url.substring(request.url.lastIndexOf("/") + 1));
        resolve(revision);
        new Redirect("/").apply(request, response);
        return true;
    }

    // Apply the current evolution script
    if (Play.mode.isDev() && request.method.equals("POST") && request.url.equals("/@evolutions/apply")) {
        applyScript(true);
        new Redirect("/").apply(request, response);
        return true;
    }
    return super.rawInvocation(request, response);
}
 
開發者ID:sismics,項目名稱:play-evolve,代碼行數:20,代碼來源:Evolve.java

示例4: mockHttpContex

import play.mvc.Http; //導入方法依賴的package包/類
private void mockHttpContex() {
    Http.Request mockRequest = mock(Http.Request.class);
    when(mockRequest.body()).thenReturn(new Http.RequestBody(toJson(new AlarmStatus("open"))));

    Http.Context mockContext = mock(Http.Context.class);
    when(mockContext.request()).thenReturn(mockRequest);

    Http.Context.current.set(mockContext);
}
 
開發者ID:Azure,項目名稱:device-telemetry-java,代碼行數:10,代碼來源:RulesControllerTest.java

示例5: setMockContext

import play.mvc.Http; //導入方法依賴的package包/類
private void setMockContext() {
    Http.Request mockRequest = mock(Http.Request.class);
    when(mockRequest.body()).thenReturn(new Http.RequestBody(toJson(new AlarmStatus("open"))));

    Http.Context mockContext = mock(Http.Context.class);
    when(mockContext.request()).thenReturn(mockRequest);

    Http.Context.current.set(mockContext);
}
 
開發者ID:Azure,項目名稱:device-telemetry-java,代碼行數:10,代碼來源:AlarmsControllerTest.java

示例6: setRequest

import play.mvc.Http; //導入方法依賴的package包/類
public static void setRequest(String body) {
    Http.Request mockRequest = mock(Http.Request.class);
    when(mockRequest.body()).thenReturn(new Http.RequestBody(Json.parse(body)));
    Http.Response mockResponse = mock(Http.Response.class);
    doNothing().when(mockResponse).setHeader(
            any(String.class), any(String.class));
    Http.Context mockContext = mock(Http.Context.class);
    when(mockContext.request()).thenReturn(mockRequest);
    when(mockContext.response()).thenReturn(mockResponse);
    Http.Context.current.set(mockContext);
}
 
開發者ID:Azure,項目名稱:pcs-storage-adapter-java,代碼行數:12,代碼來源:TestUtils.java

示例7: parseUser

import play.mvc.Http; //導入方法依賴的package包/類
public UserModel parseUser(Http.Request request) {
    DynamicForm params = Form.form().bindFromRequest(request);

    UserModel userModel = new UserModel();
    if (hasKey(params, ParamConstant.USER_EMAIL)) {
        userModel.setEmail(getString(params, ParamConstant.USER_EMAIL));
    }
    if (hasKey(params, ParamConstant.USER_NAME)) {
        userModel.setName(getString(params, ParamConstant.USER_NAME));
    }
    if (hasKey(params, ParamConstant.USER_SUR_NAME)) {
        userModel.setSurName(getString(params, ParamConstant.USER_SUR_NAME));
    }
    if (hasKey(params, ParamConstant.USER_PHONE)) {
        userModel.setPhone(getString(params, ParamConstant.USER_PHONE));
    }
    if (hasKey(params, ParamConstant.USER_COMPANY_ID)) {
        userModel.setCompanyId(getString(params, ParamConstant.USER_COMPANY_ID));
    }
    if (hasKey(params, ParamConstant.USER_PASSWORD)) {
        userModel.setPassword(getString(params, ParamConstant.USER_PASSWORD));
    }
    if (hasKey(params, ParamConstant.USER_ACCESS_ROLE)) {
        userModel.setAccessRole(getInt(params, ParamConstant.USER_ACCESS_ROLE));
    }

    return userModel;
}
 
開發者ID:shuza,項目名稱:Simple-RestFull-API,代碼行數:29,代碼來源:UserParser.java

示例8: sanitize

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
    Http.Request request = SanitizingHelper.sanitizeOptional("uid", body, Long.class, Attrs.USER_ID, ctx.request());
    Optional<String> email = SanitizingHelper.parse("email", body, String.class);
    if (email.isPresent()) {
        Constraints.EmailValidator validator = new Constraints.EmailValidator();
        if (!validator.isValid(email.get())) {
            throw new SanitizingException("bad email format");
        }
        request = request.addAttr(Attrs.EMAIL, email.get());
    }
    request = SanitizingHelper.sanitizeOptional("email", body, String.class, Attrs.EMAIL, request);
    return request;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:14,代碼來源:StudentEnrolmentSanitizer.java

示例9: sanitize

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
    if (body.has("params") && body.get("params").has("childIds")) {
        JsonNode node = body.get("params").get("childIds");
        Collection<Long> ids = StreamSupport.stream(node.spliterator(), false)
                .map(JsonNode::asLong)
                .collect(Collectors.toList());
        return ctx.request().addAttr(Attrs.ID_COLLECTION, ids);
    }
    throw new SanitizingException("no ids");
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:11,代碼來源:ExamRecordSanitizer.java

示例10: sanitize

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
    Http.Request request = SanitizingHelper.sanitize("roomId", body, Long.class, Attrs.ROOM_ID, ctx.request());
    request = SanitizingHelper.sanitize("examId", body, Long.class, Attrs.EXAM_ID, request);

    // Custom sanitizing ->

    // Optional AIDS (sic!)
    Collection<Integer> aids = new HashSet<>();
    if (body.has("aids")) {
        Iterator<JsonNode> it = body.get("aids").elements();
        while (it.hasNext()) {
            aids.add(it.next().asInt());
        }
    }
    request = request.addAttr(Attrs.ACCESSABILITES, aids);

    // Mandatory start + end dates
    if (body.has("start") && body.has("end")) {
        DateTime start = DateTime.parse(body.get("start").asText(), ISODateTimeFormat.dateTimeParser());
        DateTime end = DateTime.parse(body.get("end").asText(), ISODateTimeFormat.dateTimeParser());
        if (start.isBeforeNow() || end.isBefore(start)) {
            throw new SanitizingException("invalid dates");
        }
        request = request.addAttr(Attrs.START_DATE, start);
        request = request.addAttr(Attrs.END_DATE, end);
    } else {
        throw new SanitizingException("invalid dates");
    }
    return request;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:31,代碼來源:CalendarReservationSanitizer.java

示例11: sanitize

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
    String args = SanitizingHelper.parse("ids", body, String.class)
            .orElseThrow(() -> new SanitizingException("bad list"));
    List<Long> ids = Arrays.stream(args.split(",")).map(Long::parseLong).collect(Collectors.toList());
    if (ids.isEmpty()) {
        throw new SanitizingException("empty list");
    }
    return ctx.request().addAttr(Attrs.ID_COLLECTION, ids);
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:10,代碼來源:CommaJoinedListSanitizer.java

示例12: sanitize

import play.mvc.Http; //導入方法依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
    if (body.has("date")) {
        LocalDate date = LocalDate.parse(body.get("date").asText(), ISODateTimeFormat.dateTimeParser());
        return ctx.request().addAttr(Attrs.DATE, date);
    } else {
        throw new SanitizingException("no date");
    }
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:9,代碼來源:ExaminationDateSanitizer.java

示例13: log

import play.mvc.Http; //導入方法依賴的package包/類
public static void log(Http.Request request, User user) {
    String method = request.method();
    String userString = user == null ?
            "user <NULL>" :
            String.format("user #%d [%s]", user.getId(), user.getEmail());
    String uri = request.uri();
    StringBuilder logEntry = new StringBuilder(
            String.format("%s %s %s %s", DateTime.now(), userString, method, uri));
    if (!method.equals("GET")) {
        String body = request.body() == null || request.body().asJson() == null ? null :
                request.body().asJson().toString();
        logEntry.append(String.format(" data: %s", body));
    }
    Logger.debug(logEntry.toString());
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:16,代碼來源:AuditLogger.java

示例14: checkAuthenticationHeaders

import play.mvc.Http; //導入方法依賴的package包/類
public static boolean checkAuthenticationHeaders(Http.Request request, String username, String password) {
    if (username == null || password == null) {
        return true;
    }
    Http.Header authHeader = request.headers.get("authorization");
    if (authHeader != null) {
        String expected = "Basic " + Codec.encodeBASE64(username + ":" + password);
        if (expected.equals(authHeader.value())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:sismics,項目名稱:play-accesslog,代碼行數:14,代碼來源:BasicAuthHelper.java

示例15: getStatus

import play.mvc.Http; //導入方法依賴的package包/類
private String getStatus(Http.Request request, Http.Response response) {
  /* It seems as though the Response.current() is only valid when the request is handled by a controller
     Serving static files, static 404's and 500's etc don't populate the same Response.current()
     This prevents us from getting the bytes sent and response status all of the time
   */
    if (request.action != null && response.out.size() > 0) {
        return response.status.toString();
    }
    return "-";
}
 
開發者ID:sismics,項目名稱:play-accesslog,代碼行數:11,代碼來源:AccessLogPlugin.java


注:本文中的play.mvc.Http.Request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。