com.alibaba.dubbo.common.utils.StringUtils Java Examples

The following examples show how to use com.alibaba.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: ParseUtils.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: ParseUtils.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: HttpBraveServletFilter.java    From j360-dubbo-app-all with Apache License 2.0 6 votes vote down vote up
/** Alternative to {@link #getStatus}, but for Servlet 2.5+ */
@Override public Collection<KeyValueAnnotation> responseAnnotations() {
    String status = getHeader("status");
    String message = getHeader("message");

    if(StringUtils.isNotEmpty(status)) {
        if (Integer.parseInt(status) != 0) {
            KeyValueAnnotation keyValueAnnotation1 = KeyValueAnnotation.create(DubboKeys.HTTP_STATUS, status);
            KeyValueAnnotation keyValueAnnotation2 = KeyValueAnnotation.create(DubboKeys.HTTP_MESSAGE, message);
            return Lists.newArrayList(keyValueAnnotation1 ,keyValueAnnotation2);
        }
    }
    return Collections.singleton(
            KeyValueAnnotation.create(zipkin.TraceKeys.HTTP_STATUS_CODE, String.valueOf(httpStatus))
    );
}
 
Example #4
Source File: ServiceFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
    ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
    referenceConfig.setInterface(cls);
    StringBuilder url = new StringBuilder();
    url.append(protocol);
    url.append("://");
    url.append(targetIP);
    url.append(":");
    url.append(targetPort);
    url.append("/");
    url.append(cls.getName());
    url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
    if (!StringUtils.isEmpty(serialization)) {
        url.append("&serialization=");
        url.append(serialization);
    }
    referenceConfig.setUrl(url.toString());
    // hardcode
    referenceConfig.setConnections(clientNums);
    ApplicationConfig application = new ApplicationConfig();
    application.setName("dubbo_consumer");
    referenceConfig.setApplication(application);
    referenceConfig.setTimeout(connectTimeout);
    return referenceConfig.get();
}
 
Example #5
Source File: Applications.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: Builder.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Override
public Serializable parseFrom(GenericObjectInput in) throws IOException {
    byte b = in.read0();
    if (b == OBJECT_NULL)
        return null;
    if (b != OBJECT_STREAM)
        throw new IOException("Input format error, expect OBJECT_NULL|OBJECT_STREAM, get " + b + ".");

    UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(in.read0(in.readUInt()));
    CompactedObjectInputStream ois = new CompactedObjectInputStream(bis);
    try {
        return (Serializable) ois.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(StringUtils.toString(e));
    }
}
 
Example #7
Source File: ReferenceConfigCache.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public String generateKey(ReferenceConfig<?> referenceConfig) {
    String iName = referenceConfig.getInterface();
    if(StringUtils.isBlank(iName)) {
        Class<?> clazz = referenceConfig.getInterfaceClass();
        iName = clazz.getName();
    }
    if(StringUtils.isBlank(iName)) {
        throw new IllegalArgumentException("No interface info in ReferenceConfig" + referenceConfig);
    }

    StringBuilder ret = new StringBuilder();
    if(! StringUtils.isBlank(referenceConfig.getGroup())) {
        ret.append(referenceConfig.getGroup()).append("/");
    }
    ret.append(iName);
    if(! StringUtils.isBlank(referenceConfig.getVersion())) {
        ret.append(":").append(referenceConfig.getVersion());
    }
    return ret.toString();
}
 
Example #8
Source File: CacheFilter.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #9
Source File: Applications.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: CacheFilter.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
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(), invocation);
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            Object value = cache.get(key);
            if (value != null) {
                return new RpcResult(value);
            }
            Result result = invoker.invoke(invocation);
            if (!result.hasException() && result.getValue() != null) {
                cache.put(key, result.getValue());
            }
            return result;
        }
    }
    return invoker.invoke(invocation);
}
 
