统一httpclient版本

This commit is contained in:
黎润豪 2026-01-12 21:11:01 +08:00
parent 21fff9b403
commit b20fd06bb7
4 changed files with 84 additions and 82 deletions

10
pom.xml
View File

@ -212,11 +212,11 @@
<artifactId>qcloud-sdk-2.2.7-jar-with-dependencies</artifactId> <artifactId>qcloud-sdk-2.2.7-jar-with-dependencies</artifactId>
<version>2.2.7-SNAPSHOT</version> <version>2.2.7-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>agw</groupId> <!-- <groupId>agw</groupId>-->
<artifactId>service-client</artifactId> <!-- <artifactId>service-client</artifactId>-->
<version>2.0</version> <!-- <version>2.0</version>-->
</dependency> <!-- </dependency>-->
<dependency> <dependency>
<groupId>com.dtflys.forest</groupId> <groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId> <artifactId>forest-spring-boot-starter</artifactId>

View File

@ -12,10 +12,12 @@ import com.chinaweal.aiccs.crgs.movein.service.TbZcEntityMoveinService;
import com.chinaweal.aiccs.crgs.moveinDetails.entity.*; import com.chinaweal.aiccs.crgs.moveinDetails.entity.*;
import com.chinaweal.aiccs.crgs.moveinDetails.service.*; import com.chinaweal.aiccs.crgs.moveinDetails.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.HttpClient; import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.http.client.methods.HttpPost;
import org.apache.commons.httpclient.methods.PostMethod; import org.apache.http.entity.StringEntity;
import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
@ -29,6 +31,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
@ -650,17 +653,14 @@ public class DownLoadTask {
" </soapenv:Body>\n" + " </soapenv:Body>\n" +
"</soapenv:Envelope>"; "</soapenv:Envelope>";
try { try (CloseableHttpClient client = HttpClients.createDefault()) {
PostMethod postMethod = new PostMethod(downloadPath); HttpPost postMethod = new HttpPost(downloadPath);
byte[] b = soapRequestData.getBytes("utf-8"); postMethod.setHeader("Content-Type", "text/xml; charset=utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length); postMethod.setEntity(new StringEntity(soapRequestData, StandardCharsets.UTF_8));
//这里不能用 application/soap+xml 要改为text/xml与soap版本有关
RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient(); CloseableHttpResponse response = client.execute(postMethod);
int statusCode = httpClient.executeMethod(postMethod); int statusCode = response.getStatusLine().getStatusCode();
String soapResponseData = postMethod.getResponseBodyAsString(); String soapResponseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
// String soapResponseData = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + // String soapResponseData = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
// " <soap:Body>" + // " <soap:Body>" +

View File

@ -9,12 +9,14 @@ import com.chinaweal.aiccs.crgs.transfor.sdk.XzxkWsBO;
import com.chinaweal.aiccs.crgs.transfor.service.OtNcaseDownloadLogService; import com.chinaweal.aiccs.crgs.transfor.service.OtNcaseDownloadLogService;
import com.chinaweal.aiccs.crgs.transfor.service.OtNpermitDownloadLogService; import com.chinaweal.aiccs.crgs.transfor.service.OtNpermitDownloadLogService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.cxf.aegis.databinding.AegisDatabinding; import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -25,6 +27,7 @@ import org.springframework.stereotype.Component;
import javax.activation.DataHandler; import javax.activation.DataHandler;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -221,16 +224,14 @@ public class DownloadSchedule {
" </jog:downloadCreditInfoByXzcf>\n" + " </jog:downloadCreditInfoByXzcf>\n" +
" </soapenv:Body>\n" + " </soapenv:Body>\n" +
"</soapenv:Envelope>"; "</soapenv:Envelope>";
PostMethod postMethod = new PostMethod(String.format(caseDownloadUrl, userName, password)); try (CloseableHttpClient client = HttpClients.createDefault()) {
byte[] b = soapRequestData.getBytes("utf-8"); HttpPost postMethod = new HttpPost(String.format(caseDownloadUrl, userName, password));
InputStream contentis = new ByteArrayInputStream(b, 0, b.length); postMethod.setHeader("Content-Type", "application/xml; charset=utf-8");
//这里用 text/xml 或者 application/xml与soap版本有关 postMethod.setEntity(new StringEntity(soapRequestData, StandardCharsets.UTF_8));
RequestEntity re = new InputStreamRequestEntity(contentis, b.length, "application/xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient(); CloseableHttpResponse response = client.execute(postMethod);
int statusCode = httpClient.executeMethod(postMethod); int statusCode = response.getStatusLine().getStatusCode();
String soapResponseData = postMethod.getResponseBodyAsString(); String soapResponseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//200说明正常返回数据 //200说明正常返回数据
if (statusCode == 200) { if (statusCode == 200) {
log.info("{}异地流转行政处罚请求下载接口,返回结果:{}", uploadDateto, soapResponseData); log.info("{}异地流转行政处罚请求下载接口,返回结果:{}", uploadDateto, soapResponseData);
@ -240,6 +241,7 @@ public class DownloadSchedule {
} else { } else {
log.info("{}异地流转行政处罚请求下载接口失败,状态值:{}", uploadDateto, statusCode); log.info("{}异地流转行政处罚请求下载接口失败,状态值:{}", uploadDateto, statusCode);
} }
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -437,16 +439,14 @@ public class DownloadSchedule {
" </jog:downloadCreditInfoByXzxk>\n" + " </jog:downloadCreditInfoByXzxk>\n" +
" </soapenv:Body>\n" + " </soapenv:Body>\n" +
"</soapenv:Envelope>"; "</soapenv:Envelope>";
PostMethod postMethod = new PostMethod(String.format(permitDownloadUrl, userName, password)); try (CloseableHttpClient client = HttpClients.createDefault()) {
byte[] b = soapRequestData.getBytes("utf-8"); HttpPost postMethod = new HttpPost(String.format(permitDownloadUrl, userName, password));
InputStream contentis = new ByteArrayInputStream(b, 0, b.length); postMethod.setHeader("Content-Type", "application/xml; charset=utf-8");
//这里用 text/xml 或者 application/xml与soap版本有关 postMethod.setEntity(new StringEntity(soapRequestData, StandardCharsets.UTF_8));
RequestEntity re = new InputStreamRequestEntity(contentis, b.length, "application/xml; charset=utf-8");
postMethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient(); CloseableHttpResponse response = client.execute(postMethod);
int statusCode = httpClient.executeMethod(postMethod); int statusCode = response.getStatusLine().getStatusCode();
String soapResponseData = postMethod.getResponseBodyAsString(); String soapResponseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
//200说明正常返回数据 //200说明正常返回数据
if (statusCode == 200) { if (statusCode == 200) {
log.info("{}异地流转行政许可请求下载接口,返回结果:{}", uploadDateto, soapResponseData); log.info("{}异地流转行政许可请求下载接口,返回结果:{}", uploadDateto, soapResponseData);
@ -456,6 +456,7 @@ public class DownloadSchedule {
} else { } else {
log.info("{}异地流转行政许可请求下载接口失败,状态值:{}", uploadDateto, statusCode); log.info("{}异地流转行政许可请求下载接口失败,状态值:{}", uploadDateto, statusCode);
} }
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -2,19 +2,25 @@ package com.chinaweal.aiccs.crgs.transfor.sdk;
import cn.hutool.core.codec.Base64Encoder; import cn.hutool.core.codec.Base64Encoder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.cxf.aegis.databinding.AegisDatabinding; import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.activation.DataHandler; import javax.activation.DataHandler;
import javax.activation.FileDataSource; import javax.activation.FileDataSource;
import java.io.*; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
/** /**
* @author <a href="https://blog.lroyia.top">lroyia</a> * @author <a href="https://blog.lroyia.top">lroyia</a>
@ -79,16 +85,14 @@ public class UploadSDK {
" </upl:uploadCreditInfoByCase>\n" + " </upl:uploadCreditInfoByCase>\n" +
" </soapenv:Body>\n" + " </soapenv:Body>\n" +
"</soapenv:Envelope>"; "</soapenv:Envelope>";
try { try (CloseableHttpClient client = HttpClients.createDefault()){
PostMethod postMethod = new PostMethod(String.format(uploadUrl, userName, password)); HttpPost postMethod = new HttpPost(String.format(uploadUrl, userName, password));
byte[] b = str.getBytes("utf-8"); postMethod.setHeader("Content-Type", "text/xml; charset=utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); postMethod.setEntity(new StringEntity(str));
postMethod.setRequestEntity(re); CloseableHttpResponse execute = client.execute(postMethod);
HttpClient httpClient = new HttpClient(); int statusCode = execute.getStatusLine().getStatusCode();
int statusCode = httpClient.executeMethod(postMethod); String soapResponseData = EntityUtils.toString(execute.getEntity(), StandardCharsets.UTF_8);
String soapResponseData = postMethod.getResponseBodyAsString();
//200说明正常返回数据 //200说明正常返回数据
if (statusCode == 200) { if (statusCode == 200) {
log.info("{}异地流转行政处罚上传接口,返回结果:{}", filePath, soapResponseData); log.info("{}异地流转行政处罚上传接口,返回结果:{}", filePath, soapResponseData);
@ -99,7 +103,7 @@ public class UploadSDK {
log.info("{}异地流转行政处罚上传接口,状态值:{}", filePath, statusCode); log.info("{}异地流转行政处罚上传接口,状态值:{}", filePath, statusCode);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("上传报错", e);
} }
return fileStr; return fileStr;
} }
@ -148,16 +152,13 @@ public class UploadSDK {
" </upl:uploadCreditInfoByPermit>\n" + " </upl:uploadCreditInfoByPermit>\n" +
" </soapenv:Body>\n" + " </soapenv:Body>\n" +
"</soapenv:Envelope>"; "</soapenv:Envelope>";
try { try (CloseableHttpClient client = HttpClients.createDefault()){
PostMethod postMethod = new PostMethod(String.format(uploadUrl, userName, password)); HttpPost postMethod = new HttpPost(String.format(uploadUrl, userName, password));
byte[] b = str.getBytes("utf-8"); postMethod.setHeader("Content-Type", "text/xml; charset=utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length); postMethod.setEntity(new StringEntity(str));
CloseableHttpResponse response = client.execute(postMethod);
RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml; charset=utf-8"); int statusCode = response.getStatusLine().getStatusCode();
postMethod.setRequestEntity(re); String soapResponseData = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postMethod);
String soapResponseData = postMethod.getResponseBodyAsString();
//200说明正常返回数据 //200说明正常返回数据
if (statusCode == 200) { if (statusCode == 200) {
log.info("{}异地流转行政处罚上传接口,返回结果:{}", filePath, soapResponseData); log.info("{}异地流转行政处罚上传接口,返回结果:{}", filePath, soapResponseData);