【仅供内部供应商使用,不提供对外解答和培训】

Page tree

【仅供内部供应商使用,不提供对外解答和培训】

Skip to end of metadata
Go to start of metadata

接口作用

为解决大数据套件的冲突问题,提供一个拦截器接口用于拦截目标驱动的classLoader直接设置到dataSource中

接口内容

主要接口

DataSourceDriverLoader
package com.fr.stable.fun;

import com.fr.stable.fun.mark.Mutable;

/**
 * 提供给插件用的classLoader拦截器
 */
public interface DataSourceDriverLoader extends Mutable {

//判断是否命中目标驱动
    boolean isInterceptAllowed(String driverName);

//获取具体的classLoader
    ClassLoader getClassLoader();
}

相关方法调用

DataSourceDriverLoaderUtils
package com.fr.stable.fun.impl;

import com.fr.plugin.ExtraClassManager;
import com.fr.plugin.manage.PluginManager;
import com.fr.stable.fun.DatasourceDriverLoader;

import java.util.Set;

/**
 *具体调用接口的工具类
 */
public class DataSourceDriverLoaderUtils {

    public static ClassLoader getClassLoader(String driverName) {
    Set<DataSourceDriverLoader> dataSourceDriverLoaders = getDataSourceDriverLoader();
    //是空的话说明插件没有成功加载
    if (dataSourceDriverLoaders == null || dataSourceDriverLoaders.isEmpty()) {
        FineLoggerFactory.getLogger().info("====== not loading classloader plugin ======");
    } else {
        for (DataSourceDriverLoader datasourceDriverLoader : dataSourceDriverLoaders) {
            //判断是否是目标driver
            if (datasourceDriverLoader.isInterceptAllowed(driverName)) {
                ClassLoader classLoader = datasourceDriverLoader.getClassLoader();
                return classLoader;
            }
        }
    }
    return null;
}

private static Set<DataSourceDriverLoader> getDataSourceDriverLoader() {
    return ExtraClassManager.getInstance().getArray(DataSourceDriverLoader.XML_TAG);
}
}


接口接入

<extra-core>
    <DataSourceDriverLoader class="com.fr.plugin.dialect.classloader.ClassLoaderHandler"/>
</extra-core>


示例效果

demo里在成功命中目标驱动后设置了日志信息输出:


示例代码:

https://code.fanruan.com/fanruan/demo-driver-loader

注意事项

1、仅当实现的ClassLoader不为空时才会set进datasource中

  • No labels

1 Comment

  1. 你好  如果我现在获取到了帆软报表的accessToken,我能否带着这个token直接访问到A报表页面 类似于  http://localhost:8075/webroot/decision/view/report?viewlet=AAA.cpt?accessToken=xxxxx