Example #11
Source File: RpcContextFilter.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
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());
                }
            }
        }
    }
}
 
Example #12
Source File: Consumer.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #13
Source File: ParseUtils.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/** 
 * 是否匹配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 #14
Source File: OrderControllerImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private void transferProdIdCountJson(OrderInsertReq orderInsertReq) {
    if (orderInsertReq != null && StringUtils.isNotEmpty(orderInsertReq.getProdIdCountJson())) {
        try {
            Map<String, Long> prodIdCountMapPre = JSON.parse(orderInsertReq.getProdIdCountJson(), Map.class);
            Map<String, Integer> prodIdCountMap = Maps.newHashMap();
            if (prodIdCountMapPre.size() > 0) {
                for (String key : prodIdCountMapPre.keySet()) {
                    prodIdCountMap.put(key, (Integer) prodIdCountMapPre.get(key).intValue());
                }
            }
            orderInsertReq.setProdIdCountMap(prodIdCountMap);
        } catch (ParseException e) {
            throw new CommonBizException(ExpCodeEnum.JSONERROR);
        }
    }

}
 
Example #15
Source File: ServiceConfig.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private void checkProtocol() {
//        如果没有协议配置就从provider中获取协议配置
        if ((protocols == null || protocols.isEmpty())
                && provider != null) {
//            从provider中获取协议配置
            setProtocols(provider.getProtocols());
        }
        // backward compatibility 如果provider协议配置也没有就创建默认协议配置
        if (protocols == null || protocols.isEmpty()) {
            setProtocol(new ProtocolConfig());
        }
//        <dubbo:protocol name="dubbo" port="-1" id="dubbo" />
        for (ProtocolConfig protocolConfig : protocols) {
            if (StringUtils.isEmpty(protocolConfig.getName())) {
//                如果协议名称为空,默认dubbo协议
                protocolConfig.setName(Constants.DUBBO_VERSION_KEY);
            }
//            从系统属性中解析协议配置=》
            appendProperties(protocolConfig);
        }
    }
 
Example #16
Source File: RouteUtils.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
static Map<String, String> appendMethodsToUrls(Map<String, String> serviceUrls,
                                               Map<String, Set<String>> url2Methods) {
    // Add method parameters to 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;
}
 
Example #17
Source File: Addresses.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void search(Map<String, Object> context) {
    index(context);
    
    Set<String> newList = new HashSet<String>();
    @SuppressWarnings("unchecked")
    Set<String> list = (Set<String>)context.get("addresses");
    String keyword = (String) context.get("keyword");
    if(StringUtils.isNotEmpty(keyword)){
        keyword = keyword.toLowerCase();
        for(String o : list){
            if(o.toLowerCase().indexOf(keyword)!=-1){
                newList.add(o);
            }
        }
    }
    context.put("addresses", newList);
}
 
Example #18
Source File: OverridesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "overrides");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String application = (String)newModel.get("app");
    String address = (String)newModel.get("address");
    List<Override> overrides;
    if (StringUtils.isNotEmpty(service)) {
        overrides = overrideService.findByService(service);
    } else if (StringUtils.isNotEmpty(application)) {
        overrides = overrideService.findByApplication(application);
    } else if (StringUtils.isNotEmpty(address)) {
        overrides = overrideService.findByAddress(address);
    } else {
        overrides = overrideService.findAll();
    }
    model.addAttribute("overrides", overrides);
    return "governance/screen/overrides/index";
}
 
Example #19
Source File: Consumer.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #20
Source File: OverrideUtils.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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 #21
Source File: DubboRegistryFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example #22
Source File: CuratorZookeeperClient.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void process(WatchedEvent event) throws Exception {
    if (listener != null) {
        String path = event.getPath() == null ? "" : event.getPath();
        listener.childChanged(path,
                // if path is null, curator using watcher will throw NullPointerException.
                // if client connect or disconnect to server, zookeeper will queue
                // watched event(Watcher.Event.EventType.None, .., path = null).
                StringUtils.isNotEmpty(path)
                        ? client.getChildren().usingWatcher(this).forPath(path)
                        : Collections.<String>emptyList());
    }
}
 
Example #23
Source File: BaseCheckParamComponent.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 参数校验
 * @param param 待校验参数
 * @param expCodeEnum 异常错误码
 */
