| 
					
				 | 
			
			
				@ -1,6 +1,7 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.wlyy.util; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.ibm.mq.MQQueueManager; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.models.auth.In; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import net.sf.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import net.sf.json.xml.XMLSerializer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -110,6 +111,49 @@ public class MqSdkUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 返回的响应数据中会包含此次请求的返回数据量和当前消息在返回消息中的顺序编号,进行判断是否还要继续获取 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 请求值为前端拼接的xml字符串 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param reqMsg 请求的数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param xmlNodeName 获取请求节点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static String putReqAndGetRespByQueryStr(String reqMsg,String xmlNodeName) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        QueueTools queueTools = new QueueTools(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 队列管理器实例 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MQQueueManager queueManager = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 消息Id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String msgId = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 响应数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String respMsg = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 连接MQ,获取队列管理器实例,该实例如果不调用方法进行断开操作可长期保持连接。连接函数会自动读取配置文件标签名为“QMGR.SXX”下的配置信息进行连接。, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            queueManager = queueTools.connect(gateKeeper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 发送请求消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            msgId = queueTools.putMsg(queueManager, xmlNodeName, reqMsg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 获取响应消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            respMsg = queueTools.getMsgById(queueManager, xmlNodeName, msgId, 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return respMsg; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (MQException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 2033表示队列中没有消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (e.reasonCode == 2033) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (IOException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } finally { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //断开MQ连接 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null != queueManager) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    queueManager.disconnect(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } catch (MQException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //=======================================================封装xml============================================================================================= 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -196,18 +240,26 @@ public class MqSdkUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static String xml2jsonArrayRootRow(String xmlString) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        XMLSerializer xmlSerializer = new XMLSerializer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSON json = xmlSerializer.read(xmlString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Object jsonObject = ((net.sf.json.JSONObject) json).get("MsgInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (null != jsonObject) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONObject jsonObject1 = (net.sf.json.JSONObject) jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取到数组中的CDATA进行再解析 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONArray jsonArray = (net.sf.json.JSONArray) jsonObject1.get("Msg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONArray jsonArray1 = new net.sf.json.JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Object object : jsonArray) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSON jsonsub = xmlSerializer.read(object.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                jsonArray1.add(jsonsub); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Object retInfo=  ((JSONObject) json).get("RetInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Object retCode= ((JSONObject) retInfo).get("RetCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(retCode.equals("1")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Object jsonObject = ((net.sf.json.JSONObject) json).get("MsgInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null != jsonObject) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                net.sf.json.JSONObject jsonObject1 = (net.sf.json.JSONObject) jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //获取到数组中的CDATA进行再解析 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                net.sf.json.JSONArray jsonArray = (net.sf.json.JSONArray) jsonObject1.get("Msg"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                net.sf.json.JSONArray jsonArray1 = new net.sf.json.JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (Object object : jsonArray) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSON jsonsub = xmlSerializer.read(object.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonArray1.add(jsonsub); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //重新封装到json中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ((net.sf.json.JSONObject) json).element("MsgInfo", jsonArray1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if(retCode.equals("0")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //重新封装到json中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ((net.sf.json.JSONObject) json).element("MsgInfo", jsonArray1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ((net.sf.json.JSONObject) json).element("MsgInfo",   ((JSONObject) retInfo).get("RetCon")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return getMsgInfo(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -240,12 +292,14 @@ public class MqSdkUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static String getMsgInfo(JSON json)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObjectBak=new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Object jsonObject= (( net.sf.json.JSONObject) json).get("RetInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(null!=jsonObject){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONObject  jsonObject1=( net.sf.json.JSONObject)jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(null!=jsonObject1.get("RetCode")&&"1".equals(jsonObject1.get("RetCode").toString())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return (( net.sf.json.JSONObject) json).get("MsgInfo").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(null!=jsonObject) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONObject jsonObject1 = (net.sf.json.JSONObject) jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            jsonObjectBak.element("code", jsonObject1.get("RetCode").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            jsonObjectBak.element("MsgInfo", ((net.sf.json.JSONObject) json).get("MsgInfo").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return jsonObjectBak.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 |