org.springframework.web.bind.annotation.RequestMethod.name()方法的使用及代码示例

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

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

RequestMethod.name介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return declared HTTP methods.
 */
public Set<HttpMethod> getAllowedMethods() {
  return this.partialMatches.stream().
      flatMap(m -> m.getInfo().getMethodsCondition().getMethods().stream()).
      map(requestMethod -> HttpMethod.resolve(requestMethod.name())).
      collect(Collectors.toSet());
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return declared HTTP methods.
 */
public Set<String> getAllowedMethods() {
  Set<String> result = new LinkedHashSet<>();
  for (PartialMatch match : this.partialMatches) {
    for (RequestMethod method : match.getInfo().getMethodsCondition().getMethods()) {
      result.add(method.name());
    }
  }
  return result;
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private RequestMethodsRequestCondition matchRequestMethod(@Nullable HttpMethod httpMethod) {
  if (httpMethod != null) {
    for (RequestMethod method : getMethods()) {
      if (httpMethod.matches(method.name())) {
        return new RequestMethodsRequestCondition(method);
      }
    }
    if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
      return GET_CONDITION;
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) throws Exception {
  String methodName = requestMethod.name().toLowerCase();
  String path = "/" + methodName;
  return assertComposedAnnotationMapping(methodName, path, requestMethod);
}

代码示例来源:origin: spring-projects/spring-framework

private RequestMappingInfo assertComposedAnnotationMapping(RequestMethod requestMethod) throws Exception {
  String methodName = requestMethod.name().toLowerCase();
  String path = "/" + methodName;
  return assertComposedAnnotationMapping(methodName, path, requestMethod);
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) {
  HttpMethod httpMethod = HttpMethod.resolve(httpMethodValue);
  if (httpMethod != null) {
    for (RequestMethod method : getMethods()) {
      if (httpMethod.matches(method.name())) {
        return new RequestMethodsRequestCondition(method);
      }
    }
    if (httpMethod == HttpMethod.HEAD && getMethods().contains(RequestMethod.GET)) {
      return GET_CONDITION;
    }
  }
  return null;
}

代码示例来源:origin: spring-projects/spring-framework

private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
  MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
  assertNull(condition.getMatchingCondition(request));
}

代码示例来源:origin: spring-projects/spring-framework

private void testNoMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
  ServerWebExchange exchange = getExchange(method.name());
  assertNull(condition.getMatchingCondition(exchange));
}

代码示例来源:origin: spring-projects/spring-framework

private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) {
  MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "");
  RequestMethodsRequestCondition actual = condition.getMatchingCondition(request);
  assertNotNull(actual);
  assertEquals(Collections.singleton(method), actual.getContent());
}

代码示例来源:origin: spring-projects/spring-framework

private void testMatch(RequestMethodsRequestCondition condition, RequestMethod method) throws Exception {
  ServerWebExchange exchange = getExchange(method.name());
  RequestMethodsRequestCondition actual = condition.getMatchingCondition(exchange);
  assertNotNull(actual);
  assertEquals(Collections.singleton(method), actual.getContent());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void preflightRequestWithoutCorsConfigurationProvider() throws Exception {
  this.request.setMethod(RequestMethod.OPTIONS.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertNotNull(chain.getHandler());
  assertTrue(chain.getHandler().getClass().getSimpleName().equals("PreFlightHandler"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void preflightRequestWithCorsConfigurationProvider() throws Exception {
  this.request.setMethod(RequestMethod.OPTIONS.name());
  this.request.setRequestURI("/cors");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertNotNull(chain.getHandler());
  assertTrue(chain.getHandler().getClass().getSimpleName().equals("PreFlightHandler"));
  CorsConfiguration config = getCorsConfiguration(chain, true);
  assertNotNull(config);
  assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getMatchingConditionWithEmptyConditions() throws Exception {
  RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
  for (RequestMethod method : RequestMethod.values()) {
    if (method != OPTIONS) {
      ServerWebExchange exchange = getExchange(method.name());
      assertNotNull(condition.getMatchingCondition(exchange));
    }
  }
  testNoMatch(condition, OPTIONS);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getMatchingConditionWithEmptyConditions() {
  RequestMethodsRequestCondition condition = new RequestMethodsRequestCondition();
  for (RequestMethod method : RequestMethod.values()) {
    if (method != OPTIONS) {
      HttpServletRequest request = new MockHttpServletRequest(method.name(), "");
      assertNotNull(condition.getMatchingCondition(request));
    }
  }
  testNoMatch(condition, OPTIONS);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void preflightRequestWithMappedCorsConfiguration() throws Exception {
  CorsConfiguration config = new CorsConfiguration();
  config.addAllowedOrigin("*");
  this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/foo", config));
  this.request.setMethod(RequestMethod.OPTIONS.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertNotNull(chain.getHandler());
  assertTrue(chain.getHandler().getClass().getSimpleName().equals("PreFlightHandler"));
  config = getCorsConfiguration(chain, true);
  assertNotNull(config);
  assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void preflightRequestWithCorsConfigurationSource() throws Exception {
  this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
  this.request.setMethod(RequestMethod.OPTIONS.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertNotNull(chain.getHandler());
  assertTrue(chain.getHandler().getClass().getSimpleName().equals("PreFlightHandler"));
  CorsConfiguration config = getCorsConfiguration(chain, true);
  assertNotNull(config);
  assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
  assertEquals(true, config.getAllowCredentials());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void actualRequestWithoutCorsConfigurationProvider() throws Exception {
  this.request.setMethod(RequestMethod.GET.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertTrue(chain.getHandler() instanceof SimpleHandler);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void actualRequestWithCorsConfigurationProvider() throws Exception {
  this.request.setMethod(RequestMethod.GET.name());
  this.request.setRequestURI("/cors");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertTrue(chain.getHandler() instanceof CorsAwareHandler);
  CorsConfiguration config = getCorsConfiguration(chain, false);
  assertNotNull(config);
  assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void actualRequestWithMappedCorsConfiguration() throws Exception {
  CorsConfiguration config = new CorsConfiguration();
  config.addAllowedOrigin("*");
  this.handlerMapping.setCorsConfigurations(Collections.singletonMap("/foo", config));
  this.request.setMethod(RequestMethod.GET.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertTrue(chain.getHandler() instanceof SimpleHandler);
  config = getCorsConfiguration(chain, false);
  assertNotNull(config);
  assertArrayEquals(config.getAllowedOrigins().toArray(), new String[]{"*"});
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void actualRequestWithCorsConfigurationSource() throws Exception {
  this.handlerMapping.setCorsConfigurationSource(new CustomCorsConfigurationSource());
  this.request.setMethod(RequestMethod.GET.name());
  this.request.setRequestURI("/foo");
  this.request.addHeader(HttpHeaders.ORIGIN, "http://domain2.com");
  this.request.addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET");
  HandlerExecutionChain chain = handlerMapping.getHandler(this.request);
  assertNotNull(chain);
  assertTrue(chain.getHandler() instanceof SimpleHandler);
  CorsConfiguration config = getCorsConfiguration(chain, false);
  assertNotNull(config);
  assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
  assertEquals(true, config.getAllowCredentials());
}

相关文章