io.jboot.Jboot Java Examples

The following examples show how to use io.jboot.Jboot. 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: JbootConfig.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
private void initXxlJobExecutor() {

        // registry jobhandler
        XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler());
        XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler());
        XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler());
        XxlJobExecutor.registJobHandler("commandJobHandler", new CommandJobHandler());

        // init executor
        xxlJobExecutor = new XxlJobExecutor();
        xxlJobExecutor.setAdminAddresses(Jboot.configValue("xxl.job.admin.addresses"));
        xxlJobExecutor.setAccessToken(Jboot.configValue("xxl.job.accessToken"));
        xxlJobExecutor.setAddress(Jboot.configValue("xxl.job.executor.address"));
        xxlJobExecutor.setAppname(Jboot.configValue("xxl.job.executor.appname"));
        xxlJobExecutor.setIp(Jboot.configValue("xxl.job.executor.ip"));
        xxlJobExecutor.setPort(Integer.valueOf(Jboot.configValue("xxl.job.executor.port")));
        xxlJobExecutor.setLogPath(Jboot.configValue("xxl.job.executor.logpath"));
        xxlJobExecutor.setLogRetentionDays(Integer.valueOf(Jboot.configValue("xxl.job.executor.logretentiondays")));

        // start executor
        try {
            xxlJobExecutor.start();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
 
Example #2
Source File: RedisTestController.java    From jboot with Apache License 2.0 6 votes vote down vote up
public void set() {

        String key = getPara("key");
        if (StrUtil.isBlank(key)) {
            renderText("key is empty. ");
            return;
        }

        String value = getPara("value");
        if (StrUtil.isBlank(value)) {
            renderText("value is empty. ");
            return;
        }

        JbootRedis redis = Jboot.getRedis();
        if (redis == null) {
            renderText("can not get redis, maybe redis config is error.");
            return;
        }

        redis.set(key,value);
        renderText("set ok " );
    }
 
Example #3
Source File: JbootCoreConfig.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
    public void configConstant(Constants constants) {

        constants.setRenderFactory(JbootRenderFactory.me());
        constants.setDevMode(Jboot.isDevMode());
//        ApiConfigKit.setDevMode(Jboot.isDevMode());
//
//        JbootWechatConfig config = Jboot.config(JbootWechatConfig.class);
//        ApiConfig apiConfig = config.getApiConfig();
//        if (apiConfig != null) {
//            ApiConfigKit.putApiConfig(apiConfig);
//        }

        constants.setLogFactory(new Slf4jLogFactory());
        constants.setMaxPostSize(1024 * 1024 * 2000);
        constants.setReportAfterInvocation(false);

        constants.setControllerFactory(JbootControllerManager.me());
        constants.setJsonFactory(() -> new JbootJson());
        constants.setInjectDependency(true);


        JbootAppListenerManager.me().onConstantConfig(constants);

    }
 
Example #4
Source File: MainController.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
/**
 * 登录 基于 jwt
 */
@NotNullPara({"loginName", "pwd"})
public void postLogin(String loginName, String pwd) {

    // 此处为 demo , 实际项目这里应该调用service 判断
    if ("user1".equals(loginName) && "123123".equals(pwd)) {
        String userId = "user1";

        // 登录成功移除用户退出标识
        Jboot.me().getCache().remove(CacheKey.CACHE_JWT_TOKEN, userId);
        setJwtAttr("userId", userId);
    } else {
        throw new BusinessException("用户名密码错误");
    }

    renderJson(RestResult.buildSuccess("登录成功"));
}
 
Example #5
Source File: RedisTestController.java    From jboot with Apache License 2.0 6 votes vote down vote up
public void show() {

        String key = getPara("key");
        if (StrUtil.isBlank(key)) {
            renderText("key is empty. ");
            return;
        }

        JbootRedis redis = Jboot.getRedis();
        if (redis == null) {
            renderText("can not get redis, maybe redis config is error.");
            return;
        }

        Object object = redis.get(key);
        renderText("value : " + object);

    }
 
Example #6
Source File: RedisTestController.java    From jboot with Apache License 2.0 6 votes vote down vote up
public void del() {

        String key = getPara("key");
        if (StrUtil.isBlank(key)) {
            renderText("key is empty. ");
            return;
        }

        JbootRedis redis = Jboot.getRedis();
        if (redis == null) {
            renderText("can not get redis, maybe redis config is error.");
            return;
        }

        redis.del(key);
        renderText("del ok " );

    }
 
Example #7
Source File: CSVReporter.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void report(MetricRegistry metricRegistry) {

    JbootMetricCVRReporterConfig cvrReporterConfig = Jboot.config(JbootMetricCVRReporterConfig.class);

    if (StrUtil.isBlank(cvrReporterConfig.getPath())) {
        throw new NullPointerException("csv reporter path must not be null, please config jboot.metrics.reporter.cvr.path in you properties.");
    }

    final CsvReporter reporter = CsvReporter.forRegistry(metricRegistry)
            .formatFor(Locale.US)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(new File(cvrReporterConfig.getPath()));

    reporter.start(1, TimeUnit.SECONDS);
}
 
Example #8
Source File: LoginAuth.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public AuthorizationInfo buildAuthorizationInfo(PrincipalCollection principals) {
    String loginName = (String) principals.fromRealm("ShiroDbRealm").iterator().next();

    RoleService sysRoleApi = Jboot.service(RoleService.class);
    List<Role> sysRoleList = sysRoleApi.findByUserName(loginName);
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();

    List<String> roleNameList = new ArrayList<String>();
    for (Role sysRole : sysRoleList) {
        roleNameList.add(sysRole.getName());
    }

    ResService sysResService = Jboot.service(ResService.class);
    List<Res> sysResList = sysResService.findByUserNameAndStatusUsed(loginName);
    List<String> urls = new ArrayList<String>();
    for (Res sysRes : sysResList) {
        urls.add(sysRes.getUrl());
    }

    info.addRoles(roleNameList);
    info.addStringPermissions(urls);
    return info;
}
 
Example #9
Source File: JbootEhcacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootEhcacheImpl() {
    JbootEhCacheConfig config = Jboot.config(JbootEhCacheConfig.class);
    if (StrUtil.isBlank(config.getConfigFileName())) {
        cacheManager = CacheManager.create();
    } else {
        String configPath = config.getConfigFileName();
        if (!configPath.startsWith("/")){
            configPath = PathKit.getRootClassPath()+"/"+configPath;
        }
        cacheManager = CacheManager.create(configPath);
    }
}
 
Example #10
Source File: JbootRedisCacheImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootRedisCacheImpl() {
    JbootRedisCacheConfig redisConfig = Jboot.config(JbootRedisCacheConfig.class);
    if (redisConfig.isConfigOk()) {
        redis = JbootRedisManager.me().getRedis(redisConfig);
    } else {
        redis = Jboot.getRedis();
    }

    if (redis == null) {
        throw new JbootIllegalConfigException("can not get redis, please check your jboot.properties , please correct config jboot.cache.redis.host or jboot.redis.host ");
    }
}
 
Example #11
Source File: JfinalConfigListener.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void onJfinalEngineConfig(Engine engine) {
    engine.setDevMode(true);
    AppInfo app = Jboot.config(AppInfo.class);
    engine.addSharedObject("APP", app);
    engine.addSharedObject("RESOURCE_HOST", app.getResourceHost());
}
 
Example #12
Source File: JbootmqBase.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootSerializer getSerializer() {
    if (serializer == null) {
        if (StrUtil.isBlank(config.getSerializer())) {
            serializer = Jboot.getSerializer();
        } else {
            serializer = JbootSerializerManager.me().getSerializer(config.getSerializer());
        }
    }
    return serializer;
}
 
Example #13
Source File: LoginAuth.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean wasLocked(AuthenticationToken authenticationToken) {
    String loginName = authenticationToken.getPrincipal().toString();

    UserService sysUserApi = Jboot.service(UserService.class);
    User sysUser = sysUserApi.findByName(loginName);
    return !sysUser.getStatus().equals(UserStatus.USED);
}
 
Example #14
Source File: AopCache.java    From jboot with Apache License 2.0 5 votes vote down vote up
static JbootCache getAopCache() {
    if (aopCache == null) {
        synchronized (AopCache.class) {
            if (aopCache == null) {
                aopCache = JbootCacheManager.me().getCache(Jboot.config(JbootCacheConfig.class).getAopCacheType());
            }
        }
    }
    return aopCache;
}
 
Example #15
Source File: UserOpenidServiceProvider.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void shouldUpdateCache(int action, Model model, Object id) {
   if (model instanceof UserOpenid){
       UserOpenid userOpenid = (UserOpenid) model;
       Jboot.getCache().remove("useropenid",userOpenid.getType()+"-"+userOpenid.getValue());
   }
}
 
Example #16
Source File: LimiterManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 解析用户配置
 */
private void doParseConfig() {

    LimitConfig config = Jboot.config(LimitConfig.class);

    if (!isEnable()) {
        return;
    }

    String rule = config.getRule();
    if (StrUtil.isBlank(rule)) {
        return;
    }

    String[] rules = rule.split(",");
    for (String r : rules) {
        String[] confs = r.split(":");
        if (confs == null || confs.length != 3) {
            continue;
        }

        String packageOrTarget = confs[0];
        String type = confs[1];
        String rate = confs[2];

        if (!ensureLegal(packageOrTarget, type, rate.trim())) {
            continue;
        }
        packageOrTarget = packageOrTarget.replace(".", "\\.")
                .replace("(", "\\(")
                .replace(")", "\\)")
                .replace("*", ".*");

        configPackageOrTargets.add(packageOrTarget.trim());
        typeAndRateCache.put(packageOrTarget.trim(), new TypeAndRate(type.trim(), Integer.valueOf(rate.trim())));
    }
}
 
Example #17
Source File: JfinalConfigListener.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void onJfinalEngineConfig(Engine engine) {
    engine.setDevMode(true);
    AppInfo app = Jboot.config(AppInfo.class);
    engine.addSharedObject("APP", app);
    engine.addSharedObject("RESOURCE_HOST", app.getResourceHost());
}
 
Example #18
Source File: CodeGenHelpler.java    From jboot with Apache License 2.0 5 votes vote down vote up
public static MetaBuilder createMetaBuilder() {
    MetaBuilder metaBuilder = new MetaBuilder(getDatasource());
    metaBuilder.setGenerateRemarks(true);
    DataSourceConfig datasourceConfig = Jboot.config(DataSourceConfig.class, "jboot.datasource");
    switch (datasourceConfig.getType()) {
        case DataSourceConfig.TYPE_MYSQL:
            metaBuilder.setDialect(new MysqlDialect());
            break;
        case DataSourceConfig.TYPE_ORACLE:
            metaBuilder.setDialect(new OracleDialect());
            break;
        case DataSourceConfig.TYPE_SQLSERVER:
            metaBuilder.setDialect(new SqlServerDialect());
            break;
        case DataSourceConfig.TYPE_SQLITE:
            metaBuilder.setDialect(new Sqlite3Dialect());
            break;
        case DataSourceConfig.TYPE_ANSISQL:
            metaBuilder.setDialect(new AnsiSqlDialect());
            break;
        case DataSourceConfig.TYPE_POSTGRESQL:
            metaBuilder.setDialect(new PostgreSqlDialect());
            break;
        default:
            throw new JbootIllegalConfigException("only support datasource type : mysql、orcale、sqlserver、sqlite、ansisql and postgresql, please check your jboot.properties. ");
    }

    return metaBuilder;

}
 
Example #19
Source File: JbootHttpManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
private JbootHttp buildJbootHttp() {
    JbootHttpConfig config = Jboot.config(JbootHttpConfig.class);

    switch (config.getType()) {
        case JbootHttpConfig.TYPE_DEFAULT:
            return new JbootHttpImpl();
        case JbootHttpConfig.TYPE_OKHTTP:
            return new OKHttpImpl();
        case JbootHttpConfig.TYPE_HTTPCLIENT:
            throw new RuntimeException("not finished!!!!");
        default:
            return JbootSpiLoader.load(JbootHttp.class, config.getType());
    }

}
 
Example #20
Source File: JbootRedisLock.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 释放 锁
 */
public void release() {
    if (!isLocked()) {
        return;
    }
    if (Jboot.getRedis().del(lockName) > 0) {
        locked = false;
    }
}
 
Example #21
Source File: InstallUtil.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean createJbootPropertiesFile() {

        File propertieFile = new File(PathKit.getRootClassPath(), "jboot.properties");
        DbExecuter dbExecuter = InstallManager.me().getDbExecuter();

        Properties p = propertieFile.exists()
                ? PropKit.use("jboot.properties").getProperties()
                : new Properties();


        //jboot.app.mode
        putPropertie(p, "jboot.app.mode", "product");

        //cookieEncryptKey
        String cookieEncryptKey = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.cookieEncryptKey", cookieEncryptKey)) {
            Jboot.config(JbootWebConfig.class).setCookieEncryptKey("cookieEncryptKey");
            CookieUtil.initEncryptKey(cookieEncryptKey);
        }

        //jwtSecret
        String jwtSecret = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.jwt.secret", jwtSecret)) {
            Jboot.config(JwtConfig.class).setSecret(jwtSecret);
        }

        p.put("jboot.datasource.type", "mysql");
        p.put("jboot.datasource.url", dbExecuter.getJdbcUrl());
        p.put("jboot.datasource.user", dbExecuter.getDbUser());
        p.put("jboot.datasource.password", StrUtil.obtainDefaultIfBlank(dbExecuter.getDbPassword(), ""));

        return savePropertie(p, propertieFile);
    }
 