protected <T> void checkParam(T param, ExpCodeEnum expCodeEnum) {
    if (param == null) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof String && StringUtils.isEmpty((String) param)) {
        throw new CommonBizException(expCodeEnum);
    }

    if (param instanceof Collection && CollectionUtils.isEmpty((Collection<?>) param)) {
        throw new CommonBizException(expCodeEnum);
    }
}
 
Example #24
Source File: MulticastExchangeGroup.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private static boolean isMulticastAddress(String ip) {
    int i = ip.indexOf('.');
    if (i > 0) {
        String prefix = ip.substring(0, i);
        if (StringUtils.isInteger(prefix)) {
            int p = Integer.parseInt(prefix);
            return p >= 224 && p <= 239;
        }
    }
    return false;
}
 
Example #25
Source File: Override.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Map<String, String> toParametersMap() {
	Map<String, String> map = StringUtils.parseQueryString(getParams());
	map.remove(Constants.INTERFACE_KEY);
	map.remove(Constants.GROUP_KEY);
	map.remove(Constants.VERSION_KEY);
	map.remove(Constants.APPLICATION_KEY);
	map.remove(Constants.CATEGORY_KEY);
	map.remove(Constants.DYNAMIC_KEY);
	map.remove(Constants.ENABLED_KEY);
	return map;
}
 
Example #26
Source File: ExtensionLoader.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
/**
 * Register new extension via API
 *
 * @param name  extension name
 * @param clazz extension class
 * @throws IllegalStateException when extension with the same name has already been registered.
 */
public void addExtension(String name, Class<?> clazz) {
    getExtensionClasses(); // load classes

    if (!type.isAssignableFrom(clazz)) {
        throw new IllegalStateException("Input type " +
                clazz + "not implement Extension " + type);
    }
    if (clazz.isInterface()) {
        throw new IllegalStateException("Input type " +
                clazz + "can not be interface!");
    }

    if (!clazz.isAnnotationPresent(Adaptive.class)) {
        if (StringUtils.isBlank(name)) {
            throw new IllegalStateException("Extension name is blank (Extension " + type + ")!");
        }
        if (cachedClasses.get().containsKey(name)) {
            throw new IllegalStateException("Extension name " +
                    name + " already existed(Extension " + type + ")!");
        }

        cachedNames.put(clazz, name);
        cachedClasses.get().put(name, clazz);
    } else {
        if (cachedAdaptiveClass != null) {
            throw new IllegalStateException("Adaptive Extension already existed(Extension " + type + ")!");
        }

        cachedAdaptiveClass = clazz;
    }
}
 
Example #27
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void enableProvider(Long id) {
    if(id == null) {
        throw new IllegalStateException("no provider id");
    }
    
    Provider oldProvider = findProvider(id);
   
    if(oldProvider == null) {
        throw new IllegalStateException("Provider was changed!");
    } 
    if (oldProvider.isDynamic()) {
     //保证disable的override唯一
     if(!oldProvider.isEnabled()){
     	Override override = new Override();
     	override.setAddress(oldProvider.getAddress());
     	override.setService(oldProvider.getService());
     	override.setEnabled(true);
     	override.setParams(Constants.DISABLED_KEY+"=false");
     	overrideService.saveOverride(override);
     	return;
     }
     List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
    
     for(Override o : oList){
     	Map<String, String> params = StringUtils.parseQueryString(o.getParams());
     	if(params.containsKey(Constants.DISABLED_KEY)){
     		if(params.get(Constants.DISABLED_KEY) .equals("true")){
     			overrideService.deleteOverride(o.getId());
     		}
     	}
     }
    } else {
    	oldProvider.setEnabled(true);
    	updateProvider(oldProvider);
    }
}
 
