io.jboot.exception.JbootException Java Examples

The following examples show how to use io.jboot.exception.JbootException. 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: BusinessExceptionInterceptor.java    From jboot-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void intercept(Invocation inv) {
	try {
		inv.invoke();
	} catch (JbootException e) {
		if (inv.getTarget() instanceof JbootController) {
			JbootController controller = inv.getTarget();

			if (controller.isAjaxRequest()) {
				RestResult<String> restResult = new RestResult<String>();
				restResult.error(e.getMessage());
				controller.renderJson(restResult);
			} else {
				controller.setAttr(MESSAGE_TAG, e.getMessage()).render(exceptionView);
			}
		}
	}
}
 
Example #2
Source File: JbootAopInvocation.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public void invoke() {
    if (index < inters.length) {
        inters[index++].intercept(this);
    }
    // index++ ensure invoke action only one time
    else if (index++ == inters.length) {
        try {
            originInvocation.invoke();
        } catch (Throwable throwable) {
            if (throwable instanceof RuntimeException) {
                throw (RuntimeException) throwable;
            } else {
                throw new JbootException(throwable.getMessage(), throwable);
            }
        }
    }
}
 
Example #3
Source File: JbootPostgreSqlDialect.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
public String forFindByColumns(List<Join> joins, String table, String loadColumns, List<Column> columns, String orderBy, Object limit) {
    StringBuilder sqlBuilder = SqlBuilder.forFindByColumns(joins, table, loadColumns, columns, orderBy, '"');

    if (limit == null) {
        return sqlBuilder.toString();
    }

    if (limit instanceof Number) {
        sqlBuilder.append(" limit ").append(limit).append(" offset ").append(0);
        return sqlBuilder.toString();
    } else if (limit instanceof String && limit.toString().contains(",")) {
        String[] startAndEnd = limit.toString().split(",");
        String start = startAndEnd[0];
        String end = startAndEnd[1];

        sqlBuilder.append(" limit ").append(end).append(" offset ").append(start);
        return sqlBuilder.toString();
    } else {
        throw new JbootException("sql limit is error!,limit must is Number of String like \"0,10\"");
    }
}
 
Example #4
Source File: JbootRabbitmqImpl.java    From jboot with Apache License 2.0 6 votes vote down vote up
public JbootRabbitmqImpl() {
    super();
    JbootmqRabbitmqConfig rabbitmqConfig = Jboot.config(JbootmqRabbitmqConfig.class);

    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(rabbitmqConfig.getHost());
    factory.setPort(rabbitmqConfig.getPort());

    if (StrUtil.isNotBlank(rabbitmqConfig.getVirtualHost())) {
        factory.setVirtualHost(rabbitmqConfig.getVirtualHost());
    }
    if (StrUtil.isNotBlank(rabbitmqConfig.getUsername())) {
        factory.setUsername(rabbitmqConfig.getUsername());
    }

    if (StrUtil.isNotBlank(rabbitmqConfig.getPassword())) {
        factory.setPassword(rabbitmqConfig.getPassword());
    }

    try {
        connection = factory.newConnection();
    } catch (Exception e) {
        throw new JbootException("can not connection rabbitmq server", e);
    }
}
 
Example #5
Source File: JbootRabbitmqImpl.java    From jboot with Apache License 2.0 6 votes vote down vote up
private Channel getChannel(String toChannel) {

        Channel channel = channelMap.get(toChannel);
        if (channel == null) {
            try {
                channel = connection.createChannel();
                channel.queueDeclare(toChannel, false, false, false, null);
                channel.exchangeDeclare(toChannel, BuiltinExchangeType.FANOUT);
                String queueName = channel.queueDeclare().getQueue();
                channel.queueBind(queueName, toChannel, toChannel);
            } catch (IOException e) {
                throw new JbootException("can not create channel", e);
            }

            if (channel != null) {
                channelMap.put(toChannel, channel);
            }
        }

        return channel;
    }
 