Example #22
Source File: JfinalConfigListener.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void onJfinalEngineConfig(Engine engine) {
    engine.setDevMode(true);
    AppInfo app = Jboot.config(AppInfo.class);
    engine.addSharedObject("APP", app);
    engine.addSharedObject("RESOURCE_HOST", app.getResourceHost());
}
 
Example #23
Source File: JfinalConfigListener.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public void onJFinalStarted() {
    JbootWechatConfig wechatConfig = Jboot.config(JbootWechatConfig.class);
    ApiConfig apiConfig = new ApiConfig();
    apiConfig.setAppId(wechatConfig.getAppId());
    apiConfig.setAppSecret(wechatConfig.getAppSecret());
    apiConfig.setToken(wechatConfig.getToken());
    ApiConfigKit.putApiConfig(apiConfig);
}
 
Example #24
Source File: CaffeineTester.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Test
public void testGet() {
    JbootCache cache = Jboot.getCache();
    cache.put(cacheName, "key", "value~~~~~~~");
    String value = cache.get(cacheName, "key");
    System.out.println("value:"+value);
    Assert.assertTrue("value~~~~~~~".equals(value));
}
 
Example #25
Source File: HikariDataSourceFactory.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource createDataSource(DataSourceConfig config) {

    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setJdbcUrl(config.getUrl());
    hikariConfig.setUsername(config.getUser());
    hikariConfig.setPassword(config.getPassword());
    hikariConfig.addDataSourceProperty("cachePrepStmts", config.isCachePrepStmts());
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", config.getPrepStmtCacheSize());
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", config.getPrepStmtCacheSqlLimit());
    hikariConfig.setDriverClassName(config.getDriverClassName());
    hikariConfig.setPoolName(config.getPoolName());
    hikariConfig.setMaximumPoolSize(config.getMaximumPoolSize());

    if (config.getMaxLifetime() != null) {
        hikariConfig.setMaxLifetime(config.getMaxLifetime());
    }
    if (config.getIdleTimeout() != null) {
        hikariConfig.setIdleTimeout(config.getIdleTimeout());
    }

    if (config.getMinimumIdle() != null) {
        hikariConfig.setMinimumIdle(config.getMinimumIdle());
    }

    if (config.getConnectionInitSql() != null) {
        hikariConfig.setConnectionInitSql(config.getConnectionInitSql());
    }


    HikariDataSource dataSource = new HikariDataSource(hikariConfig);

    if (Jboot.getMetric() != null) {
        dataSource.setMetricRegistry(Jboot.getMetric());
    }

    return dataSource;
}
 
