Java Code Examples for cn.hutool.core.util.StrUtil#splitTrim()

The following examples show how to use cn.hutool.core.util.StrUtil#splitTrim() . 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: MockUrlLogicServiceImpl.java    From v-mock with MIT License 8 votes vote down vote up
/**
 * 通过url查询logic字符串
 *
 * @param url 路径
 * @return logic字符串
 */
@Override
public String selectLogicStrByUrl(String url) {
    // 拆分为子url
    List<String> subUrls = StrUtil.splitTrim(url, StrUtil.C_SLASH);
    // empty -> put '/'
    if (subUrls.isEmpty()) {
        subUrls.add(StrUtil.SLASH);
    }
    // 查询对应logicId
    List<MockUrlLogic> urlLogics = this.list(Wrappers.<MockUrlLogic>lambdaQuery()
            // in 查询请求的url
            .in(MockUrlLogic::getSubUrl, subUrls));
    // 转为map
    Map<String, Long> subUrlAndLogicId = urlLogics.stream().collect(Collectors.toMap(MockUrlLogic::getSubUrl, MockUrlLogic::getLogicId));
    StringJoiner logicStrJoiner = new StringJoiner(StrUtil.COMMA);
    // 删除空元素,循环拼接
    subUrls.stream().filter(StrUtil::isNotBlank).forEach(item -> {
        // 2.get logicId, ※ 如果是null,那么推测此处用户用了path传参, 则返回占位符!
        Long logicId = subUrlAndLogicId.get(item);
        // 拼接
        logicStrJoiner.add(logicId == null ? CommonConst.PATH_PLACEHOLDER : logicId.toString());
    });
    return logicStrJoiner.toString();
}
 
Example 2
Source File: LinuxSystemCommander.java    From Jpom with MIT License 6 votes vote down vote up
@Override
public String stopService(String serviceName) {
    if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
        String ps = getPs(serviceName);
        List<String> list = StrUtil.splitTrim(ps, StrUtil.LF);
        if (list == null || list.isEmpty()) {
            return "stop";
        }
        String s = list.get(0);
        list = StrUtil.splitTrim(s, StrUtil.SPACE);
        if (list == null || list.size() < 2) {
            return "stop";
        }
        File file = new File(SystemUtil.getUserInfo().getHomeDir());
        int pid = Convert.toInt(list.get(1), 0);
        if (pid <= 0) {
            return "error stop";
        }
        return kill(file, pid);
    }
    String format = StrUtil.format("service {} stop", serviceName);
    return CommandUtil.execSystemCommand(format);
}
 
Example 3
Source File: ScriptProcessBuilder.java    From Jpom with MIT License 5 votes vote down vote up
private ScriptProcessBuilder(ScriptModel scriptModel, String args) {
    this.logFile = scriptModel.logFile();
    this.scriptFile = scriptModel.getFile(true);
    //
    String script = FileUtil.getAbsolutePath(scriptFile);
    processBuilder = new ProcessBuilder();
    List<String> command = StrUtil.splitTrim(args, StrUtil.SPACE);
    command.add(0, script);
    if (SystemUtil.getOsInfo().isLinux()) {
        command.add(0, CommandUtil.SUFFIX);
    }
    DefaultSystemLog.getLog().info(CollUtil.join(command, StrUtil.SPACE));
    processBuilder.command(command);
}
 
Example 4
Source File: DynamicRouteLocator.java    From Taroco with Apache License 2.0 5 votes vote down vote up
/**
 * 从Redis中读取缓存的路由信息,没有从rbac拉取,避免启动链路依赖问题(取舍),网关依赖业务模块的问题
 *
 * @return 缓存中的路由表
 */
private Map<String, ZuulProperties.ZuulRoute> locateRoutesFromCache() {
    Map<String, ZuulProperties.ZuulRoute> routes = new LinkedHashMap<>();

    String vals = redisRepository.get(CacheConstants.ROUTE_KEY);
    if (vals == null) {
        return routes;
    }

    List<SysRoute> results = JSONArray.parseArray(vals, SysRoute.class);
    for (SysRoute result : results) {
        if (StrUtil.isBlank(result.getPath()) && StrUtil.isBlank(result.getUrl())) {
            continue;
        }

        ZuulProperties.ZuulRoute zuulRoute = new ZuulProperties.ZuulRoute();
        try {
            zuulRoute.setId(result.getServiceId());
            zuulRoute.setPath(result.getPath());
            zuulRoute.setServiceId(result.getServiceId());
            zuulRoute.setRetryable(StrUtil.equals(result.getRetryable(), "0") ? Boolean.FALSE : Boolean.TRUE);
            zuulRoute.setStripPrefix(StrUtil.equals(result.getStripPrefix(), "0") ? Boolean.FALSE : Boolean.TRUE);
            zuulRoute.setUrl(result.getUrl());
            List<String> sensitiveHeadersList = StrUtil.splitTrim(result.getSensitiveheadersList(), ",");
            if (sensitiveHeadersList != null) {
                Set<String> sensitiveHeaderSet = CollUtil.newHashSet();
                sensitiveHeaderSet.addAll(sensitiveHeadersList);
                zuulRoute.setSensitiveHeaders(sensitiveHeaderSet);
                zuulRoute.setCustomSensitiveHeaders(true);
            }
        } catch (Exception e) {
            log.error("从数据库加载路由配置异常", e);
        }
        log.debug("添加数据库自定义的路由配置,path:{},serviceId:{}", zuulRoute.getPath(), zuulRoute.getServiceId());
        routes.put(zuulRoute.getPath(), zuulRoute);
    }
    return routes;
}