refactor(hzya-nifi-Zsyh-cbs-processors):优化 HTTP 请求处理逻辑
-调整 HTTP 状态码检查逻辑,移到解密后 - 优化异常信息输出,增加失败详情 - 更新测试用例和配置 - 调整 pom.xml 依赖,排除 commons-logging 冲突
This commit is contained in:
parent
e318905355
commit
d44e73556f
|
@ -58,6 +58,12 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on -->
|
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk18on -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -69,43 +75,49 @@
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.15.2</version>
|
<version>2.15.2</version>
|
||||||
<!-- <scope>test</scope>-->
|
<!-- <scope>test</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>org.projectlombok</groupId>-->
|
<!-- <groupId>org.projectlombok</groupId>-->
|
||||||
<!-- <artifactId>lombok</artifactId>-->
|
<!-- <artifactId>lombok</artifactId>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.36</version>
|
||||||
<!-- <scope>provided</scope>-->
|
<!-- <scope>provided</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>org.slf4j</groupId>-->
|
<groupId>org.slf4j</groupId>
|
||||||
<!-- <artifactId>slf4j-api</artifactId>-->
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<!-- <version>1.7.36</version> </dependency>-->
|
<version>1.7.36</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>org.slf4j</groupId>-->
|
||||||
|
<!-- <artifactId>slf4j-api</artifactId>-->
|
||||||
|
<!-- <version>1.7.36</version> </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<version>1.7.36</version>
|
<version>1.7.36</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
<!-- <groupId>commons-logging</groupId>-->
|
<!-- <groupId>commons-logging</groupId>-->
|
||||||
<!-- <artifactId>commons-logging</artifactId>-->
|
<!-- <artifactId>commons-logging</artifactId>-->
|
||||||
<!-- <version>1.2</version>-->
|
<!-- <version>1.2</version>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
<version>1.15</version>
|
<version>1.15</version>
|
||||||
<!-- <scope>test</scope>-->
|
<!-- <scope>test</scope>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -129,15 +129,13 @@ public class ZsyhCbsProcessor extends AbstractProcessor {
|
||||||
HttpPost httpPost = sm2Example.setupRequest();
|
HttpPost httpPost = sm2Example.setupRequest();
|
||||||
try (CloseableHttpResponse response = client.execute(httpPost)) {
|
try (CloseableHttpResponse response = client.execute(httpPost)) {
|
||||||
|
|
||||||
|
byte[] finalResponseData = sm2Example.handleResponse(response);
|
||||||
|
String finalResponseDataStr = new String(finalResponseData);
|
||||||
|
|
||||||
if (response.getStatusLine().getStatusCode() >= 300) {
|
if (response.getStatusLine().getStatusCode() >= 300) {
|
||||||
throw new IOException("HTTP请求失败,状态码: " + response.getStatusLine().getStatusCode());
|
throw new IOException("HTTP请求失败,状态码: " + response.getStatusLine().getStatusCode() + " 失败详情:" + finalResponseDataStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] finalResponseData = sm2Example.handleResponse(response);
|
|
||||||
|
|
||||||
//将最终解密后的结果写入FlowFile并路由到success
|
|
||||||
String finalResponseDataStr = new String(finalResponseData);
|
|
||||||
getLogger().info("接口返回结果:{}", finalResponseDataStr);
|
|
||||||
flowFile = session.write(flowFile, out -> out.write(finalResponseData));
|
flowFile = session.write(flowFile, out -> out.write(finalResponseData));
|
||||||
session.transfer(flowFile, REL_SUCCESS);
|
session.transfer(flowFile, REL_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,19 @@ try {
|
||||||
"applyDateStart": currentDate, "applyDateEnd": currentDate, "initAccountList": "591915131310106"
|
"applyDateStart": currentDate, "applyDateEnd": currentDate, "initAccountList": "591915131310106"
|
||||||
};
|
};
|
||||||
|
|
||||||
var jsonString = JSON.stringify(jsonData);
|
var jsonString = JSON.stringify({
|
||||||
|
"applyDateEnd": "2025-09-10",
|
||||||
|
"applyDateStart": "2025-09-01",
|
||||||
|
"currentPage": 1,
|
||||||
|
"initAccountList": [
|
||||||
|
"755930515810902",
|
||||||
|
"755930515810504",
|
||||||
|
"755930515910501",
|
||||||
|
"655905707410000",
|
||||||
|
"655905707110000"
|
||||||
|
],
|
||||||
|
"pageSize": 50
|
||||||
|
});
|
||||||
|
|
||||||
flowFile = session.write(flowFile, new (Java.type('org.apache.nifi.processor.io.OutputStreamCallback'))({
|
flowFile = session.write(flowFile, new (Java.type('org.apache.nifi.processor.io.OutputStreamCallback'))({
|
||||||
process: function (outputStream) {
|
process: function (outputStream) {
|
||||||
|
|
|
@ -26,9 +26,9 @@ public class ZsyhCbsProcessorTest {
|
||||||
|
|
||||||
// 定义用于测试的密钥和配置(请使用有效的Hex编码密钥对用于测试)
|
// 定义用于测试的密钥和配置(请使用有效的Hex编码密钥对用于测试)
|
||||||
// 注意:这里的密钥仅用于测试,实际密钥应通过NiFi界面配置
|
// 注意:这里的密钥仅用于测试,实际密钥应通过NiFi界面配置
|
||||||
private static final String MOCK_PLATFORM_PUBLIC_KEY = "04D0A5CDD879058F1D4DEFFFCE7F902402026B1C39F03FF426E6C0D43F0EBA5F8617D5ABC7501EA5E53038D93CD33036CEFF2F5A64D226144AB3D6D73CE901C3B8";//财资管理云公钥(平台公钥)
|
private static final String MOCK_PLATFORM_PUBLIC_KEY = "0469146F06BF3B01236E84632441E826F3067A6B93BC3839C836A06007869CD351FBBE388B51F742859388BBC1DE089923AAFBC69E448F15141DDF30EE6CE90185";//财资管理云公钥(平台公钥)
|
||||||
private static final String MOCK_ENTERPRISE_SIGN_PRIVATE_KEY = "D735102B815123AFB3B0779928FA8264B050BEB43071DEBD88BB115B28E4661C";//企业私钥(加密)
|
private static final String MOCK_ENTERPRISE_SIGN_PRIVATE_KEY = "83BA7EC821D35F4CB31FF9A51C1EFA520FC52AF828C2337F88E91CF119B07F44";//企业私钥(加密)
|
||||||
private static final String MOCK_ENTERPRISE_DECRYPT_PRIVATE_KEY = "D735102B815123AFB3B0779928FA8264B050BEB43071DEBD88BB115B28E4661C";//企业私钥(解密)
|
private static final String MOCK_ENTERPRISE_DECRYPT_PRIVATE_KEY = "83BA7EC821D35F4CB31FF9A51C1EFA520FC52AF828C2337F88E91CF119B07F44";//企业私钥(解密)
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -57,6 +57,7 @@ public class ZsyhCbsProcessorTest {
|
||||||
runner.setProperty(ZsyhCbsProcessor.PROP_TOKEN_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/app/v1/app/token");//获取token
|
runner.setProperty(ZsyhCbsProcessor.PROP_TOKEN_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/app/v1/app/token");//获取token
|
||||||
runner.setProperty(ZsyhCbsProcessor.PROP_REFRESH_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/app/v1/app/refresh-token");//刷新token
|
runner.setProperty(ZsyhCbsProcessor.PROP_REFRESH_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/app/v1/app/refresh-token");//刷新token
|
||||||
runner.setProperty(ZsyhCbsProcessor.PROP_TARGET_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/draft2/openapi/v2/trsinfo/query-trs-info-page");//交易明细查询
|
runner.setProperty(ZsyhCbsProcessor.PROP_TARGET_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/draft2/openapi/v2/trsinfo/query-trs-info-page");//交易明细查询
|
||||||
|
// runner.setProperty(ZsyhCbsProcessor.PROP_TARGET_URL, "https://cbs8-openapi-reprd.csuat.cmburl.cn/openapi/draft/openapi/v1/dta/query");//票据查询
|
||||||
|
|
||||||
// 配置其他必要的密钥和ID
|
// 配置其他必要的密钥和ID
|
||||||
runner.setProperty(ZsyhCbsProcessor.PROP_APP_ID, "1P4AGrpz");
|
runner.setProperty(ZsyhCbsProcessor.PROP_APP_ID, "1P4AGrpz");
|
||||||
|
@ -67,10 +68,19 @@ public class ZsyhCbsProcessorTest {
|
||||||
|
|
||||||
// 3. 准备输入的FlowFile,其内容就是原始的业务请求JSON
|
// 3. 准备输入的FlowFile,其内容就是原始的业务请求JSON
|
||||||
String businessRequestJson = "{\n" +
|
String businessRequestJson = "{\n" +
|
||||||
"\t\"applyDateStart\":\"2025-08-01\",\n" +
|
" \"applyDateEnd\": \"2025-09-10\",\n" +
|
||||||
"\t\"applyDateEnd\":\"2025-08-31\",\n" +
|
" \"applyDateStart\": \"2025-09-01\",\n" +
|
||||||
"\t\"initAccountList\":\"591915131310106\"\n" +
|
" \"currentPage\": 1,\n" +
|
||||||
|
" \"initAccountList\": [\n" +
|
||||||
|
" \"755930515810902\",\n" +
|
||||||
|
" \"755930515810504\",\n" +
|
||||||
|
" \"755930515910501\",\n" +
|
||||||
|
" \"655905707410000\",\n" +
|
||||||
|
" \"655905707110000\"\n" +
|
||||||
|
" ],\n" +
|
||||||
|
" \"pageSize\": 50\n" +
|
||||||
"}";
|
"}";
|
||||||
|
// String businessRequestJson = "{\"displayHoldOrganizationCodeList\":[\"0001\"],\"holdAccountList\":[\"591915131310106\"]}";
|
||||||
runner.enqueue(businessRequestJson);
|
runner.enqueue(businessRequestJson);
|
||||||
|
|
||||||
// --- 执行阶段 (Act) ---
|
// --- 执行阶段 (Act) ---
|
||||||
|
|
Loading…
Reference in New Issue