This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d84de8  Enable intercept filters only when interceptors are 
configured  (#8157)
1d84de8 is described below

commit 1d84de8138dc67016dd0b046a0e8990e47e3a544
Author: Yong Zhang <[email protected]>
AuthorDate: Fri Oct 9 23:35:19 2020 +0800

    Enable intercept filters only when interceptors are configured  (#8157)
    
    **Modification**
    
    Enable intercept filters only when interceptors are configured
---
 .../main/java/org/apache/pulsar/broker/ServiceConfiguration.java   | 7 +++++++
 .../java/org/apache/pulsar/broker/web/ResponseHandlerFilter.java   | 7 +++++--
 .../src/main/java/org/apache/pulsar/broker/web/WebService.java     | 5 ++++-
 .../org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java  | 2 ++
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
index d6cd589..3ab5890 100644
--- 
a/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
+++ 
b/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfiguration.java
@@ -751,12 +751,19 @@ public class ServiceConfiguration implements 
PulsarConfiguration {
     private Set<String> brokerInterceptors = Sets.newTreeSet();
 
     @FieldContext(
+        category = CATEGORY_SERVER,
+        doc = "Enable or disable the broker interceptor, which is only used 
for testing for now"
+    )
+    private boolean disableBrokerInterceptors = true;
+
+    @FieldContext(
         doc = "There are two policies when zookeeper session expired happens, 
\"shutdown\" and \"reconnect\". \n\n"
         + " If uses \"shutdown\" policy, shutdown the broker when zookeeper 
session expired happens.\n\n"
         + " If uses \"reconnect\" policy, try to reconnect to zookeeper server 
and re-register metadata to zookeeper."
     )
     private String zookeeperSessionExpiredPolicy = "shutdown";
 
+
     /**** --- Messaging Protocols --- ****/
 
     @FieldContext(
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/ResponseHandlerFilter.java
 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/ResponseHandlerFilter.java
index 823209c..647590f 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/ResponseHandlerFilter.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/ResponseHandlerFilter.java
@@ -43,10 +43,12 @@ public class ResponseHandlerFilter implements Filter {
 
     private final String brokerAddress;
     private final BrokerInterceptor interceptor;
+    private final boolean interceptorEnabled;
 
     public ResponseHandlerFilter(PulsarService pulsar) {
         this.brokerAddress = pulsar.getAdvertisedAddress();
         this.interceptor = pulsar.getBrokerInterceptor();
+        this.interceptorEnabled = 
!pulsar.getConfig().getBrokerInterceptors().isEmpty();
     }
 
     @Override
@@ -63,8 +65,9 @@ public class ResponseHandlerFilter implements Filter {
                 /* connection is already invalidated */
             }
         }
-        interceptor.onWebserviceResponse(request, response);
-
+        if (interceptorEnabled) {
+            interceptor.onWebserviceResponse(request, response);
+        }
     }
 
     @Override
diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
index 5386c2f..3fd2d50 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/web/WebService.java
@@ -155,8 +155,11 @@ public class WebService implements AutoCloseable {
             });
         }
 
-        context.addFilter(new FilterHolder(new 
PreInterceptFilter(pulsar.getBrokerInterceptor())),
+        if (!pulsar.getConfig().getBrokerInterceptors().isEmpty() || 
!pulsar.getConfig().isDisableBrokerInterceptors()) {
+            // Enable PreInterceptFilter only when interceptors are enabled
+            context.addFilter(new FilterHolder(new 
PreInterceptFilter(pulsar.getBrokerInterceptor())),
                 MATCH_ALL, EnumSet.allOf(DispatcherType.class));
+        }
 
         if (requiresAuthentication && 
pulsar.getConfiguration().isAuthenticationEnabled()) {
             FilterHolder filter = new FilterHolder(new AuthenticationFilter(
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
index 55edf49..5ff73fc 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/intercept/BrokerInterceptorTest.java
@@ -51,6 +51,8 @@ public class BrokerInterceptorTest extends 
ProducerConsumerBase {
 
     @BeforeMethod
     public void setup() throws Exception {
+        this.conf.setDisableBrokerInterceptors(false);
+
         this.listener1 = mock(BrokerInterceptor.class);
         this.ncl1 = mock(NarClassLoader.class);
         this.listener2 = mock(BrokerInterceptor.class);

Reply via email to