From b93dbb8f077b5415a0002c66973b716f874f1953 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期三, 29 十月 2025 10:37:12 +0800
Subject: [PATCH] 更新为正式环境配置
---
src/main/java/com/gs/xiaomi/service/SoapApiService.java | 56 +++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 45 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/gs/xiaomi/service/SoapApiService.java b/src/main/java/com/gs/xiaomi/service/SoapApiService.java
index 696917a..031828e 100644
--- a/src/main/java/com/gs/xiaomi/service/SoapApiService.java
+++ b/src/main/java/com/gs/xiaomi/service/SoapApiService.java
@@ -3,6 +3,7 @@
import com.gs.xiaomi.config.DataAcquisitionConfiguration;
import com.gs.xiaomi.dto.BizDocumentResult;
+import com.gs.xiaomi.dto.SoapApiResponse;
import com.gs.xiaomi.dto.ZfmWsApiRequest;
import com.gs.xiaomi.util.SoapXmlBuilder;
import com.gs.xiaomi.util.X5StringUtils;
@@ -12,13 +13,21 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.StringReader;
+import java.util.concurrent.TimeUnit;
@Service
public class SoapApiService {
- private static final OkHttpClient client = new OkHttpClient.Builder().build();
- public BizDocumentResult callAndParse(String url, ZfmWsApiRequest request) throws Exception {
+ private final OkHttpClient client;
+
+ public SoapApiService() {
+ this.client = new OkHttpClient.Builder().connectTimeout(3000, TimeUnit.SECONDS) // Set connection timeout
+ .readTimeout(90, TimeUnit.SECONDS) // Set read timeout
+ .build();
+ }
+
+ public SoapApiResponse<BizDocumentResult> callAndParse(String url, ZfmWsApiRequest request) throws Exception {
String soapXml = SoapXmlBuilder.build(request);
Response response = sendRequest(url, soapXml);
@@ -26,18 +35,24 @@
String bodyStr = response.body().string();
String evCode = extractEvCode(bodyStr);
- if (!"Y".equalsIgnoreCase(evCode)) {
- throw new RuntimeException("SOAP business failed, EV_CODE: " + evCode);
- }
-
String decodedXml = decodeXmlEntities(bodyStr);
+ if (!"Y".equalsIgnoreCase(evCode)) {
+ // 浠� decodedXml 涓彁鍙栭敊璇彁绀轰俊鎭�
+ String evMessage = extractEvMessage(decodedXml);
+ return SoapApiResponse.fail(evCode, evMessage != null ? evMessage : "SOAP涓氬姟澶勭悊澶辫触, EV_CODE: " + evCode);
+ }
+
String innerXml = extractCdata(decodedXml);
- if (innerXml == null) throw new RuntimeException("No CDATA <document> found in response");
+ if (innerXml == null) {
+ throw new RuntimeException("No CDATA <document> found in response");
+ }
JAXBContext context = JAXBContext.newInstance(BizDocumentResult.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
- return (BizDocumentResult) unmarshaller.unmarshal(new StringReader(innerXml));
+ BizDocumentResult result = (BizDocumentResult) unmarshaller.unmarshal(new StringReader(innerXml));
+
+ return SoapApiResponse.success(evCode, result);
} else {
throw new RuntimeException("SOAP request failed: " + response.code() + " - " + response.message());
}
@@ -53,13 +68,10 @@
Request request = new Request.Builder()
.url(url)
.method("POST", body)
-// .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
.addHeader("Content-Type", "application/xml")
.addHeader("Authorization", "Basic " + auth)
.addHeader("Accept", "*/*")
-// .addHeader("Host", "mipoq.p.mi.com")
.addHeader("Connection", "keep-alive")
-// .addHeader("Cookie", "saplb_*=(J2EE4281420)4281450; MYSAPSSO2=AjExMDAgABJwb3J0YWw6UkZDWkpYSUFPQlWIAAdkZWZhdWx0AQALUkZDWkpYSUFPQlUCAAMwMDADAANQT1EEAAwyMDI1MDQwOTAwMTcFAAQAAAAICgALUkZDWkpYSUFPQlX%2FAQUwggEBBgkqhkiG9w0BBwKggfMwgfACAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHATGB0DCBzQIBATAiMB0xDDAKBgNVBAMTA1BPUTENMAsGA1UECxMESjJFRQIBADAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjUwNDA5MDAxNzU2WjAjBgkqhkiG9w0BCQQxFgQUvvJ1HSnOLckboGYaMR9Wiaem6z4wCQYHKoZIzjgEAwQvMC0CFQDKLPrpUC19VM2gcslWaHAnh7dfxQIUNs2dTxwGcKdNU%2FdAQPs4f08yaw4%3D; JSESSIONID=_6bPldDq9mFJPXEd11bc-GvrWMAVlgFqVEEA_SAPF-GrpRbcuqxMK_gShBYGdmdp; JSESSIONMARKID=QPmRVwktCDxMazp0fUbEMC40LWvmuqOMUbIGpUQQA")
.build();
return client.newCall(request).execute();
@@ -72,6 +84,28 @@
return xml.substring(start + 9, end).trim();
}
+ private String extractEvMessage(String xml) {
+ String value = extractTagValue(xml, "ev_message");
+ if (value != null) {
+ return value;
+ }
+ return extractTagValue(xml, "EV_MESSAGE");
+ }
+
+ private String extractTagValue(String xml, String tagName) {
+ if (xml == null || tagName == null) {
+ return null;
+ }
+ String openTag = "<" + tagName + ">";
+ String closeTag = "</" + tagName + ">";
+ int start = xml.indexOf(openTag);
+ int end = xml.indexOf(closeTag, start);
+ if (start == -1 || end == -1) {
+ return null;
+ }
+ return xml.substring(start + openTag.length(), end).trim();
+ }
+
private String decodeXmlEntities(String xml) {
return xml.replace("<", "<")
.replace(">", ">")
--
Gitblit v1.9.3