|  |  | 
 |  |  |         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) | 
 |  |  |             { | 
 |  |  | 
 |  |  | //            Map<String, List<String>> map = connection1.getHeaderFields(); | 
 |  |  | //            token = map.get("x-csrf-token").toString(); | 
 |  |  |         } catch (Exception e1) { | 
 |  |  |             e1.printStackTrace(); | 
 |  |  |             logger.error("SAP ERROR-----调用上架完成接口1,get请求获取cookie失败。" + e1.getMessage()); | 
 |  |  | //            e1.printStackTrace(); | 
 |  |  |         }finally { | 
 |  |  |             if(connection1!=null){ | 
 |  |  |                 connection1.disconnect(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |          | 
 |  |  |         try { | 
 |  |  | 
 |  |  |             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"); | 
 |  |  | 
 |  |  |                 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"); | 
 |  |  | 
 |  |  |         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[] 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("调用下架完成接口,get请求获取cookie失败" + e1.getMessage()); | 
 |  |  | //            e1.printStackTrace(); | 
 |  |  |         }finally{ | 
 |  |  |             if(connection1!=null){ | 
 |  |  |                 connection1.disconnect(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |          | 
 |  |  |         try { | 
 |  |  | 
 |  |  |             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); | 
 |  |  | 
 |  |  |                 waitPakOutService.upWaitPakOut(waitPakOut,0); | 
 |  |  |                 logger.error("出库通知档回报异常--"+waitPakOut.getMatnr() + "---" + e.getMessage()); | 
 |  |  | //                System.out.println(e.getMessage()); | 
 |  |  |             }finally{ | 
 |  |  |                 if(connection!=null){ | 
 |  |  |                     connection.disconnect(); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }catch (Exception e) { | 
 |  |  |             waitPakOut.setIo_status("X"); | 
 |  |  | 
 |  |  |         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"); | 
 |  |  | 
 |  |  | //            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++) { | 
 |  |  | 
 |  |  |             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); | 
 |  |  | 
 |  |  |                 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())); | 
 |  |  | 
 |  |  |                 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); | 
 |  |  | 
 |  |  |                             waitPakOut.setAction(1);     //模式变为1单独确认 | 
 |  |  |                             waitPakOut.setPrnstatus(2);  //打印完成 | 
 |  |  |                             waitPakOutService.upWaitPakOut(waitPakOut,0); | 
 |  |  | //                            logger.error("调用打印接口成功,请求json数据--" + jsObj.toString()); | 
 |  |  |                             logger.error("sendPrinCommand5---调用打印接口成功,请求json数据--" + jsObj.toString()); | 
 |  |  |                         }else if(zstatus.equals("e")) {//上报SAP失败,更新io_status=X | 
 |  |  |                             waitPakOut.setPrnstatus(3);     //打印失败 | 
 |  |  |                             waitPakOut.setMemo(message); | 
 |  |  |                             waitPakOutService.upWaitPakOut(waitPakOut,0); | 
 |  |  |                             logger.error("sendPrinCommand6---调用打印接口失败,请求json数据--" + message); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } | 
 |  |  | 
 |  |  |                 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; |