Skip to content

Commit dbb2f9c

Browse files
committed
Revert "GH-3366: Return null from HTTP handleNoMatch"
This reverts commit 9aa9707. See spring-projects/spring-framework#25636 (comment)
1 parent 9aa9707 commit dbb2f9c

File tree

4 files changed

+16
-50
lines changed

4 files changed

+16
-50
lines changed

spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,18 @@ public void initialize(ConfigurableListableBeanFactory beanFactory) throws Beans
5555
* which could also be overridden by the user by simply registering
5656
* a {@link IntegrationRequestMappingHandlerMapping} {@code <bean>} with 'id'
5757
* {@link HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}.
58-
* <p> In addition, checks if the {@code javax.servlet.Servlet} class is present on the classpath.
58+
* <p>
59+
* In addition, checks if the {@code javax.servlet.Servlet} class is present on the classpath.
5960
* When Spring Integration HTTP is used only as an HTTP client, there is no reason to use and register
6061
* the HTTP server components.
6162
*/
6263
private void registerRequestMappingHandlerMappingIfNecessary(BeanDefinitionRegistry registry) {
6364
if (HttpContextUtils.WEB_MVC_PRESENT &&
6465
!registry.containsBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)) {
6566
BeanDefinitionBuilder requestMappingBuilder =
66-
BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class)
67-
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE)
68-
.addPropertyValue(IntegrationNamespaceUtils.ORDER, -1);
67+
BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class);
68+
requestMappingBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
69+
requestMappingBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, 0);
6970
registry.registerBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME,
7071
requestMappingBuilder.getBeanDefinition());
7172
}

spring-integration-http/src/main/java/org/springframework/integration/http/inbound/IntegrationRequestMappingHandlerMapping.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
import java.util.HashMap;
2222
import java.util.List;
2323
import java.util.Map;
24-
import java.util.Set;
2524
import java.util.concurrent.atomic.AtomicBoolean;
2625

27-
import javax.servlet.ServletException;
2826
import javax.servlet.http.HttpServletRequest;
2927
import javax.servlet.http.HttpServletResponse;
3028

@@ -179,18 +177,6 @@ protected CorsConfiguration initCorsConfiguration(Object handler, Method method,
179177
return null;
180178
}
181179

182-
@Override
183-
protected HandlerMethod handleNoMatch(Set<RequestMappingInfo> infos, String path, HttpServletRequest request) {
184-
try {
185-
return super.handleNoMatch(infos, path, request);
186-
}
187-
catch (ServletException ex) {
188-
// Since this component has a higher precedence the 'null' return allows a
189-
// 'DispatcherServlet' to try other 'HandlerMapping'
190-
return null;
191-
}
192-
}
193-
194180
private static CorsConfiguration buildCorsConfiguration(CrossOrigin crossOrigin, RequestMappingInfo mappingInfo) {
195181
CorsConfiguration config = new CorsConfiguration();
196182
for (RequestMethod requestMethod : crossOrigin.getMethod()) {

spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpInboundChannelAdapterParserTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.integration.http.config;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2021
import static org.mockito.ArgumentMatchers.any;
2122
import static org.mockito.BDDMockito.willReturn;
2223

@@ -55,6 +56,7 @@
5556
import org.springframework.util.AntPathMatcher;
5657
import org.springframework.util.MultiValueMap;
5758
import org.springframework.validation.Validator;
59+
import org.springframework.web.HttpRequestMethodNotSupportedException;
5860
import org.springframework.web.servlet.HandlerMapping;
5961

6062

@@ -193,13 +195,18 @@ public void withExpressions() throws Exception {
193195
}
194196

195197
@Test
196-
public void getRequestNotAllowed() throws Exception {
198+
public void getRequestNotAllowed() {
197199
MockHttpServletRequest request = new MockHttpServletRequest();
198200
request.setMethod("GET");
199201
request.setParameter("foo", "bar");
200202
request.setRequestURI("/postOnly");
201203

202-
assertThat(this.integrationRequestMappingHandlerMapping.getHandler(request)).isNull();
204+
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class)
205+
.isThrownBy(() -> this.integrationRequestMappingHandlerMapping.getHandler(request))
206+
.satisfies((ex) -> {
207+
assertThat(ex.getMethod()).isEqualTo("GET");
208+
assertThat(ex.getSupportedMethods()).containsExactly("POST");
209+
});
203210
}
204211

205212
@Test

spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,16 +78,13 @@
7878
import org.springframework.util.StringUtils;
7979
import org.springframework.validation.Errors;
8080
import org.springframework.validation.Validator;
81-
import org.springframework.web.bind.annotation.GetMapping;
82-
import org.springframework.web.bind.annotation.RestController;
8381
import org.springframework.web.client.DefaultResponseErrorHandler;
8482
import org.springframework.web.client.HttpClientErrorException;
8583
import org.springframework.web.context.WebApplicationContext;
8684
import org.springframework.web.multipart.MultipartResolver;
8785
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
8886
import org.springframework.web.server.ResponseStatusException;
8987
import org.springframework.web.servlet.DispatcherServlet;
90-
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
9188

9289
/**
9390
* @author Artem Bilan
@@ -211,7 +208,6 @@ public void testMultiPartFiles() throws Exception {
211208
}
212209

213210
@Autowired
214-
@Qualifier("customValidator")
215211
private Validator validator;
216212

217213
@Test
@@ -297,20 +293,9 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
297293
flowRegistration.destroy();
298294
}
299295

300-
@Test
301-
public void testMixWithMvcRequestMapping() throws Exception {
302-
this.mockMvc.perform(
303-
get("/mvcRequest")
304-
.with(httpBasic("user", "user")))
305-
.andExpect(status().isOk())
306-
.andExpect(content().string("MVC reply"));
307-
}
308-
309296
@Configuration
310297
@EnableWebSecurity
311298
@EnableIntegration
312-
@EnableWebMvc
313-
@RestController
314299
public static class ContextConfiguration extends WebSecurityConfigurerAdapter {
315300

316301
@Override
@@ -424,19 +409,6 @@ public Validator customValidator() {
424409
return new TestModelValidator();
425410
}
426411

427-
428-
@GetMapping("/mvcRequest")
429-
ResponseEntity<?> mvcGet() {
430-
return ResponseEntity.ok("MVC reply");
431-
}
432-
433-
@Bean
434-
HttpRequestHandlerEndpointSpec mvcHandler() {
435-
return Http.inboundChannelAdapter("/mvcRequest")
436-
.requestMapping((mapping) -> mapping.methods(HttpMethod.POST));
437-
}
438-
439-
440412
}
441413

442414
public static class HttpProxyResponseErrorHandler extends DefaultResponseErrorHandler {

0 commit comments

Comments
 (0)