返回xml错误信息转换为json

master
anthonyywj2 3 years ago
parent ed40658354
commit 1af8424afa

@ -25,7 +25,6 @@ import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.io.SAXReader;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -101,7 +100,7 @@ public class ZaxyyClient {
zaZyHeareRequest.setMsgHeader(getMsgHeader("getMaterialUnit"));
zaZyHeareRequest.setMsgBody(JSONUtil.toJsonStr(unitRequest));
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -122,7 +121,7 @@ public class ZaxyyClient {
zaZyHeareRequest.setMsgBody(JSONUtil.toJsonStr(udiwmsProductRequest));
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -143,6 +142,7 @@ public class ZaxyyClient {
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -173,6 +173,7 @@ public class ZaxyyClient {
// BasicThirdSysBusApiEntity basicThirdSysBusApiEntity = basicThirdSysBusApiService.selectByKey(bussinessOriginTypeResponse.getThirdAction(), bussinessOriginTypeResponse.getThirdSys(), 1);
BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailDao.selectByKey("orderQueryUrl", thirdSysConfig.getThirdSysConfig().getThirdId());
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -203,6 +204,7 @@ public class ZaxyyClient {
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + interStr, zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -226,6 +228,7 @@ public class ZaxyyClient {
zaZyHeareRequest.setMsgBody(JSONUtil.toJsonStr(udiwmsPreInOrderRequest));
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + interStr, zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -244,15 +247,7 @@ public class ZaxyyClient {
zaZyHeareRequest.setMsgHeader(getMsgHeader("getMaterialStorage"));
zaZyHeareRequest.setMsgBody(JSONUtil.toJsonStr(udiwmsOnhandRequest));
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
if (response.contains("<root")) {
SAXReader saxReader = new SAXReader();
try {
Document document = DocumentHelper.parseText(response);
} catch (DocumentException e) {
e.printStackTrace();
}
}
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -272,7 +267,7 @@ public class ZaxyyClient {
BasicThirdSysDetailEntity basicThirdSysDetailEntity = basicThirdSysDetailDao.selectByKey("warehouseQueryUrl", thirdSysConfig.getThirdSysConfig().getThirdId());
String response = httpClient.postJson(thirdSysConfig.getThirdSysConfig().getThirdSysUrl() + basicThirdSysDetailEntity.getValue(), zaZyHeareRequest, getHeaderArray());
response = parseErrorMsg(response);
try {
BaseResponse baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse>() {
@ -285,4 +280,19 @@ public class ZaxyyClient {
return ResultVOUtils.error(500, "网络错误,或远程服务器异常无法返回正确结果" + "" + response + ")");
}
public String parseErrorMsg(String response) {
if (response.contains("<root")) {
try {
Document document = DocumentHelper.parseText(response);
String message = document.getRootElement().element("message").getText();
return message;
} catch (DocumentException e) {
e.printStackTrace();
}
}
return response;
}
}

@ -2,6 +2,9 @@ package com.glxp.mipsdl.admin;
import com.glxp.mipsdl.admin.client.http.ZaxyyXmlClient;
import com.glxp.mipsdl.admin.http.UHttpUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.junit.Test;
import javax.annotation.Resource;
@ -14,6 +17,27 @@ public class JsonTest {
String json = "{\\\"invname\\\":\\\"Glucose Oxidase\\\\\\\"Amano\\\\\\\" 2\\\"}";
System.out.println(json1);
System.out.println(UHttpUtils.formatResponse(json1));
String test = "<root><code>AE</code><data /><message>{\n" +
" \"code\" : 500,\n" +
" \"message\" : \"已存在单据号MY202207180167的预备货记录\",\n" +
" \"data\" : \"\"\n" +
"}</message><error>AE</error><requestId></requestId><processResultCode>AE</processResultCode><processResult>{\n" +
" \"code\" : 500,\n" +
" \"message\" : \"已存在单据号MY202207180167的预备货记录\",\n" +
" \"data\" : \"\"\n" +
"}</processResult></root>";
if (test.contains("<root")) {
try {
Document document = DocumentHelper.parseText(test);
String message = document.getRootElement().element("message").getText();
System.out.println(message);
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
@Resource

Loading…
Cancel
Save