本文整理匯總了Java中play.mvc.Http.Context方法的典型用法代碼示例。如果您正苦於以下問題:Java Http.Context方法的具體用法?Java Http.Context怎麽用?Java Http.Context使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類play.mvc.Http
的用法示例。
在下文中一共展示了Http.Context方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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 = mock(play.api.mvc.RequestHeader.class);
Http.Context context = new Http.Context(id, header, request, flashData, flashData, argData);
Http.Context.current.set(context);
}
示例2: getUsername
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public String getUsername(Http.Context context) {
System.out.println("auth_service ====/ getUserName called @ @ @");
try {
JsonNode params = context.request().body().asJson();
String token = params.get("token").asText();
UserSessionModel model = UserSessionDao.getInstance().getUserSession(token);
if (model != null) {
return model.getToken();
} else {
return super.getUsername(context);
}
} catch (Exception e) {
LogUtil.printLogMessage("Auth service", "params error", e.getMessage());
e.printStackTrace();
return super.getUsername(context);
}
}
示例3: callback
import play.mvc.Http; //導入方法依賴的package包/類
/**
* Function called by the GitHub authentication flow which takes the resulting code as a parameter.
* This function will take the code passed and exchange it for a client access token used to make
* GitHub api requests.
* @param code
* @return
*/
public CompletionStage<Result> callback(String code) {
final Http.Context context = Http.Context.current();
return wsClient.url("https://github.com/login/oauth/access_token")
.setQueryParameter("client_id", configuration.getString("gh.id"))
.setQueryParameter("client_secret", configuration.getString("gh.secret"))
.setQueryParameter("code", code)
.setHeader("accept", "application/json")
.setRequestTimeout(10 * 1000)
.post("")
.thenApply(response -> {
String accessToken = response.asJson().get("access_token").asText();
context.session().put(TOKEN_KEY, accessToken);
return redirect("/configHelper");
});
}
示例4: isAllowed
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Boolean> isAllowed(String name, Optional<String> meta, DeadboltHandler deadboltHandler, Http.Context ctx) {
if (meta.isPresent() && meta.get().matches("pattern=.+,role=.+,anyMatch=(true|false)")) {
String[] config = meta.get().split(",");
String pattern = config[0].substring(config[0].indexOf('=') + 1);
String[] roles = {config[1].substring(config[1].indexOf('=') + 1)};
Boolean anyMatch = Boolean.valueOf(config[2].substring(config[2].indexOf('=') + 1));
return deadboltHandler.getSubject(ctx).thenApplyAsync(s -> {
DeadboltAnalyzer da = new DeadboltAnalyzer();
if (anyMatch) {
return da.checkPatternEquality(s, Optional.of(pattern)) ||
da.checkRole(s, roles);
} else {
return da.checkPatternEquality(s, Optional.of(pattern)) &&
da.checkRole(s, roles);
}
});
} else {
return CompletableFuture.completedFuture(false);
}
}
示例5: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> call(Http.Context ctx) {
Optional<String> contentType = ctx.request().contentType();
if (contentType.isPresent()) {
if (contentType.get().contains("json")) {
return handleJsonContentType(ctx);
} else if (contentType.get().contains("multipart")) {
return handleMultipartContentType(ctx);
} else {
Logger.warn("Content-type " + contentType.get() + " not implemented yet or unknown!");
return delegate.call(ctx);
}
} else {
if (configuration.required()) {
return CompletableFuture.completedFuture(badRequest("Content-type is needed when calling an endpoint with required body parameters"));
} else {
ctx.args.put(configuration.name(), Optional.empty());
return delegate.call(ctx);
}
}
}
示例6: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> call(Http.Context ctx) {
return swagplashProvider.get()
.thenCompose(swagplash -> {
if (swagplash == null) {
Logger.error("Could not load Swagplash definition");
return delegate.call(ctx);
} else {
String method = ctx.request().method();
if (method.equals("POST") || (method.equals("PUT"))) {
Optional<Result> consumesError = checkConsumes(ctx, swagplash);
if (consumesError.isPresent())
return CompletableFuture.completedFuture(consumesError.get());
}
Optional<Result> producesError = checkProduces(ctx, swagplash);
if (producesError.isPresent()) {
return CompletableFuture.completedFuture(producesError.get());
}
return delegate.call(ctx);
}
});
}
示例7: call
import play.mvc.Http; //導入方法依賴的package包/類
public CompletionStage<Result> call(Http.Context ctx) {
JsonNode body = ctx.request().body().asJson();
try {
return delegate.call(ctx.withRequest(sanitize(ctx, body)));
} catch (SanitizingException e) {
Logger.error("Sanitizing error: " + e.getMessage(), e);
return CompletableFuture.supplyAsync(Results::badRequest);
}
}
示例8: call
import play.mvc.Http; //導入方法依賴的package包/類
public CompletionStage<Result> call(final Http.Context ctx) {
String username = ctx.session().get("username");
if (username == null) {
// User is not authenticated, show him Login form
Result login = unauthorized(views.html.login.render(loginDTOForm.withGlobalError("Please login to see this page.")));
return CompletableFuture.completedFuture(login);
} else {
// User is authenticated, call delegate
return delegate.call(ctx);
}
}
示例9: checkPermission
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Boolean> checkPermission(String permissionValue,
Optional<String> meta,
DeadboltHandler deadboltHandler,
Http.Context ctx) {
return CompletableFuture.completedFuture(false);
}
示例10: getProjectPageRequest
import play.mvc.Http; //導入方法依賴的package包/類
private CompletionStage<WSResponse> getProjectPageRequest(int page, Http.Context context) {
return wsClient.url("https://api.github.com/user/repos")
.setQueryParameter("access_token", context.session().get(TOKEN_KEY))
.setQueryParameter("per_page", "100")
.setQueryParameter("page", String.valueOf(page))
.setHeader("accept", "application/json")
.setRequestTimeout(10 * 1000)
.get();
}
示例11: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public Promise<Result> call(Http.Context ctx) throws java.lang.Throwable {
long startTime = System.currentTimeMillis();
ProjectLogger.log("Learning Service Call start for api ==" + ctx.request().path()
+ " start time " + startTime, LoggerEnum.PERF_LOG);
Promise<Result> result = null;
Http.Response response = ctx.response();
response.setHeader("Access-Control-Allow-Origin", "*");
String message = RequestInterceptor.verifyRequestData(ctx);
if (message.contains("{userId}")) {
ctx.flash().put(JsonKey.USER_ID, message.replace("{userId}", ""));
ctx.flash().put(JsonKey.IS_AUTH_REQ, "false");
for(String uri : RequestInterceptor.restrictedUriList){
if(ctx.request().path().contains(uri)){
ctx.flash().put(JsonKey.IS_AUTH_REQ, "true");
break;
}
}
result = delegate.call(ctx);
} else if (!ProjectUtil.isStringNullOREmpty(message)) {
result = onDataValidationError(ctx.request(), message,ResponseCode.UNAUTHORIZED.getResponseCode());
} else {
result = delegate.call(ctx);
}
ProjectLogger.log("Learning Service Call Ended for api ==" + ctx.request().path()
+ " end time " + System.currentTimeMillis() + " Time taken "
+ (System.currentTimeMillis() - startTime), LoggerEnum.PERF_LOG);
return result;
}
示例12: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public CompletionStage<Result> call(Http.Context ctx) {
try {
if (!isValid(ctx.request().body().asJson())) {
return CompletableFuture.supplyAsync(Results::badRequest);
}
} catch (Exception e) {
return CompletableFuture.supplyAsync(Results::internalServerError);
}
return delegate.call(ctx);
}
示例13: 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;
}
示例14: call
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public F.Promise<Result> call(Http.Context context) throws Throwable {
// finding out which method in which controller is performed
final String METHOD = context.args.get("ROUTE_CONTROLLER") + "." + context.args.get("ROUTE_ACTION_METHOD");
Logger.info("Method " + METHOD + " started");
long start = System.currentTimeMillis();
F.Promise<Result> result = delegate.call(context);
long end = System.currentTimeMillis();
Logger.info("Method " + METHOD + " end in " + (end - start) + " milliseconds.");
return result;
}
示例15: getUsername
import play.mvc.Http; //導入方法依賴的package包/類
@Override
public String getUsername(Http.Context ctx) {
User user = getUser(ctx);
if (user != null) {
return user.email;
}
return null;
}