org.apache.dubbo.common.utils.StringUtils Java Examples

The following examples show how to use org.apache.dubbo.common.utils.StringUtils. 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 File: LegacyBlockFilter.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    RpcContext context = RpcContext.getContext();
    String filters = (String) context.getAttachment("filters");
    if (StringUtils.isEmpty(filters)) {
        filters = "";
    }
    filters += " legacy-block-filter";
    context.setAttachment("filters", filters);

    Result result = invoker.invoke(invocation);

    logger.info("This is the default return value: " + result.getValue());

    if (result.hasException()) {
        System.out.println("LegacyBlockFilter: This will only happen when the real exception returns: " + result.getException());
        logger.warn("This will only happen when the real exception returns", result.getException());
    }

    logger.info("LegacyBlockFilter: This msg should not be blocked.");
    return result;
}
 
Example #2
Source File: NacosServiceName.java    From dubbo-registry-nacos with Apache License 2.0 5 votes vote down vote up
public boolean isCompatible(NacosServiceName concreteServiceName) {

        if (!concreteServiceName.isConcrete()) { // The argument must be the concrete NacosServiceName
            return false;
        }

        // Not match comparison
        if (!StringUtils.isEquals(this.category, concreteServiceName.category)
                && !matchRange(this.category, concreteServiceName.category)) {
            return false;
        }

        if (!StringUtils.isEquals(this.serviceInterface, concreteServiceName.serviceInterface)) {
            return false;
        }

        // wildcard condition
        if (isWildcard(this.version)) {
            return true;
        }

        if (isWildcard(this.group)) {
            return true;
        }

        // range condition
        if (!StringUtils.isEquals(this.version, concreteServiceName.version)
                && !matchRange(this.version, concreteServiceName.version)) {
            return false;
        }

        if (!StringUtils.isEquals(this.group, concreteServiceName.group) &&
                !matchRange(this.group, concreteServiceName.group)) {
            return false;
        }

        return true;
    }
 
Example #3
Source File: LegacyListenableFilter.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    RpcContext context = RpcContext.getContext();
    String filters = (String) context.getAttachment("filters");
    if (StringUtils.isEmpty(filters)) {
        filters = "";
    }
    filters += " legacy-block-filter";
    context.setAttachment("filters", filters);

    return invoker.invoke(invocation);
}
 
Example #4
Source File: AsyncPostprocessFilter.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    RpcContext context = RpcContext.getContext();
    String filters = (String) context.getAttachment("filters");
    if (StringUtils.isEmpty(filters)) {
        filters = "";
    }
    filters += " async-post-process-filter";
    context.setAttachment("filters", filters);

    return invoker.invoke(invocation);
}
 
Example #5
Source File: NacosRegistry.java    From dubbo-registry-nacos with Apache License 2.0 4 votes vote down vote up
private void appendIfPresent(StringBuilder target, URL url, String parameterName) {
    String parameterValue = url.getParameter(parameterName);
    if (!org.apache.commons.lang3.StringUtils.isBlank(parameterValue)) {
        target.append(SERVICE_NAME_SEPARATOR).append(parameterValue);
    }
}
 
Example #6
Source File: NacosRegistry.java    From dubbo-registry-nacos with Apache License 2.0 4 votes vote down vote up
private void filterServiceNames(Set<String> serviceNames, URL url) {

        final List<String> categories = getCategories(url);

        final String targetServiceInterface = url.getServiceInterface();

        final String targetVersion = url.getParameter(VERSION_KEY, "");

        final String targetGroup = url.getParameter(GROUP_KEY, "");

        filterData(serviceNames, serviceName -> {
            // split service name to segments
            // (required) segments[0] = category
            // (required) segments[1] = serviceInterface
            // (optional) segments[2] = version
            // (optional) segments[3] = group
            String[] segments = serviceName.split(SERVICE_NAME_SEPARATOR, -1);
            int length = segments.length;
            if (length != 4) { // must present 4 segments
                return false;
            }

            String category = segments[CATEGORY_INDEX];
            if (!categories.contains(category)) { // no match category
                return false;
            }

            String serviceInterface = segments[SERVICE_INTERFACE_INDEX];
            // no match service interface
            if (!WILDCARD.equals(targetServiceInterface) &&
                    !StringUtils.isEquals(targetServiceInterface, serviceInterface)) {
                return false;
            }

            // no match service version
            String version = segments[SERVICE_VERSION_INDEX];
            if (!WILDCARD.equals(targetVersion) && !StringUtils.isEquals(targetVersion, version)) {
                return false;
            }

            String group = segments[SERVICE_GROUP_INDEX];
            return group == null || WILDCARD.equals(targetGroup) || StringUtils.isEquals(targetGroup, group);
        });
    }
 
Example #7
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #8
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #9
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #10
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #11
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #12
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #13
Source File: ZKTools.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}
 
Example #14
Source File: RuleUtil.java    From dubbo-samples with Apache License 2.0 4 votes vote down vote up
private static String pathToKey(String path) {
    if (StringUtils.isEmpty(path)) {
        return path;
    }
    return path.replace("/dubbo/config/", "").replaceAll("/", ".");
}