diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/ServerConfiguration.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/ServerConfiguration.java new file mode 100644 index 0000000000..5533fe1b7d --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/ServerConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.sample.boundary; + +import org.apache.catalina.connector.Connector; +import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ServerConfiguration implements WebServerFactoryCustomizer { + + @Override + public void customize(TomcatServletWebServerFactory factory) { + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { + @Override + public void customize(Connector connector) { + connector.setProperty("maxHttpResponseHeaderSize", "100000"); + } + }); + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/TodosController.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/TodosController.java index 7efa7dfee3..cf21303659 100644 --- a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/TodosController.java +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/TodosController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController; import java.net.URI; import java.util.Collection; +import java.util.List; import java.util.stream.Collectors; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; @@ -35,6 +36,13 @@ public class TodosController { // Mapping zwischen den Schichten private final TodoDtoMapper mapper; + + @GetMapping(value = {"/name"},produces = DEFAULT_MEDIA_TYPE) + public List findAllName(){ + return List.of("Hello", "World"); + } + + @GetMapping(produces = DEFAULT_MEDIA_TYPE) public Collection findAll() { return service.findAll().stream() @@ -80,4 +88,4 @@ public class TodosController { service.delete(id); } -} +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/WebConfiguration.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/WebConfiguration.java new file mode 100644 index 0000000000..24bbc223ae --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/sample/boundary/WebConfiguration.java @@ -0,0 +1,13 @@ +package com.baeldung.sample.boundary; + +import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +public class WebConfiguration implements WebMvcConfigurer { + + @Override + public void configurePathMatch(PathMatchConfigurer configurer) { + configurer.setUseTrailingSlashMatch(true); + } + +} diff --git a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/sample/boundary/TodosControllerApiIntegrationTest.java b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/sample/boundary/TodosControllerApiIntegrationTest.java index 680b6c85bb..3a80bc8a6c 100644 --- a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/sample/boundary/TodosControllerApiIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/sample/boundary/TodosControllerApiIntegrationTest.java @@ -215,4 +215,18 @@ class TodosControllerApiIntegrationTest { .andExpect(status().isNotFound()); } + @Test + void whenThereIsNoSlashMatching_ThenHttpStatusIs404() throws Exception { + mvc + .perform(get(BASEURL + "/name/").contentType(DEFAULT_MEDIA_TYPE)) + .andExpect(status().isNotFound()); + } + + @Test + void whenThereIsNoSlashMatching_ThenHttpStatusIs200() throws Exception { + mvc + .perform(get(BASEURL + "/name").contentType(DEFAULT_MEDIA_TYPE)) + .andExpect(status().isOk()); + } + }