FilterChain implements Invoker { public static FilterChain buildProviderChain(ProviderConfig<?> providerConfig, FilterInvoker lastFilter) { return new FilterChain(selectActualFilters(providerConfig, PROVIDER_AUTO_ACTIVES), lastFilter, providerConfig); } protected  FilterChain(List<Filter> filters, FilterInvoker lastInvoker, AbstractInterfaceConfig config); static FilterChain buildProviderChain(ProviderConfig<?> providerConfig, FilterInvoker lastFilter); static FilterChain buildConsumerChain(ConsumerConfig<?> consumerConfig, FilterInvoker lastFilter); @Override SofaResponse invoke(SofaRequest sofaRequest); void onAsyncResponse(ConsumerConfig config, SofaRequest request, SofaResponse response, Throwable throwable);  }
@Test public void buildProviderChain() { ProviderConfig providerConfig = new ProviderConfig(); providerConfig.setFilter(Arrays.asList("testChainFilter0", "-testChainFilter8")); providerConfig.setInterfaceId(Serializer.class.getName()); ConsumerConfig consumerConfig = new ConsumerConfig(); ArrayList<Filter> list = new ArrayList<Filter>(); consumerConfig.setFilter(Arrays.asList("testChainFilter0", "-testChainFilter8")); list.add(new TestChainFilter1()); list.add(new TestChainFilter2()); list.add(new TestChainFilter3()); list.add(new TestChainFilter4()); list.add(new ExcludeFilter("-testChainFilter5")); consumerConfig.setFilterRef(list); consumerConfig.setInterfaceId(Serializer.class.getName()); FilterChain providerChain = FilterChain.buildProviderChain(providerConfig, new TestProviderFilterInvoker(providerConfig)); FilterChain consumerChain = FilterChain.buildConsumerChain(consumerConfig, new TestConsumerFilterInvoker(consumerConfig, providerChain)); Assert.assertNotNull(consumerChain.getChain()); SofaRequest request = new SofaRequest(); request.setMethodArgs(new String[] { "xxx" }); request.setInvokeType("sync"); String result = (String) consumerChain.invoke(request).getAppResponse(); Assert.assertEquals("xxx_q0_q7_q2_q4_q0_q6_q7_s7_s6_s0_s4_s2_s7_s0", result); request = new SofaRequest(); request.setMethodArgs(new String[] { "xxx" }); request.setInvokeType("callback"); SofaResponse response = consumerChain.invoke(request); consumerChain.onAsyncResponse(consumerConfig, request, response, null); result = (String) response.getAppResponse(); Assert.assertEquals("xxx_q0_q7_q2_q4_q0_q6_q7_a4_a2_a7_a0", result); }