private void assertHttpMethod(String method) { for (HttpMethod httpMethod : HttpMethod.values()) { if (httpMethod.name().equalsIgnoreCase(method)) { return; } } throw new IllegalArgumentException("Invalid HTTP method: " + method); }
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { result.add(method); } } } else { for (String method : declaredMethods) { HttpMethod httpMethod = HttpMethod.valueOf(method); result.add(httpMethod); if (httpMethod == HttpMethod.GET) { result.add(HttpMethod.HEAD); } } result.add(HttpMethod.OPTIONS); } return result; }
private void initAllowHeader() { Collection<String> allowedMethods; if (this.supportedMethods == null) { allowedMethods = new ArrayList<>(HttpMethod.values().length - 1); for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { allowedMethods.add(method.name()); } } } else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) { allowedMethods = this.supportedMethods; } else { allowedMethods = new ArrayList<>(this.supportedMethods); allowedMethods.add(HttpMethod.OPTIONS.name()); } this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods); }
private void assertHttpMethod(String method) { for (HttpMethod httpMethod : HttpMethod.values()) { if (httpMethod.name().equalsIgnoreCase(method)) { return; } } throw new IllegalArgumentException("Invalid HTTP method: " + method); }
public RetryConfig allMethods() { return setMethods(HttpMethod.values()); }
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) { Set<HttpMethod> result = new LinkedHashSet<>(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { result.add(method); } } } else { for (String method : declaredMethods) { HttpMethod httpMethod = HttpMethod.valueOf(method); result.add(httpMethod); if (httpMethod == HttpMethod.GET) { result.add(HttpMethod.HEAD); } } result.add(HttpMethod.OPTIONS); } return result; }
private void initAllowHeader() { Collection<String> allowedMethods; if (this.supportedMethods == null) { allowedMethods = new ArrayList<>(HttpMethod.values().length - 1); for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { allowedMethods.add(method.name()); } } } else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) { allowedMethods = this.supportedMethods; } else { allowedMethods = new ArrayList<>(this.supportedMethods); allowedMethods.add(HttpMethod.OPTIONS.name()); } this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods); }
@Test public void getHandlerHttpOptions() { List<HttpMethod> allMethodExceptTrace = new ArrayList<>(Arrays.asList(HttpMethod.values())); allMethodExceptTrace.remove(HttpMethod.TRACE); testHttpOptions("/foo", EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS)); testHttpOptions("/person/1", EnumSet.of(HttpMethod.PUT, HttpMethod.OPTIONS)); testHttpOptions("/persons", EnumSet.copyOf(allMethodExceptTrace)); testHttpOptions("/something", EnumSet.of(HttpMethod.PUT, HttpMethod.POST)); }
@Test public void testResolvePathWithTraversal() throws Exception { for (HttpMethod method : HttpMethod.values()) { testResolvePathWithTraversal(method); } }
@Test public void resourceNotFound() throws Exception { for (HttpMethod method : HttpMethod.values()) { resourceNotFound(method); } }
@Test public void resolvePathWithTraversal() throws Exception { for (HttpMethod method : HttpMethod.values()) { this.request = new MockHttpServletRequest("GET", ""); this.response = new MockHttpServletResponse(); testResolvePathWithTraversal(method); } }
@Test public void resourceNotFound() throws Exception { for (HttpMethod method : HttpMethod.values()) { this.request = new MockHttpServletRequest("GET", ""); this.response = new MockHttpServletResponse(); resourceNotFound(method); } }
@Test public void wrapPutPatchAndDeleteOnly() throws Exception { for (HttpMethod method : HttpMethod.values()) { MockHttpServletRequest request = new MockHttpServletRequest(method.name(), "/"); request.setContent("foo=bar".getBytes("ISO-8859-1")); request.setContentType("application/x-www-form-urlencoded; charset=ISO-8859-1"); this.filterChain = new MockFilterChain(); this.filter.doFilter(request, this.response, this.filterChain); if (method == HttpMethod.PUT || method == HttpMethod.PATCH || method == HttpMethod.DELETE) { assertNotSame(request, this.filterChain.getRequest()); } else { assertSame(request, this.filterChain.getRequest()); } } }
for (HttpMethod httpMethod : HttpMethod.values()) { config.addAllowedMethod(httpMethod);
private void assertHttpMethod(String method) { for (HttpMethod httpMethod : HttpMethod.values()) { if (httpMethod.name().equalsIgnoreCase(method)) { return; } } throw new IllegalArgumentException("Invalid HTTP method: " + method); }
public static void main(String[] args) { SpringApplication.run(Spr13944Application.class, args); RestTemplate restTemplate = new RestTemplate(); String badUrl = "http://localhost:8080/greetings"; for (HttpMethod httpMethod : HttpMethod.values()) { try { restTemplate.execute(badUrl, httpMethod, null, null); } catch (Exception e) { log.error("Failed to " + httpMethod + " -- " + e.getMessage()); } } }
private void assertHttpMethod(String method) { for (HttpMethod httpMethod : HttpMethod.values()) { if (httpMethod.name().equalsIgnoreCase(method)) { return; } } throw new IllegalArgumentException("Invalid HTTP method: " + method); }
private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethods) { Set<HttpMethod> result = new LinkedHashSet<HttpMethod>(declaredMethods.size()); if (declaredMethods.isEmpty()) { for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { result.add(method); } } } else { for (String method : declaredMethods) { HttpMethod httpMethod = HttpMethod.valueOf(method); result.add(httpMethod); if (httpMethod == HttpMethod.GET) { result.add(HttpMethod.HEAD); } } } return result; }
private void initAllowHeader() { Collection<String> allowedMethods; if (this.supportedMethods == null) { allowedMethods = new ArrayList<String>(HttpMethod.values().length - 1); for (HttpMethod method : HttpMethod.values()) { if (method != HttpMethod.TRACE) { allowedMethods.add(method.name()); } } } else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) { allowedMethods = this.supportedMethods; } else { allowedMethods = new ArrayList<String>(this.supportedMethods); allowedMethods.add(HttpMethod.OPTIONS.name()); } this.allowHeader = StringUtils.collectionToCommaDelimitedString(allowedMethods); }
@Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); final CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.setAllowedOrigins(Collections.singletonList("*")); config.setAllowedHeaders(Collections.singletonList("*")); config.setAllowedMethods(Arrays.stream(HttpMethod.values()).map(HttpMethod::name).collect(Collectors.toList())); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); } }