Search in sources :

Example 1 with ExcludeFilter

use of com.alipay.sofa.rpc.filter.ExcludeFilter in project sofa-boot by alipay.

the class RpcBindingConverter method parseFilter.

protected void parseFilter(Element element, RpcBindingParam param, BindingConverterContext bindingConverterContext) {
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(bindingConverterContext.getApplicationContext()));
    if (element != null) {
        List<String> filterNames = new ArrayList<String>();
        String filterStrs = element.getAttribute(RpcBindingXmlConstants.TAG_FILTER);
        if (StringUtils.hasText(filterStrs)) {
            String[] subFilter = filterStrs.split(FILTER_SEPERATOR_SYMBOL);
            for (String subfilterName : subFilter) {
                if (StringUtils.hasText(subfilterName)) {
                    if (subfilterName.charAt(0) == EXCLUDE_FILTER_BEGIN_SYMBOL) {
                        String realFilterName = subfilterName.substring(1);
                        if (StringUtils.hasText(realFilterName)) {
                            filters.add(new ExcludeFilter(realFilterName));
                        }
                    } else {
                        filterNames.add(subfilterName);
                    }
                }
            }
        }
        if (!CollectionUtils.isEmpty(filterNames)) {
            for (String filterName : filterNames) {
                Object filter = bindingConverterContext.getApplicationContext().getBean(filterName);
                if (filter instanceof Filter) {
                    filters.add((Filter) filter);
                } else {
                    throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
                }
            }
        }
    }
    param.setFilters(filters);
}
Also used : ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) ArrayList(java.util.ArrayList)

Example 2 with ExcludeFilter

use of com.alipay.sofa.rpc.filter.ExcludeFilter in project sofa-boot by sofastack.

the class RpcBindingConverter method parseFilter.

protected void parseFilter(Element element, RpcBindingParam param, BindingConverterContext bindingConverterContext) {
    List<Filter> filters = new ArrayList<Filter>(RpcFilterContainer.getInstance().getFilters(bindingConverterContext.getApplicationContext()));
    if (element != null) {
        List<String> filterNames = new ArrayList<String>();
        String filterStrs = element.getAttribute(RpcBindingXmlConstants.TAG_FILTER);
        if (StringUtils.hasText(filterStrs)) {
            String[] subFilter = filterStrs.split(FILTER_SEPERATOR_SYMBOL);
            for (String subfilterName : subFilter) {
                if (StringUtils.hasText(subfilterName)) {
                    if (subfilterName.charAt(0) == EXCLUDE_FILTER_BEGIN_SYMBOL) {
                        String realFilterName = subfilterName.substring(1);
                        if (StringUtils.hasText(realFilterName)) {
                            filters.add(new ExcludeFilter(realFilterName));
                        }
                    } else {
                        filterNames.add(subfilterName);
                    }
                }
            }
        }
        if (!CollectionUtils.isEmpty(filterNames)) {
            for (String filterName : filterNames) {
                Object filter = bindingConverterContext.getApplicationContext().getBean(filterName);
                if (filter instanceof Filter) {
                    filters.add((Filter) filter);
                } else {
                    throw new SofaBootRpcRuntimeException("filter name[" + filterName + "] is not ref a Filter.");
                }
            }
        }
    }
    param.setFilters(filters);
}
Also used : ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) SofaBootRpcRuntimeException(com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException) ExcludeFilter(com.alipay.sofa.rpc.filter.ExcludeFilter) Filter(com.alipay.sofa.rpc.filter.Filter) ArrayList(java.util.ArrayList)

Aggregations

SofaBootRpcRuntimeException (com.alipay.sofa.rpc.boot.common.SofaBootRpcRuntimeException)2 ExcludeFilter (com.alipay.sofa.rpc.filter.ExcludeFilter)2 Filter (com.alipay.sofa.rpc.filter.Filter)2 ArrayList (java.util.ArrayList)2