Java Code Examples for play.mvc.Http#Request

The following examples show how to use play.mvc.Http#Request . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public CompletionStage<Result> createUserV3Sync(Http.Request httpRequest) {

  return handleRequest(
    ActorOperations.CREATE_USER.getValue(),
    httpRequest.body().asJson(),
    req -> {
      Request request = (Request) req;
      request.getRequest().put("sync", true);
      new UserRequestValidator().validateCreateUserV2Request(request);
      request.getContext().put(JsonKey.VERSION, JsonKey.VERSION_3);
      return null;
    },
    null,
    null,
    true,
    httpRequest
  );
}
 
Example 2
Source File: BadgeClassController.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
/**
 * Get details of requsted badge class.
 *
 * @param badgeId The ID of the Badge Class whose details to view
 * @return Return a promise for get badge class API result.
 */
public CompletionStage<Result> getBadgeClass(String badgeId, Http.Request httpRequest) {
  ProjectLogger.log("getBadgeClass called.", LoggerEnum.DEBUG.name());

  try {
    Request request = createAndInitRequest(BadgingActorOperations.GET_BADGE_CLASS.getValue(), httpRequest);
    request.put(BadgingJsonKey.BADGE_ID, badgeId);

    new BadgeClassValidator().validateGetBadgeClass(request);

    return actorResponseHandler(getActorRef(), request, timeout, null, httpRequest);
  } catch (Exception e) {
    ProjectLogger.log("getBadgeClass: exception = ", e);

    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 3
Source File: ClientController.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
/**
 * Method to update the client key for the given clientId in the header
 *
 * @return Response object on success else Error object
 */
public CompletionStage<Result> updateClientKey(Http.Request httpRequest) {
  try {
    JsonNode requestData = httpRequest.body().asJson();
    ProjectLogger.log("Update client key: " + requestData, LoggerEnum.INFO.name());
    Optional<String> masterKey =
        httpRequest.getHeaders().get(HeaderParam.X_Authenticated_Client_Token.getName());
    Optional<String> clientId =
        httpRequest.getHeaders().get(HeaderParam.X_Authenticated_Client_Id.getName());
    Request reqObj = (Request) mapper.RequestMapper.mapRequest(requestData, Request.class);
    RequestValidator.validateUpdateClientKey(clientId.get(), masterKey.get());
    reqObj.setOperation(ActorOperations.UPDATE_CLIENT_KEY.getValue());
    reqObj.setRequestId(httpRequest.flash().get(JsonKey.REQUEST_ID));
    reqObj.setEnv(getEnvironment());
    HashMap<String, Object> innerMap = (HashMap<String, Object>) reqObj.getRequest();
    innerMap.put(JsonKey.CLIENT_ID, clientId);
    innerMap.put(JsonKey.MASTER_KEY, masterKey);
    reqObj.setRequest(innerMap);
    return actorResponseHandler(getActorRef(), reqObj, timeout, null, httpRequest);
  } catch (Exception e) {
    ProjectLogger.log("Error in controller", e);
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 4
Source File: OrganisationMetricsController.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
public CompletionStage<Result> orgCreationReport(String orgId, Http.Request httpRequest) {
  ProjectLogger.log("Start Org Creation Report Contoller");
  try {
    String periodStr = httpRequest.getQueryString(JsonKey.PERIOD);
    String format = httpRequest.getQueryString(JsonKey.FORMAT);
    Map<String, Object> map = new HashMap<>();
    map.put(JsonKey.ORG_ID, orgId);
    map.put(JsonKey.PERIOD, periodStr);
    map.put(JsonKey.FORMAT, format);
    map.put(JsonKey.REQUESTED_BY, ctx().flash().get(JsonKey.USER_ID));
    Request request = new Request();
    request.setEnv(getEnvironment());
    request.setOperation(ActorOperations.ORG_CREATION_METRICS_REPORT.getValue());
    request.setRequest(map);
    request.setRequestId(httpRequest.flash().get(JsonKey.REQUEST_ID));
    ProjectLogger.log("Return from Org Creation Report Contoller");
    return actorResponseHandler(getActorRef(), request, timeout, null, httpRequest);
  } catch (Exception e) {
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 5
Source File: PluginCollection.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public boolean serveStatic(VirtualFile file, Http.Request request, Http.Response response){
    for (PlayPlugin plugin : getEnabledPlugins()) {
        if (plugin.serveStatic(file, request, response)) {
            //raw = true;
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: PluginCollection.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public boolean rawInvocation(Http.Request request, Http.Response response)throws Exception{
    for (PlayPlugin plugin : getEnabledPlugins()) {
        if (plugin.rawInvocation(request, response)) {
            //raw = true;
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: BulkUploadController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> userBulkUpload(Http.Request httpRequest) {
  try {
    Request request =
        createAndInitBulkRequest(
            BulkUploadActorOperation.USER_BULK_UPLOAD.getValue(), JsonKey.USER, true, httpRequest);
    return actorResponseHandler(getActorRef(), request, timeout, null, httpRequest);
  } catch (Exception e) {
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 8
Source File: UserProfileController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> setProfileVisibility(Http.Request httpRequest) {
  return handleRequest(
      ActorOperations.PROFILE_VISIBILITY.getValue(),
      httpRequest.body().asJson(),
      (req) -> {
        Request request = (Request) req;
        new UserProfileRequestValidator().validateProfileVisibility(request);
        return null;
      },
      null,
      null,
      true,
          httpRequest);
}
 
Example 9
Source File: UserController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> createUserV4(Http.Request httpRequest) {
  return handleRequest(
    ActorOperations.CREATE_USER_V4.getValue(),
    httpRequest.body().asJson(),
    req -> {
      Request request = (Request) req;
      new UserRequestValidator().validateUserCreateV4(request);
      request.getContext().put(JsonKey.VERSION, JsonKey.VERSION_4);
      return null;
    },
    null,
    null,
    true,
    httpRequest);
}
 
Example 10
Source File: TestUtils.java    From remote-monitoring-services-java with MIT License 5 votes vote down vote up
public static Http.Response 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);
    return mockResponse;
}
 
Example 11
Source File: QueryStringUtils.java    From commercetools-sunrise-java with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts the query string from the request.
 * @param httpRequest current HTTP request
 * @param ignoredParams params that should not be included in the link
 * @return query string from the request
 */
public static Map<String, List<String>> extractQueryString(final Http.Request httpRequest,final Set<String> ignoredParams) {

    return httpRequest.queryString().entrySet().stream()
            .filter(stringEntry -> !ignoredParams.contains(stringEntry.getKey()))
            .collect(toMap(Map.Entry::getKey, entry -> asList(entry.getValue())));
}
 
Example 12
Source File: DbOperationController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
/**
 * This method will allow to search Data from ES.
 *
 * @return CompletionStage<Result>
 */
public CompletionStage<Result> search(Http.Request httpRequest) {
  try {
    JsonNode requestData = httpRequest.body().asJson();
    ProjectLogger.log("DbOperationController: search called", LoggerEnum.DEBUG.name());
    Request reqObj = (Request) mapper.RequestMapper.mapRequest(requestData, Request.class);
    reqObj.setOperation(ActorOperations.SEARCH_DATA.getValue());
    reqObj.setRequestId(httpRequest.flash().get(JsonKey.REQUEST_ID));
    reqObj.getRequest().put(JsonKey.REQUESTED_BY, httpRequest.flash().get(JsonKey.USER_ID));
    reqObj.setEnv(getEnvironment());
    return actorResponseHandler(getActorRef(), reqObj, timeout, null, httpRequest);
  } catch (Exception e) {
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 13
Source File: UserSkillController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> updateSkill(Http.Request httpRequest) {
  try {
    JsonNode bodyJson = httpRequest.body().asJson();
    Request reqObj = createAndInitRequest(ActorOperations.UPDATE_SKILL.getValue(), bodyJson, httpRequest);
    new UserSkillRequestValidator().validateUpdateSkillRequest(reqObj);
    return actorResponseHandler(getActorRef(), reqObj, timeout, null, httpRequest);
  } catch (Exception e) {
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 14
Source File: ThreadDumpController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> threaddump(Http.Request httpRequest) {
  final StringBuilder dump = new StringBuilder();
  final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
  final ThreadInfo[] threadInfos =
      threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
  for (ThreadInfo threadInfo : threadInfos) {
    dump.append('"');
    dump.append(threadInfo.getThreadName());
    dump.append("\" ");
    final Thread.State state = threadInfo.getThreadState();
    dump.append("\n   java.lang.Thread.State: ");
    dump.append(state);
    final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
    for (final StackTraceElement stackTraceElement : stackTraceElements) {
      dump.append("\n        at ");
      dump.append(stackTraceElement);
    }
    dump.append("\n\n");
  }
  System.out.println("=== thread-dump start ===");
  System.out.println(dump.toString());
  System.out.println("=== thread-dump end ===");
  Request request = new Request();
  request.setOperation("takeThreadDump");
  request.setEnv(getEnvironment());
  if ("off".equalsIgnoreCase(BackgroundRequestRouter.getMode())) {
    actorResponseHandler(
        SunbirdMWService.getBackgroundRequestRouter(), request, timeout, null, httpRequest);
  }
  return CompletableFuture.supplyAsync(() -> ok("successful"));
}
 
Example 15
Source File: OrgMemberController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
public CompletionStage<Result> addMemberToOrganisation(Http.Request httpRequest) {
  return handleRequest(
      ActorOperations.ADD_MEMBER_ORGANISATION.getValue(),
      httpRequest.body().asJson(),
      orgRequest -> {
        new OrgMemberRequestValidator().validateAddMemberRequest((Request) orgRequest);
        return null;
      },
      getAllRequestHeaders(request()), httpRequest);
}
 
Example 16
Source File: Utils.java    From NationStatesPlusPlus with MIT License 5 votes vote down vote up
public static String getPostValue(Http.Request request, String property) {
	Map<String, String[]> post = request.body().asFormUrlEncoded();
	if (post != null) {
		String[] value = post.get(property);
		if (value != null && value.length > 0) {
			return value[0];
		}
	}
	return null;
}
 
Example 17
Source File: KeyManagementController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
/**
 * this action method will validate and save the enc and signIn keys into organisation db.
 * @return Result
 */
public CompletionStage<Result> assignKeys(Http.Request httpRequest) {
    return handleRequest(
            ActorOperations.ASSIGN_KEYS.getValue(),
            httpRequest.body().asJson(),
            orgRequest -> {
                KeyManagementValidator.getInstance((Request) orgRequest).validate();
                return null;
            },
            null, null, true,
            httpRequest);
}
 
Example 18
Source File: SearchController.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
/**
 * This method will do data search for user and organization. Search type will be decide based on
 * request object type coming with filter if objectType key is not coming then we need to do the
 * search for all the types.
 *
 * @return CompletionStage<Result>
 */
public CompletionStage<Result> compositeSearch(Http.Request httpRequest) {
  try {
    JsonNode requestData = httpRequest.body().asJson();
    ProjectLogger.log("getting search request data = " + requestData, LoggerEnum.INFO.name());
    Request reqObj = (Request) mapper.RequestMapper.mapRequest(requestData, Request.class);
    reqObj.setOperation(ActorOperations.COMPOSITE_SEARCH.getValue());
    reqObj.setRequestId(httpRequest.flash().get(JsonKey.REQUEST_ID));
    reqObj.getRequest().put(JsonKey.CREATED_BY, httpRequest.flash().get(JsonKey.USER_ID));
    reqObj.setEnv(getEnvironment());
    return actorResponseHandler(getActorRef(), reqObj, timeout, null, httpRequest);
  } catch (Exception e) {
    return CompletableFuture.completedFuture(createCommonExceptionResponse(e, httpRequest));
  }
}
 
Example 19
Source File: TracingFilterTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public Http.Request withBody(Http.RequestBody requestBody) {
    return null;
}
 
Example 20
Source File: UserLanguageImpl.java    From commercetools-sunrise-java with Apache License 2.0 4 votes vote down vote up
private static Stream<Locale> requestAcceptedLanguages(final Http.Request httpRequest, final ProjectContext projectContext) {
    return httpRequest.acceptLanguages().stream()
            .map(lang -> Locale.forLanguageTag(lang.code()))
            .filter(projectContext::isLocaleSupported);
}