Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -750,13 +750,20 @@ 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,8 +65,9 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
/* connection is already invalidated */
}
}
interceptor.onWebserviceResponse(request, response);

if (interceptorEnabled) {
interceptor.onWebserviceResponse(request, response);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ public void addServlet(String path, ServletHolder servletHolder, boolean require
});
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down