spark.Request.queryParams()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中spark.Request.queryParams方法的一些代码示例,展示了Request.queryParams的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.queryParams方法的具体详情如下:
包路径:spark.Request
类名称:Request
方法名:queryParams

Request.queryParams介绍

[英]Returns all query parameters
[中]返回所有查询参数

代码示例

代码示例来源:origin: perwendel/spark

/**
 * Gets the query param, or returns default value
 *
 * @param queryParam   the query parameter
 * @param defaultValue the default value
 * @return the value of the provided queryParam, or default if value is null
 * Example: query parameter 'id' from the following request URI: /hello?id=foo
 */
public String queryParamOrDefault(String queryParam, String defaultValue) {
  String value = queryParams(queryParam);
  return value != null ? value : defaultValue;
}

代码示例来源:origin: perwendel/spark

@Override
public String queryParams(String queryParam) {
  return delegate.queryParams(queryParam);
}

代码示例来源:origin: perwendel/spark

@Override
public Set<String> queryParams() {
  return delegate.queryParams();
}

代码示例来源:origin: gocd/gocd

private String getViewName(Request request) {
    final String viewName = request.queryParams(VIEW_NAME);
    return StringUtils.isBlank(viewName) ? DEFAULT_NAME : viewName;
  }
}

代码示例来源:origin: gocd/gocd

private String getViewName(Request request) {
    final String viewName = request.queryParams(VIEW_NAME);
    return StringUtils.isBlank(viewName) ? DEFAULT_NAME : viewName;
  }
}

代码示例来源:origin: gocd/gocd

private String requiredQueryParam(final Request req, final String name) {
    String value = req.queryParams(name);

    if (StringUtils.isBlank(value)) {
      throw HaltApiResponses.haltBecauseRequiredParamMissing(name);
    }

    return value;
  }
}

代码示例来源:origin: gocd/gocd

private void checkPipelineExists(Request request, Response response) {
  if (isPipelineRequest(request)) {
    if (null == pipelineConfigService.pipelineConfigNamed(request.queryParams("pipeline_name"))) {
      throw halt(404, format("Cannot generate analytics. Pipeline with name: '%s' not found.", request.queryParams("pipeline_name")));
    }
  }
}

代码示例来源:origin: gocd/gocd

private CaseInsensitiveString getPipelineNameFromRequest(Request request) {
  String pipelineName = request.params("pipeline_name");
  if (StringUtils.isBlank(pipelineName)) {
    pipelineName = request.queryParams("pipeline_name");
  }
  return new CaseInsensitiveString(pipelineName);
}

代码示例来源:origin: gocd/gocd

private ConfigRepoConfig repoFromRequest(Request req) {
    String repoId = req.queryParams("repoId");
    if (null == repoId) {
      return null;
    }

    ConfigRepoConfig repo = service.getConfigRepo(repoId);

    if (null == repo) {
      throw HaltApiResponses.haltBecauseNotFound("Could not find a config-repo with id `%s`", repoId);
    }

    return repo;
  }
}

代码示例来源:origin: gocd/gocd

private ConfigRepoPlugin pluginFromRequest(Request req) {
  String pluginId = req.queryParams("pluginId");
  if (StringUtils.isBlank(pluginId)) {
    throw HaltApiResponses.haltBecauseRequiredParamMissing("pluginId");
  }
  return (ConfigRepoPlugin) pluginService.partialConfigProviderFor(pluginId);
}

代码示例来源:origin: gocd/gocd

public String search(Request request, Response response) throws IOException {
    String pipelineName = request.queryParams("pipeline_name");
    String fingerprint = request.queryParams("fingerprint");
    String searchText = request.queryParamOrDefault("search_text", "");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    List<MatchedRevision> matchedRevisions = materialService.searchRevisions(pipelineName, fingerprint, searchText, currentUsername(), result);
    if (result.isSuccessful()) {
      return writerForTopLevelArray(request, response, outputListWriter -> MatchedRevisionRepresenter.toJSON(outputListWriter, matchedRevisions));
    } else {
      return renderHTTPOperationResult(result, request, response);
    }
  }
}

代码示例来源:origin: gocd/gocd

public String show(Request req, Response res) throws IOException {
  HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
  String searchTerm = req.queryParams("q");
  if (isBlank(searchTerm)) {
    throw haltBecauseOfReason("Search term not specified!");
  }
  List<UserSearchModel> userSearchModels = userSearchService.search(searchTerm, result);
  if (result.isSuccessful()) {
    return writerForTopLevelObject(req, res, writer -> UserSearchResultsRepresenter.toJSON(writer, searchTerm, userSearchModels));
  } else {
    return renderHTTPOperationResult(result, req, res);
  }
}

代码示例来源:origin: gocd/gocd

public String index(Request req, Response res) throws InvalidPluginTypeException, IOException {
  String pluginType = req.queryParams("type");
  RolesConfig roles = roleConfigService.getRoles().ofType(pluginType);
  String etag = entityHashingService.md5ForEntity(roles);
  if (fresh(req, etag)) {
    return notModified(res);
  } else {
    setEtagHeader(res, etag);
    return writerForTopLevelObject(req, res, writer -> RolesRepresenter.toJSON(writer, roles));
  }
}

