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

The following examples show how to use com.alibaba.dubbo.common.utils.StringUtils#isNotEmpty() . 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: 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 2
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 3
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 4
Source File: Overrides.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    String address = (String) context.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();
    }
    context.put("overrides", overrides);
}
 
Example 5
Source File: Overrides.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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))));
    }
}
 
Example 6
Source File: Overrides.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    String address = (String) context.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();
    }
    context.put("overrides", overrides);
}
 
Example 7
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 8
Source File: Overrides.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void index(Map<String, Object> context) {
    String service = (String) context.get("service");
    String application = (String) context.get("application");
    String address = (String) context.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();
    }
    context.put("overrides", overrides);
}
 
Example 9
Source File: Applications.java    From dubbox-hystrix 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: OrderServiceImpl.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 6 votes vote down vote up
private <T> OrderProcessContext<String> buildContext(String orderId, String userId, T reqData, ProcessReqEnum processReqEnum) {
    OrderProcessContext context = new OrderProcessContext();

    // 受理请求
    OrderProcessReq req = new OrderProcessReq();
    req.setProcessReqEnum(processReqEnum);
    req.setUserId(userId);

    if (StringUtils.isNotEmpty(orderId)) {
        req.setOrderId(orderId);
    }

    if (reqData != null) {
        req.setReqData(reqData);
    }

    context.setOrderProcessReq(req);
    return context;
}
 
Example 11
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 12
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 13
Source File: Overrides.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
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))));
    }
}
 
Example 14
Source File: HttpRemoteInvocation.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object targetObject) throws NoSuchMethodException, IllegalAccessException,
        InvocationTargetException {
    RpcContext context = RpcContext.getContext();
    context.setAttachments((Map<String, String>) getAttribute(dubboAttachmentsAttrName));

    String generic = (String) getAttribute(Constants.GENERIC_KEY);
    if (StringUtils.isNotEmpty(generic)) {
        context.setAttachment(Constants.GENERIC_KEY, generic);
    }
    try {
        return super.invoke(targetObject);
    } finally {
        context.setAttachments(null);

    }
}
 
Example 15
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolPortOverride() throws Exception {
    String dubboPort = System.getProperty("dubbo.protocol.dubbo.port");
    int port = 55555;
    System.setProperty("dubbo.protocol.dubbo.port", String.valueOf(port));
    ServiceConfig<DemoService> service = null;
    try {
        ApplicationConfig application = new ApplicationConfig();
        application.setName("dubbo-protocol-port-override");

        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");

        ProtocolConfig protocol = new ProtocolConfig();

        service = new ServiceConfig<DemoService>();
        service.setInterface(DemoService.class);
        service.setRef(new DemoServiceImpl());
        service.setApplication(application);
        service.setRegistry(registry);
        service.setProtocol(protocol);
        service.export();

        Assert.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (service != null) {
            service.unexport();
        }
    }
}
 
Example 16
Source File: OverridesController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model,"add", "overrides");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String application = (String)newModel.get("app");
    String service = (String)newModel.get("service");
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    if (StringUtils.isNotEmpty(application)) {
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        model.addAttribute("serviceList", serviceList);
    } else if (StringUtils.isNotEmpty(service)) {
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        model.addAttribute("applicationList", applicationList);
    } else {
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    model.addAttribute("serviceList", serviceList);

    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        model.addAttribute("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
    return "governance/screen/overrides/add";
}
 
Example 17
Source File: AuthorizationValve.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void invoke(PipelineContext pipelineContext) throws Exception {
      if (logger.isInfoEnabled()) {
          logger.info("AuthorizationValve of uri: " + request.getRequestURI());
      }
      String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (contextPath != null && contextPath.length() > 0  && ! "/".equals(contextPath)) {
    uri = uri.substring(contextPath.length());
}
      if (uri.equals(logout)) {
    if (! isLogout()) {
        setLogout(true);
  		    showLoginForm();
    } else {
        setLogout(false);
        response.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
    }
          return;
}
      //FIXME
      if(! uri.startsWith("/status/")){
      	User user = null;
          String authType = null;
          String authorization = request.getHeader("Authorization");
          if (authorization != null && authorization.length() > 0) {
              int i = authorization.indexOf(' ');
              if (i >= 0) {
                  authType = authorization.substring(0, i);
                  String authPrincipal = authorization.substring(i + 1);
                  if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByBase(authPrincipal);
                  } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                      user = loginByDigest(authPrincipal);
                  }
              }
          }
          if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
              showLoginForm();
              pipelineContext.breakPipeline(1);
          }
          if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
              request.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
              pipelineContext.invokeNext();
          }
      }else{
          pipelineContext.invokeNext();
      }
  }
 