Example #26
Source File: LimiterManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void doInitFallbackProcesser() {
    LimitConfig config = Jboot.config(LimitConfig.class);
    if (StrUtil.isBlank(config.getFallbackProcesser())) {
        this.fallbackProcesser = new LimitFallbackProcesserDefault();
    } else {
        this.fallbackProcesser = Objects.requireNonNull(ClassUtil.newInstance(config.getFallbackProcesser()),
                "can not newInstance class for " + config.getFallbackProcesser());
    }
}
 
Example #27
Source File: ApolloConfigManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
private Config getDefaultConfig() {
    ApolloServerConfig apolloServerConfig = Jboot.config(ApolloServerConfig.class);
    if (StrUtil.isNotBlank(apolloServerConfig.getDefaultNamespace())) {
        return ConfigService.getConfig(apolloServerConfig.getDefaultNamespace());
    } else {
        return ConfigService.getAppConfig();
    }
}
 
Example #28
Source File: JbootRedisBase.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootRedisBase(JbootRedisConfig config) {
    if (config == null || StrUtil.isBlank(config.getSerializer())) {
        serializer = Jboot.getSerializer();
    } else {
        serializer = JbootSerializerManager.me().getSerializer(config.getSerializer());
    }
}
 
Example #29
Source File: JbootScheduleManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootScheduleManager() {
    config = Jboot.config(JbooScheduleConfig.class);
    fixedScheduler = new ScheduledThreadPoolExecutor(config.getPoolSize(),new NamedThreadFactory("jboot-scheduler"));

    File cron4jProperties = new File(PathKit.getRootClassPath(), config.getCron4jFile());
    cron4jPlugin = cron4jProperties.exists()
            ? new JbootCron4jPlugin(new Prop(config.getCron4jFile()))
            : new JbootCron4jPlugin();
}
 
Example #30
Source File: JbootRedisLock.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 创建redis分布式锁
 *
 * @param lockName 锁的名称
 */
public JbootRedisLock(String lockName) {
    if (lockName == null) {
        throw new NullPointerException("lockName must not null !");
    }
    this.lockName = lockName;
    this.redis = Jboot.getRedis();
}