Example #28
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void disableProvider(Long id) {
    if(id == null) {
        throw new IllegalStateException("no provider id");
    }
    
    Provider oldProvider = findProvider(id);
    if(oldProvider == null) {
        throw new IllegalStateException("Provider was changed!");
    }
    
    if (oldProvider.isDynamic()) {
     //保证disable的override唯一
     if(oldProvider.isEnabled()){
     	Override override = new Override();
     	override.setAddress(oldProvider.getAddress());
     	override.setService(oldProvider.getService());
     	override.setEnabled(true);
     	override.setParams(Constants.DISABLED_KEY+"=true");
     	overrideService.saveOverride(override);
     	return;
     }
     List<Override> oList = overrideService.findByServiceAndAddress(oldProvider.getService(), oldProvider.getAddress());
    
     for(Override o : oList){
     	Map<String, String> params = StringUtils.parseQueryString(o.getParams());
     	if(params.containsKey(Constants.DISABLED_KEY)){
     		if(params.get(Constants.DISABLED_KEY) .equals("false")){
     			overrideService.deleteOverride(o.getId());
     		}
     	}
     }
    } else {
    	oldProvider.setEnabled(false);
    	updateProvider(oldProvider);
    }
    
}
 
Example #29
Source File: RegistryDirectory.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public RegistryDirectory(Class<T> serviceType, URL url) {
    super(url);
    if(serviceType == null )
        throw new IllegalArgumentException("service type is null.");
    if(url.getServiceKey() == null || url.getServiceKey().length() == 0)
        throw new IllegalArgumentException("registry serviceKey is null.");
    this.serviceType = serviceType;
    this.serviceKey = url.getServiceKey();
    this.queryMap = StringUtils.parseQueryString(url.getParameterAndDecoded(Constants.REFER_KEY));
    this.overrideDirectoryUrl = this.directoryUrl = url.setPath(url.getServiceInterface()).clearParameters().addParameters(queryMap).removeParameter(Constants.MONITOR_KEY);
    String group = directoryUrl.getParameter( Constants.GROUP_KEY, "" );
    this.multiGroup = group != null && ("*".equals(group) || group.contains( "," ));
    String methods = queryMap.get(Constants.METHODS_KEY);
    this.serviceMethods = methods == null ? null : Constants.COMMA_SPLIT_PATTERN.split(methods);
}
 
Example #30
Source File: AbstractInterfaceConfig.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected URL loadMonitor(URL registryURL) {
    if (monitor == null) {
        String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address");
        String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol");
        if (monitorAddress != null && monitorAddress.length() > 0
                || monitorProtocol != null && monitorProtocol.length() > 0) {
            monitor = new MonitorConfig();
        } else {
            return null;
        }
    }
    appendProperties(monitor);
    Map<String, String> map = new HashMap<String, String>();
    map.put(Constants.INTERFACE_KEY, MonitorService.class.getName());
    map.put("dubbo", Version.getVersion());
    map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
    if (ConfigUtils.getPid() > 0) {
        map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
    }
    appendParameters(map, monitor);
    String address = monitor.getAddress();
    String sysaddress = System.getProperty("dubbo.monitor.address");
    if (sysaddress != null && sysaddress.length() > 0) {
        address = sysaddress;
    }
    if (ConfigUtils.isNotEmpty(address)) {
        if (! map.containsKey(Constants.PROTOCOL_KEY)) {
            if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) {
                map.put(Constants.PROTOCOL_KEY, "logstat");
            } else {
                map.put(Constants.PROTOCOL_KEY, "dubbo");
            }
        }
        return UrlUtils.parseURL(address, map);
    } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
        return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map));
    }
    return null;
}