|
@@ -1,6 +1,13 @@
|
|
|
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;
|
|
@@ -56,10 +63,13 @@ public class ViewController extends Controller {
|
|
|
/**
|
|
|
* 在被连接数据库执行sql语句
|
|
|
*/
|
|
|
- public void test() {
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("studyuid", "0200355");
|
|
|
- doPost("http://10.84.138.254:8080/services/getReportByStudyuid?wsdl", params);
|
|
|
+ public void test2() {
|
|
|
+ try {
|
|
|
+ test();
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void executeSql2() {
|
|
@@ -144,41 +154,65 @@ public class ViewController extends Controller {
|
|
|
return date;
|
|
|
}
|
|
|
|
|
|
- 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 void test() throws IOException {
|
|
|
+ //第一步:创建服务地址
|
|
|
+ URL url = new URL("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?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();
|
|
|
+ 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());
|
|
|
+ render(sb.toString());
|
|
|
+ is.close();
|
|
|
+ isr.close();
|
|
|
+ br.close();
|
|
|
+ }
|
|
|
+ os.close();
|
|
|
|
|
|
- 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;
|
|
|
}
|
|
|
|
|
|
+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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|