添加http调用webservice

3.2.4.44
wyb 2 years ago
parent 6ad9353f2a
commit 12538de7b0

@ -0,0 +1,60 @@
package com.docus.server.report.client;
import com.docus.core.util.Func;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;
/**
* http webservice
*/
public class HttpWsClient {
private static final Logger logger = LoggerFactory.getLogger(HttpWsClient.class);
public static String send(String wsdlUrl, Map<String, String> requestProperty, String param) {
try {
byte[] paramBytes = param.getBytes(StandardCharsets.UTF_8);
URL url = new URL(wsdlUrl);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestProperty("Content-Length", String.valueOf(paramBytes.length));
httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
// 额外的一些请求信息
if (Func.isNotEmpty(requestProperty)) {
for (Map.Entry<String, String> entry : requestProperty.entrySet()) {
httpConn.setRequestProperty(entry.getKey(), entry.getValue());
}
}
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setConnectTimeout(60000);
// 输入内容
OutputStream outputStream = httpConn.getOutputStream();
outputStream.write(paramBytes);
outputStream.flush();
outputStream.close();
// 获取返回内容
InputStreamReader inputStreamReader = new InputStreamReader(httpConn.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String str = null;
while ((str = bufferedReader.readLine()) != null) {
stringBuilder.append(str).append("\n");
}
bufferedReader.close();
inputStreamReader.close();
return stringBuilder.toString();
} catch (Exception ex) {
logger.error("wsdl"+wsdlUrl+", ext requestProperty:"+requestProperty+", param:"+param,ex);
return null;
}
}
}

@ -8,7 +8,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.namespace.QName;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -22,22 +21,22 @@ public class JaxWsDynamicClient {
private static final Map<String, Client> CLIENT_MAP=new ConcurrentHashMap<>();
private static final Logger logger= LoggerFactory.getLogger(JaxWsDynamicClient.class);
public static String send(String wsdlUrl,String namespaceUri,String operationName,Object[] params){
public static String send(String wsdlUrl,String namespaceUri,String operationName,Object param){
try {
Client client = getClient(wsdlUrl);
Object[] result;
if (namespaceUri == null || namespaceUri.isEmpty()) {
result = client.invoke(operationName, params);
result = client.invoke(operationName, param);
} else {
QName qName = new QName(namespaceUri, operationName);
result = client.invoke(qName, params);
result = client.invoke(qName, param);
}
if (result == null || result[0] == null) {
return null;
}
return String.valueOf(result[0]);
} catch (Exception ex) {
logger.error("wsdlUrl" + wsdlUrl + " operationName" + operationName + "params:" + Arrays.toString(params) + " 调用失败了!", ex);
logger.error("wsdlUrl" + wsdlUrl + " operationName" + operationName + "param:" + param + " 调用失败了!", ex);
return null;
}
}

@ -170,7 +170,7 @@ public class ReportJob {
try {
List<ReportDto> reportDtos = new ArrayList<>();
int pageNum = 1;
final int pageSize=10;
final int pageSize = 5;
boolean loopCondition = true;
do {
String requestParam = organizationQuerySdRyInspectReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize);
@ -226,6 +226,7 @@ public class ReportJob {
map.put("StartTime", startTime);
map.put("EndTime", endTime);
map.put("PatientId", sdRyReportPatientId);
map.put("PatentTypeCode", "1");
return Func.toJson(map);
}
@ -292,6 +293,7 @@ public class ReportJob {
/**
* job
*
* @param jobType job
* @return job 1801-01-01 00:00:00
*/
@ -331,7 +333,7 @@ public class ReportJob {
try {
List<ReportDto> reportDtos = new ArrayList<>();
int pageNum = 1;
final int pageSize=10;
final int pageSize = 5;
boolean loopCondition = true;
do {
String requestParam = organizationQuerySdRyLisReportParam(sdRyReportPatientId, tBasic, pageNum, pageSize);
@ -444,6 +446,7 @@ public class ReportJob {
map.put("StartTime", startTime);
map.put("EndTime", endTime);
map.put("PatientId", sdRyReportPatientId);
map.put("PatentTypeCode", "1");
return Func.toJson(map);
}
@ -460,11 +463,11 @@ public class ReportJob {
return new ArrayList<>();
}
String param = organizationQuerySdRyReportIndexParam(sDryIndex);
String[] params = {param};
String namespaceUri = sdRyReportQueryConfig.getQueryReportIndexWsdlNamespaceUri();
String wsdlAddr = sdRyReportQueryConfig.getQueryReportIndexWsdlAddr();
String operationName = sdRyReportQueryConfig.getQueryReportIndexWsdlOperationName();
String result = JaxWsDynamicClient.send(wsdlAddr, namespaceUri, operationName, params);
String result = JaxWsDynamicClient.send(wsdlAddr, namespaceUri, operationName, param);
log.info("查询顺德人医患者交叉索引数据,返回值:{}", result);
if (result == null) {
return new ArrayList<>();

Loading…
Cancel
Save