當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。