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


Java Http.Context方法代码示例

本文整理汇总了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);
}
 
开发者ID:thomas-young-2013,项目名称:wherehowsX,代码行数:10,代码来源:DatasetControllerTest.java

示例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);
    }
}
 
开发者ID:shuza,项目名称:Simple-RestFull-API,代码行数:19,代码来源:AuthService.java

示例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");
            });
}
 
开发者ID:btkelly,项目名称:gnag-website,代码行数:27,代码来源:GitHubAuthController.java

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

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

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

}
 
开发者ID:AlbertoSH,项目名称:Swagplash,代码行数:26,代码来源:ApiOperationAction.java

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

示例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);
    }
}
 
开发者ID:reljicd,项目名称:play-framework-blog,代码行数:12,代码来源:AuthenticatedAction.java

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

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

示例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;
}
 
开发者ID:project-sunbird,项目名称:sunbird-lms-service,代码行数:31,代码来源:Global.java

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

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

示例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;
}
 
开发者ID:peterszatmary,项目名称:learning-play-framework,代码行数:13,代码来源:LogPerformanceInterceptor.java

示例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;
}
 
开发者ID:Telecooperation,项目名称:assistance-platform-server,代码行数:11,代码来源:UserAuthenticator.java


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