From d081bbed0647a8d5a717899f3771f6825bd1ebb2 Mon Sep 17 00:00:00 2001 From: 18516761980 <4761516tqsxp> Date: 星期一, 07 六月 2021 15:33:52 +0800 Subject: [PATCH] # --- src/main/java/com/slcf/filter/UpdateThread.java | 83 +++++++++++++++++++++++++++++++++-------- 1 files changed, 67 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/slcf/filter/UpdateThread.java b/src/main/java/com/slcf/filter/UpdateThread.java index de4481e..cd28c74 100644 --- a/src/main/java/com/slcf/filter/UpdateThread.java +++ b/src/main/java/com/slcf/filter/UpdateThread.java @@ -105,15 +105,21 @@ String encodedPassword; String token=""; String session_value=""; + + HttpURLConnection connection1 = null; try { encodedPassword = base.encode(input.getBytes("UTF-8")); URL url1 = new URL(httpUrl); - HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection(); + 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) { @@ -126,7 +132,12 @@ // Map<String, List<String>> map = connection1.getHeaderFields(); // token = map.get("x-csrf-token").toString(); } catch (Exception e1) { - e1.printStackTrace(); + logger.error("SAP ERROR-----璋冪敤涓婃灦瀹屾垚鎺ュ彛1锛実et璇锋眰鑾峰彇cookie澶辫触銆�" + e1.getMessage()); +// e1.printStackTrace(); + }finally { + if(connection1!=null){ + connection1.disconnect(); + } } try { @@ -150,16 +161,19 @@ 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); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + 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"); @@ -227,6 +241,10 @@ waitPakInService.upWaitPakIn(waitPakIn); logger.error("SAP Error sendPakInStatus--"+waitPakIn.getMatnr()+"---" + e.getMessage()); // System.out.println(e.getMessage()); + }finally { + if(connection!=null){ + connection.disconnect(); + } } }catch (Exception e) { waitPakIn.setIo_status("X"); @@ -265,12 +283,16 @@ String encodedPassword; String token=""; String session_value=""; + + HttpURLConnection connection1 = null; try { encodedPassword = base.encode(input.getBytes("UTF-8")); URL url1 = new URL(httpUrl); - HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection(); + 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"); @@ -283,10 +305,16 @@ 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) { - e1.printStackTrace(); + logger.error("璋冪敤涓嬫灦瀹屾垚鎺ュ彛锛実et璇锋眰鑾峰彇cookie澶辫触" + e1.getMessage()); +// e1.printStackTrace(); + }finally{ + if(connection1!=null){ + connection1.disconnect(); + } } try { @@ -325,15 +353,18 @@ 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); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + 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); @@ -401,6 +432,10 @@ waitPakOutService.upWaitPakOut(waitPakOut,0); logger.error("鍑哄簱閫氱煡妗e洖鎶ュ紓甯�--"+waitPakOut.getMatnr() + "---" + e.getMessage()); // System.out.println(e.getMessage()); + }finally{ + if(connection!=null){ + connection.disconnect(); + } } }catch (Exception e) { waitPakOut.setIo_status("X"); @@ -438,13 +473,17 @@ String encodedPassword; String token=""; String session_value=""; + + HttpURLConnection connection1 = null; try { -// logger.error("TQS-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); +// logger.error("sendPrinCommand-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); encodedPassword = base.encode(input.getBytes("UTF-8")); URL url1 = new URL(httpUrl); - HttpURLConnection connection1 = (HttpURLConnection) url1.openConnection(); + 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"); @@ -460,12 +499,16 @@ // Map<String, List<String>> map = connection1.getHeaderFields(); // token = map.get("x-csrf-token").toString(); } catch (Exception e1) { - logger.error("TQS1-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); + logger.error("sendPrinCommand1-----璋冪敤鎵撳嵃鎺ュ彛璇锋眰cookie澶辫触" + waitPakOut.getMaktx() + e1.getMessage()); e1.printStackTrace(); + }finally{ + if(connection1!=null){ + connection1.disconnect(); + } } try { - logger.error("TQS2-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); +// logger.error("sendPrinCommand2-----寮�濮嬭皟鐢ㄦ墦鍗版帴鍙�" + waitPakOut.getMaktx()); JSONObject jsObj = new JSONObject(); JSONArray arr = new JSONArray(); for(int i=0;i<1;i++) { @@ -493,15 +536,18 @@ 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); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + 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); @@ -518,7 +564,7 @@ OutputStream out = connection.getOutputStream(); out.write(buff); out.close(); - logger.error("TQS3-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); +// logger.error("sendPrinCommand3-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); //璇诲彇鍝嶅簲 BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream())); @@ -536,7 +582,7 @@ JSONObject jsonItem = JSONObject.fromObject(Item); String results = jsonItem.get("results").toString(); JSONArray array = JSONArray.fromObject(results); - logger.error("TQS4-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); + logger.error("sendPrinCommand4-----璋冪敤鎵撳嵃鎺ュ彛" + waitPakOut.getMaktx()); if(array.size()>0) { for(int i=0;i<array.size();i++){ JSONObject job = array.getJSONObject(i); @@ -552,11 +598,12 @@ waitPakOut.setAction(1); //妯″紡鍙樹负1鍗曠嫭纭 waitPakOut.setPrnstatus(2); //鎵撳嵃瀹屾垚 waitPakOutService.upWaitPakOut(waitPakOut,0); -// logger.error("璋冪敤鎵撳嵃鎺ュ彛鎴愬姛锛岃姹俲son鏁版嵁--" + jsObj.toString()); + logger.error("sendPrinCommand5---璋冪敤鎵撳嵃鎺ュ彛鎴愬姛锛岃姹俲son鏁版嵁--" + jsObj.toString()); }else if(zstatus.equals("e")) {//涓婃姤SAP澶辫触,鏇存柊io_status=X waitPakOut.setPrnstatus(3); //鎵撳嵃澶辫触 waitPakOut.setMemo(message); waitPakOutService.upWaitPakOut(waitPakOut,0); + logger.error("sendPrinCommand6---璋冪敤鎵撳嵃鎺ュ彛澶辫触锛岃姹俲son鏁版嵁--" + message); } } } @@ -565,14 +612,18 @@ waitPakOut.setPrnstatus(3); //鎵撳嵃澶辫触 waitPakOut.setMemo(e.getMessage()); waitPakOutService.upWaitPakOut(waitPakOut,0); - logger.error("璋冪敤鎵撳嵃鎺ュ彛鍥炴姤寮傚父--"+waitPakOut.getMatnr() + "---" + e.getMessage()); + logger.error("sendPrinCommand7---璋冪敤鎵撳嵃鎺ュ彛鍥炴姤寮傚父--"+waitPakOut.getMatnr() + "---" + e.getMessage()); // 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("璋冪敤鎵撳嵃鎺ュ彛鍥炴姤寮傚父--"+waitPakOut.getMatnr() + "---" + e.getMessage()); + logger.error("sendPrinCommand8---璋冪敤鎵撳嵃鎺ュ彛鍥炴姤寮傚父--"+waitPakOut.getMatnr() + "---" + e.getMessage()); // System.out.println(e.getMessage()); } return result; -- Gitblit v1.9.1