|
@@ -7,8 +7,7 @@ import java.io.OutputStreamWriter;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLConnection;
|
|
|
-import java.security.KeyManagementException;
|
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
+
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
@@ -65,9 +64,9 @@ public class ViewController extends Controller {
|
|
|
public void test() {
|
|
|
// Map<String, String> params = new HashMap<String, String>();
|
|
|
// params.put("studyuid", "1.2.840.1424321.23532.201804071725566372");
|
|
|
-// String cotentString = doPost("http://10.84.138.254:8080/rest/getReportByStudyuid", params);
|
|
|
-// renderText(cotentString);
|
|
|
- testPost("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
|
+ String cotentString = creatPostAndTransData("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
|
+ renderText(cotentString);
|
|
|
+// testPost("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
|
}
|
|
|
|
|
|
public void executeSql2() {
|
|
@@ -188,35 +187,54 @@ public class ViewController extends Controller {
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
- void testPost(String urlStr) {
|
|
|
- try {
|
|
|
- URL url = new URL(urlStr);
|
|
|
- URLConnection con = url.openConnection();
|
|
|
- con.setDoOutput(true);
|
|
|
- con.setRequestProperty("Pragma:", "no-cache");
|
|
|
- con.setRequestProperty("Cache-Control", "no-cache");
|
|
|
- con.setRequestProperty("Content-Type", "text/xml");
|
|
|
-
|
|
|
- OutputStreamWriter out = new OutputStreamWriter(con
|
|
|
- .getOutputStream());
|
|
|
- String xmlInfo = getXmlInfo();
|
|
|
- System.out.println("urlStr=" + urlStr);
|
|
|
- System.out.println("xmlInfo=" + xmlInfo);
|
|
|
- out.write(new String(xmlInfo.getBytes("ISO-8859-1")));
|
|
|
- out.flush();
|
|
|
- out.close();
|
|
|
- BufferedReader br = new BufferedReader(new InputStreamReader(con
|
|
|
- .getInputStream()));
|
|
|
- String line = "";
|
|
|
- for (line = br.readLine(); line != null; line = br.readLine()) {
|
|
|
- System.out.println(line);
|
|
|
- }
|
|
|
- } catch (MalformedURLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
+ public String creatPostAndTransData(String urlString) {
|
|
|
+ String urlStr = "";
|
|
|
+ String line = "";
|
|
|
+ StringBuffer resultSting = new StringBuffer();
|
|
|
+ try {
|
|
|
+ //urlStr,写在了配置文件中,直接进行获取
|
|
|
+ urlStr = urlString;
|
|
|
+ //声明URL
|
|
|
+ URL url = new URL(urlStr);
|
|
|
+ //1.创建链接
|
|
|
+ URLConnection con = url.openConnection();
|
|
|
+ //2.封装报文传输进行传输
|
|
|
+ //调用getXmlInfo(Map<String, Object> dataMap)进行报文的封装
|
|
|
+ String xmlInfo = getXmlInfo();
|
|
|
+ byte[] xmlData = xmlInfo.getBytes();
|
|
|
+ con.setDoOutput(true);
|
|
|
+ con.setDoInput(true);
|
|
|
+ con.setUseCaches(false);
|
|
|
+ con.setRequestProperty("Pragma:", "no-cache");
|
|
|
+ con.setRequestProperty("Cache-Control", "no-cache");
|
|
|
+ con.setRequestProperty("Content-Type", "text/xml");
|
|
|
+ con.setRequestProperty("Content-length",String.valueOf(xmlData.length));
|
|
|
+ OutputStreamWriter out = new OutputStreamWriter(
|
|
|
+ con.getOutputStream());
|
|
|
+ System.out.println(">>>>>>>>>>接口地址为urlStr=" + urlStr);
|
|
|
+ System.out.println(">>>>>>>>>>传入的报文xmlInfo=" + xmlInfo);
|
|
|
+ out.write(new String(xmlInfo.getBytes("UTF-8")));
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ //3.获取返回报文
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
|
+ con.getInputStream()));
|
|
|
+ //对返回值报文进行打印
|
|
|
+ for (line = br.readLine(); line != null; line = br.readLine()) {
|
|
|
+ //对返回的报文进行结果判断<RspCode>0000</RspCode>
|
|
|
+ System.out.println(">>>>>>>>>>>>>>>>>>>返回的结果报文内容为:---------"+line);
|
|
|
+ //对返回的报文进行拼接,然后返回给业务层,在业务层进行判断
|
|
|
+ resultSting.append(line);
|
|
|
+ }
|
|
|
+ return resultSting.toString();
|
|
|
+ } catch (MalformedURLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return resultSting.toString();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private String getXmlInfo() {
|
|
|
StringBuilder sb = new StringBuilder();
|