use of com.netflix.zuul.filters.ZuulFilter in project zuul by Netflix.
the class ZuulFilterChainHandler method fireEndpointFinish.
protected void fireEndpointFinish(final boolean error) {
final ZuulFilter endpoint = ZuulEndPointRunner.getEndpoint(zuulRequest);
if (endpoint instanceof ProxyEndpoint) {
final ProxyEndpoint edgeProxyEndpoint = (ProxyEndpoint) endpoint;
edgeProxyEndpoint.finish(error);
}
zuulRequest = null;
}
use of com.netflix.zuul.filters.ZuulFilter in project zuul by Netflix.
the class BaseZuulChannelInitializer method addZuulFilterChainHandler.
protected void addZuulFilterChainHandler(final ChannelPipeline pipeline) {
final ZuulFilter<HttpResponseMessage, HttpResponseMessage>[] responseFilters = getFilters(new OutboundPassportStampingFilter(FILTERS_OUTBOUND_START), new OutboundPassportStampingFilter(FILTERS_OUTBOUND_END));
// response filter chain
final ZuulFilterChainRunner<HttpResponseMessage> responseFilterChain = getFilterChainRunner(responseFilters, filterUsageNotifier);
// endpoint | response filter chain
final FilterRunner<HttpRequestMessage, HttpResponseMessage> endPoint = getEndpointRunner(responseFilterChain, filterUsageNotifier, filterLoader);
final ZuulFilter<HttpRequestMessage, HttpRequestMessage>[] requestFilters = getFilters(new InboundPassportStampingFilter(FILTERS_INBOUND_START), new InboundPassportStampingFilter(FILTERS_INBOUND_END));
// request filter chain | end point | response filter chain
final ZuulFilterChainRunner<HttpRequestMessage> requestFilterChain = getFilterChainRunner(requestFilters, filterUsageNotifier, endPoint);
pipeline.addLast(new ZuulFilterChainHandler(requestFilterChain, responseFilterChain));
}
use of com.netflix.zuul.filters.ZuulFilter in project zuul by Netflix.
the class ZuulFilterChainRunnerTest method testInboundFilterChain.
@Test
public void testInboundFilterChain() {
final SimpleInboundFilter inbound1 = spy(new SimpleInboundFilter(true));
final SimpleInboundFilter inbound2 = spy(new SimpleInboundFilter(false));
final ZuulFilter[] filters = new ZuulFilter[] { inbound1, inbound2 };
final FilterUsageNotifier notifier = mock(FilterUsageNotifier.class);
final Registry registry = mock(Registry.class);
final ZuulFilterChainRunner runner = new ZuulFilterChainRunner(filters, notifier, registry);
runner.filter(request);
verify(inbound1, times(1)).applyAsync(eq(request));
verify(inbound2, never()).applyAsync(eq(request));
verify(notifier).notify(eq(inbound1), eq(ExecutionStatus.SUCCESS));
verify(notifier).notify(eq(inbound2), eq(ExecutionStatus.SKIPPED));
verifyNoMoreInteractions(notifier);
}
use of com.netflix.zuul.filters.ZuulFilter in project zuul by Netflix.
the class ZuulFilterChainRunnerTest method testOutboundFilterChain.
@Test
public void testOutboundFilterChain() {
final SimpleOutboundFilter outbound1 = spy(new SimpleOutboundFilter(true));
final SimpleOutboundFilter outbound2 = spy(new SimpleOutboundFilter(false));
final ZuulFilter[] filters = new ZuulFilter[] { outbound1, outbound2 };
final FilterUsageNotifier notifier = mock(FilterUsageNotifier.class);
final Registry registry = mock(Registry.class);
final ZuulFilterChainRunner runner = new ZuulFilterChainRunner(filters, notifier, registry);
runner.filter(response);
verify(outbound1, times(1)).applyAsync(any());
verify(outbound2, never()).applyAsync(any());
verify(notifier).notify(eq(outbound1), eq(ExecutionStatus.SUCCESS));
verify(notifier).notify(eq(outbound2), eq(ExecutionStatus.SKIPPED));
verifyNoMoreInteractions(notifier);
}
use of com.netflix.zuul.filters.ZuulFilter in project zuul by Netflix.
the class StaticFilterLoader method loadFilterTypesFromResources.
public static Set<Class<ZuulFilter<?, ?>>> loadFilterTypesFromResources(ClassLoader loader) throws IOException {
Set<Class<ZuulFilter<?, ?>>> filterTypes = new LinkedHashSet<>();
for (URL url : Collections.list(loader.getResources(RESOURCE_NAME))) {
try (InputStream is = url.openStream();
InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
BufferedReader br = new BufferedReader(isr)) {
String line;
while ((line = br.readLine()) != null) {
String trimmed = line.trim();
if (!trimmed.isEmpty()) {
Class<?> clz;
try {
clz = Class.forName(trimmed, false, loader);
} catch (ClassNotFoundException e) {
// This can happen if a filter is deleted, but the annotation processor doesn't
// remove it from the list. This is mainly a problem with IntelliJ, which
// forces append only annotation processors. Incremental recompilation drops
// most of the classpath, making the processor unable to reconstruct the filter
// list. To work around this problem, use the stale, cached filter list from
// the initial full compilation and add to it. This makes incremental
// compilation work later, at the cost of polluting the filter list. It's a
// better experience to log a warning (and do a clean build), than to
// mysteriously classes.
logger.warn("Missing Filter", e);
continue;
}
@SuppressWarnings("unchecked") Class<ZuulFilter<?, ?>> filterClz = (Class<ZuulFilter<?, ?>>) clz.asSubclass(ZuulFilter.class);
filterTypes.add(filterClz);
}
}
}
}
return Collections.unmodifiableSet(filterTypes);
}
Aggregations