本文整理汇总了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));
}
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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");
}
示例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;
}
示例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);
}
示例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");
}
}
示例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());
}
示例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;
}
示例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 "-";
}