Search in sources :

Example 1 with BaseAppException

use of com.littlefisher.core.common.exception.BaseAppException in project littlefisher-system by littlefishercoder.

the class PackageUtil method scanTypePackage.

/**
 * 扫描获取指定包路径所有类
 *
 * @param typePackage 扫描类包路径
 * @return Set<Class>
 */
public static Set<Class> scanTypePackage(String typePackage) {
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
    String pkg = ClassUtils.convertClassNameToResourcePath(typePackage) + ".class";
    /*
         * 将加载多个绝对匹配的所有Resource
         * 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
         */
    try {
        Set<Class> set = Sets.newHashSet();
        Resource[] resources = resolver.getResources(pkg);
        if (ArrayUtils.isNotEmpty(resources)) {
            MetadataReader metadataReader;
            for (Resource resource : resources) {
                if (resource.isReadable()) {
                    metadataReader = metadataReaderFactory.getMetadataReader(resource);
                    set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
                }
            }
        }
        return set;
    } catch (Exception e) {
        throw new BaseAppException("CORE-000007", null, e);
    }
}
Also used : BaseAppException(com.littlefisher.core.common.exception.BaseAppException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) BaseAppException(com.littlefisher.core.common.exception.BaseAppException)

Example 2 with BaseAppException

use of com.littlefisher.core.common.exception.BaseAppException in project littlefisher-system by littlefishercoder.

the class ExceptionHandler method publish.

public static void publish(String errorCode, String message, Throwable t, String param1, String param2, String param3, String param4, String param5) {
    BaseAppException baseAppException;
    if (t != null && t instanceof BaseAppException) {
        baseAppException = (BaseAppException) t;
    } else if (t != null && t instanceof InvocationTargetException) {
        // 仅仅对此情况进行处理,不能进行深层检查!
        Throwable cause = t.getCause();
        if (cause instanceof BaseAppException) {
            baseAppException = (BaseAppException) cause;
        } else {
            baseAppException = new BaseAppException(errorCode, message, t, param1, param2, param3, param4, param5);
        }
    } else {
        baseAppException = new BaseAppException(errorCode, message, t, param1, param2, param3, param4, param5);
    }
    logErrorInfo(baseAppException);
    throw baseAppException;
}
Also used : BaseAppException(com.littlefisher.core.common.exception.BaseAppException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

BaseAppException (com.littlefisher.core.common.exception.BaseAppException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Resource (org.springframework.core.io.Resource)1 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)1 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)1 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)1 MetadataReader (org.springframework.core.type.classreading.MetadataReader)1 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)1