Example #6
Source File: DataSourceBuilder.java    From jboot with Apache License 2.0 6 votes vote down vote up
public DataSource build() {

        String shardingConfigYaml = config.getShardingConfigYaml();

        // 不启用分库分表的配置
        if (StrUtil.isBlank(shardingConfigYaml)) {
            DataSource ds = createDataSource(config);
            return JbootSeataManager.me().wrapDataSource(ds);
        }


        File yamlFile = shardingConfigYaml.startsWith(File.separator)
                ? new File(shardingConfigYaml)
                : new File(PathKit.getRootClassPath(), shardingConfigYaml);

        try {
            return YamlShardingDataSourceFactory.createDataSource(yamlFile);
        } catch (Exception e) {
            throw new JbootException(e);
        }
    }
 
Example #7
Source File: Utils.java    From jboot with Apache License 2.0 6 votes vote down vote up
static void doCacheEvict(Object[] arguments, Class targetClass, Method method, CacheEvict evict) {
    String unless = AnnotationUtil.get(evict.unless());
    if (Utils.isUnless(unless, method, arguments)) {
        return;
    }

    String cacheName = AnnotationUtil.get(evict.name());
    if (StrUtil.isBlank(cacheName)) {
        throw new JbootException(String.format("CacheEvict.name()  must not empty in method [%s].",
                ClassUtil.buildMethodString(method)));
    }

    String cacheKey = AnnotationUtil.get(evict.key());

    if (StrUtil.isBlank(cacheKey) || "*".equals(cacheKey)) {
        AopCache.removeAll(cacheName);
    } else {
        cacheKey = Utils.buildCacheKey(cacheKey, targetClass, method, arguments);
        AopCache.remove(cacheName, cacheKey);
    }
}
 
Example #8
Source File: ClassUtil.java    From jboot with Apache License 2.0 6 votes vote down vote up
public static <T> T newInstanceByStaticConstruct(Class<T> clazz, StaticConstruct staticConstruct) {

        Method method = getStaticConstruct(staticConstruct.value(), clazz);

        if (method == null) {
            throw new JbootException("can not new instance by static constrauct for class : " + clazz);
        }

        try {
            return (T) method.invoke(null, null);
        } catch (Exception e) {

            log.error("can not invoke method:" + method.getName()
                    + " in class : "
                    + clazz + "\n"
                    + e.toString(), e);

            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new RuntimeException(e);
            }
        }
    }
 
