diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java deleted file mode 100644 index 4fb6938694..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/Application.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.exclude_urls_filter; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -@ComponentScan(basePackages = "com.baeldung.exclude_urls_filter") -@Configuration -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java deleted file mode 100644 index 1463af6bfd..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/FAQController.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.exclude_urls_filter.controller; - -import com.baeldung.exclude_urls_filter.service.FAQService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class FAQController { - - private final FAQService faqService; - - @Autowired - public FAQController(FAQService faqService) { - this.faqService = faqService; - } - - @RequestMapping(value = "/faq/helpline", method = RequestMethod.GET) - public ResponseEntity getHelpLineNumber() { - String helplineNumber = faqService.getHelpLineNumber(); - if (helplineNumber != null) { - return new ResponseEntity(helplineNumber, HttpStatus.OK); - } else { - return new ResponseEntity("Unavailable", HttpStatus.NOT_FOUND); - } - } - - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java deleted file mode 100644 index c8a0723ba6..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/controller/Ping.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.exclude_urls_filter.controller; - -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class Ping { - - @RequestMapping(value = "/health", method = RequestMethod.GET) - public ResponseEntity pingGet() { - return new ResponseEntity("pong", HttpStatus.OK); - } - - @RequestMapping(value = "/health", method = RequestMethod.POST) - public ResponseEntity pingPost() { - return new ResponseEntity("pong", HttpStatus.OK); - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java deleted file mode 100644 index ff99b4cc25..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/FilterRegistrationConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.exclude_urls_filter.filter; - -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class FilterRegistrationConfig { - - @Bean - public FilterRegistrationBean logFilter() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - registrationBean.setFilter(new LogFilter()); - registrationBean.addUrlPatterns("/health", "/faq/*"); - return registrationBean; - } - - - @Bean - public FilterRegistrationBean headerValidatorFilter() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - registrationBean.setFilter(new HeaderValidatorFilter()); - registrationBean.addUrlPatterns("*"); - return registrationBean; - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java deleted file mode 100644 index d6c1777326..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/HeaderValidatorFilter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.exclude_urls_filter.filter; - -import org.springframework.core.annotation.Order; -import org.springframework.http.HttpStatus; -import org.springframework.web.filter.OncePerRequestFilter; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@Order(1) -public class HeaderValidatorFilter extends OncePerRequestFilter { - @Override - protected void doFilterInternal(HttpServletRequest request, - HttpServletResponse response, - FilterChain filterChain) - throws ServletException, - IOException { - String countryCode = request.getHeader("X-Country-Code"); - if (!"US".equals(countryCode)) { - response.sendError(HttpStatus.BAD_REQUEST.value(), "Invalid Locale"); - return; - } - filterChain.doFilter(request, response); - } - - @Override - protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { - String path = request.getRequestURI(); - return "/health".equals(path); - } -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java deleted file mode 100644 index fcde4f7f8f..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/filter/LogFilter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.exclude_urls_filter.filter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.Order; -import org.springframework.web.filter.OncePerRequestFilter; - -import javax.servlet.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@Order(1) -public class LogFilter extends OncePerRequestFilter { - private final Logger logger = LoggerFactory.getLogger(LogFilter.class); - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, - FilterChain filterChain) throws ServletException, IOException { - String path = request.getRequestURI(); - String contentType = request.getContentType(); - logger.info("Request URL path : {}, Request content type: {}", path, contentType); - filterChain.doFilter(request, response); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java deleted file mode 100644 index a2949ea0a2..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQService.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.exclude_urls_filter.service; - -public interface FAQService { - String getHelpLineNumber(); -} \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java deleted file mode 100644 index 6f841e4ec1..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/exclude_urls_filter/service/FAQServiceImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.exclude_urls_filter.service; - -import org.springframework.stereotype.Service; - -@Service -public class FAQServiceImpl implements FAQService { - - private static final String HELPLINE_NUMBER = "+1 888-777-66"; - - @Override - public String getHelpLineNumber() { - return HELPLINE_NUMBER; - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java deleted file mode 100644 index 34c14141b0..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.form_submission; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -@SpringBootApplication -public class Application extends SpringBootServletInitializer { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java deleted file mode 100644 index 791fc75cef..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/controllers/FeedbackForm.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.form_submission.controllers; - -import com.baeldung.form_submission.model.Feedback; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.*; - -@Controller -public class FeedbackForm { - - @GetMapping(path = "/feedback") - public String getFeedbackForm(Model model) { - Feedback feedback = new Feedback(); - model.addAttribute("feedback", feedback); - return "feedback"; - } - - @PostMapping( - path = "/web/feedback", - consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}) - public String handleBrowserSubmissions(Feedback feedback) throws Exception { - // Save feedback data - return "redirect:/feedback/success"; - } - - @GetMapping("/feedback/success") - public ResponseEntity getSuccess() { - return new ResponseEntity("Thank you for submitting feedback.", HttpStatus.OK); - } - - @PostMapping( - path = "/feedback", - consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE}) - public ResponseEntity handleNonBrowserSubmissions(@RequestParam MultiValueMap paramMap) throws Exception { - // Save feedback data - return new ResponseEntity("Thank you for submitting feedback", HttpStatus.OK); - } -} \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java deleted file mode 100644 index f8d416460c..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/form_submission/model/Feedback.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.form_submission.model; - -public class Feedback { - private String emailId; - private String comment; - - public String getEmailId() { - return this.emailId; - } - - public void setEmailId(String emailId) { - this.emailId = emailId; - } - - public String getComment() { - return this.comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java deleted file mode 100644 index 7db6ac3755..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/Application.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.spring.slash; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@SpringBootApplication -public class Application implements WebMvcConfigurer { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java b/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java deleted file mode 100644 index 635587ee5b..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/main/java/com/baeldung/spring/slash/SlashParsingController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.spring.slash; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("slash") -public class SlashParsingController { - - @GetMapping("mypaths/{anything}") - public String pathVariable(@PathVariable("anything") String anything) { - return anything; - } - - @GetMapping("all/**") - public String allDirectories(HttpServletRequest request) { - return request.getRequestURI() - .split(request.getContextPath() + "/all/")[1]; - } - - @GetMapping("all") - public String queryParameter(@RequestParam("param") String param) { - return param; - } - -} diff --git a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java b/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java deleted file mode 100644 index d81b34f7bf..0000000000 --- a/spring-web-modules/spring-mvc-basics-3/src/test/java/com/baeldung/spring/slash/SlashParsingControllerIntTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.spring.slash; - -import static org.junit.Assert.assertEquals; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import java.net.URI; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; - -@AutoConfigureMockMvc -@ExtendWith(SpringExtension.class) -@SpringBootTest -public class SlashParsingControllerIntTest { - - @Autowired - private MockMvc mockMvc; - - @Test - public void whenUsingPathVariablemWithoutSlashes_thenStatusOk() throws Exception { - final String stringWithoutSlashes = "noslash"; - - MvcResult mvcResult = mockMvc.perform(get("/slash/mypaths/" + stringWithoutSlashes)) - .andExpect(status().isOk()) - .andReturn(); - - assertEquals(stringWithoutSlashes, mvcResult.getResponse() - .getContentAsString()); - } - - @Test - public void whenUsingPathVariableWithSlashes_thenStatusNotFound() throws Exception { - final String stringWithSlashes = "url/with/slashes"; - - mockMvc.perform(get("/slash/mypaths/" + stringWithSlashes)) - .andExpect(status().isNotFound()); - } - - @Test - public void givenAllFallbackEndpoint_whenUsingPathWithSlashes_thenStatusOk() throws Exception { - final String stringWithSlashes = "url/for/testing/purposes"; - - MvcResult mvcResult = mockMvc.perform(get("/slash/all/" + stringWithSlashes)) - .andExpect(status().isOk()) - .andReturn(); - - assertEquals(stringWithSlashes, mvcResult.getResponse() - .getContentAsString()); - } - - @Test - public void givenAllFallbackEndpoint_whenUsingConsecutiveSlashes_thenPathNormalized() throws Exception { - final String stringWithSlashes = "http://myurl.com"; - - MvcResult mvcResult = mockMvc.perform(get("/slash/all/" + stringWithSlashes)) - .andExpect(status().isOk()) - .andReturn(); - - String stringWithSlashesNormalized = URI.create("/slash/all/" + stringWithSlashes) - .normalize() - .toString() - .split("/slash/all/")[1]; - - assertEquals(stringWithSlashesNormalized, mvcResult.getResponse() - .getContentAsString()); - } - - @Test - public void whenUsingSlashesInQueryParam_thenParameterAccepted() throws Exception { - final String stringWithSlashes = "url/for////testing/purposes"; - - MvcResult mvcResult = mockMvc.perform(get("/slash/all").param("param", stringWithSlashes)) - .andExpect(status().isOk()) - .andReturn(); - - assertEquals(stringWithSlashes, mvcResult.getResponse() - .getContentAsString()); - } - -}