|
@@ -31,6 +31,7 @@ import org.apache.http.message.BasicNameValuePair;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.jfinal.core.Controller;
|
|
import com.jfinal.core.Controller;
|
|
|
|
+import com.jfinal.kit.HttpKit;
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
import com.zskk.model.Doctors;
|
|
import com.zskk.model.Doctors;
|
|
@@ -64,8 +65,14 @@ public class ViewController extends Controller {
|
|
public void test() {
|
|
public void test() {
|
|
// Map<String, String> params = new HashMap<String, String>();
|
|
// Map<String, String> params = new HashMap<String, String>();
|
|
// params.put("studyuid", "1.2.840.1424321.23532.201804071725566372");
|
|
// params.put("studyuid", "1.2.840.1424321.23532.201804071725566372");
|
|
- String cotentString = creatPostAndTransData("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
|
|
- renderText(cotentString);
|
|
|
|
|
|
+ try {
|
|
|
|
+ String cotentString = creatPostAndTransData("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
|
|
+ renderText(cotentString);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // TODO: handle exception
|
|
|
|
+ this.renderText(e.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
// testPost("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
// testPost("http://10.84.138.254:8080/rest/getReportByStudyuid");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -188,53 +195,10 @@ public class ViewController extends Controller {
|
|
}
|
|
}
|
|
|
|
|
|
public String creatPostAndTransData(String urlString) {
|
|
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();
|
|
|
|
- renderText(e.toString());
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- renderText(e.toString());
|
|
|
|
- }
|
|
|
|
- return resultSting.toString();
|
|
|
|
|
|
+ Map headerString = new HashMap();
|
|
|
|
+ headerString.put("Content-Type","text/xml");
|
|
|
|
+ String respoString = HttpKit.post(urlString, getXmlInfo(), headerString);
|
|
|
|
+ return respoString;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|