Example #9
Source File: LimitFallbackProcesserDefault.java    From jboot with Apache License 2.0 6 votes vote down vote up
protected void doProcessFallback(String fallback, Invocation inv) {
    Method method = getMethodByName(fallback, inv);
    if (method == null) {
        throw new JbootException("can not find method[" + fallback + "] in class " +
                ClassUtil.getUsefulClass(inv.getTarget().getClass()));
    }

    try {
        method.setAccessible(true);
        Object invokeValue = method.getParameterCount() == 0
                ? method.invoke(inv.getTarget())
                : method.invoke(inv.getTarget(), inv.getArgs());
        inv.setReturnValue(invokeValue);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #10
Source File: JbootCacheInterceptor.java    From jboot with Apache License 2.0 5 votes vote down vote up
private JbootException newException(Exception ex, Invocation inv, Object data) {
    String msg = "can not copy data for type [" + data.getClass().getName() + "] in method :"
            + ClassUtil.buildMethodString(inv.getMethod())
            + " , can not use @Cacheable(returnCopyEnable=true) annotation";

    return ex == null ? new JbootException(msg) : new JbootException(msg, ex);
}
 
Example #11
Source File: JbootSerializerManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootSerializer buildSerializer(String serializerString) {

        if (serializerString == null){
            throw new JbootException("can not get serializer config, please set jboot.serializer value to jboot.proerties");
        }
        /**
         * 可能是某个类名
         */
        if (serializerString != null && serializerString.contains(".")) {

            JbootSerializer serializer = ClassUtil.newInstance(serializerString);

            if (serializer != null) {
                return serializer;
            }
        }


        switch (serializerString) {
            case JbootSerializerConfig.KRYO:
                return new KryoSerializer();
            case JbootSerializerConfig.FST:
                return new FstSerializer();
            case JbootSerializerConfig.FASTJSON:
                return new FastjsonSerializer();

            default:
                return JbootSpiLoader.load(JbootSerializer.class, serializerString);
        }
    }
 
Example #12
Source File: GatewayHttpProxy.java    From jboot with Apache License 2.0 5 votes vote down vote up
private static HttpURLConnection getConnection(String urlString) {
    try {
        if (urlString.toLowerCase().startsWith("https")) {
            return getHttpsConnection(urlString);
        } else {
            return getHttpConnection(urlString);
        }
    } catch (Throwable ex) {
        throw new JbootException(ex);
    }
}
 
Example #13
Source File: JbootHttpImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
private static HttpURLConnection getConnection(JbootHttpRequest request) {
    try {
        if (request.isPostRequest() == false) {
            request.initGetUrl();
        }
        if (request.getRequestUrl().toLowerCase().startsWith("https")) {
            return getHttpsConnection(request);
        } else {
            return getHttpConnection(request.getRequestUrl());
        }
    } catch (Throwable ex) {
        throw new JbootException(ex);
    }
}
 
Example #14
Source File: JbootHttpImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
private static void checkFileNormal(File file) {
    if (!file.exists()) {
        throw new JbootException("file not exists!!!!" + file);
    }
    if (file.isDirectory()) {
        throw new JbootException("cannot upload directory!!!!" + file);
    }
    if (!file.canRead()) {
        throw new JbootException("cannnot read file!!!" + file);
    }
}
 
Example #15
Source File: JbootQpidmqImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStartListening() {
    try {
        startReceiveMsgThread();
    } catch (Exception e) {
        throw new JbootException(e.toString(), e);
    }
}
 
Example #16
Source File: JbootQpidmqImpl.java    From jboot with Apache License 2.0 5 votes vote down vote up
public JbootQpidmqImpl() {
    super();
    JbootQpidmqConfig qpidConfig = Jboot.config(JbootQpidmqConfig.class);
    serializerEnable = qpidConfig.isSerializerEnable();

    try {
        String url = getConnectionUrl();
        connection = new AMQConnection(url);
        connection.start();

    } catch (Exception e) {
        throw new JbootException("can not connection qpidmq server", e);
    }
}
 
Example #17
Source File: Utils.java    From jboot with Apache License 2.0 5 votes vote down vote up
public static void ensureArgumentNotNull(String argument, Class clazz, Method method) {
    if (argument == null) {
        throw new JbootException("not support empty key for annotation @Cacheable, @CacheEvict or @CachePut " +
                "at method[" + ClassUtil.buildMethodString(method) + "], " +
                "please config key properties in @Cacheable, @CacheEvict or @CachePut annotation.");
    }
}
 
Example #18
Source File: JbootmqBase.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public boolean startListening() {
    if (isStartListen) {
        throw new JbootException("jboot mq is started before.");
    }

    if (channels == null || channels.isEmpty()) {
        throw new JbootException("mq channels is null or empty, please config channels");
    }

    onStartListening();
    isStartListen = true;
    return true;
}
 
Example #19
Source File: JbootrpcManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void exportRPCBean(Jbootrpc jbootrpc) {
        List<Class> classes = ClassScanner.scanClassByAnnotation(RPCBean.class, true);
        if (ArrayUtil.isNullOrEmpty(classes)) {
            return;
        }

        for (Class clazz : classes) {
            RPCBean rpcBean = (RPCBean) clazz.getAnnotation(RPCBean.class);
            Class[] inters = clazz.getInterfaces();
            if (inters == null || inters.length == 0) {
                throw new JbootException(String.format("class[%s] has no interface, can not use @RPCBean", clazz));
            }

            //对某些系统的类 进行排除,例如:Serializable 等
            Class[] excludes = ArrayUtil.concat(default_excludes, rpcBean.exclude());
            for (Class inter : inters) {
                boolean isContinue = false;
                for (Class ex : excludes) {
                    if (ex.isAssignableFrom(inter)) {
                        isContinue = true;
                        break;
                    }
                }

                if (isContinue) {
                    continue;
                }

                if (jbootrpc.serviceExport(inter, Aop.get(clazz), new JbootrpcServiceConfig(rpcBean))) {
                    if (Jboot.isDevMode()) {
//                        System.out.println("rpc service[" + inter + "] has exported ok!");
                    }
                }
            }
        }
    }
 
Example #20
Source File: DbExecuter.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Connection getConnection() {
    try {
        return dataSource.getConnection();
    } catch (SQLException e) {
        throw new JbootException(e);
    }
}
 
Example #21
Source File: JbootModel.java    From jboot with Apache License 2.0 5 votes vote down vote up
public String[] _getPrimaryKeys() {
    if (primaryKeys != null) {
        return primaryKeys;
    }
    primaryKeys = _getTable(true).getPrimaryKey();

    if (primaryKeys == null) {
        throw new JbootException(String.format("primaryKeys == null in [%s]", getClass()));
    }
    return primaryKeys;
}
 
Example #22
Source File: ExceptionLoader.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
public static String read(JbootException e) {
    String message = null;

    if (e.getClass() == BusinessException.class) {
        message = e.getMessage();
    } else if (e.getCause() != null && e.getCause().getClass() == BusinessException.class) {
        message = e.getCause().getMessage();
    } else {
        throw e;
    }

    return message;
}
 
Example #23
Source File: ModelCopier.java    From jboot with Apache License 2.0 5 votes vote down vote up
private static <T> T newInstance(Class<T> clazz) {
    try {
        return clazz.newInstance();
    } catch (Exception e) {
        throw new JbootException("can not newInstance class:" + clazz + "\n" + e.toString(), e);
    }
}
 
Example #24
Source File: JwtManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public String createJwtToken(Map map) {

        if (!getConfig().isConfigOk()) {
            throw new JbootException("can not create jwt, please config jboot.web.jwt.secret in jboot.properties.");
        }

        SecretKey secretKey = generalKey();

        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
        long nowMillis = System.currentTimeMillis();
        Date now = new Date(nowMillis);

        map.put(JwtInterceptor.ISUUED_AT, nowMillis);
        String subject = JsonKit.toJson(map);

        JwtBuilder builder = Jwts.builder()
                .setIssuedAt(now)
                .setSubject(subject)
                .signWith(signatureAlgorithm, secretKey);

        if (getConfig().getValidityPeriod() > 0) {
            long expMillis = nowMillis + getConfig().getValidityPeriod();
            builder.setExpiration(new Date(expMillis));
        }

        return builder.compact();
    }
 
Example #25
Source File: JbootServiceBase.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化 DAO
 * 子类可以复写 自定义自己的DAO
 *
 * @return
 */
protected M initDao() {
    Class<M> modelClass = ClassUtil.getGenericClass(getClass());
    if (modelClass == null) {
        throw new JbootException("can not get model class name in JbootServiceBase");
    }

    //默认不通过AOP构建DAO,提升性能,若特殊需要重写initDao()方法即可
    return ClassUtil.newInstance(modelClass, false);
}
 
Example #26
Source File: JbootModel.java    From jboot with Apache License 2.0 5 votes vote down vote up
protected JbootDialect _getDialect() {
    Config config = _getConfig();
    if (config == null) {
        throw new JbootException(
                String.format("class %s can not mapping to database table, maybe cannot connect to database. "
                        , _getUsefulClass().getName()));

    }
    return (JbootDialect) config.getDialect();
}
 
Example #27
Source File: JbootModel.java    From jboot with Apache License 2.0 5 votes vote down vote up
public Table _getTable(boolean validateMapping) {
    if (table == null) {
        table = super._getTable();
        if (table == null && validateMapping) {
            throw new JbootException(
                    String.format("class %s can not mapping to database table,maybe application cannot connect to database. "
                            , _getUsefulClass().getName()));
        }
    }
    return table;
}
 
Example #28
Source File: JbootAnsiSqlDialect.java    From jboot with Apache License 2.0 5 votes vote down vote up
@Override
public String forFindByColumns(List<Join> joins, String table, String loadColumns, List<Column> columns, String orderBy, Object limit) {
    StringBuilder sqlBuilder = SqlBuilder.forFindByColumns(joins, table, loadColumns, columns, orderBy, ' ');

    if (limit != null) {
        throw new JbootException("limit param not finished JbootAnsiSqlDialect.");
    }

    return sqlBuilder.toString();
}
 
Example #29
Source File: JbootJedisClusterImpl.java    From jboot with Apache License 2.0 4 votes vote down vote up
/**
     * 对象被引用的数量
     */
    public Long objectRefcount(Object key) {

//        return jedisCluster.objectRefcount(keyToBytes(key));
        throw new JbootException("not support move objectRefcount in redis cluster.");
    }
 
Example #30
Source File: JbootRedisManager.java    From jboot with Apache License 2.0 4 votes vote down vote up
private JbootRedis getRedissonClient(JbootRedisConfig config) {
    throw new JbootException("redisson is not finished.");
}