首页 > 其他分享 >自定义jar包供ERP使用

自定义jar包供ERP使用

时间:2022-12-09 13:24:33浏览次数:49  
标签:ERP 自定义 org jar httpPost import apache http resp

功能要求:需要在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 

 

标签:ERP,自定义,org,jar,httpPost,import,apache,http,resp
From: https://www.cnblogs.com/smarttony/p/16968441.html

相关文章

  • Linux-jar操作脚本
    service.sh使用说明:./service.shstart./service.shstop#!/bin/bash#这里可替换为你自己的执行程序,其他代码无需更改APP_NAME=mxy_system-0.0.1-SNAPSHOT.jar#she......
  • 自定义分页样式
    一.基本安装和配置1.pipinstalldjango-pure-pagination2.settings.py中installapp中添加'pure_pagination',3.settings.py中添加参数PAGINATION_SETTINGS={......
  • WPF TextBox搜索框&自定义TextBox样式
    先看效果图咯:   前面的文章中,button样式告一段落。接下来分享几个TextBox样式。后续持续更新中~代码都在git上同步。有需要的可以下载查看。项目地址在之前的文......
  • Android 动画实现 从基础到自定义
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......
  • 调用自定义的包
    创建被调用的包mkdirtestcdtestgomodinitexample.com/testcattest/test.gopackagetestpackagetestimport"fmt"//func定义函数//Hello函数名//......
  • 自定义RBAC(3)
    您好,我是湘王,这是我的51CTO博客,欢迎您来,欢迎您再来~​RBAC类型的权限,本质上是一种对资源访问路径的控制,且具有典型的树型层次结构。而树型结构,天然地就有父结点和子结点的关......
  • 自定义RBAC(3)
    您好,我是湘王,这是我的博客园,欢迎您来,欢迎您再来~ RBAC类型的权限,本质上是一种对资源访问路径的控制,且具有典型的树型层次结构。而树型结构,天然地就有父结点和子结点的关......
  • vue实现自定义字体库
      先看效果是不是你所需要的,再看具体如何实现。   效果如下图所示:         有些字体需要下载,用图片就会变得很不清楚,这样我们就需要去下载字......
  • Android自定义View和Canvas绘图解析
    自定义view的流程分为measure、layout、draw三个主要步骤,今天我们通过源码来分下下measure的过程我们从顶级view开始,顶级view即DecorView,view的事件都是先经过这个DecorVi......
  • Failed to collect dependencies for [net.rforge:REngine:jar:0.6-8.1
    使用maven打包的时候报了这个错误:Failedtoreadartifactdescriptorfororg.clojars.strongh:rserveengine:jar:1.7.0:Couldnottransferartifactorg.clojars.strong......