#
mrzhssss
2022-07-26 7c560277576d8fc05cca0a2176c7f64f7267d83e
#
7个文件已修改
1个文件已添加
1个文件已删除
946 ■■■■■ 已修改文件
.idea/artifacts/kls_asrs_war.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/artifacts/kls_asrs_war_exploded.xml 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/compiler.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/kls-asrs.iml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/libraries/Maven__com_oracle_ojdbc6_11_2_0_1_0.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/slcf/filter/UpdateThread.java 659 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/slcf/util/HttpHandler.java 213 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/jdbc.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
.idea/artifacts/kls_asrs_war.xml
@@ -1,7 +1,13 @@
<component name="ArtifactManager">
  <artifact type="war" name="kls-asrs:war">
    <output-path>$PROJECT_DIR$/target</output-path>
    <root id="archive" name="asrs-0.0.1-SNAPSHOT.war">
    <properties id="maven-jee-properties">
      <options>
        <module>kls-asrs</module>
        <packaging>war</packaging>
      </options>
    </properties>
    <root id="archive" name="asrs.war">
      <element id="artifact" artifact-name="kls-asrs:war exploded" />
    </root>
  </artifact>
.idea/artifacts/kls_asrs_war_exploded.xml
@@ -1,6 +1,13 @@
<component name="ArtifactManager">
  <artifact type="exploded-war" name="kls-asrs:war exploded">
    <output-path>$PROJECT_DIR$/target/asrs-0.0.1-SNAPSHOT</output-path>
    <output-path>$PROJECT_DIR$/target/asrs</output-path>
    <properties id="maven-jee-properties">
      <options>
        <exploded>true</exploded>
        <module>kls-asrs</module>
        <packaging>war</packaging>
      </options>
    </properties>
    <root id="root">
      <element id="directory" name="WEB-INF">
        <element id="directory" name="classes">
@@ -31,7 +38,6 @@
          <element id="library" level="project" name="Maven: cglib:cglib:3.1" />
          <element id="library" level="project" name="Maven: org.ow2.asm:asm:4.2" />
          <element id="library" level="project" name="Maven: org.ehcache:ehcache:3.4.0" />
          <element id="library" level="project" name="Maven: com.oracle:ojdbc6:11.2.0.1.0" />
          <element id="library" level="project" name="Maven: log4j:log4j:1.2.17" />
          <element id="library" level="project" name="Maven: org.slf4j:slf4j-api:1.7.21" />
          <element id="library" level="project" name="Maven: org.slf4j:slf4j-log4j12:1.7.21" />
@@ -114,12 +120,15 @@
          <element id="library" level="project" name="Maven: commons-collections:commons-collections:3.2.1" />
          <element id="library" level="project" name="Maven: commons-lang:commons-lang:2.5" />
          <element id="library" level="project" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" />
          <element id="library" level="project" name="Maven: com.alibaba:fastjson:1.2.66" />
          <element id="library" level="project" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" />
          <element id="library" level="project" name="Maven: com.squareup.okio:okio:1.14.0" />
          <element id="library" level="project" name="Maven: com.google.zxing:core:3.0.0" />
          <element id="library" level="project" name="Maven: com.google.zxing:javase:3.0.0" />
        </element>
      </element>
      <element id="directory" name="META-INF">
        <element id="file-copy" path="$PROJECT_DIR$/target/asrs-0.0.1-SNAPSHOT/META-INF/MANIFEST.MF" />
        <element id="file-copy" path="$PROJECT_DIR$/target/asrs/META-INF/MANIFEST.MF" />
      </element>
      <element id="javaee-facet-resources" facet="kls-asrs/web/Web" />
    </root>
.idea/compiler.xml
@@ -10,7 +10,7 @@
      </profile>
    </annotationProcessing>
    <bytecodeTargetLevel>
      <module name="kls-asrs" target="1.5" />
      <module name="kls-asrs" target="1.8" />
    </bytecodeTargetLevel>
  </component>
</project>
.idea/kls-asrs.iml
@@ -29,7 +29,7 @@
      </configuration>
    </facet>
  </component>
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
    <output url="file://$MODULE_DIR$/target/classes" />
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
    <content url="file://$MODULE_DIR$">
@@ -65,7 +65,6 @@
    <orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" />
    <orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" />
    <orderEntry type="library" name="Maven: org.ehcache:ehcache:3.4.0" level="project" />
    <orderEntry type="library" name="Maven: com.oracle:ojdbc6:11.2.0.1.0" level="project" />
    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
@@ -153,6 +152,9 @@
    <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
    <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
    <orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" />
    <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.66" level="project" />
    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
    <orderEntry type="library" name="Maven: com.google.zxing:core:3.0.0" level="project" />
    <orderEntry type="library" name="Maven: com.google.zxing:javase:3.0.0" level="project" />
  </component>
.idea/libraries/Maven__com_oracle_ojdbc6_11_2_0_1_0.xml
File was deleted
pom.xml
@@ -118,11 +118,11 @@
<!--             <version>${mysql.version}</version> -->
<!--         </dependency> -->
        <!--Oracle驱动包 添加oracle jdbc driver -->
         <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.1.0</version>
        </dependency>