Example 18
Source File: RestProtocol.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
Example 19
Source File: RestProtocol.java    From dubbox with Apache License 2.0 4 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    Class implClass = ServiceClassHolder.getInstance().popServiceClass();
    RestServer server = servers.get(addr);
    if (server == null) {
        server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
        server.start(url);
        servers.put(addr, server);
    }

    String contextPath = getContextPath(url);
    if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
        ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
        if (servletContext == null) {
            throw new RpcException("No servlet context found. Since you are using server='servlet', " +
                    "make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
        }
        String webappPath = servletContext.getContextPath();
        if (StringUtils.isNotEmpty(webappPath)) {
            webappPath = webappPath.substring(1);
            if (!contextPath.startsWith(webappPath)) {
                throw new RpcException("Since you are using server='servlet', " +
                        "make sure that the 'contextpath' property starts with the path of external webapp");
            }
            contextPath = contextPath.substring(webappPath.length());
            if (contextPath.startsWith("/")) {
                contextPath = contextPath.substring(1);
            }
        }
    }

    final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;

    server.deploy(resourceDef, impl, contextPath);

    final RestServer s = server;
    return new Runnable() {
        public void run() {
            // TODO due to dubbo's current architecture,
            // it will be called from registry protocol in the shutdown process and won't appear in logs
            s.undeploy(resourceDef);
        }
    };
}
 
Example 20
Source File: LoginFilter.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest)request;
    HttpServletResponse resp = (HttpServletResponse) response;
    if (logger.isInfoEnabled()) {
        logger.info("AuthorizationValve of uri: " + req.getRequestURI());
    }
    String uri = req.getRequestURI();
    String contextPath = req.getContextPath();
    if (contextPath != null && contextPath.length() > 0 && !"/".equals(contextPath)) {
        uri = uri.substring(contextPath.length());
    }
    if (uri.equals(logout)) {
        if (!isLogout(req)) {
            setLogout(true, resp);
            showLoginForm(resp);
        } else {
            setLogout(false, resp);
            resp.sendRedirect(contextPath == null || contextPath.length() == 0 ? "/" : contextPath);
        }
        return;
    }
    User user = null;
    String authType = null;
    String authorization = req.getHeader("Authorization");
    if (authorization != null && authorization.length() > 0) {
        int i = authorization.indexOf(' ');
        if (i >= 0) {
            authType = authorization.substring(0, i);
            String authPrincipal = authorization.substring(i + 1);
            if (BASIC_CHALLENGE.equalsIgnoreCase(authType)) {
                user = loginByBase(authPrincipal);
            } else if (DIGEST_CHALLENGE.equalsIgnoreCase(authType)) {
                user = loginByDigest(authPrincipal, req);
            }
        }
    }
    if (user == null || user.getUsername() == null || user.getUsername().length() == 0) {
        showLoginForm(resp);
        return;
        //pipelineContext.breakPipeline(1);
    }
    if (user != null && StringUtils.isNotEmpty(user.getUsername())) {
        req.getSession().setAttribute(WebConstants.CURRENT_USER_KEY, user);
        chain.doFilter(request, response);
    }

}