From a5ee0d6b6f6a7360d04272858d003671959e88f8 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:23:58 +0100 Subject: [PATCH] JAVA-86: Remove spring-boot-add-filter --- spring-boot-modules/spring-boot/README.MD | 1 - .../bootcustomfilters/FilterConfig.java | 25 ---------- .../SpringBootFiltersApplication.java | 17 ------- .../controller/UserController.java | 35 ------------- .../filters/RequestResponseLoggingFilter.java | 50 ------------------- .../filters/TransactionFilter.java | 47 ----------------- .../bootcustomfilters/model/User.java | 45 ----------------- 7 files changed, 220 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index 16f20d889c..3397ad3b75 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -22,7 +22,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [An Introduction to Kong](https://www.baeldung.com/kong) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) -- [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) - [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes) - [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java deleted file mode 100644 index aa794182de..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.bootcustomfilters; - -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter; - -@Configuration -public class FilterConfig { - - // uncomment this and comment the @Component in the filter class definition to register only for a url pattern - // @Bean - public FilterRegistrationBean loggingFilter() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - - registrationBean.setFilter(new RequestResponseLoggingFilter()); - - registrationBean.addUrlPatterns("/users/*"); - - return registrationBean; - - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java deleted file mode 100644 index c4653932c0..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.bootcustomfilters; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Boot application - * @author hemant - * - */ -@SpringBootApplication -public class SpringBootFiltersApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootFiltersApplication.class, args); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java deleted file mode 100644 index 97165f2cf3..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.bootcustomfilters.controller; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.bootcustomfilters.model.User; - -/** - * Rest controller for User - * @author hemant - * - */ -@RestController -@RequestMapping("/users") -public class UserController { - - private static final Logger LOG = LoggerFactory.getLogger(UserController.class); - - @GetMapping("") - public List getAllUsers() { - LOG.info("Fetching all the users"); - return Arrays.asList( - new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), - new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), - new User(UUID.randomUUID().toString(), "User1", "user1@test.com")); - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java deleted file mode 100644 index e42ea7d2dd..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.bootcustomfilters.filters; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -/** - * A servlet filter to log request and response - * The logging implementation is pretty native and for demonstration only - * @author hemant - * - */ -@Component -@Order(2) -public class RequestResponseLoggingFilter implements Filter { - - private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class); - - @Override - public void init(final FilterConfig filterConfig) throws ServletException { - LOG.info("Initializing filter :{}", this); - } - - @Override - public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) - throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - HttpServletResponse res = (HttpServletResponse) response; - LOG.info("Logging Request {} : {}", req.getMethod(), req.getRequestURI()); - chain.doFilter(request, response); - LOG.info("Logging Response :{}", res.getContentType()); - } - - @Override - public void destroy() { - LOG.warn("Destructing filter :{}", this); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java deleted file mode 100644 index d92b723e73..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.bootcustomfilters.filters; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -/** - * A filter to create transaction before and commit it once request completes - * The current implemenatation is just for demo - * @author hemant - * - */ -@Component -@Order(1) -public class TransactionFilter implements Filter { - - private final static Logger LOG = LoggerFactory.getLogger(TransactionFilter.class); - - @Override - public void init(final FilterConfig filterConfig) throws ServletException { - LOG.info("Initializing filter :{}", this); - } - - @Override - public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - LOG.info("Starting Transaction for req :{}", req.getRequestURI()); - chain.doFilter(request, response); - LOG.info("Committing Transaction for req :{}", req.getRequestURI()); - } - - @Override - public void destroy() { - LOG.warn("Destructing filter :{}", this); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java deleted file mode 100644 index ab8e6c8206..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.bootcustomfilters.model; - -/** - * User model - * @author hemant - * - */ -public class User { - - private String id; - private String name; - private String email; - - public User(String id, String name, String email) { - super(); - this.id = id; - this.name = name; - this.email = email; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - -}