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

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

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

Request.pathInfo介绍

[英]Returns the path info Example return: "/example/foo"
[中]返回路径信息示例返回:“/Example/foo”

代码示例

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

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

代码示例来源:origin: bwssytems/ha-bridge

before(SYSTEM_CONTEXT + "/*", (request, response) -> {
  if(bridgeSettings.getBridgeSecurity().isSecure()) {
    String pathInfo = request.pathInfo();
    if(pathInfo == null || (!pathInfo.equals(SYSTEM_CONTEXT + "/login") && !pathInfo.equals(SYSTEM_CONTEXT + "/habridge/version"))) {
      User authUser = bridgeSettings.getBridgeSecurity().getAuthenticatedUser(request);

代码示例来源:origin: com.sparkjava/spark-core

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

代码示例来源:origin: cinchapi/concourse

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

代码示例来源:origin: pac4j/spark-pac4j

@Override
public String getPath() {
  return request.pathInfo();
}

代码示例来源:origin: bwssytems/ha-bridge

log.debug("HueMulator " + request.requestMethod() + " called on api/* with request <<<" + request.pathInfo() + ">>>, and body <<<" + request.body() + ">>>");
if(bridgeSettingMaster.getBridgeSecurity().isSecure()) {
  String pathInfo = request.pathInfo();
  if(pathInfo != null && pathInfo.contains(HUE_CONTEXT + "/devices")) {
    User authUser = bridgeSettingMaster.getBridgeSecurity().getAuthenticatedUser(request);

代码示例来源:origin: cagataygurturk/lambadaframework

public Object handle(Request request, Response response)
    throws Exception {
  String path = request.pathInfo();
  for(Map.Entry<String, String> entry : request.params().entrySet()) {
    String paramName = entry.getKey();
    String paramValue = entry.getValue();
    path = path.replace(paramValue, paramName.replace(":", "{") + "}");
  }
  getLog().info(path);
  return "hello world";
}

代码示例来源:origin: pyloque/captain

public void initExceptionHandlers() {
  Spark.exception(Exception.class, (exc, req, res) -> {
    LOG.error(String.format("error occured on path=%s", req.pathInfo()), exc);
    res.status(500);
  });
}

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

@Override
  public void handle(Request request, Response response) throws Exception {
    Metrics.log.debug(request.requestMethod() + " " + request.pathInfo());

    response.header("Access-Control-Allow-Origin", "*");
    response.type("application/json");
  }
}

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

@Override
  public void handle(Exception exception, Request request, Response response) {
    Metrics.log.error(request.requestMethod() + " " + request.pathInfo(), exception);

    response.body(ExceptionUtils.getStackTrace(exception));
    response.type("text/plain");
    response.status(500);
  }
}

代码示例来源:origin: dessalines/torrenttunes-client

public static void logRequestInfo(Request req) {
  String origin = req.headers("Origin");
  String origin2 = req.headers("origin");
  String host = req.headers("Host");
  log.debug("request host: " + host);
  log.debug("request origin: " + origin);
  log.debug("request origin2: " + origin2);
  //		System.out.println("origin = " + origin);
  //		if (DataSources.ALLOW_ACCESS_ADDRESSES.contains(req.headers("Origin"))) {
  //			res.header("Access-Control-Allow-Origin", origin);
  //		}
  for (String header : req.headers()) {
    log.debug("request header | " + header + " : " + req.headers(header));
  }
  log.debug("request ip = " + req.ip());
  log.debug("request pathInfo = " + req.pathInfo());
  log.debug("request host = " + req.host());
  log.debug("request url = " + req.url());
}

代码示例来源:origin: tipsy/spark-basic-structure

public static void ensureUserIsLoggedIn(Request request, Response response) {
  if (request.session().attribute("currentUser") == null) {
    request.session().attribute("loginRedirect", request.pathInfo());
    response.redirect(Path.Web.LOGIN);
  }
};

代码示例来源:origin: tipsy/spark-basic-structure

public static void ensureUserIsLoggedIn(Request request, Response response) {
  if (request.session().attribute("currentUser") == null) {
    request.session().attribute("loginRedirect", request.pathInfo());
    response.redirect(Path.Web.LOGIN);
  }
};

代码示例来源:origin: lamarios/Homedash2

/**
 * Checks if the api key provided is correct
 *
 * @param req
 * @param res
 * @throws SQLException
 */
private void beforeFilter(Request req, Response res) throws SQLException {
  res.header("Access-Control-Allow-Origin", "*");
  logger.info("API request : [{}]", req.pathInfo());
  Settings useRemote = SettingsController.INSTANCE.get(Settings.USE_REMOTE);
  if (useRemote != null && useRemote.getValue().equalsIgnoreCase("1")) {
    String clientKey = req.headers(HEADER_AUTHORIZATION);
    Settings localKey = SettingsController.INSTANCE.get(Settings.REMOTE_API_KEY);
    if (localKey == null) {
      Spark.halt(401);
    } else if (!localKey.getValue().equalsIgnoreCase(clientKey)) {
      Spark.halt(401);
    }
  } else {
    Spark.halt(401);
  }
}

代码示例来源:origin: mgtechsoftware/smockin

String extractInboundValue(final RuleMatchingTypeEnum matchingType, final String fieldName, final Request req) {
  switch (matchingType) {
    case REQUEST_HEADER:
      return req.headers(fieldName);
    case REQUEST_PARAM:
      return extractRequestParam(req, fieldName);
    case REQUEST_BODY:
      return req.body();
    case PATH_VARIABLE:
      return req.params(fieldName);
    case PATH_VARIABLE_WILD:
      final int argPosition = NumberUtils.toInt(fieldName, -1);
      if (argPosition == -1
          || req.splat().length < argPosition) {
        throw new IllegalArgumentException("Unable to perform wildcard matching on the mocked endpoint '" + req.pathInfo() + "'. Path variable arg count does not align.");
      }
      return req.splat()[(argPosition - 1)];
    case REQUEST_BODY_JSON_ANY:
      final Map<String, ?> json = GeneralUtils.deserialiseJSONToMap(req.body());
      return (json != null)?(String)json.get(fieldName):null;
    default:
      throw new IllegalArgumentException("Unsupported Rule Matching Type : " + matchingType);
  }
}

代码示例来源:origin: ViDA-NYU/ache

@Override
public void handle(Request request, Response response) throws Exception {
  String path = request.pathInfo();
  boolean requestConsumed = false;
  if (patterns.matches(path)) {
    renderIndexHtml(request, response);
    requestConsumed = true;
  } else {
    requestConsumed = staticFilesHandler.consume(request.raw(), response.raw());
  }
  if(requestConsumed) {
    response.body(""); // needed to suppress spark-java route mapping error log
  }
}

代码示例来源:origin: mgtechsoftware/smockin

String processRequest(final RestfulMock mock, final Request req, final Response res) {
  logger.debug("processRequest called");
  RestfulResponseDTO outcome;
  switch (mock.getMockType()) {
    case RULE:
      outcome = ruleEngine.process(req, mock.getRules());
      break;
    case PROXY_HTTP:
      outcome = proxyService.waitForResponse(req.pathInfo(), mock);
      break;
    case SEQ:
    default:
      outcome = mockOrderingCounterService.process(mock);
      break;
  }
  if (outcome == null) {
    // Load in default values
    outcome = getDefault(mock);
  }
  res.status(outcome.getHttpStatusCode());
  res.type(outcome.getResponseContentType());
  // Apply any response headers
  outcome.getHeaders().entrySet().forEach(e ->
    res.header(e.getKey(), e.getValue())
  );
  final String response = inboundParamMatchService.enrichWithInboundParamMatches(req, outcome.getResponseBody());
  return StringUtils.defaultIfBlank(response,"");
}

代码示例来源:origin: lamarios/Homedash2

private static void staticResources() {
  Route route = (Route) (req, res) -> {
    if (Constants.DEV_MODE) {
      String content = getDevStaticResource(req.splat()[0], res);
      if (content != null) {
        return content;
      }
      //if it's not in the assets we just load it as a normal file
    }
    String fullPath = "web" + req.pathInfo();
    return getContent(res, fullPath);
  };
  get("/css/*", route);
  get("/fonts/*", route);
  get("/js/*", route);
  get("/images/*", route);
}

代码示例来源:origin: apache/james-project

@Override
  public void handle(Request request, Response response) throws Exception {
    Closeable mdcCloseable = MDCBuilder.create()
      .addContext(MDCBuilder.IP, request.ip())
      .addContext(MDCBuilder.HOST, request.host())
      .addContext(VERB, request.requestMethod())
      .addContext(MDCBuilder.PROTOCOL, "webadmin")
      .addContext(MDCBuilder.ACTION, request.pathInfo())
      .addContext(MDCBuilder.USER, request.attribute(AuthenticationFilter.LOGIN))
      .build();
    request.attribute(MDC_CLOSEABLE, mdcCloseable);
  }
}

代码示例来源:origin: apache/james-project

private void configureExceptionHanding() {
  service.notFound((req, res) -> ErrorResponder.builder()
    .statusCode(NOT_FOUND_404)
    .type(NOT_FOUND)
    .message(String.format("%s %s can not be found", req.requestMethod(), req.pathInfo()))
    .asString());
  service.internalServerError((req, res) -> ErrorResponder.builder()
    .statusCode(INTERNAL_SERVER_ERROR_500)
    .type(SERVER_ERROR)
    .message("WebAdmin encountered an unexpected internal error")
    .asString());
  service.exception(JsonExtractException.class, (ex, req, res) -> {
    res.status(BAD_REQUEST_400);
    res.body(ErrorResponder.builder()
      .statusCode(BAD_REQUEST_400)
      .type(INVALID_ARGUMENT)
      .message("JSON payload of the request is not valid")
      .cause(ex)
      .asString());
  });
}

相关文章