Java Code Examples for com.alibaba.dubbo.common.utils.StringUtils#parseQueryString()

The following examples show how to use com.alibaba.dubbo.common.utils.StringUtils#parseQueryString() . 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: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
   }
 
Example 2
Source File: Providers.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
/**
   * 装载新增服务页面,获取所有的服务名称
   * @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));
		}
	}
}
  }
 
Example 3
Source File: Providers.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
   * 装载新增服务页面,获取所有的服务名称
   * @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));
		}
	}
}
  }
 
Example 4
Source File: OverrideUtils.java    From dubbox-hystrix 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 5
Source File: RegistryProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
   }
 
Example 6
Source File: Consumer.java    From open-capacity-platform 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 7
Source File: ConvertUtil.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register) {
    Map<String, Map<String, String>> newRegister = new HashMap<String, Map<String, String>>();
    for (Map.Entry<String, Map<String, String>> entry : register.entrySet()) {
        String serviceName = entry.getKey();
        Map<String, String> serviceUrls = entry.getValue();
        if (! serviceName.contains(":") && ! serviceName.contains("/")) {
            for (Map.Entry<String, String> entry2 : serviceUrls.entrySet()) {
                String serviceUrl = entry2.getKey();
                String serviceQuery = entry2.getValue();
                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;
                }
                Map<String, String> newUrls = newRegister.get(name);
                if (newUrls == null) {
                    newUrls = new HashMap<String, String>();
                    newRegister.put(name, newUrls);
                }
                newUrls.put(serviceUrl, StringUtils.toQueryString(params));
            }
        } else {
            newRegister.put(serviceName, serviceUrls);
        }
    }
    return newRegister;
}
 
Example 8
Source File: Versions.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void index(Map<String, Object> context) {
    List<Provider> providers = providerService.findAll();
    List<Consumer> consumers = consumerService.findAll();
    Set<String> parametersSet = new HashSet<String>();
    for (Provider provider : providers) {
        parametersSet.add(provider.getParameters());
    }
    for (Consumer consumer : consumers) {
        parametersSet.add(consumer.getParameters());
    }
    Map<String, Set<String>> versions = new HashMap<String, Set<String>>();
    Iterator<String> temp = parametersSet.iterator();
    while (temp.hasNext()) {
        Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
        if (parameter != null) {
            String dubbo = parameter.get("dubbo");
            if(dubbo == null) dubbo = "0.0.0";
            String application = parameter.get("application");
            if (versions.get(dubbo) == null) {
                Set<String> apps = new HashSet<String>();
                versions.put(dubbo, apps);
            }
            versions.get(dubbo).add(application);
        }
    }
    context.put("versions", versions);
}
 
Example 9
Source File: Tool.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static boolean isProviderEnabled(Provider provider, List<Override> oList){
	for(Override o : oList){
		if (o.isMatch(provider)) {
 		Map<String, String> params = StringUtils.parseQueryString(o.getParams());
 		String disbaled = params.get(Constants.DISABLED_KEY);
     	if(disbaled != null && disbaled.length() > 0){
     		return ! "true".equals(disbaled);
     	}
		}
	}
	return provider.isEnabled();
}
 
Example 10
Source File: Versions.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void show(Long[] ids, Map<String, Object> context) {
    String version =(String)context.get("version");
    if (version != null && version.length() > 0) {
        List<Provider> providers = providerService.findAll();
        List<Consumer> consumers = consumerService.findAll();
        Set<String> parametersSet = new HashSet<String>();
        Set<String> applications = new HashSet<String>();
        for (Provider provider : providers) {
            parametersSet.add(provider.getParameters());
        }
        for (Consumer consumer : consumers) {
            parametersSet.add(consumer.getParameters());
        }
        Iterator<String> temp = parametersSet.iterator();
        while (temp.hasNext()) {
            Map<String, String> parameter = StringUtils.parseQueryString(temp.next());
            if (parameter != null) {
                String dubbo = parameter.get("dubbo");
                if(dubbo == null) dubbo = "0.0.0";
                String application = parameter.get("application");
                if (version.equals(dubbo)) {
                    applications.add(application);
                }
            }
        }
        context.put("applications", applications);
    }
}
 
Example 11
Source File: OverrideUtils.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public static List<LoadBalance> overridesToLoadBalances(List<Override> overrides) {
    List<LoadBalance> loadBalances = new ArrayList<LoadBalance>();
    if (overrides == null) {
        return loadBalances;
    }
    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().endsWith("loadbalance")) {
                    LoadBalance loadBalance = new LoadBalance();
                    String method = null;
                    if (entry.getKey().endsWith(".loadbalance")) {
                        method = entry.getKey().split(".loadbalance")[0];
                    } else {
                        method = "*";
                    }

                    loadBalance.setMethod(method);
                    loadBalance.setId(o.getId());
                    loadBalance.setService(o.getService());
                    loadBalance.setStrategy(entry.getValue());
                    loadBalances.add(loadBalance);

                }
            }
        }
    }
    return loadBalances;
}
 
Example 12
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 13
Source File: Tool.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public static int getProviderWeight(Provider provider, List<Override> oList) {
	for(Override o : oList){
		if (o.isMatch(provider)) {
 		Map<String, String> params = StringUtils.parseQueryString(o.getParams());
 		String weight = params.get(Constants.WEIGHT_KEY);
     	if(weight != null && weight.length() > 0){
     		return Integer.parseInt(weight);
     	}
		}
	}
	return provider.getWeight();
}
 
Example 14
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 15
Source File: Tool.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static boolean isProviderEnabled(Provider provider, List<Override> oList){
	for(Override o : oList){
		if (o.isMatch(provider)) {
 		Map<String, String> params = StringUtils.parseQueryString(o.getParams());
 		String disbaled = params.get(Constants.DISABLED_KEY);
     	if(disbaled != null && disbaled.length() > 0){
     		return ! "true".equals(disbaled);
     	}
		}
	}
	return provider.isEnabled();
}
 
Example 16
Source File: RegistryDirectory.java    From dubbo3 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 17
Source File: ConvertUtil.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static Map<String, Map<String, String>> convertRegister(Map<String, Map<String, String>> register) {
    Map<String, Map<String, String>> newRegister = new HashMap<String, Map<String, String>>();
    for (Map.Entry<String, Map<String, String>> entry : register.entrySet()) {
        String serviceName = entry.getKey();
        Map<String, String> serviceUrls = entry.getValue();
        if (! serviceName.contains(":") && ! serviceName.contains("/")) {
            for (Map.Entry<String, String> entry2 : serviceUrls.entrySet()) {
                String serviceUrl = entry2.getKey();
                String serviceQuery = entry2.getValue();
                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;
                }
                Map<String, String> newUrls = newRegister.get(name);
                if (newUrls == null) {
                    newUrls = new HashMap<String, String>();
                    newRegister.put(name, newUrls);
                }
                newUrls.put(serviceUrl, StringUtils.toQueryString(params));
            }
        } else {
            newRegister.put(serviceName, serviceUrls);
        }
    }
    return newRegister;
}
 
Example 18
Source File: ProviderServiceImpl.java    From dubbox-hystrix 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 19
Source File: ConsumersController.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/update", method = RequestMethod.POST) //post
public String update(@ModelAttribute Consumer newConsumer, HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "update", "consumers");
    boolean success = true;
    Long id = newConsumer.getId();
    String parameters = newConsumer.getParameters();
    Consumer consumer = consumerService.findConsumer(id);
    if (consumer == null) {
        model.addAttribute("message", getMessage("NoSuchOperationData", id));
        success = false;
        model.addAttribute("success", success);
        model.addAttribute("redirect", "governance/consumers");
        return "governance/screen/redirect";
    }
    String service = consumer.getService();
    if (!super.currentUser.hasServicePrivilege(service)) {
        model.addAttribute("message", getMessage("HaveNoServicePrivilege", service));
        success = false;
        model.addAttribute("success", success);
        model.addAttribute("redirect", "governance/consumers");
        return "governance/screen/redirect";
    }
    Map<String, String> oldMap = StringUtils.parseQueryString(consumer.getParameters());
    Map<String, String> newMap = StringUtils.parseQueryString(parameters);
    for (Map.Entry<String, String> entry : oldMap.entrySet()) {
        if (entry.getValue().equals(newMap.get(entry.getKey()))) {
            newMap.remove(entry.getKey());
        }
    }
    String address = consumer.getAddress();
    List<Override> overrides = overrideService.findByServiceAndAddress(consumer.getService(), consumer.getAddress());
    OverrideUtils.setConsumerOverrides(consumer, overrides);
    Override override = consumer.getOverride();
    if (override != null) {
        if (newMap.size() > 0) {
            override.setParams(StringUtils.toQueryString(newMap));
            override.setEnabled(true);
            override.setOperator(operator);
            override.setOperatorAddress(operatorAddress);
            overrideService.updateOverride(override);
        } else {
            overrideService.deleteOverride(override.getId());
        }
    } else {
        override = new Override();
        override.setService(service);
        override.setAddress(address);
        override.setParams(StringUtils.toQueryString(newMap));
        override.setEnabled(true);
        override.setOperator(operator);
        override.setOperatorAddress(operatorAddress);
        overrideService.saveOverride(override);
    }
    model.addAttribute("success", success);
    model.addAttribute("redirect", "governance/consumers");
    return "governance/screen/redirect";
}
 
Example 20
Source File: Tool.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public static Map<String, String> toParameterMap(String parameters){
	return StringUtils.parseQueryString(parameters);
}