Java Code Examples for com.netflix.zuul.FilterLoader

The following examples show how to use com.netflix.zuul.FilterLoader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-specialagent   Source File: ZuulTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
  final ZuulFilter preFilter = FilterLoader.getInstance().getFiltersByType("pre").get(0);
  assertTrue(preFilter instanceof TracePreZuulFilter);

  // verify we don't add pre filter continuously
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("pre").size());
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("pre").size());

  final ZuulFilter postFilter = FilterLoader.getInstance().getFiltersByType("post").get(0);
  assertTrue(postFilter instanceof TracePostZuulFilter);

  // verify we don't add post filter continuously
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("post").size());
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("post").size());
}
 
Example 2
Source Project: java-specialagent   Source File: ZuulTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void verifyContextCleared(final MockTracer tracer) {
  final RequestContext context = RequestContext.getCurrentContext();
  final HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
  context.setRequest(httpServletRequest);
  Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");

  final ZuulFilter preFilter = FilterLoader.getInstance().getFiltersByType("pre").get(0);
  preFilter.run();
  assertNotNull(context.get(TracePreZuulFilter.CONTEXT_SPAN_KEY));

  final ZuulFilter postFilter = FilterLoader.getInstance().getFiltersByType("post").get(0);
  postFilter.run();
  assertNull(context.get(TracePreZuulFilter.CONTEXT_SPAN_KEY));

  assertEquals(1, tracer.finishedSpans().size());
}
 
Example 3
Source Project: zuul   Source File: BaseServerStartup.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public BaseServerStartup(ServerStatusManager serverStatusManager, FilterLoader filterLoader,
                         SessionContextDecorator sessionCtxDecorator, FilterUsageNotifier usageNotifier,
                         RequestCompleteHandler reqCompleteHandler, Registry registry,
                         DirectMemoryMonitor directMemoryMonitor, EventLoopGroupMetrics eventLoopGroupMetrics,
                         EurekaClient discoveryClient, ApplicationInfoManager applicationInfoManager,
                         AccessLogPublisher accessLogPublisher)
{
    this.serverStatusManager = serverStatusManager;
    this.registry = registry;
    this.directMemoryMonitor = directMemoryMonitor;
    this.eventLoopGroupMetrics = eventLoopGroupMetrics;
    this.discoveryClient = discoveryClient;
    this.applicationInfoManager = applicationInfoManager;
    this.accessLogPublisher = accessLogPublisher;
    this.sessionCtxDecorator = sessionCtxDecorator;
    this.reqCompleteHandler = reqCompleteHandler;
    this.filterLoader = filterLoader;
    this.usageNotifier = usageNotifier;
}
 
Example 4
Source Project: pig   Source File: GroovyLoadInitListener.java    License: MIT License 5 votes vote down vote up
@EventListener(value = {EmbeddedServletContainerInitializedEvent.class})
public void init() {
    MonitoringHelper.initMocks();
    FilterLoader.getInstance().setCompiler(new GroovyCompiler());
    FilterFileManager.setFilenameFilter(new GroovyFileFilter());
    try {
        FilterFileManager.init(10, groovyPath);
    } catch (Exception e) {
        log.error("初始化网关Groovy 文件失败 {}", e);
    }
    log.warn("初始化网关Groovy 文件成功");
}
 
Example 5
Source Project: heimdall   Source File: InterceptorFileService.java    License: Apache License 2.0 5 votes vote down vote up
private void clearLoaderCache() {
    FilterLoader filterLoader = FilterLoader.getInstance();
    Field field = ReflectionUtils.findField(FilterLoader.class, "hashFiltersByType");
    ReflectionUtils.makeAccessible(field);
    Map<?, ?> cache = (Map<?, ?>) ReflectionUtils.getField(field, filterLoader);
    cache.clear();
}
 
