接口获取财物系统数据一点想法

         因财务系统数据保密性,大数据平台无法直连,于是搭建了一个JS2E小功能,实现HTTPClient 远程访问 API接口,此功能将实现多个财务接口数据的查询。在大数据平台Shell调生成的JAR包(根据 Apache CLI 命令参数 传递参数区分不同的调用接口,类似Web多线程)。

具体一些小细节如下:

一 工具类:

 

       1.1    Base64 工具

public class Base64Util {

final static Base64.Encoder encoder = Base64.getEncoder();
final static Base64.Decoder decoder = Base64.getDecoder();

public static String base64Encoder(String text) {
return encoder.encodeToString(text.getBytes(Charset.forName("GBK")));
}

public static String base64Decoder(String text) {
return new String(decoder.decode(text), Charset.forName("GBK"));
}

}

        1.2  FastJsonUtil  工具

public class FastJsonUtil {

public static String beanToJson(Object object) {
return beanToJson(object, null);
}


public static String beanToJson(Object object, String datePattern) {

if (ObjectUtils.isEmpty(object)) {
return null;
}
String json;
try {
if (StringUtils.isBlank(datePattern)) {
json = JSON.toJSONString(object);
} else {
json = JSON.toJSONStringWithDateFormat(object, datePattern);
}
return json;
} catch (JSONException e) {
throw new RuntimeException("对象[" + object.getClass().getName() + "]转换成JSON异常,", e);
}

}

}

1.3  Dom 工具  

// resultCode
public static String getResultCode(String rootXml) throws DocumentException {
Document document = DocumentHelper.parseText(rootXml);
Node resultCode = document.selectSingleNode("/XML_ROOT/ResultInfo/Result/@CODE");
return resultCode.getText();
}

// po
public static String getPo(String rootXml) throws DocumentException {
Document document = DocumentHelper.parseText(rootXml);
Node Value0 = document.selectSingleNode("/XML_ROOT/ResultInfo/Values/Value0");
return Base64Util.base64Decoder(Value0.getText());

}

// Node
public static Node singleNode(String rootXml, String xmlPath) throws DocumentException {
Document document = DocumentHelper.parseText(rootXml);
return document.selectSingleNode(xmlPath);
}

// xmlPathValue
public static List<Node> multipleNodes(String rootXml, String xmlPath) throws DocumentException {
SAXReader reader = new SAXReader();
Document document = DocumentHelper.parseText(rootXml);
List<Node> nodes = document.selectNodes(xmlPath);
return nodes;
}

1.4  JDBCUtil 工具   

String driver = PropertiesUtil.getProperty("application.datalake.oracle.driver");
String url = PropertiesUtil.getProperty("application.datalake.oracle.url");
String username = PropertiesUtil.getProperty("application.datalake.oracle.username");
String password = PropertiesUtil.getProperty("application.datalake.oracle.password");

Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
return connection;

1.5    PropertiesUtil 工具

public class PropertiesUtil {

private static Logger logger = LogManager.getLogger(PropertiesUtil.class);

private final static Properties props = new Properties();

static {
try {
props.load(PropertiesUtil.class.getClassLoader().getResourceAsStream("application-dev.properties"));
} catch (Exception e) {
e.printStackTrace();
logger.error(" PropertiesUtil 静态加载, exception=[{}]", FastJsonUtil.beanToJson(e.toString()));
}
}

public static String getProperty(String key) {
return props.getProperty(key);
}

}


二   log4j2  配置 

 

2.1   Pom 配置

 
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.12.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>

 

2.2   log4j2 配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="WARN" monitorInterval="30" isThreadContextMapInheritable="true">
<appenders>

<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{threadId}] [%X{sessionId}] [%p] - %l - %m%n"/>
</console>

<RollingFile name="RollingFileInfo" fileName="${sys:user.home}/logs/fmisApp/info.log"
filePattern="${sys:user.home}/logs/fmisApp/$${date:yyyy-MM}/info-%d{yyyy-MM-dd}-%i.log.gz">
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{threadId}] [%X{sessionId}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy max="100" compressionLevel="1">
<Delete basePath="${sys:user.home}/logs/fmisApp" maxDepth="2">
<IfFileName glob="*/info-*.log.gz"/>
<IfLastModified age="30D"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

<RollingFile name="RollingFileWarn" fileName="${sys:user.home}/logs/fmisApp/warn.log"
filePattern="${sys:user.home}/logs/fmisApp/$${date:yyyy-MM}/warn-%d{yyyy-MM-dd}-%i.log.gz">
<ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{threadId}] [%X{sessionId}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy max="100" compressionLevel="1">
<Delete basePath="${sys:user.home}/logs/fmisApp" maxDepth="2">
<IfFileName glob="*/warn-*.log.gz"/>
<IfLastModified age="30D"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

<RollingFile name="RollingFileError" fileName="${sys:user.home}/logs/fmisApp/error.log"
filePattern="${sys:user.home}/logs/fmisApp/$${date:yyyy-MM}/error-%d{yyyy-MM-dd}-%i.log.gz">
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{threadId}] [%X{sessionId}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
<DefaultRolloverStrategy max="100" compressionLevel="1">
<Delete basePath="${sys:user.home}/logs/fmisApp" maxDepth="2">
<IfFileName glob="*/error-*.log.gz"/>
<IfLastModified age="30D"/>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>

</appenders>
<loggers>
<root level="ALL">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFileInfo"/>
<appender-ref ref="RollingFileWarn"/>
<appender-ref ref="RollingFileError"/>
</root>
</loggers>
</configuration>

 

2.3   java 代码

private static Logger logger = LogManager.getLogger(FApp.class);
ThreadContext.put("threadId","Thread-Id:"+UUID.randomUUID().toString());
ThreadContext.put("sessionId", HttpConnUtil.getSessionid());
ThreadContext.clearMap();

logger.info("执行结果 [FApp 方法 main] : interfaceLogin  : resultXml=[{}]", FastJsonUtil.beanToJson(resultXml));

全局线程ID 

 

 



posted @   163博客  阅读(32)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示