<!--         <dependency>-->
<!--            <groupId>com.oracle</groupId>-->
<!--            <artifactId>ojdbc6</artifactId>-->
<!--            <version>11.2.0.1.0</version>-->
<!--        </dependency> -->
        <!--  <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
@@ -319,6 +319,16 @@
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.66</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>3.10.0</version>
        </dependency>
<!--         <dependency> -->
<!--         <groupId>net.sf.barcode4j</groupId> -->
<!--         <artifactId>barcode4j-light</artifactId> -->
@@ -362,6 +372,14 @@
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
src/main/java/com/slcf/filter/UpdateThread.java
@@ -1,16 +1,20 @@
package com.slcf.filter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import com.slcf.pojo.SapRequestLogBean;
import com.slcf.service.SapRequestLogService;
import com.slcf.util.HttpHandler;
import net.sf.json.JSONString;
import org.activiti.engine.impl.transformer.IntegerToString;
import org.apache.log4j.Logger;
@@ -85,6 +89,31 @@
            }
        }
    }
    public JSONObject requestSAP(JSONObject body, String url) {
        logger.info(url);
        JSONObject resp;
            HashMap<String, Object> requestHeader = new HashMap<>();
            requestHeader.put("Accept", "application/json");
            requestHeader.put("Content-Type", "application/json");
            requestHeader.put("X-Requested-With", "X");
            requestHeader.put("Authorization","Basic TElRSTpzdGFydDEu");
            requestHeader.put("sap-client","100");
        String s = null;
        try {
            s = new HttpHandler.Builder()
                    .setUri(url)
                    .setJson(body.toString())
                    .setHeaders(requestHeader)
                    .build()
                    .doPost();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        resp = JSONObject.fromObject(s);
        logger.info("返回体:" + resp);
        return resp;
    }
    /**
     * 处理入库通知档数据
@@ -94,7 +123,7 @@
//            logger.info("waitIn:" + count++);
            WaitPakInBean waitPakInBean = waitPakInService.queryWaitPakInFnh();
            if(waitPakInBean!=null) {
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/AsrsTrSet";
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/AsrsTrSet";
                int result = sendPakInStatus(httpUrl,waitPakInBean);
            }
        }catch(Exception e) {
@@ -115,55 +144,55 @@
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
        try {
            encodedPassword = base.encode(input.getBytes("UTF-8"));
            URL url1 = new URL(httpUrl);
            connection1 = (HttpURLConnection) url1.openConnection();
            connection1.setDoOutput(true);
            connection1.setDoInput(true);
            connection1.setConnectTimeout(30000);
            connection1.setReadTimeout(30000);
            connection1.setRequestMethod("GET");
            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
            connection1.setRequestProperty("x-csrf-token","Fetch");
            String sessionCookie = connection1.getHeaderField("Set-Cookie");
            if(sessionCookie==null || sessionCookie.length()<1)
            {
                logger.error("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
                // SAP INFO-----调用上架完成接口,日志记录
                SapRequestLogBean logInfo = new SapRequestLogBean();
                logInfo.setMatnr(waitPakIn.getMatnr());
                logInfo.setRequest("获取cookie失败,cookie值:" + sessionCookie);
                logInfo.setResponse("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
                logInfo.setCreate_time(new Date());
                logInfo.setType(2);
//                sapRequestLogService.addSapLog(logInfo);
                return result;
            }
            String[] sessionId = sessionCookie.split(";");
            session_value = sessionId[0];
            token = connection1.getHeaderField("x-csrf-token");
//            Map<String, List<String>> map = connection1.getHeaderFields();
//            token = map.get("x-csrf-token").toString();
        } catch (Exception e1) {
            logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
            // SAP INFO-----调用上架完成接口,日志记录
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakIn.getMatnr());
            logInfo.setRequest("获取cookie失败");
            logInfo.setResponse("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
//            e1.printStackTrace();
        }finally {
            if(connection1!=null){
                connection1.disconnect();
            }
        }
//        HttpURLConnection connection1 = null;
//        try {
//            encodedPassword = base.encode(input.getBytes("UTF-8"));
//            URL url1 = new URL(httpUrl);
//            connection1 = (HttpURLConnection) url1.openConnection();
//            connection1.setDoOutput(true);
//            connection1.setDoInput(true);
//            connection1.setConnectTimeout(30000);
//            connection1.setReadTimeout(30000);
//            connection1.setRequestMethod("GET");
//            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//            connection1.setRequestProperty("x-csrf-token","Fetch");
//
//
//            String sessionCookie = connection1.getHeaderField("Set-Cookie");
//            if(sessionCookie==null || sessionCookie.length()<1)
//            {
//                logger.error("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
//                // SAP INFO-----调用上架完成接口,日志记录
//                SapRequestLogBean logInfo = new SapRequestLogBean();
//                logInfo.setMatnr(waitPakIn.getMatnr());
//                logInfo.setRequest("获取cookie失败,cookie值:" + sessionCookie);
//                logInfo.setResponse("SAP ERROR-----调用上架完成接口,get请求获取cookie失败");
//                logInfo.setCreate_time(new Date());
//                logInfo.setType(2);
////                sapRequestLogService.addSapLog(logInfo);
//                return result;
//            }
//            String[] sessionId = sessionCookie.split(";");
//            session_value = sessionId[0];
//            token = connection1.getHeaderField("x-csrf-token");
////            Map<String, List<String>> map = connection1.getHeaderFields();
////            token = map.get("x-csrf-token").toString();
//        } catch (Exception e1) {
//            logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
//            // SAP INFO-----调用上架完成接口,日志记录
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakIn.getMatnr());
//            logInfo.setRequest("获取cookie失败");
//            logInfo.setResponse("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage());
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
////            sapRequestLogService.addSapLog(logInfo);
////            e1.printStackTrace();
//        }finally {
//            if(connection1!=null){
//                connection1.disconnect();
//            }
//        }
        JSONObject jsObj = new JSONObject();
        try {
@@ -185,48 +214,50 @@
            jsObj.put("item", arr);
            byte[] buff = jsObj.toString().getBytes();
            int buffLen = buff.length;
            JSONObject json = requestSAP(jsObj, httpUrl);
            //创建连接
            HttpURLConnection connection = null;
            try {
//                String input = "ZHANGX:654321";
//                BASE64Encoder base = new BASE64Encoder();
//                String encodedPassword = base.encode(input.getBytes("UTF-8"));
                URL url = new URL(httpUrl);
                connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                connection.setRequestMethod("POST");
                connection.setConnectTimeout(30000);
                connection.setReadTimeout(30000);
//                connection.setUseCaches(false);
//                connection.setInstanceFollowRedirects(true);
//                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
                connection.setRequestProperty("Cookie", session_value);
                connection.setRequestProperty("Content-Type","application/json");
                connection.setRequestProperty("Accept","application/json");
                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
                connection.setRequestProperty("Content-Length","" + buffLen);
//                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
                connection.setRequestProperty("x-csrf-token",token);
                //POST请求
                OutputStream out = connection.getOutputStream();
                out.write(buff);
                out.close();
                //读取响应
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
                String lines;
                StringBuffer sb = new StringBuffer("");
                while ((lines = reader.readLine()) != null) {
                    lines = new String(lines.getBytes(), "utf-8");
                    sb.append(lines);
                }
//            HttpURLConnection connection = null;
//            try {
////                String input = "ZHANGX:654321";
////                BASE64Encoder base = new BASE64Encoder();
////                String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//                URL url = new URL(httpUrl);
//                connection = (HttpURLConnection) url.openConnection();
//                connection.setDoOutput(true);
//                connection.setDoInput(true);
//                connection.setRequestMethod("POST");
//                connection.setConnectTimeout(30000);
//                connection.setReadTimeout(30000);
////                connection.setUseCaches(false);
////                connection.setInstanceFollowRedirects(true);
////                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//                connection.setRequestProperty("Cookie", session_value);
//                connection.setRequestProperty("Content-Type","application/json");
//                connection.setRequestProperty("Accept","application/json");
//                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//                connection.setRequestProperty("Content-Length","" + buffLen);
////                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//                connection.setRequestProperty("x-csrf-token",token);
//
//                //POST请求
//                OutputStream out = connection.getOutputStream();
//                out.write(buff);
//                out.close();
//
//                //读取响应
//                BufferedReader reader = new BufferedReader(new InputStreamReader(
//                        connection.getInputStream()));
//                String lines;
//                StringBuffer sb = new StringBuffer("");
//                while ((lines = reader.readLine()) != null) {
//                    lines = new String(lines.getBytes(), "utf-8");
//                    sb.append(lines);
//                }
//                logger.error("SAP INFO-----调用上架完成接口,返回JSON数据:" + sb.toString());
//                System.out.println(sb.toString());
                JSONObject json = JSONObject.fromObject(sb.toString());
//                JSONObject json = JSONObject.fromObject(sb.toString());
                String d = json.get("d").toString();
                JSONObject jsonD = JSONObject.fromObject(d);
                String Item = jsonD.get("item").toString();
@@ -250,7 +281,7 @@
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakIn.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setRemark("上架完成接口:" + message);
                            logInfo.setType(1);
@@ -264,7 +295,7 @@
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakIn.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setRemark("上架完成接口:" + message);
                            logInfo.setType(2);
@@ -285,19 +316,15 @@
                logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
                logger.error("1入库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//                System.out.println(e.getMessage());
            }finally {
                if(connection!=null){
                    connection.disconnect();
                }
            }
        }catch (Exception e) {
            waitPakIn.setIo_status("X");
            waitPakIn.setMemo(e.getMessage());
            waitPakInService.upWaitPakIn(waitPakIn);
            logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
            logger.error("2入库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//            System.out.println(e.getMessage());
        }
//        }catch (Exception e) {
//            waitPakIn.setIo_status("X");
//            waitPakIn.setMemo(e.getMessage());
//            waitPakInService.upWaitPakIn(waitPakIn);
//            logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage());
//            logger.error("2入库完成回报异常时ASRS请求JSON:" + jsObj.toString());
////            System.out.println(e.getMessage());
//        }
        return result;
    }
@@ -311,7 +338,7 @@
            logger.info("TEST===>>1");
            if(waitPakOutBean!=null) {
                logger.info("TEST===>>2");
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/ToConHeadSet";
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/ToConHeadSet";
                int result = sendPakOutStatus(httpUrl,waitPakOutBean);
            }
        }catch(Exception e) {
@@ -332,54 +359,54 @@
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
        try {
            encodedPassword = base.encode(input.getBytes("UTF-8"));
            URL url1 = new URL(httpUrl);
            connection1 = (HttpURLConnection) url1.openConnection();
            connection1.setDoOutput(true);
            connection1.setDoInput(true);
            connection1.setConnectTimeout(30000);
            connection1.setReadTimeout(30000);
            connection1.setRequestMethod("GET");
            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
            connection1.setRequestProperty("x-csrf-token","Fetch");
            String sessionCookie = connection1.getHeaderField("Set-Cookie");
            if(sessionCookie==null || sessionCookie.length()<1)
            {
                logger.error("调用下架完成接口,get请求获取cookie失败");
                // SAP INFO-----调用上架完成接口,日志记录
                SapRequestLogBean logInfo = new SapRequestLogBean();
                logInfo.setMatnr(waitPakOut.getMatnr());
                logInfo.setRequest("获取cookie值失败,cookie:" + sessionCookie);
                logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
                logInfo.setCreate_time(new Date());
                logInfo.setType(2);
//                sapRequestLogService.addSapLog(logInfo);
                return result;
            }
            String[] sessionId = sessionCookie.split(";");
            session_value = sessionId[0];
            token = connection1.getHeaderField("x-csrf-token");
//            Map<String, List<String>> map = connection1.getHeaderFields();
//            token = map.get("x-csrf-token").toString();
        } catch (Exception e1) {
            logger.error("调用下架完成接口,get请求获取cookie失败" + e1.getMessage());
            // SAP INFO-----调用上架完成接口,日志记录
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest("获取cookie失败");
            logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
//            e1.printStackTrace();
        }finally{
            if(connection1!=null){
                connection1.disconnect();
            }
        }
//        HttpURLConnection connection1 = null;
//        try {
//            encodedPassword = base.encode(input.getBytes("UTF-8"));
//            URL url1 = new URL(httpUrl);
//            connection1 = (HttpURLConnection) url1.openConnection();
//            connection1.setDoOutput(true);
//            connection1.setDoInput(true);
//            connection1.setConnectTimeout(30000);
//            connection1.setReadTimeout(30000);
//            connection1.setRequestMethod("GET");
//            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//            connection1.setRequestProperty("x-csrf-token","Fetch");
//            String sessionCookie = connection1.getHeaderField("Set-Cookie");
//            if(sessionCookie==null || sessionCookie.length()<1)
//            {
//                logger.error("调用下架完成接口,get请求获取cookie失败");
//                // SAP INFO-----调用上架完成接口,日志记录
//                SapRequestLogBean logInfo = new SapRequestLogBean();
//                logInfo.setMatnr(waitPakOut.getMatnr());
//                logInfo.setRequest("获取cookie值失败,cookie:" + sessionCookie);
//                logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
//                logInfo.setCreate_time(new Date());
//                logInfo.setType(2);
////                sapRequestLogService.addSapLog(logInfo);
//                return result;
//            }
//            String[] sessionId = sessionCookie.split(";");
//            session_value = sessionId[0];
//            token = connection1.getHeaderField("x-csrf-token");
//
////            Map<String, List<String>> map = connection1.getHeaderFields();
////            token = map.get("x-csrf-token").toString();
//        } catch (Exception e1) {
//            logger.error("调用下架完成接口,get请求获取cookie失败" + e1.getMessage());
//            // SAP INFO-----调用上架完成接口,日志记录
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakOut.getMatnr());
//            logInfo.setRequest("获取cookie失败");
//            logInfo.setResponse("调用出库完成接口,get请求获取cookie失败");
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
////            sapRequestLogService.addSapLog(logInfo);
////            e1.printStackTrace();
//        }finally{
//            if(connection1!=null){
//                connection1.disconnect();
//            }
//        }
        logger.info("TEST===>>4");
@@ -419,46 +446,47 @@
            byte[] buff = jsObj.toString().getBytes();
            int buffLen = buff.length;
            //创建连接
            HttpURLConnection connection = null;
            try {
//                String input = "ZHANGX:654321";
//                BASE64Encoder base = new BASE64Encoder();
//                String encodedPassword = base.encode(input.getBytes("UTF-8"));
                URL url = new URL(httpUrl);
                connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                connection.setConnectTimeout(30000);
                connection.setReadTimeout(30000);
                connection.setRequestMethod("POST");
        //        connection.setUseCaches(false);
        //        connection.setInstanceFollowRedirects(true);
//                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
                connection.setRequestProperty("Cookie", session_value);
                connection.setRequestProperty("Content-Type","application/json");
                connection.setRequestProperty("Accept","application/json");
                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
                connection.setRequestProperty("Content-Length","" + buffLen);
//                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
                connection.setRequestProperty("x-csrf-token",token);
                //POST请求
                OutputStream out = connection.getOutputStream();
                out.write(buff);
                out.close();
                //读取响应
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
                String lines;
                StringBuffer sb = new StringBuffer("");
                while ((lines = reader.readLine()) != null) {
                    lines = new String(lines.getBytes(), "utf-8");
                    sb.append(lines);
                }
//            HttpURLConnection connection = null;
//            try {
////                String input = "ZHANGX:654321";
////                BASE64Encoder base = new BASE64Encoder();
////                String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//                URL url = new URL(httpUrl);
//                connection = (HttpURLConnection) url.openConnection();
//                connection.setDoOutput(true);
//                connection.setDoInput(true);
//                connection.setConnectTimeout(30000);
//                connection.setReadTimeout(30000);
//                connection.setRequestMethod("POST");
//        //        connection.setUseCaches(false);
//        //        connection.setInstanceFollowRedirects(true);
////                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//                connection.setRequestProperty("Cookie", session_value);
//                connection.setRequestProperty("Content-Type","application/json");
//                connection.setRequestProperty("Accept","application/json");
//                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//                connection.setRequestProperty("Content-Length","" + buffLen);
////                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//                connection.setRequestProperty("x-csrf-token",token);
//
//                //POST请求
//                OutputStream out = connection.getOutputStream();
//                out.write(buff);
//                out.close();
//
//                //读取响应
//                BufferedReader reader = new BufferedReader(new InputStreamReader(
//                        connection.getInputStream()));
//                String lines;
//                StringBuffer sb = new StringBuffer("");
//                while ((lines = reader.readLine()) != null) {
//                    lines = new String(lines.getBytes(), "utf-8");
//                    sb.append(lines);
//                }
//                System.out.println(sb.toString());
                JSONObject json = JSONObject.fromObject(sb.toString());
                JSONObject json = requestSAP(jsObj, httpUrl);
//                JSONObject json = JSONObject.fromObject(sb.toString());
                String d = json.get("d").toString();
                JSONObject jsonD = JSONObject.fromObject(d);
                String Item = jsonD.get("item").toString();
@@ -482,7 +510,7 @@
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakOut.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setType(1);
                            logInfo.setRemark("出库完成接口:" + message);
@@ -496,7 +524,7 @@
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakOut.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setType(2);
                            logInfo.setRemark("出库完成接口:" + message);
@@ -518,19 +546,15 @@
                logger.error("出库通知档回报异常1--"+waitPakOut.getMatnr() + "---" + e.getMessage());
                logger.error("1出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//                System.out.println(e.getMessage());
            }finally{
                if(connection!=null){
                    connection.disconnect();
                }
            }
        }catch (Exception e) {
            waitPakOut.setIo_status("X");
            waitPakOut.setMemo(e.getMessage());
            waitPakOutService.upWaitPakOut(waitPakOut,0);
            logger.error("出库通知档回报异常2--"+waitPakOut.getMatnr() + "---" + e.getMessage());
            logger.error("2出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
//            System.out.println(e.getMessage());
        }
//        }catch (Exception e) {
//            waitPakOut.setIo_status("X");
//            waitPakOut.setMemo(e.getMessage());
//            waitPakOutService.upWaitPakOut(waitPakOut,0);
//            logger.error("出库通知档回报异常2--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//            logger.error("2出库完成回报异常时ASRS请求JSON:" + jsObj.toString());
////            System.out.println(e.getMessage());
//        }
        return result;
    }
@@ -541,7 +565,7 @@
        try {
            WaitPakOutBean waitPakOutBean = waitPakOutService.getWaitPakOutPrint();
            if(waitPakOutBean!=null) {
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_SRV/ToConHeadSet";
                String httpUrl = Constants.SAP_URL + "/sap/opu/odata/SAP/Z_WM_H5_DW_SRV/ToConHeadSet";
                int result = sendPrinCommand(httpUrl,waitPakOutBean);
            }
        }catch(Exception e) {
@@ -560,55 +584,55 @@
        String encodedPassword;
        String token="";
        String session_value="";
        HttpURLConnection connection1 = null;
        try {
//            logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
            encodedPassword = base.encode(input.getBytes("UTF-8"));
            URL url1 = new URL(httpUrl);
            connection1 = (HttpURLConnection) url1.openConnection();
            connection1.setDoOutput(true);
            connection1.setDoInput(true);
            connection1.setConnectTimeout(30000);
            connection1.setReadTimeout(30000);
            connection1.setRequestMethod("GET");
            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
            connection1.setRequestProperty("x-csrf-token","Fetch");
            String sessionCookie = connection1.getHeaderField("Set-Cookie");
            if(sessionCookie==null || sessionCookie.length()<1)
            {
                logger.error("调用打印接口,get请求获取cookie失败");
                // 调用sap打印接口,记录日志
                SapRequestLogBean logInfo = new SapRequestLogBean();
                logInfo.setMatnr(waitPakOut.getMatnr());
                logInfo.setRequest("调用打印接口,get请求获取cookie失败");
                logInfo.setResponse(sessionCookie);
                logInfo.setCreate_time(new Date());
                logInfo.setType(2);
                sapRequestLogService.addSapLog(logInfo);
                return result;
            }
            String[] sessionId = sessionCookie.split(";");
            session_value = sessionId[0];
            token = connection1.getHeaderField("x-csrf-token");
//            Map<String, List<String>> map = connection1.getHeaderFields();
//            token = map.get("x-csrf-token").toString();
        } catch (Exception e1) {
            logger.error("sendPrinCommand1-----调用打印接口请求cookie失败" + waitPakOut.getMaktx() + e1.getMessage());
            // 调用sap打印接口,记录日志
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest("sendPrinCommand1-----调用打印接口请求cookie失败"  + waitPakOut.getMaktx());
            logInfo.setResponse(e1.getMessage());
            logInfo.setCreate_time(new Date());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
            e1.printStackTrace();
        }finally{
            if(connection1!=null){
                connection1.disconnect();
            }
        }
//
//        HttpURLConnection connection1 = null;
//        try {
////            logger.error("sendPrinCommand-----调用打印接口" + waitPakOut.getMaktx());
//            encodedPassword = base.encode(input.getBytes("UTF-8"));
//            URL url1 = new URL(httpUrl);
//            connection1 = (HttpURLConnection) url1.openConnection();
//            connection1.setDoOutput(true);
//            connection1.setDoInput(true);
//            connection1.setConnectTimeout(30000);
//            connection1.setReadTimeout(30000);
//            connection1.setRequestMethod("GET");
//            connection1.setRequestProperty("Authorization", "Basic " + encodedPassword);
//            connection1.setRequestProperty("x-csrf-token","Fetch");
//            String sessionCookie = connection1.getHeaderField("Set-Cookie");
//            if(sessionCookie==null || sessionCookie.length()<1)
//            {
//                logger.error("调用打印接口,get请求获取cookie失败");
//                // 调用sap打印接口,记录日志
//                SapRequestLogBean logInfo = new SapRequestLogBean();
//                logInfo.setMatnr(waitPakOut.getMatnr());
//                logInfo.setRequest("调用打印接口,get请求获取cookie失败");
//                logInfo.setResponse(sessionCookie);
//                logInfo.setCreate_time(new Date());
//                logInfo.setType(2);
//                sapRequestLogService.addSapLog(logInfo);
//                return result;
//            }
//            String[] sessionId = sessionCookie.split(";");
//            session_value = sessionId[0];
//            token = connection1.getHeaderField("x-csrf-token");
////            Map<String, List<String>> map = connection1.getHeaderFields();
////            token = map.get("x-csrf-token").toString();
//        } catch (Exception e1) {
//            logger.error("sendPrinCommand1-----调用打印接口请求cookie失败" + waitPakOut.getMaktx() + e1.getMessage());
//            // 调用sap打印接口,记录日志
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakOut.getMatnr());
//            logInfo.setRequest("sendPrinCommand1-----调用打印接口请求cookie失败"  + waitPakOut.getMaktx());
//            logInfo.setResponse(e1.getMessage());
//            logInfo.setCreate_time(new Date());
//            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
//            e1.printStackTrace();
//        }finally{
//            if(connection1!=null){
//                connection1.disconnect();
//            }
//        }
        try {
//            logger.error("sendPrinCommand2-----开始调用打印接口" + waitPakOut.getMaktx());
@@ -639,46 +663,47 @@
            byte[] buff = jsObj.toString().getBytes();
            int buffLen = buff.length;
            //创建连接
            HttpURLConnection connection = null;
            try {
//                String input = "ZHANGX:654321";
//                BASE64Encoder base = new BASE64Encoder();
//                String encodedPassword = base.encode(input.getBytes("UTF-8"));
                URL url = new URL(httpUrl);
                connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setDoInput(true);
                connection.setConnectTimeout(30000);
                connection.setReadTimeout(30000);
                connection.setRequestMethod("POST");
        //        connection.setUseCaches(false);
        //        connection.setInstanceFollowRedirects(true);
//                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
                connection.setRequestProperty("Cookie", session_value);
                connection.setRequestProperty("Content-Type","application/json");
                connection.setRequestProperty("Accept","application/json");
                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
                connection.setRequestProperty("Content-Length","" + buffLen);
//                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
                connection.setRequestProperty("x-csrf-token",token);
                //POST请求
                OutputStream out = connection.getOutputStream();
                out.write(buff);
                out.close();
//                logger.error("sendPrinCommand3-----调用打印接口" + waitPakOut.getMaktx());
                //读取响应
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        connection.getInputStream()));
                String lines;
                StringBuffer sb = new StringBuffer("");
                while ((lines = reader.readLine()) != null) {
                    lines = new String(lines.getBytes(), "utf-8");
                    sb.append(lines);
                }
//                System.out.println(sb.toString());
                JSONObject json = JSONObject.fromObject(sb.toString());
//            HttpURLConnection connection = null;
//            try {
////                String input = "ZHANGX:654321";
////                BASE64Encoder base = new BASE64Encoder();
////                String encodedPassword = base.encode(input.getBytes("UTF-8"));
//
//                URL url = new URL(httpUrl);
//                connection = (HttpURLConnection) url.openConnection();
//                connection.setDoOutput(true);
//                connection.setDoInput(true);
//                connection.setConnectTimeout(30000);
//                connection.setReadTimeout(30000);
//                connection.setRequestMethod("POST");
//        //        connection.setUseCaches(false);
//        //        connection.setInstanceFollowRedirects(true);
////                connection.setRequestProperty("Content-Type","text/json;charset=gb2312");
//                connection.setRequestProperty("Cookie", session_value);
//                connection.setRequestProperty("Content-Type","application/json");
//                connection.setRequestProperty("Accept","application/json");
//                connection.setRequestProperty("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
//                connection.setRequestProperty("Content-Length","" + buffLen);
////                connection.setRequestProperty("Authorization", "Basic " + encodedPassword);
//                connection.setRequestProperty("x-csrf-token",token);
//
//                //POST请求
//                OutputStream out = connection.getOutputStream();
//                out.write(buff);
//                out.close();
////                logger.error("sendPrinCommand3-----调用打印接口" + waitPakOut.getMaktx());
//                //读取响应
//                BufferedReader reader = new BufferedReader(new InputStreamReader(
//                        connection.getInputStream()));
//                String lines;
//                StringBuffer sb = new StringBuffer("");
//                while ((lines = reader.readLine()) != null) {
//                    lines = new String(lines.getBytes(), "utf-8");
//                    sb.append(lines);
//                }
////                System.out.println(sb.toString());
//                JSONObject json = JSONObject.fromObject(sb.toString());
                JSONObject json = requestSAP(jsObj, httpUrl);
                String d = json.get("d").toString();
                JSONObject jsonD = JSONObject.fromObject(d);
                String Item = jsonD.get("item").toString();
@@ -702,12 +727,12 @@
                            waitPakOut.setPrnstatus(2);  //打印完成
                            waitPakOutService.upWaitPakOut(waitPakOut,0);
                            logger.error("sendPrinCommand5---调用打印接口成功,请求json数据--" + jsObj.toString());
                            logger.info("sendPrinCommand5---调用打印接口成功,返回json数据--" + sb.toString());
                            logger.info("sendPrinCommand5---调用打印接口成功,返回json数据--" + json.toString());
                            // 调用sap打印接口,记录日志
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakOut.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setRemark(message);
                            logInfo.setType(1);
@@ -721,7 +746,7 @@
                            SapRequestLogBean logInfo = new SapRequestLogBean();
                            logInfo.setMatnr(waitPakOut.getMatnr());
                            logInfo.setRequest(jsObj.toString());
                            logInfo.setResponse(sb.toString());
                            logInfo.setResponse(json.toString());
                            logInfo.setCreate_time(new Date());
                            logInfo.setRemark(message);
                            logInfo.setType(2);
@@ -738,34 +763,30 @@
                // 调用sap打印接口,记录日志
                SapRequestLogBean logInfo = new SapRequestLogBean();
                logInfo.setMatnr(waitPakOut.getMatnr());
                logInfo.setRequest(jsObj.toString());
//                logInfo.setRequest(jsObj.toString());
                logInfo.setResponse("sendPrinCommand7---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
                logInfo.setCreate_time(new Date());
                logInfo.setRemark(e.getMessage());
                logInfo.setType(2);
                sapRequestLogService.addSapLog(logInfo);
//                System.out.println(e.getMessage());
            }finally{
                if(connection!=null){
                    connection.disconnect();
                }
            }
        }catch (Exception e) {
            waitPakOut.setPrnstatus(3);     //打印失败
            waitPakOut.setMemo(e.getMessage());
            waitPakOutService.upWaitPakOut(waitPakOut,0);
            logger.error("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
            // 调用sap打印接口,记录日志
            SapRequestLogBean logInfo = new SapRequestLogBean();
            logInfo.setMatnr(waitPakOut.getMatnr());
            logInfo.setRequest("打印请求失败");
            logInfo.setResponse("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
            logInfo.setCreate_time(new Date());
            logInfo.setRemark(e.getMessage());
            logInfo.setType(2);
            sapRequestLogService.addSapLog(logInfo);
//            System.out.println(e.getMessage());
        }
//        }catch (Exception e) {
//            waitPakOut.setPrnstatus(3);     //打印失败
//            waitPakOut.setMemo(e.getMessage());
//            waitPakOutService.upWaitPakOut(waitPakOut,0);
//            logger.error("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage());
//            // 调用sap打印接口,记录日志
//            SapRequestLogBean logInfo = new SapRequestLogBean();
//            logInfo.setMatnr(waitPakOut.getMatnr());
//            logInfo.setRequest("打印请求失败");
//            logInfo.setResponse("sendPrinCommand8---调用打印接口回报异常--"+waitPakOut.getMatnr() + "---");
//            logInfo.setCreate_time(new Date());
//            logInfo.setRemark(e.getMessage());
//            logInfo.setType(2);
//            sapRequestLogService.addSapLog(logInfo);
////            System.out.println(e.getMessage());
//        }
        return result;
    }
src/main/java/com/slcf/util/HttpHandler.java
New file
@@ -0,0 +1,213 @@
package com.slcf.util;
import okhttp3.*;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
 * Http协议客户端
 * @author luxiaotao
 * @date 2018-9-27
 */
public class HttpHandler {
    private static final Integer DEFAULT_TIMEOUT_SECONDS = 5;
    private static final MediaType MEDIA_TYPE = MediaType.parse("application/json;charset=utf-8");
    private String uri;
    private String path;
    private String json;
    private Map<String, Object> params;
    private Map<String, Object> headers;
    private boolean https;
    private Integer timeout;
    private TimeUnit timeUnit;
    public HttpHandler(Builder builder){
        this.uri = builder.uri;
        this.path = builder.path;
        this.json = builder.json;
        this.params = builder.params;
        this.headers = builder.headers;
        this.https = builder.https;
        this.timeout = builder.timeout;
        this.timeUnit = builder.timeUnit;
    }
    /**
     * GET请求执行
     * @return the HttpHandler response
     */
    public String doGet() throws IOException {
        String url = paramsToUrl(uri, path, params, https);
        Request.Builder headerBuilder = new Request.Builder();
        if (headers != null && headers.size()>0){
            for (Map.Entry<String, Object> entry : headers.entrySet()){
                headerBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
        Request request = headerBuilder.url(url).build();
        Response response = getClient(timeout, timeUnit).newCall(request).execute();
        return response.isSuccessful() ? response.body().string() : null;
    }
    /**
     * POST请求执行
     * @return the HttpHandler response
     */
    public String doPost() throws IOException {
        Request request;
        Request.Builder headerBuilder = new Request.Builder();
        if (headers != null && headers.size()>0){
            for (Map.Entry<String, Object> entry : headers.entrySet()){
                headerBuilder.addHeader(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
        if (json == null || "".equals(json)){
            FormBody.Builder builder = new FormBody.Builder();
            for (Map.Entry<String, Object> entry : params.entrySet()){
                builder.add(entry.getKey(), String.valueOf(entry.getValue()));
            }
            FormBody body = builder.build();
            request = headerBuilder
                    .url((https?"https://":"http://")+uri+path)
                    .post(body)
                    .build();
        } else {
            RequestBody body = RequestBody.create(MEDIA_TYPE, json);
            Request.Builder builder = headerBuilder.url((https?"https://":"http://")+uri+path);
            builder.header("Content-Type", "application/json;charset=UTF-8");
            request = builder.post(body).build();
        }
        Call call = getClient(timeout, timeUnit).newCall(request);
        Response response = call.execute();
        return response.body().string();
    }
    /**
     * get请求参数拼接方法
     * @return 请求行
     */
    private String paramsToUrl(String uri, String path, Map<String, Object> params, boolean isHttps) {
        StringBuilder res = new StringBuilder();
        res.append(isHttps ? "https://" : "http://");
        res.append(uri);
        if (path.length() > 0 && !(path.charAt(0) == '/')){
            res.append("/");
        }
        res.append(path);
        Optional.ofNullable(params).ifPresent(
                args -> {
                    res.append("?");
                    args.forEach((key, value) -> {
                        res.append(key);
                        res.append("=");
                        res.append(value);
                        res.append("&");
                    });
                }
        );
        String url = res.toString();
        if ("&".equals(url.substring(url.length()-1, url.length()))){
            url = url.substring(0, url.length()-1);
        }
        return url;
    }
    /**
     * 获取 okHttpClient
     * @return the HttpHandler instance
     */
    private OkHttpClient getClient(Integer timeout, TimeUnit timeUnit){
        return new OkHttpClient
                .Builder()
                .connectTimeout(timeout, timeUnit)
                .readTimeout(timeout, timeUnit)
                .build();
    }
    /**
     * Http协议报文建造者
     */
    public static class Builder {
        private String uri;
        private String path;
        private String json;
        private Map<String, Object> params;
        private Map<String, Object> headers;
        private boolean https;
        private Integer timeout;
        private TimeUnit timeUnit;
        {
            // 默认5s超时
            timeout = DEFAULT_TIMEOUT_SECONDS;
            timeUnit = TimeUnit.SECONDS;
            path = "";
        }
        /**
         * 建造器
         * @return the HttpHandler instance
         */
        public HttpHandler build(){
            if (null == this.uri || "".equals(this.uri)){
                throw new RuntimeException("uri is null");
            }
            if (this.uri.startsWith("http://")){
                this.uri = this.uri.substring(6,uri.length());
            } else if (this.uri.startsWith("https://")){
                this.uri = this.uri.substring(7,uri.length());
            }
            return new HttpHandler(this);
        }
        public Builder setUri(String uri) {
            this.uri = uri;
            return this;
        }
        public Builder setPath(String path) {
            if (!path.startsWith("/")){
                path = "/" + path;
            }
            this.path = path;
            return this;
        }
        public Builder setTimeout(Integer timeout, TimeUnit timeUnit) {
            this.timeout = timeout;
            this.timeUnit = timeUnit;
            return this;
        }
        public Builder setParams(Map<String, Object> params) {
            this.params = params;
            return this;
        }
        public Builder setHeaders(Map<String, Object> headers) {
            this.headers = headers;
            return this;
        }
        public Builder setHttps(boolean https) {
            this.https = https;
            return this;
        }
        public Builder setJson(String json) {
            this.json = json;
            return this;
        }
    }
}
src/main/resources/jdbc.properties
@@ -6,7 +6,7 @@
Local Env
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://127.0.0.1:1433;databaseName=klsasrs
jdbc.url=jdbc:sqlserver://172.20.177.11:1433;databaseName=klsasrs
jdbc.username=sa
jdbc.password=sa@123