Example 6
@Override
public void run(String... args) throws Exception {
  MonitoringHelper.initMocks();
  FilterLoader.getInstance().setCompiler(new GroovyCompiler());
  try {
    FilterFileManager.setFilenameFilter(new GroovyFileFilter());

    String basePath = "D:/写书/code/microservice-gateway-zuul-filter-groovy/src/main/filters/";

    FilterFileManager.init(1, basePath + "pre", basePath + "post");
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 7
@Override
public void run(String... args) throws Exception {
  MonitoringHelper.initMocks();
  FilterLoader.getInstance().setCompiler(new GroovyCompiler());
  try {
    FilterFileManager.setFilenameFilter(new GroovyFileFilter());

    String basePath = "D:/写书/code/microservice-gateway-zuul-filter-groovy/src/main/filters/";

    FilterFileManager.init(1, basePath + "pre", basePath + "post");
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example 8
Source Project: zuul   Source File: SampleServerStartup.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public SampleServerStartup(ServerStatusManager serverStatusManager, FilterLoader filterLoader,
                           SessionContextDecorator sessionCtxDecorator, FilterUsageNotifier usageNotifier,
                           RequestCompleteHandler reqCompleteHandler, Registry registry,
                           DirectMemoryMonitor directMemoryMonitor, EventLoopGroupMetrics eventLoopGroupMetrics,
                           EurekaClient discoveryClient, ApplicationInfoManager applicationInfoManager,
                           AccessLogPublisher accessLogPublisher, PushConnectionRegistry pushConnectionRegistry,
                           SamplePushMessageSenderInitializer pushSenderInitializer) {
    super(serverStatusManager, filterLoader, sessionCtxDecorator, usageNotifier, reqCompleteHandler, registry,
            directMemoryMonitor, eventLoopGroupMetrics, discoveryClient, applicationInfoManager,
            accessLogPublisher);
    this.pushConnectionRegistry = pushConnectionRegistry;
    this.pushSenderInitializer = pushSenderInitializer;
}
 
Example 9
Source Project: zuul   Source File: ZuulSampleModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    try {
      ConfigurationManager.loadCascadedPropertiesFromResources("application");
    } catch (Exception ex) {
      throw new RuntimeException("Error loading configuration: " + ex.getMessage(), ex);
    }

    bind(AbstractConfiguration.class).toInstance(ConfigurationManager.getConfigInstance());
    bind(DynamicCodeCompiler.class).to(GroovyCompiler.class);
    bind(FilenameFilter.class).to(GroovyFileFilter.class);

    install(new EurekaModule());

    // sample specific bindings
    bind(BaseServerStartup.class).to(SampleServerStartup.class);

    // use provided basic netty origin manager
    bind(OriginManager.class).to(BasicNettyOriginManager.class);

    // zuul filter loading
    install(new ZuulFiltersModule());
    bind(FilterLoader.class).to(DynamicFilterLoader.class);
    bind(FilterRegistry.class).to(MutableFilterRegistry.class);
    bind(FilterFileManager.class).asEagerSingleton();


    // general server bindings
    bind(ServerStatusManager.class); // health/discovery status
    bind(SessionContextDecorator.class).to(ZuulSessionContextDecorator.class); // decorate new sessions when requests come in
    bind(Registry.class).to(DefaultRegistry.class); // atlas metrics registry
    bind(RequestCompleteHandler.class).to(BasicRequestCompleteHandler.class); // metrics post-request completion
    bind(RequestMetricsPublisher.class).to(BasicRequestMetricsPublisher.class); // timings publisher

    // access logger, including request ID generator
    bind(AccessLogPublisher.class).toInstance(new AccessLogPublisher("ACCESS",
            (channel, httpRequest) -> ClientRequestReceiver.getRequestFromChannel(channel).getContext().getUUID()));
}
 
Example 10
Source Project: Sentinel   Source File: SampleServerStartup.java    License: Apache License 2.0 4 votes vote down vote up
@Inject
public SampleServerStartup(ServerStatusManager serverStatusManager, FilterLoader filterLoader, SessionContextDecorator sessionCtxDecorator, FilterUsageNotifier usageNotifier, RequestCompleteHandler reqCompleteHandler, Registry registry, DirectMemoryMonitor directMemoryMonitor, EventLoopGroupMetrics eventLoopGroupMetrics, EurekaClient discoveryClient, ApplicationInfoManager applicationInfoManager, AccessLogPublisher accessLogPublisher) {
    super(serverStatusManager, filterLoader, sessionCtxDecorator, usageNotifier, reqCompleteHandler, registry, directMemoryMonitor, eventLoopGroupMetrics, discoveryClient, applicationInfoManager, accessLogPublisher);
}
 
Example 11
Source Project: heimdall   Source File: StartServer.java    License: Apache License 2.0 4 votes vote down vote up
private void initGroovyFilterManager() {

		try {

			Set<String> filesAbsolutePath = filesAbsolutePath();

			FilterLoader.getInstance().setCompiler(new GroovyCompiler());

			HeimdallFilterFileManager.setFilenameFilter(new GroovyFileFilter());
			HeimdallFilterFileManager.init(zuulFilterInterval, filesAbsolutePath);

		} catch (Exception e) {
			throw new RuntimeException(e);
		}

	}
 
Example 12
Source Project: zuul   Source File: BaseZuulChannelInitializer.java    License: Apache License 2.0 4 votes vote down vote up
protected ZuulEndPointRunner getEndpointRunner(ZuulFilterChainRunner<HttpResponseMessage> responseFilterChain,
                                               FilterUsageNotifier filterUsageNotifier, FilterLoader filterLoader) {
    return new ZuulEndPointRunner(filterUsageNotifier, filterLoader, responseFilterChain);
}
 
Example 13
Source Project: zuul   Source File: ZuulEndPointRunner.java    License: Apache License 2.0 4 votes vote down vote up
public ZuulEndPointRunner(FilterUsageNotifier usageNotifier, FilterLoader filterLoader,
                          FilterRunner<HttpResponseMessage, HttpResponseMessage> respFilters) {
    super(FilterType.ENDPOINT, usageNotifier, respFilters);
    this.filterLoader = filterLoader;
}
 
Example 14
Source Project: heimdall   Source File: HeimdallFilterFileManager.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * puts files into the FilterLoader. The FilterLoader will only addd new or changed filters
 *
 * @param aFiles a List<File>
 * @throws IOException
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
void processGroovyFiles(List<File> aFiles) throws Exception, InstantiationException, IllegalAccessException {
    for (File file : aFiles) {
        FilterLoader.getInstance().putFilter(file);
    }
}