刘韬 6 年 前
コミット
7482198ea3
1 ファイル変更38 行追加75 行削除
  1. 38 75
      DataFusion/src/com/zskk/control/ViewController.java

+ 38 - 75
DataFusion/src/com/zskk/control/ViewController.java

@@ -1,13 +1,6 @@
 package com.zskk.control;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
 import java.security.KeyManagementException;
 import java.security.NoSuchAlgorithmException;
 import java.text.ParseException;
@@ -63,15 +56,10 @@ public class ViewController extends Controller {
 	/**
 	 * 在被连接数据库执行sql语句
 	 */
-	public void test2() {
-		try {
-			test();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			render(e.toString());
-			e.printStackTrace();
-			
-		}
+	public void test() {
+		Map<String, String> params = new HashMap<String, String>();
+		params.put("studyuid", "1.2.840.1424321.23532.201804071725566372");
+		doPost("http://10.84.138.254:8080/services/getReportByStudyuid?wsdl", params);
 	}
 	
 	public void executeSql2() {
@@ -156,66 +144,41 @@ public class ViewController extends Controller {
         return date;
 	}
 	
-	public void test() throws IOException {
-		//第一步:创建服务地址  
-        URL url = new URL("http://10.84.138.254:8080/services/getReportByStudyuid?wsdl");  
-        //第二步:打开一个通向服务地址的连接  
-        HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
-        //第三步:设置参数  
-        //3.1发送方式设置:POST必须大写  
-        connection.setRequestMethod("POST");  
-        //3.2设置数据格式:content-type  
-        connection.setRequestProperty("content-type", "text/xml;charset=utf-8");  
-        //3.3设置输入输出,因为默认新创建的connection没有读写权限,  
-        connection.setDoInput(true);  
-        connection.setDoOutput(true);  
-  
-        //第四步:组织SOAP数据,发送请求  
-        String soapXML = getXML("17321242779");  
-        OutputStream os = connection.getOutputStream();  
-        os.write(soapXML.getBytes());  
-        //第五步:接收服务端响应,打印  
-        int responseCode = connection.getResponseCode();  
-        render(String.valueOf(responseCode));
-
-        if(200 == responseCode){//表示服务端响应成功  
-            InputStream is = connection.getInputStream();  
-            InputStreamReader isr = new InputStreamReader(is);  
-            BufferedReader br = new BufferedReader(isr);  
-              
-            StringBuilder sb = new StringBuilder();  
-            String temp = null;  
-            while(null != (temp = br.readLine())){  
-                sb.append(temp);  
-            }  
-            
-            /**
-             * 打印结果
-             */
-            System.out.println(sb.toString());  
-            is.close();  
-            isr.close();  
-            br.close();  
-        }  
-        os.close();  
+	private String doPost(String url,Map<String, String> params){
+		StringBuilder apiLog 		= new StringBuilder();
+		apiLog.append(url).append("\t").append("params:").append(JSON.toJSONString(params));
+		CloseableHttpClient client 	= HttpClients.custom().setConnectionManager(POOL_CM).build();
+		String content              = null;
+		try{
+			HttpPost post = new HttpPost(url);
+			if (params != null){
+				List<NameValuePair> list = new ArrayList<NameValuePair>();
+				for(Map.Entry<String, String> entry: params.entrySet()){
+					list.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+				}
+				post.setEntity(new UrlEncodedFormEntity(list, "UTF-8"));
+			}
 		
-	}
-	
-public static String getXML(String phone){  
-    	
-    	String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"  
-    	        +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2003/XMLSchema-instance\" " 
-    			+"xmlns:web=\"http://WebXml.com.cn/\"  " 
-    	        +"xmlns:xsd=\"http://www.w3.org/2003/XMLSchema\" " 
-    			+"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"  
-    	            +"<request>"  
-    	              +"<studyuid>"    
-    	              +"0200355"
-    	              +"</studyuid>"  
-    	            +"</request>"  
-    	        +"</soap:Envelope>";  
-        return soapXML;  
-    } 
+		post.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+		CloseableHttpResponse response 	= null;
+		try{
+			response 		= client.execute(post);
+			int code 		= response.getStatusLine().getStatusCode();
+			if (code == 200){
+				content = IOUtils.toString(response.getEntity().getContent(), CAHR_CODE);
+			}else{
+				content = "{\"code\":" + code + "}";
+			}
+		}finally{
+			if (response != null){
+				response.close();
+			}
+		}
+	}catch(Exception e){
 
+	}
+		render("nmsl");
+		return content;
+	}
 	
 }