代码示例来源:origin: gocd/gocd

public String index(Request req, Response res) throws InvalidPluginTypeException, IOException {
  String pluginType = req.queryParams("type");
  RolesConfig roles = roleConfigService.getRoles().ofType(pluginType);
  String etag = entityHashingService.md5ForEntity(roles);
  if (fresh(req, etag)) {
    return notModified(res);
  } else {
    setEtagHeader(res, etag);
    return writerForTopLevelObject(req, res, writer -> RolesRepresenter.toJSON(writer, roles));
  }
}

代码示例来源:origin: komoot/photon

@Override
  public Point apply(Request webRequest) throws BadRequestException {
    Point location;
    String lonParam = webRequest.queryParams("lon");
    String latParam = webRequest.queryParams("lat");
    if (!mandatory && lonParam == null && latParam == null) {
      return null;
    }
    
    try {
      Double lon = Double.valueOf(lonParam);
      if (lon > 180.0 || lon < -180.00) {
        throw new BadRequestException(400, "invalid search term 'lon', expected number >= -180.0 and <= 180.0");
      }
      Double lat = Double.valueOf(latParam);
      if (lat > 90.0 || lat < -90.00) {
        throw new BadRequestException(400, "invalid search term 'lat', expected number >= -90.0 and <= 90.0");
      }
      location = geometryFactory.createPoint(new Coordinate(lon, lat));
    } catch (NullPointerException | NumberFormatException e) {
      throw new BadRequestException(400, "invalid search term 'lat' and/or 'lon', try instead lat=51.5&lon=8.0");
    }
    return location;
  }
}

代码示例来源:origin: komoot/photon

public <R extends PhotonRequest> R create(Request webRequest) throws BadRequestException {
  for (String queryParam : webRequest.queryParams())
    if (!m_hsRequestQueryParams.contains(queryParam))
      throw new BadRequestException(400, "unknown query parameter '" + queryParam + "'.  Allowed parameters are: " + m_hsRequestQueryParams);
  String language = webRequest.queryParams("lang");
  language = language == null ? "en" : language;
  languageChecker.apply(language);
  String query = webRequest.queryParams("q");
  if (query == null) throw new BadRequestException(400, "missing search term 'q': /?q=berlin");
  Integer limit;
  try {
    limit = Integer.valueOf(webRequest.queryParams("limit"));
  } catch (NumberFormatException e) {
    limit = 15;
  String scaleStr = webRequest.queryParams("location_bias_scale");
  if (scaleStr != null && !scaleStr.isEmpty())
    try {

代码示例来源:origin: komoot/photon

@Override
  public String handle(Request request, Response response) {
    R photonRequest = null;
    try {
      photonRequest = photonRequestFactory.create(request);
    } catch (BadRequestException e) {
      JSONObject json = new JSONObject();
      json.put("message", e.getMessage());
      halt(e.getHttpStatus(), json.toString());
    }
    PhotonRequestHandler<R> handler = requestHandlerFactory.createHandler(photonRequest);
    List<JSONObject> results = handler.handle(photonRequest);
    JSONObject geoJsonResults = geoJsonConverter.convert(results);
    response.type("application/json; charset=utf-8");
    response.header("Access-Control-Allow-Origin", "*");
    if (request.queryParams("debug") != null)
      return geoJsonResults.toString(4);

    return geoJsonResults.toString();
  }
}

代码示例来源:origin: komoot/photon

@Override
  public String handle(Request request, Response response) {
    R photonRequest = null;
    try {
      photonRequest = reverseRequestFactory.create(request);
    } catch (BadRequestException e) {
      JSONObject json = new JSONObject();
      json.put("message", e.getMessage());
      halt(e.getHttpStatus(), json.toString());
    }
    ReverseRequestHandler<R> handler = requestHandlerFactory.createHandler(photonRequest);
    List<JSONObject> results = handler.handle(photonRequest);
    JSONObject geoJsonResults = geoJsonConverter.convert(results);
    response.type("application/json; charset=utf-8");
    response.header("Access-Control-Allow-Origin", "*");
    if (request.queryParams("debug") != null)
      return geoJsonResults.toString(4);

    return geoJsonResults.toString();
  }
}

代码示例来源:origin: awslabs/aws-serverless-java-container

if (req.queryParams("limit") != null) {
  limit = Integer.parseInt(req.queryParams("limit"));

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

/**
 * Creates a controller that maps requests to actions.
 */
public UserController(final UserService userService) {
 Spark.staticFileLocation("/public");
 get("/api/users", (req, res) -> userService.getAllUsers(), json());
 get("/api/users/:id", (req, res) -> userService.getUser(req.params(":id")), json());
 post("/api/users",
   (req, res) -> userService.createUser(req.queryParams("name"), req.queryParams("email")),
   json());
 put("/api/users/:id", (req, res) -> userService.updateUser(
     req.params(":id"),
     req.queryParams("name"),
     req.queryParams("email")
   ), json());
 delete("/api/users/:id", (req, res) -> userService.deleteUser(req.params(":id")), json());
 after((req, res) -> {
  res.type("application/json");
 });
 exception(IllegalArgumentException.class, (error, req, res) -> {
  res.status(400);
  res.body(toJson(new ResponseError(error)));
 });
}

相关文章