Java Code Examples for com.alibaba.dubbo.common.utils.StringUtils#isEmpty()
The following examples show how to use
com.alibaba.dubbo.common.utils.StringUtils#isEmpty() .
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: OverrideUtils.java From dubbox with Apache License 2.0 | 6 votes |
public static List<Weight> overridesToWeights(List<Override> overrides){ List<Weight> weights = new ArrayList<Weight>(); if(overrides == null){ return weights; } for(Override o : overrides){ if(StringUtils.isEmpty(o.getParams())){ continue; }else{ Map<String,String> params = StringUtils.parseQueryString(o.getParams()); for(Map.Entry<String, String> entry : params.entrySet()){ if(entry.getKey().equals("weight")){ Weight weight = new Weight(); weight.setAddress(o.getAddress()); weight.setId(o.getId()); weight.setService(o.getService()); weight.setWeight(Integer.valueOf(entry.getValue())); weights.add(weight); } } } } return weights; }
Example 2
Source File: UserControllerImpl.java From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 | 6 votes |
/** * 获取SessionID对应的用户信息 * @param sessionID * @return */ private UserEntity getUserEntity(String sessionID) { // SessionID为空 if (StringUtils.isEmpty(sessionID)) { return null; } // 获取UserEntity // TODO 暂时存储本地 // Object userEntity = redisService.get(sessionID); Object userEntity = RedisServiceTemp.userMap.get(sessionID); if (userEntity==null) { return null; } return (UserEntity) userEntity; }
Example 3
Source File: ServiceConfig.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
private void checkProtocol() { if ((protocols == null || protocols.size() == 0) && provider != null) { setProtocols(provider.getProtocols()); } // 兼容旧版本 if (protocols == null || protocols.size() == 0) { setProtocol(new ProtocolConfig()); } for (ProtocolConfig protocolConfig : protocols) { if (StringUtils.isEmpty(protocolConfig.getName())) { protocolConfig.setName("dubbo"); } appendProperties(protocolConfig); } }
Example 4
Source File: UserServiceImpl.java From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 | 6 votes |
private void checkParam(LocationCreateReq locationCreateReq, String userId) { // 参数不能为空 if (locationCreateReq==null) { throw new CommonBizException(ExpCodeEnum.PARAM_NULL); } // UserId不能为空 if (StringUtils.isEmpty(userId)) { throw new CommonBizException(ExpCodeEnum.USERID_NULL); } // 地址不能为空 if (StringUtils.isEmpty(locationCreateReq.getLocation())) { throw new CommonBizException(ExpCodeEnum.LOCATION_NULL); } // 电话不能为空 if (StringUtils.isEmpty(locationCreateReq.getPhone())) { throw new CommonBizException(ExpCodeEnum.PHONE_NULL); } // 姓名不能为空 if (StringUtils.isEmpty(locationCreateReq.getName())) { throw new CommonBizException(ExpCodeEnum.NAME_NULL); } }
Example 5
Source File: UserServiceImpl.java From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 | 6 votes |
private void checkParam(LocationUpdateReq locationUpdateReq, String userId) { if (locationUpdateReq == null) { throw new CommonBizException(ExpCodeEnum.LOCATIONUPDATEREQ_NULL); } // UserId不能为空 if (StringUtils.isEmpty(userId)) { throw new CommonBizException(ExpCodeEnum.USERID_NULL); } // LocationUpdateReq中的参数不能全为空 if (StringUtils.isEmpty(locationUpdateReq.getLocation()) && StringUtils.isEmpty(locationUpdateReq.getLocationId()) && StringUtils.isEmpty(locationUpdateReq.getName()) && StringUtils.isEmpty(locationUpdateReq.getPhone()) && StringUtils.isEmpty(locationUpdateReq.getPostCode())) { throw new CommonBizException(ExpCodeEnum.LOCATIONUPDATEREQ_NULL); } }
Example 6
Source File: ServiceConfig.java From dubbo3 with Apache License 2.0 | 6 votes |
private void checkProtocol() { if ((protocols == null || protocols.size() == 0) && provider != null) { setProtocols(provider.getProtocols()); } // 兼容旧版本 if (protocols == null || protocols.size() == 0) { setProtocol(new ProtocolConfig()); } for (ProtocolConfig protocolConfig : protocols) { if (StringUtils.isEmpty(protocolConfig.getName())) { protocolConfig.setName("dubbo"); } appendProperties(protocolConfig); } }
Example 7
Source File: ParseUtils.java From dubbox with Apache License 2.0 | 6 votes |
/** * 是否匹配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; }
Example 8
Source File: ParseUtils.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
/** * 是否匹配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; }
Example 9
Source File: ServiceConfig.java From dubbox with Apache License 2.0 | 6 votes |
private void checkProtocol() { if ((protocols == null || protocols.size() == 0) && provider != null) { setProtocols(provider.getProtocols()); } // 兼容旧版本 if (protocols == null || protocols.size() == 0) { setProtocol(new ProtocolConfig()); } for (ProtocolConfig protocolConfig : protocols) { if (StringUtils.isEmpty(protocolConfig.getName())) { protocolConfig.setName("dubbo"); } appendProperties(protocolConfig); } }
Example 10
Source File: ParseUtils.java From dubbox with Apache License 2.0 | 6 votes |
public static String appendParamsToUri(String uri, Map<String, String> params) { StringBuilder buf = new StringBuilder(uri); boolean first = (uri.indexOf('?') < 0); for(Map.Entry<String, String> entry : params.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if(StringUtils.isEmpty(key) || StringUtils.isEmpty(value)) continue; if (first) { buf.append("?"); first = false; } else { buf.append("&"); } buf.append(key); buf.append("="); buf.append(value); } return buf.toString(); }
Example 11
Source File: BaseRestServer.java From dubbox with Apache License 2.0 | 5 votes |
public void deploy(Class resourceDef, Object resourceInstance, String contextPath) { if (StringUtils.isEmpty(contextPath)) { getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef)); } else { getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef), contextPath); } }
Example 12
Source File: OverrideUtils.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance){ Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if(StringUtils.isEmpty(method) ||method.equals("*")){ override.setParams("loadbalance=" + strategy); }else{ override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example 13
Source File: CacheConfig.java From dubbo-plus with Apache License 2.0 | 5 votes |
public static long getProperty(String key,long defaultValue){ String value = getProperty(key); if(!StringUtils.isEmpty(value)){ return Long.parseLong(value); } return defaultValue; }
Example 14
Source File: DubboClientWrapper.java From dubbo-plus with Apache License 2.0 | 5 votes |
private static Class<? extends InvokeHandler> getInvokeHandler(Class<?> clientType,String id){ //dubbo.wrapper.[clientfacadefullname].handler String handlerName = ConfigUtils.getProperty(DUBBO_WRAPPER_KEY_PREFIX + id + INVOKE_HANDLER_KEY_SUFFIX); if(StringUtils.isEmpty(handlerName)){ return DEFAULT_HANDLER; } return generateHandler(handlerName); }
Example 15
Source File: OverrideUtils.java From open-capacity-platform with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance) { Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if (StringUtils.isEmpty(method) || method.equals("*")) { override.setParams("loadbalance=" + strategy); } else { override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example 16
Source File: ServiceConfig.java From dubbox with Apache License 2.0 | 5 votes |
public void setGeneric(String generic) { if (StringUtils.isEmpty(generic)) { return; } if (ProtocolUtils.isGeneric(generic)) { this.generic = generic; } else { throw new IllegalArgumentException("Unsupported generic type " + generic); } }
Example 17
Source File: ConvertUtil.java From dubbox with Apache License 2.0 | 5 votes |
public static Map<String, String> serviceName2Map(String serviceName) { String group = null; String version = null; int i = serviceName.indexOf("/"); if (i > 0) { group = serviceName.substring(0, i); serviceName = serviceName.substring(i + 1); } i = serviceName.lastIndexOf(":"); if (i > 0) { version = serviceName.substring(i + 1); serviceName = serviceName.substring(0, i); } Map<String, String> ret = new HashMap<String, String>(); if(!StringUtils.isEmpty(serviceName)) { ret.put(Constants.INTERFACE_KEY, serviceName); } if(!StringUtils.isEmpty(version)) { ret.put(Constants.VERSION_KEY, version); } if(!StringUtils.isEmpty(group)) { ret.put(Constants.GROUP_KEY, group); } return ret; }
Example 18
Source File: OverrideUtils.java From dubbox with Apache License 2.0 | 5 votes |
public static Override loadBalanceToOverride(LoadBalance loadBalance){ Override override = new Override(); override.setId(loadBalance.getId()); override.setService(loadBalance.getService()); override.setEnabled(true); String method = loadBalance.getMethod(); String strategy = loadBalance.getStrategy(); if(StringUtils.isEmpty(method) ||method.equals("*")){ override.setParams("loadbalance=" + strategy); }else{ override.setParams(method + ".loadbalance=" + strategy); } return override; }
Example 19
Source File: BaseRestServer.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void deploy(Class resourceDef, Object resourceInstance, String contextPath) { if (StringUtils.isEmpty(contextPath)) { getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef)); } else { getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef), contextPath); } }
Example 20
Source File: RestProtocol.java From dubbox with Apache License 2.0 | 4 votes |
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException { if (connectionMonitor == null) { connectionMonitor = new ConnectionMonitor(); } // TODO more configs to add PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); // 20 is the default maxTotal of current PoolingClientConnectionManager connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20)); connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20)); connectionMonitor.addConnectionManager(connectionManager); // BasicHttpContext localContext = new BasicHttpContext(); DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager); httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { public long getKeepAliveDuration(HttpResponse response, HttpContext context) { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { return Long.parseLong(value) * 1000; } } // TODO constant return 30 * 1000; } }); HttpParams params = httpClient.getParams(); // TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSoKeepalive(params, true); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/); ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build(); clients.add(client); client.register(RpcContextFilter.class); for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) { if (!StringUtils.isEmpty(clazz)) { try { client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim())); } catch (ClassNotFoundException e) { throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e); } } } // TODO protocol ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url)); return target.proxy(serviceType); }