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

The following examples show how to use org.apache.dubbo.common.utils.StringUtils. 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: dubbo-samples   Source File: LegacyBlockFilter.java    License: 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 Project: dubbo-registry-nacos   Source File: NacosServiceName.java    License: 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 Project: dubbo-samples   Source File: LegacyListenableFilter.java    License: 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 Project: dubbo-samples   Source File: AsyncPostprocessFilter.java    License: 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 Project: dubbo-registry-nacos   Source File: NacosRegistry.java    License: 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 Project: dubbo-registry-nacos   Source File: NacosRegistry.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: ZKTools.java    License: 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 Project: dubbo-samples   Source File: RuleUtil.java    License: 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("/", ".");
}