filter-valve: use lambdas 72/57172/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:47:09 +0000 (17:47 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 16 May 2017 23:27:05 +0000 (23:27 +0000)
This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: I1d754b40d7a0b5b75e8069522f4d5278f08938cd
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/FilterValve.java
opendaylight/commons/filter-valve/src/main/java/org/opendaylight/controller/filtervalve/cors/model/FilterProcessor.java

index b78abda..d096cf6 100644 (file)
@@ -13,8 +13,6 @@ import java.io.IOException;
 import java.util.Objects;
 import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.valves.ValveBase;
@@ -39,19 +37,16 @@ public class FilterValve extends ValveBase {
             throw new IllegalStateException("Initialization error");
         }
 
-        FilterChain nextValveFilterChain = new FilterChain() {
-            @Override
-            public void doFilter(ServletRequest req, ServletResponse resp) throws IOException, ServletException {
-                boolean reqEquals = Objects.equals(request, req);
-                boolean respEquals = Objects.equals(response, resp);
-                if (reqEquals == false || respEquals == false) {
-                    logger.error("Illegal change was detected by valve - request {} or " +
-                            "response {} was replaced by a filter. This is not supported by this valve",
-                            reqEquals, respEquals);
-                    throw new IllegalStateException("Request or response was replaced in a filter");
-                }
-                getNext().invoke(request, response);
+        FilterChain nextValveFilterChain = (req, resp) -> {
+            boolean reqEquals = Objects.equals(request, req);
+            boolean respEquals = Objects.equals(response, resp);
+            if (reqEquals == false || respEquals == false) {
+                logger.error("Illegal change was detected by valve - request {} or " +
+                        "response {} was replaced by a filter. This is not supported by this valve",
+                        reqEquals, respEquals);
+                throw new IllegalStateException("Request or response was replaced in a filter");
             }
+            getNext().invoke(request, response);
         };
         filterProcessor.process(request, response, nextValveFilterChain);
     }
index ae9d79a..2aa2301 100644 (file)
@@ -14,8 +14,6 @@ import java.util.List;
 import java.util.ListIterator;
 import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.opendaylight.controller.filtervalve.cors.jaxb.Context;
@@ -51,15 +49,12 @@ public class FilterProcessor {
             while (it.hasPrevious()) {
                 final Filter currentFilter = it.previous();
                 final FilterChain copy = fromLast;
-                fromLast = new FilterChain() {
-                    @Override
-                    public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
-                        if (trace) {
-                            logger.trace("Applying {}", currentFilter);
-                        }
-                        javax.servlet.Filter actualFilter = currentFilter.getActualFilter();
-                        actualFilter.doFilter(request, response, copy);
+                fromLast = (request1, response1) -> {
+                    if (trace) {
+                        logger.trace("Applying {}", currentFilter);
                     }
+                    javax.servlet.Filter actualFilter = currentFilter.getActualFilter();
+                    actualFilter.doFilter(request1, response1, copy);
                 };
             }
             // call first filter

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.