自定义jar包供ERP使用
2024-09-08 16:07:04
功能要求:需要在ERP中调用其他web服务或者自身web服务(比如跨账套过账等)
1.编写java程序,并将程序打包成jar包
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
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.HttpClientBuilder;
import org.apache.http.util.EntityUtils; public class KbdErpHttpClient {
public static String doPost(String soapXML){
//创建HttpClientBuilder
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
//创建HTTPClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
//创建HTTPPOST
HttpPost httpPost = new HttpPost("http://xxx.xxx.xxx.xxx/web/ws/r/aws_ttsrv2");
//设置超时时间
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(1000*30).setConnectTimeout(1000*30).build();
httpPost.setConfig(requestConfig);
//System.out.println("配置完成");
//创建返回响应体
String resp = null;
try{
//配置post请求头
httpPost.setHeader("Content-Type","text/xml;charset=UTF-8");
httpPost.setHeader("SOAPAction","\"\"");
httpPost.setHeader("Connection","keep-alive");
httpPost.setHeader("Accept-Encoding","gzip,deflate");
//配置post请求体
StringEntity data = new StringEntity(soapXML,"UTF-8");
data.setContentType("application/xml");
httpPost.setEntity(data);
//发送请求
CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
//获取响应体
HttpEntity httpEntity = response.getEntity();
//System.out.println(response.getStatusLine().getStatusCode());
if(httpEntity != null){
resp = EntityUtils.toString(httpEntity,"UTF-8");
}
closeableHttpClient.close();
}catch (Exception e){
System.out.println(e.toString());
}
return resp;
}
}
打包jar
上传JAR到服务器,并将jar包添加至classpath中
2.在程序中引用上一部的jar包,并调用相关类的静态方法
FUNCTION i001_http_test()
DEFINE l_str STRING
DEFINE l_xml_str STRING
LET l_xml_str = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ",
"xmlns:tip=\"http://www.dsc.com.tw/tiptop/TIPTOPServiceGateWay\">\n",
" <soapenv:Header/>\n",
" <soapenv:Body>\n",
" <tip:OperaNorPostRequest>\n",
" <tip:request><![CDATA[<Request>\n",
" <Access>\n",
" <Authentication user='tiptop' password=''/>\n",
" <Organization name='WCTZ'/>\n",
" </Access>\n",
" <RequestContent>\n",
" <Parameter>\n",
" <Record>\n",
" <Field name='type' value='DB'/>\n",
" <Field name='rec' value='K141-221207001'/>\n",
" </Record>\n",
" </Parameter>\n",
" </RequestContent>\n",
"</Request>]]></tip:request>\n",
" </tip:OperaNorPostRequest>\n",
" </soapenv:Body>\n",
"</soapenv:Envelope>"
LET l_str = KbdErpHttpClient.doPost(l_xml_str)
DISPLAY l_str
{DEFINE req com.HTTPRequest
IF resp.getStatusCode() != 200 THEN
DISPLAY "HTTP Error ("||resp.getStatusCode()||") ",resp.getStatusDescription()
ELSE
DISPLAY "HTTP Response is : ",resp.getTextResponse()
END IF
CATCH
DISPLAY "ERROR :",STATUS||" ("||SQLCA.SQLERRM||")"
END TRY}
END FUNCTION
最新文章
- Logcat使用总结
- adb push命令的使用
- 【BZOJ 4569】【SCOI 2016】萌萌哒
- git命令的使用 【备用】
- URAL 1915 Titan Ruins: Reconstruction of Bygones(思路)
- group by 获取总记录数
- Static、final、abstract、接口、构造方法及java语法总结
- mina socket底层主流程源码实现
- iOS 网络与多线程--3.异步Get方式的网络请求(非阻塞)
- bind新发现
- NXT项目准备资料
- Ubuntu16.04 install jdk-8u144-linux-x64.tar.gz
- 51NOD 1238 最小公倍数之和 V3 [杜教筛]
- qt5.11.2+vs2017环境下配置pcl1.8.1以及第三方依赖库vtk的编译
- 并发编程之CountDownLatch
- 20155312 张竞予 Exp4 恶意代码分析
- egg.js异步请求数据
- C# Winfrom常用的几个公共控件
- .net core 与ELK(5)安装logstash
- LS下怎样最大限度的提高Domino下Web应用的速度
热门文章
- FTP调优
- C++ MFC学习 (四)
- fiddler的界面详细讲解
- replace 常用积累
- windows mongo 开启副本集 6.x版本 mongo : 无法将“mongo”项识别为 cmdlet、函数、脚
- springcloud 整合email的坑(Unrecognized SSL message, plaintext connection?)
- M1芯片的Mac上如何安装Windows系统
- Docker部署Springboot+Vue项目
- vim 小记录
- 错误 : 资产文件&;ldquo;\obj\project.assets.json&;rdquo;没有&;ldquo;.NETCoreApp,Version=v2.0&;rdquo;的目标。确保已运行还原,且&;ldquo;netcoreapp2.0&;rdquo;已包含在项目的 TargetFrameworks 中。