From 67e4090b578770b80113ee6ab3b83f43f3043dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20R=C3=A4del?= Date: Sat, 1 Oct 2016 04:37:07 +0200 Subject: [PATCH] BAEL-325: Removed old project folder. --- .../intercepting-filter-pattern/pom.xml | 49 -------------- .../patterns/FrontControllerServlet.java | 66 ------------------- .../patterns/commands/CheckoutCommand.java | 27 -------- .../patterns/commands/FrontCommand.java | 43 ------------ .../patterns/commands/HomeCommand.java | 17 ----- .../patterns/commands/LoginCommand.java | 20 ------ .../patterns/commands/LogoutCommand.java | 16 ----- .../patterns/commands/OrderCommand.java | 33 ---------- .../patterns/commands/SearchCommand.java | 25 ------- .../patterns/commands/ShowCommand.java | 21 ------ .../patterns/commands/UnknownCommand.java | 12 ---- .../java/com/baeldung/patterns/data/Book.java | 19 ------ .../com/baeldung/patterns/data/BookImpl.java | 58 ---------------- .../com/baeldung/patterns/data/Bookshelf.java | 18 ----- .../baeldung/patterns/data/BookshelfImpl.java | 23 ------- .../com/baeldung/patterns/data/Order.java | 11 ---- .../com/baeldung/patterns/data/OrderImpl.java | 40 ----------- .../filters/AuthenticationFilter.java | 40 ----------- .../baeldung/patterns/filters/BaseFilter.java | 25 ------- .../patterns/filters/EncodingFilter.java | 30 --------- .../patterns/filters/FilterChainImpl.java | 28 -------- .../patterns/filters/FilterManager.java | 21 ------ .../patterns/filters/LoggingFilter.java | 33 ---------- .../patterns/filters/OnIntercept.java | 5 -- .../main/webapp/WEB-INF/jsp/book-found.jsp | 24 ------- .../main/webapp/WEB-INF/jsp/book-notfound.jsp | 11 ---- .../src/main/webapp/WEB-INF/jsp/home.jsp | 27 -------- .../src/main/webapp/WEB-INF/jsp/login.jsp | 16 ----- .../webapp/WEB-INF/jsp/shopping-cart-hint.jsp | 16 ----- .../main/webapp/WEB-INF/jsp/shopping-cart.jsp | 29 -------- .../src/main/webapp/WEB-INF/jsp/unknown.jsp | 9 --- .../webapp/WEB-INF/jsp/visitor-counter.jsp | 5 -- 32 files changed, 817 deletions(-) delete mode 100644 enterprise-patterns/intercepting-filter-pattern/pom.xml delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/FrontControllerServlet.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/CheckoutCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/FrontCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/HomeCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LoginCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LogoutCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/OrderCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/SearchCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/ShowCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/UnknownCommand.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Book.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookImpl.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Bookshelf.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookshelfImpl.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Order.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/OrderImpl.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/AuthenticationFilter.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/BaseFilter.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/EncodingFilter.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterChainImpl.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterManager.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/LoggingFilter.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/OnIntercept.java delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-found.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-notfound.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/home.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/login.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart-hint.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/unknown.jsp delete mode 100644 enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/visitor-counter.jsp diff --git a/enterprise-patterns/intercepting-filter-pattern/pom.xml b/enterprise-patterns/intercepting-filter-pattern/pom.xml deleted file mode 100644 index 0e1008657a..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - 4.0.0 - - intercepting-filter-pattern - war - - - enterprise-patterns-parent - com.baeldung.enterprise.patterns - 1.0.0-SNAPSHOT - - - - - javax.servlet - javax.servlet-api - 3.1.0 - provided - - - org.slf4j - slf4j-api - 1.7.21 - provided - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.eclipse.jetty - jetty-maven-plugin - 9.4.0.M1 - - - /intercepting-filter - - - - - - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/FrontControllerServlet.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/FrontControllerServlet.java deleted file mode 100644 index 67400897c4..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/FrontControllerServlet.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller; - -import com.baeldung.enterprise.patterns.front.controller.commands.FrontCommand; -import com.baeldung.enterprise.patterns.front.controller.commands.UnknownCommand; -import com.baeldung.enterprise.patterns.front.controller.data.Bookshelf; -import com.baeldung.enterprise.patterns.front.controller.data.BookshelfImpl; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@WebServlet(name = "front-controller", urlPatterns = "/index") -public class FrontControllerServlet extends HttpServlet { - @Override - public void init(ServletConfig config) throws ServletException { - super.init(config); - Bookshelf bookshelf = new BookshelfImpl(); - bookshelf.init(); - getServletContext().setAttribute("bookshelf", bookshelf); - } - - @Override - protected void doGet( - HttpServletRequest request, - HttpServletResponse response - ) throws ServletException, IOException { - doCommand(request, response); - } - - @Override - protected void doPost( - HttpServletRequest request, - HttpServletResponse response - ) throws ServletException, IOException { - doCommand(request, response); - } - - private void doCommand( - HttpServletRequest request, - HttpServletResponse response - ) throws ServletException, IOException { - FrontCommand command = getCommand(request); - command.init(request, response); - command.process(); - } - - private FrontCommand getCommand(HttpServletRequest request) { - try { - Class type = Class.forName( - String.format( - "com.baeldung.enterprise.patterns.front.controller.commands.%sCommand", - request.getParameter("command") - ) - ); - return (FrontCommand) type - .asSubclass(FrontCommand.class) - .newInstance(); - } catch (Exception e) { - return new UnknownCommand(); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/CheckoutCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/CheckoutCommand.java deleted file mode 100644 index 876e439139..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/CheckoutCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.data.Order; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpSession; -import java.io.IOException; - -public class CheckoutCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - HttpSession session = request.getSession(false); - if (request.getMethod().equals("POST")) { - session.removeAttribute("order"); - response.sendRedirect("index?command=Home&message=Thank you for buying!"); - } else { - Order order = (Order) session.getAttribute("order"); - Double total = order.getItems().entrySet().stream() - .map(entry -> entry.getKey().getPrice() * entry.getValue()) - .reduce((p1, p2) -> p1 + p2) - .orElse(0.00); - request.setAttribute("total", total); - forward("shopping-cart"); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/FrontCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/FrontCommand.java deleted file mode 100644 index 370127b7f7..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/FrontCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.filters.FilterManager; -import com.baeldung.enterprise.patterns.front.controller.filters.OnIntercept; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public abstract class FrontCommand implements OnIntercept { - protected HttpServletRequest request; - protected HttpServletResponse response; - private boolean intercept; - - public FrontCommand() { - } - - public void init(HttpServletRequest request, HttpServletResponse response) { - this.request = request; - this.response = response; - } - - public void process() throws ServletException, IOException { - FilterManager.process(request, response, this); - } - - public void forward(String target) throws ServletException, IOException { - if (intercept) { - return; - } - String path = String.format("/WEB-INF/jsp/%s.jsp", target); - RequestDispatcher dispatcher = request.getServletContext() - .getRequestDispatcher(path); - dispatcher.forward(request, response); - } - - @Override - public void intercept() { - intercept = true; - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/HomeCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/HomeCommand.java deleted file mode 100644 index 49b62a29bd..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/HomeCommand.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.data.Bookshelf; - -import javax.servlet.ServletException; -import java.io.IOException; - -public class HomeCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - Bookshelf bookshelf = (Bookshelf) request.getServletContext() - .getAttribute("bookshelf"); - request.setAttribute("books", bookshelf); - forward("home"); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LoginCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LoginCommand.java deleted file mode 100644 index beef42d269..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LoginCommand.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpSession; -import java.io.IOException; - -public class LoginCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - if (request.getMethod().equals("POST")) { - HttpSession session = request.getSession(true); - session.setAttribute("username", request.getParameter("username")); - response.sendRedirect(request.getParameter("redirect")); - } else { - request.setAttribute("redirect", request.getRequestURL() - .append("?").append(request.getQueryString()).toString()); - forward("login"); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LogoutCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LogoutCommand.java deleted file mode 100644 index b502112558..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/LogoutCommand.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpSession; -import java.io.IOException; - -public class LogoutCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - HttpSession session = request.getSession(false); - session.removeAttribute("username"); - session.removeAttribute("order"); - response.sendRedirect("index?command=Home"); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/OrderCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/OrderCommand.java deleted file mode 100644 index 91ed909a77..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/OrderCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.data.Book; -import com.baeldung.enterprise.patterns.front.controller.data.Bookshelf; -import com.baeldung.enterprise.patterns.front.controller.data.Order; -import com.baeldung.enterprise.patterns.front.controller.data.OrderImpl; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpSession; -import java.io.IOException; - -public class OrderCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - if (request.getMethod().equals("POST")) { - HttpSession session = request.getSession(false); - Order order = (Order) session.getAttribute("order"); - if (order == null) { - String username = (String) session.getAttribute("username"); - order = new OrderImpl(username); - } - Bookshelf bookshelf = (Bookshelf) request.getServletContext() - .getAttribute("bookshelf"); - String isbn = request.getParameter("isbn"); - Integer quantity = Integer.parseInt(request.getParameter("quantity")); - Book book = bookshelf.get(isbn); - order.add(book, quantity); - session.setAttribute("order", order); - response.sendRedirect(String.format("index?command=Show&isbn=%s", isbn)); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/SearchCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/SearchCommand.java deleted file mode 100644 index 517092508a..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/SearchCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.data.Book; -import com.baeldung.enterprise.patterns.front.controller.data.Bookshelf; - -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.List; - -public class SearchCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - Bookshelf bookshelf = (Bookshelf) request.getServletContext() - .getAttribute("bookshelf"); - String q = request.getParameter("q"); - List books = bookshelf.find(q); - if (books.size() > 0) { - request.setAttribute("books", books); - forward("book-found"); - } else { - forward("book-notfound"); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/ShowCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/ShowCommand.java deleted file mode 100644 index eb615f075d..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/ShowCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import com.baeldung.enterprise.patterns.front.controller.data.Book; -import com.baeldung.enterprise.patterns.front.controller.data.Bookshelf; - -import javax.servlet.ServletException; -import java.io.IOException; -import java.util.Collections; - -public class ShowCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - Bookshelf bookshelf = (Bookshelf) request.getServletContext() - .getAttribute("bookshelf"); - String title = request.getParameter("isbn"); - Book book = bookshelf.get(title); - request.setAttribute("books", Collections.singletonList(book)); - forward("book-found"); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/UnknownCommand.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/UnknownCommand.java deleted file mode 100644 index 439ae0c8da..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/commands/UnknownCommand.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.commands; - -import javax.servlet.ServletException; -import java.io.IOException; - -public class UnknownCommand extends FrontCommand { - @Override - public void process() throws ServletException, IOException { - super.process(); - forward("unknown"); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Book.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Book.java deleted file mode 100644 index 472ba4c2fa..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Book.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -public interface Book { - String getIsbn(); - - void setIsbn(String isbn); - - String getAuthor(); - - void setAuthor(String author); - - String getTitle(); - - void setTitle(String title); - - Double getPrice(); - - void setPrice(Double price); -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookImpl.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookImpl.java deleted file mode 100644 index c633607f41..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -public class BookImpl implements Book { - private String isbn; - private String author; - private String title; - private Double price; - - public BookImpl() { - } - - public BookImpl(String isbn, String author, String title, Double price) { - this.isbn = isbn; - this.author = author; - this.title = title; - this.price = price; - } - - @Override - public String getIsbn() { - return isbn; - } - - @Override - public void setIsbn(String isbn) { - this.isbn = isbn; - } - - @Override - public String getAuthor() { - return author; - } - - @Override - public void setAuthor(String author) { - this.author = author; - } - - @Override - public String getTitle() { - return title; - } - - @Override - public void setTitle(String title) { - this.title = title; - } - - @Override - public Double getPrice() { - return price; - } - - @Override - public void setPrice(Double price) { - this.price = price; - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Bookshelf.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Bookshelf.java deleted file mode 100644 index e479d27d0e..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Bookshelf.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -import java.util.List; - -public interface Bookshelf { - - default void init() { - add(new BookImpl("001", "Wilson, Robert Anton & Shea, Robert", "Illuminati", 9.99)); - add(new BookImpl("002", "Fowler, Martin", "Patterns of Enterprise Application Architecture", 27.88)); - add(new BookImpl("003", "Unknown", "Something about German Umlauts (äüö) and ß", 5.49)); - } - - boolean add(E book); - - Book get(String isbn); - - List find(String q); -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookshelfImpl.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookshelfImpl.java deleted file mode 100644 index 26090acf74..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/BookshelfImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -public class BookshelfImpl extends ArrayList implements Bookshelf { - @Override - public Book get(String isbn) { - return this.stream() - .filter(book -> book.getIsbn().equals(isbn)) - .findFirst() - .orElse(null); - } - - @Override - public List find(String q) { - return this.stream() - .filter(book -> book.getTitle().toLowerCase().contains(q.toLowerCase()) - || book.getAuthor().toLowerCase().contains(q.toLowerCase())) - .collect(Collectors.toList()); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Order.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Order.java deleted file mode 100644 index 2b6b36568a..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/Order.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -import java.util.Map; - -public interface Order { - String getUsername(); - - Map getItems(); - - void add(Book item, Integer quantity); -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/OrderImpl.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/OrderImpl.java deleted file mode 100644 index eb4a6674cc..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/data/OrderImpl.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.data; - -import java.util.HashMap; -import java.util.Map; - -public class OrderImpl implements Order { - private String username; - private Map items = new HashMap<>(); - - public OrderImpl(String username) { - this.username = username; - } - - @Override - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Override - public Map getItems() { - return items; - } - - public void setItems(Map items) { - this.items = items; - } - - @Override - public void add(Book item, Integer quantity) { - Integer q = 0; - if (this.items.containsKey(item)) { - q = this.items.get(item); - } - this.items.put(item, quantity + q); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/AuthenticationFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/AuthenticationFilter.java deleted file mode 100644 index 2d43116faa..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/AuthenticationFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import com.baeldung.enterprise.patterns.front.controller.commands.FrontCommand; -import com.baeldung.enterprise.patterns.front.controller.commands.LoginCommand; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.IOException; - -public class AuthenticationFilter extends BaseFilter { - private OnIntercept callback; - - public AuthenticationFilter(OnIntercept callback) { - this.callback = callback; - } - - @Override - public void doFilter( - ServletRequest request, - ServletResponse response, - FilterChain chain - ) throws IOException, ServletException { - HttpServletRequest httpServletRequest = (HttpServletRequest) request; - HttpServletResponse httpServletResponse = (HttpServletResponse) response; - HttpSession session = httpServletRequest.getSession(false); - if (session == null || session.getAttribute("username") == null) { - callback.intercept(); - FrontCommand command = new LoginCommand(); - command.init(httpServletRequest, httpServletResponse); - command.process(); - } else { - chain.doFilter(request, response); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/BaseFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/BaseFilter.java deleted file mode 100644 index 81b5027187..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/BaseFilter.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.Filter; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; - -public abstract class BaseFilter implements Filter { - private static final Logger log = LoggerFactory.getLogger(BaseFilter.class); - - protected FilterConfig filterConfig; - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - log.info("Initialize filter: {}", getClass().getSimpleName()); - this.filterConfig = filterConfig; - } - - @Override - public void destroy() { - log.info("Destroy filter: {}", getClass().getSimpleName()); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/EncodingFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/EncodingFilter.java deleted file mode 100644 index d36e204dd5..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/EncodingFilter.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import javax.servlet.*; -import javax.servlet.annotation.WebFilter; -import java.io.IOException; - -@WebFilter(servletNames = "front-controller") -public class EncodingFilter extends BaseFilter { - private String encoding; - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - super.init(filterConfig); - this.encoding = filterConfig.getInitParameter("encoding"); - } - - @Override - public void doFilter( - ServletRequest request, - ServletResponse response, - FilterChain chain - ) throws IOException, ServletException { - String encoding = request.getParameter("encoding"); - if (encoding == null) { - encoding = this.encoding; - } - response.setCharacterEncoding(encoding); - chain.doFilter(request, response); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterChainImpl.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterChainImpl.java deleted file mode 100644 index dd92759e8b..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterChainImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import javax.servlet.Filter; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import java.io.IOException; -import java.util.Arrays; -import java.util.Iterator; - -public class FilterChainImpl implements javax.servlet.FilterChain { - private Iterator filters; - - public FilterChainImpl(Filter... filters) { - this.filters = Arrays.asList(filters).iterator(); - } - - @Override - public void doFilter( - ServletRequest request, - ServletResponse response - ) throws IOException, ServletException { - if (filters.hasNext()) { - Filter filter = filters.next(); - filter.doFilter(request, response, this); - } - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterManager.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterManager.java deleted file mode 100644 index e374b241c4..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/FilterManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -public class FilterManager { - public static void process( - HttpServletRequest request, - HttpServletResponse response, - OnIntercept callback - ) throws ServletException, IOException { - FilterChain filterChain = new FilterChainImpl( - new AuthenticationFilter(callback), - new VisitorCounterFilter() - ); - filterChain.doFilter(request, response); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/LoggingFilter.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/LoggingFilter.java deleted file mode 100644 index 8617fba581..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/LoggingFilter.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.annotation.WebFilter; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; - -@WebFilter(servletNames = "front-controller") -public class LoggingFilter extends BaseFilter { - private static final Logger log = LoggerFactory.getLogger(LoggingFilter.class); - - @Override - public void doFilter( - ServletRequest request, - ServletResponse response, - FilterChain chain - ) throws IOException, ServletException { - chain.doFilter(request, response); - HttpServletRequest httpServletRequest = (HttpServletRequest) request; - String username = (String) httpServletRequest.getAttribute("username"); - if (username == null) { - username = "guest"; - } - log.info("Request from '{}@{}': {}?{}", username, request.getRemoteAddr(), - httpServletRequest.getRequestURI(), request.getParameterMap()); - } -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/OnIntercept.java b/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/OnIntercept.java deleted file mode 100644 index 54da744e78..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/java/com/baeldung/patterns/filters/OnIntercept.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.enterprise.patterns.front.controller.filters; - -public interface OnIntercept { - void intercept(); -} diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-found.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-found.jsp deleted file mode 100644 index 5a03fe92ad..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-found.jsp +++ /dev/null @@ -1,24 +0,0 @@ -<%@ page import="com.baeldung.enterprise.patterns.front.controller.data.Book" %> -<%@ page import="java.util.List" %> - - - - Bookshelf: Title found - - -

Our Bookshelf contains following titles:

- <% for (Book book : (List) request.getAttribute("books")) { %> -

<%= book.getTitle() %>

-

Author: <%= book.getAuthor() %>

-
- - - - - Go back... -
- <% } %> - <%@ include file="shopping-cart-hint.jsp"%> - <%@ include file="visitor-counter.jsp"%> - - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-notfound.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-notfound.jsp deleted file mode 100644 index 284b1e4759..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/book-notfound.jsp +++ /dev/null @@ -1,11 +0,0 @@ - - - - Bookshelf: Title not found - - -

Our Bookshelf doesn't contains this title:

-

<%= request.getParameter("q") %>

- <%@ include file="visitor-counter.jsp"%> - - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/home.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/home.jsp deleted file mode 100644 index f892738c63..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/home.jsp +++ /dev/null @@ -1,27 +0,0 @@ -<%@ page import="com.baeldung.enterprise.patterns.front.controller.data.Book" %> -<%@ page import="java.util.List" %> - - - - Bookshelf: Home - - -
- - -
- <% if (request.getParameter("message") != null) { %> -

<%= request.getParameter("message") %>

- <% } else { %> -

Welcome to the Bookshelf!

- <% } %> - <% for (Book book : (List) request.getAttribute("books")) { %> -
-

<%= book.getAuthor() %>:

-

<%= book.getTitle() %>

- More... - <% } %> - <%@ include file="shopping-cart-hint.jsp"%> - <%@ include file="visitor-counter.jsp"%> - - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/login.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/login.jsp deleted file mode 100644 index 6983fba949..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/login.jsp +++ /dev/null @@ -1,16 +0,0 @@ - - - - Bookshelf: Login - - -

Please input a username:

-

Login

-
- - "> - -
- <%@ include file="visitor-counter.jsp" %> - - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart-hint.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart-hint.jsp deleted file mode 100644 index 5b7c1d9849..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart-hint.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%@ page import="com.baeldung.enterprise.patterns.front.controller.data.Order" %> -<% if (session != null && session.getAttribute("order") != null) { %> - <% Order order = ((Order) session.getAttribute("order")); %> - <% if (order != null && order.getItems().size() > 0) { %> -
-

- Your shopping cart is holding - <% if (order.getItems().size() == 1) { %> - 1 item. - <% } else { %> - <%= (order.getItems().size()) %> items. - <% } %> - Checkout -

- <% } %> -<% } %> diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart.jsp deleted file mode 100644 index 31b25968ee..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/shopping-cart.jsp +++ /dev/null @@ -1,29 +0,0 @@ -<%@ page import="com.baeldung.enterprise.patterns.front.controller.data.Book" %> -<%@ page import="com.baeldung.enterprise.patterns.front.controller.data.Order" %> -<%@ page import="java.util.Map" %> - - - - Bookshelf: Checkout - - -

You are about to buy the following books:

-

Shopping Cart

- <% Order order = (Order) session.getAttribute("order"); %> -
    - <% for (Map.Entry entry : order.getItems().entrySet()) { %> -
  • - <%= entry.getValue() %> x <%= entry.getKey().getPrice() %> -

    <%= entry.getKey().getTitle() %>

    - by <%= entry.getKey().getAuthor()%> -
  • - <% } %> -
-

- Total: <%= request.getAttribute("total") %> -

-
- -
- - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/unknown.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/unknown.jsp deleted file mode 100644 index b52b2de8d5..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/unknown.jsp +++ /dev/null @@ -1,9 +0,0 @@ - - - - Bookshelf: Command unknown - - -

Sorry, this command is not known!

- - diff --git a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/visitor-counter.jsp b/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/visitor-counter.jsp deleted file mode 100644 index 397364e2b3..0000000000 --- a/enterprise-patterns/intercepting-filter-pattern/src/main/webapp/WEB-INF/jsp/visitor-counter.jsp +++ /dev/null @@ -1,5 +0,0 @@ -<% Integer counter = (Integer) request.getAttribute("counter"); %> -<% if (counter != null && counter > 0) { %> -
-

You are visitor #<%= counter %>. Logout

-<% } %>