本文整理汇总了Java中com.alibaba.dubbo.common.utils.StringUtils类的典型用法代码示例。如果您正苦于以下问题:Java StringUtils类的具体用法?Java StringUtils怎么用?Java StringUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringUtils类属于com.alibaba.dubbo.common.utils包,在下文中一共展示了StringUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRegistryURL
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
private static URL getRegistryURL(URL url) {
return url.setPath(RegistryService.class.getName())
.removeParameter(Constants.EXPORT_KEY).removeParameter(Constants.REFER_KEY)
.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName())
.addParameter(Constants.CLUSTER_STICKY_KEY, "true")
.addParameter(Constants.LAZY_CONNECT_KEY, "true")
.addParameter(Constants.RECONNECT_KEY, "false")
.addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000")
.addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000")
.addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000")
.addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ","))
//.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName())
//.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch
//.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect")
.addParameter("subscribe.1.callback", "true")
.addParameter("unsubscribe.1.callback", "false");
}
示例2: appendMethodsToUrls
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
static Map<String, String> appendMethodsToUrls(Map<String, String> serviceUrls,
Map<String, Set<String>> url2Methods) {
// 为URL上加上方法参数
Map<String, String> results = new HashMap<String, String>();
for (Map.Entry<String, Set<String>> entry : url2Methods.entrySet()) {
String url = entry.getKey();
String query = serviceUrls.get(url);
Set<String> methodNames = entry.getValue();
if (methodNames != null && methodNames.size() > 0) {
String ms = StringUtils.join(methodNames.toArray(new String[0]), ParseUtils.METHOD_SPLIT);
query = ParseUtils.replaceParameter(query, "methods", ms);
}
results.put(url, query);
}
return results;
}
示例3: add
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public void add(Map<String, Object> context) {
List<String> serviceList = new ArrayList<String>();
List<String> applicationList = new ArrayList<String>();
String service = (String) context.get("service");
String application = (String) context.get("application");
if (StringUtils.isNotEmpty(application)) {
serviceList.addAll(providerService.findServicesByApplication(application));
serviceList.addAll(consumerService.findServicesByApplication(application));
context.put("serviceList", serviceList);
} else if (StringUtils.isNotEmpty(service)) {
applicationList.addAll(providerService.findApplicationsByServiceName(service));
applicationList.addAll(consumerService.findApplicationsByServiceName(service));
context.put("applicationList", applicationList);
} else {
serviceList.addAll(providerService.findServices());
serviceList.addAll(consumerService.findServices());
providerService.findServicesByApplication(application);
consumerService.findServicesByApplication(application);
}
context.put("serviceList", serviceList);
if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
}
}
示例4: filter
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
RpcContext.getContext().setRequest(request);
// this only works for servlet containers
if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
}
RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));
String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
if (headers != null) {
for (String header : headers.split(",")) {
int index = header.indexOf("=");
if (index > 0) {
String key = header.substring(0, index);
String value = header.substring(index + 1);
if (!StringUtils.isEmpty(key)) {
RpcContext.getContext().setAttachment(key.trim(), value.trim());
}
}
}
}
}
示例5: exeMockExceptionThrow
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
/**
* 模拟异常抛出
*/
private void exeMockExceptionThrow(MockTestConfig mockTestConfig) {
String exceptionPath = mockTestConfig.getExceptionClass();
String exceptionMsg = mockTestConfig.getExceptionJson();
if (StringUtils.isNotEmpty(exceptionPath)) {
try {
if (StringUtils.isEmpty(exceptionMsg)) {
exceptionMsg = "Mock模拟Exception抛出 exceptionPath:" + exceptionPath;
}
Class exceptionClass = Class.forName(exceptionPath);
Exception exceptionObj = (Exception) exceptionClass.newInstance();
throw exceptionObj;
} catch (ClassNotFoundException cnfe) {
log.error( "异常类全路径没有找到 exceptionPath:" + exceptionPath);
} catch (Exception e) {
RpcException rpcException = new RpcException(exceptionMsg, e);
rpcException.setStackTrace(e.getStackTrace());
throw rpcException;
}
}
}
示例6: add
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public void add(Map<String, Object> context){
List<String> serviceList = new ArrayList<String>();
List<String> applicationList = new ArrayList<String>();
String service = (String) context.get("service");
String application = (String) context.get("application");
if(StringUtils.isNotEmpty(application)){
serviceList.addAll(providerService.findServicesByApplication(application));
serviceList.addAll(consumerService.findServicesByApplication(application));
context.put("serviceList", serviceList);
}else if(StringUtils.isNotEmpty(service)){
applicationList.addAll(providerService.findApplicationsByServiceName(service));
applicationList.addAll(consumerService.findApplicationsByServiceName(service));
context.put("applicationList", applicationList);
}else{
serviceList.addAll(providerService.findServices());
serviceList.addAll(consumerService.findServices());
providerService.findServicesByApplication(application);
consumerService.findServicesByApplication(application);
}
context.put("serviceList", serviceList);
if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
context.put("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
}
}
示例7: refer
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
url = url.setProtocol(url.getParameter(Constants.REGISTRY_KEY, Constants.DEFAULT_REGISTRY)).removeParameter(Constants.REGISTRY_KEY);
Registry registry = registryFactory.getRegistry(url);
if (RegistryService.class.equals(type)) {
return proxyFactory.getInvoker((T) registry, type, url);
}
// group="a,b" or group="*"
Map<String, String> qs = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
String group = qs.get(Constants.GROUP_KEY);
if (group != null && group.length() > 0 ) {
if ( ( Constants.COMMA_SPLIT_PATTERN.split( group ) ).length > 1
|| "*".equals( group ) ) {
return doRefer( getMergeableCluster(), registry, type, url );
}
}
return doRefer(cluster, registry, type, url);
}
示例8: add
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
/**
* 装载新增服务页面,获取所有的服务名称
*
* @param context
*/
public void add(Long id, Map<String, Object> context) {
if (context.get("service") == null) {
List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
context.put("serviceList", serviceList);
}
if (id != null) {
Provider p = providerService.findProvider(id);
if (p != null) {
context.put("provider", p);
String parameters = p.getParameters();
if (parameters != null && parameters.length() > 0) {
Map<String, String> map = StringUtils.parseQueryString(parameters);
map.put("timestamp", String.valueOf(System.currentTimeMillis()));
map.remove("pid");
p.setParameters(StringUtils.toQueryString(map));
}
}
}
}
示例9: search
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public void search(Map<String, Object> context) {
index(context);
Set<String> newList = new HashSet<String>();
@SuppressWarnings("unchecked")
Set<String> apps = (Set<String>)context.get("applications");
String keyword = (String) context.get("keyword");
if(StringUtils.isNotEmpty(keyword)){
keyword = keyword.toLowerCase();
for(String o : apps){
if(o.toLowerCase().indexOf(keyword)!=-1){
newList.add(o);
}
}
}
context.put("applications", newList);
}
示例10: globalDataTranster
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
private void globalDataTranster(HttpServletRequest request) {
String traceIdValue = request.getHeader("traceId");
String spanIdValue = request.getHeader("spanId");
Map<String, String> globalMap = CallChainContext.getContext().get();
if(globalMap == null){
globalMap = new ConcurrentHashMap<String, String>();
}
if(StringUtils.isNotEmpty(traceIdValue) && StringUtils.isNotEmpty(spanIdValue)){
globalMap.put(CallChainContext.TRACEID, traceIdValue);
globalMap.put(CallChainContext.SPANID, spanIdValue);
globalMap.put(CallChainContext.CURRENTID, spanIdValue);
CallChainContext.getContext().add(globalMap);
}
}
示例11: convertSubscribe
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public static Map<String, String> convertSubscribe(Map<String, String> subscribe) {
Map<String, String> newSubscribe = new HashMap<String, String>();
for (Map.Entry<String, String> entry : subscribe.entrySet()) {
String serviceName = entry.getKey();
String serviceQuery = entry.getValue();
if (! serviceName.contains(":") && ! serviceName.contains("/")) {
Map<String, String> params = StringUtils.parseQueryString(serviceQuery);
String group = params.get("group");
String version = params.get("version");
params.remove("group");
params.remove("version");
String name = serviceName;
if (group != null && group.length() > 0) {
name = group + "/" + name;
}
if (version != null && version.length() > 0 && ! "0.0.0".equals(version)) {
name = name + ":" + version;
}
newSubscribe.put(name, StringUtils.toQueryString(params));
} else {
newSubscribe.put(serviceName, serviceQuery);
}
}
return newSubscribe;
}
示例12: invoke
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
if (cache != null) {
String key = StringUtils.toArgumentString(invocation.getArguments());
if (cache != null && key != null) {
Object value = cache.get(key);
if (value != null) {
return new RpcResult(value);
}
Result result = invoker.invoke(invocation);
if (! result.hasException()) {
cache.put(key, result.getValue());
}
return result;
}
}
}
return invoker.invoke(invocation);
}
示例13: toUrl
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public URL toUrl() {
String group = null;
String version = null;
String path = service;
int i = path.indexOf("/");
if (i > 0) {
group = path.substring(0, i);
path = path.substring(i + 1);
}
i = path.lastIndexOf(":");
if (i > 0) {
version = path.substring(i + 1);
path = path.substring(0, i);
}
Map<String, String> param = StringUtils.parseQueryString(parameters);
param.put(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY);
if (group != null) {
param.put(Constants.GROUP_KEY, group);
}
if (version != null) {
param.put(Constants.VERSION_KEY, version);
}
return URL.valueOf(Constants.CONSUMER_PROTOCOL + "://" + address + "/" + path
+ "?" + StringUtils.toQueryString(param));
}
示例14: isMatchGlobPatternsNeedInterpolate
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
/**
* 是否匹配Glob模式。Glob模式是要插值的表达式。Glob模式有多个,只要匹配一个模式,就认为匹配成功。
*
* @param patternsNeedInterpolate 多个要进行插值的Glob模式
* @param interpolateParams 用于插值的变量集
* @param value 进行Glob模式的值
*/
public static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value) {
if(patternsNeedInterpolate != null && ! patternsNeedInterpolate.isEmpty()) {
for (String patternNeedItp : patternsNeedInterpolate) {
if(StringUtils.isEmpty(patternNeedItp)) {
continue;
}
// FIXME ERROR!! 原来的实现,这里只和第一个不为空的pattern比较,返回对应的结果! 和梁飞确认
String pattern = interpolate(patternNeedItp, interpolateParams);
if(isMatchGlobPattern(pattern, value)) {
return true;
}
}
}
return false;
}
示例15: ConditionRouter
import com.alibaba.dubbo.common.utils.StringUtils; //导入依赖的package包/类
public ConditionRouter(URL url) {
this.url = url;
this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
this.force = url.getParameter(Constants.FORCE_KEY, false);
try {
String rule = url.getParameterAndDecoded(Constants.RULE_KEY);
if (rule == null || rule.trim().length() == 0) {
throw new IllegalArgumentException("Illegal route rule!");
}
rule = rule.replace("consumer.", "").replace("provider.", "");
int i = rule.indexOf("=>");
String whenRule = i < 0 ? null : rule.substring(0, i).trim();
String thenRule = i < 0 ? rule.trim() : rule.substring(i + 2).trim();
Map<String, MatchPair> when = StringUtils.isBlank(whenRule) || "true".equals(whenRule) ? new HashMap<String, MatchPair>() : parseRule(whenRule);
Map<String, MatchPair> then = StringUtils.isBlank(thenRule) || "false".equals(thenRule) ? null : parseRule(thenRule);
// NOTE: When条件是允许为空的,外部业务来保证类似的约束条件
this.whenCondition = when;
this.thenCondition = then;
} catch (ParseException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}