国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

使用java發送Infor XA ERP SystemLink請求

2024-06-28 16:03:52
字體:
來源:轉載
供稿:網友

      Infor XA ERP二次開發,目前最好的最方便的交互就是通過發送SystemLink請求

      這里記錄個人在實際工作中java編寫的發送SystemLink請求工具

package cn.markwins.yinfor.utils.net;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import java.net.URLDecoder;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Set;import org.apache.log4j.Logger;import org.apache.http.HttpEntity;import org.apache.http.HttPResponse;import org.apache.http.NameValuePair;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.BufferedHttpEntity;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClientBuilder;import org.apache.http.message.BasicNameValuePair;import cn.markwins.yinfor.global.GlobalParameters;import cn.markwins.yinfor.utils.common.StringTools;/** * @Description Http網絡請求工具欄 * @author 李yi輝 * @date 2016年3月23日 */public class HttpTools {	private static final String encodingUTF8 ="UTF-8"; 	private static final Logger logger = Logger.getLogger(HttpTools.class);		/**	 * @Description 發送Http請求	 * @param url 請求地址	 * @param xml xml請求內容	 * @return String 請求后的響應消息	 */	public static Map<Boolean,String> postXMLRequest(String url, String xml){		if(StringTools.isNullOrWhiteSpace(xml) || StringTools.isNullOrWhiteSpace(xml)){			return null;		}		HttpURLConnection httpConn = null;		OutputStream os = null;		InputStream is = null;		StringBuffer responseBuffer = null;		Boolean postStatus = false;		String postMsg = ":發送SystemLink請求失敗";		try {			//1、得到http連接			httpConn = (HttpURLConnection) new URL(url).openConnection();						//2、設置http請求參數			httpConn.setRequestMethod("POST");	        httpConn.setDoInput(true);	        httpConn.setDoOutput(true);	        httpConn.setUseCaches(false);	        httpConn.setConnectTimeout(50000);	        httpConn.setReadTimeout(50000);	        httpConn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");	        	        //3、通過http連接服務器	        httpConn.connect();	        	        //4、向服務器發送xml數據	        os = httpConn.getOutputStream();	        os.write(xml.getBytes());	        os.flush();	        	        //5、得到http請求后,服務器返回的響應	        int responseCode = httpConn.getResponseCode();	        switch (responseCode) {			case 200:				is = httpConn.getInputStream();	        	int length = 0;	            byte[] buffer = new byte[1024];	            responseBuffer = new StringBuffer();	            while((length=is.read(buffer)) != -1){	            	responseBuffer.append(new String(buffer,0,length,GlobalParameters.ENCODING));	            }	            if(responseBuffer.length() > 10){	            	postStatus = true;	            	postMsg = URLDecoder.decode(responseBuffer.toString().trim(), "UTF-8");	            		            }else{	            	postMsg = "200:" + responseBuffer.toString();	            }				break;			case 400:				postMsg = "400:錯誤請求";				break;			case 404:				postMsg = "404:未找到";				break;			case 408:				postMsg = "408:請求超時";				break;			case 500:				postMsg = "500:SystemLink XA服務器錯誤";				break;			default:				postMsg = responseCode + postMsg;				break;			}	        	        //6、返回響應消息			Map<Boolean, String> resultMap = new HashMap<Boolean, String>();			resultMap.put(postStatus, postMsg);			return resultMap;		} catch (Exception e) {			logger.error("發送Http請求失敗", e);		} finally {			try {				if(is != null){					is.close();					is = null;				}				if(os != null){					os.close();					os = null;				}				if(httpConn != null){					httpConn.disconnect();					httpConn = null;				}			} catch (IOException e) {				logger.error("關閉Http請求連接資源失敗", e);			}		}				return null;	}}

我們將SystemLink請求的響應結果放在了一個map里面,通過map的key值ture/false就可以知道請求是否發送成功,

如果成功了,就可以解析出SystemLink的響應報文,我們在下一篇里面介紹如何解析SystemLink的報文信息。

http://blog.csdn.net/yihuiworld


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 茌平县| 临海市| 青铜峡市| 于都县| 盘锦市| 佛冈县| 虞城县| 贵港市| 抚宁县| 池州市| 大悟县| 醴陵市| 额尔古纳市| 永平县| 三亚市| 蒙阴县| 东丰县| 肇州县| 依安县| 特克斯县| 清苑县| 葫芦岛市| 屯昌县| 阜新市| 黄山市| 鄱阳县| 达州市| 定边县| 永靖县| 富川| 三亚市| 会东县| 错那县| 武胜县| 湖州市| 渭南市| 二连浩特市| 武山县| 页游| 东平县| 河源市|