package cn.org.bjca.treport.ws.demo;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import cn.org.bjca.treport.ws.demo.element.DeleteReport;
import cn.org.bjca.treport.ws.demo.element.DeleteReportResponse;
import cn.org.bjca.treport.ws.demo.element.DownloadReport;
import cn.org.bjca.treport.ws.demo.element.DownloadReportResponse;
import cn.org.bjca.treport.ws.demo.element.QueryReport;
import cn.org.bjca.treport.ws.demo.element.QueryReportResponse;
import cn.org.bjca.treport.ws.demo.element.ReportWSReqMessage;
import cn.org.bjca.treport.ws.demo.element.ReportWSRespMessage;
import cn.org.bjca.treport.ws.demo.element.UploadReport;
import cn.org.bjca.treport.ws.demo.element.UploadReportResponse;
/***************************************************************************
* <pre>可信报告单 ws客户端测试</pre>
***************************************************************************/
public class TrustReportWSClientTest {
//命名空间
public static final String targetNamespace = "urn:edms:names:jaxws:ws";
//服务名
public static final String serverName = "DocumentLifeCycleProviderService";
//端口名
public static final String portName = "DocumentLifeCycleProviderPort";
//服务地址
public static final String endpointAddress = "http://127.0.0.1:82/tdms/DocumentLifeCycleProviderService?wsdl";
//webservice 服务
private static Service service;
//webservice 端口
private static QName portQName;
/**
* <p>初始化webservice连接信息</p>
* @Description:
*/
@Before
public void init() {
try {
URL wsdlURL = new URL(endpointAddress);
QName serviceQName = new QName(targetNamespace, serverName);
service = Service.create(wsdlURL, serviceQName);
portQName = new QName(targetNamespace, portName);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
@Test
public void testUploadReportFile() throws JAXBException, IOException{
// jaxb 绑定请求GenDocument 响应GenDocumentResponse
JAXBContext ctxt = JAXBContext.newInstance(UploadReport.class, UploadReportResponse.class);
// 创建与生成的 JAXB 对象一起使用的 Dispatch 实例
Dispatch<Object> dispatchJAXB = service.createDispatch(portQName, ctxt, Service.Mode.PAYLOAD);
String reportNum = "200000004";
String reportTitle = "报告单2018061300004";
String patientName = "王五一";
String visitNum = "2018061300005";
String documentRuleNum = "7F3AC46883BDA2F0";
byte[] reportBty = FileUtils.readFileToByteArray(new File("C:/Users/rocky/Desktop/1.pdf"));
ReportWSReqMessage reqMessage = new ReportWSReqMessage();
reqMessage.setReportNum(reportNum);
reqMessage.setReportTitle(reportTitle);
reqMessage.setPatientName(patientName);
reqMessage.setVisitNum(visitNum);
reqMessage.setDocumentRuleNum(documentRuleNum);
reqMessage.setReportFileBty(reportBty);
UploadReport upload = new UploadReport();
upload.setReportReqMessage(reqMessage);
UploadReportResponse response = (UploadReportResponse) dispatchJAXB.invoke(upload);
ReportWSRespMessage respMsg = response.get_return();
System.out.println("************状态码: " + respMsg.getStatusCode());
}
@Test
public void testQueryReport() throws JAXBException, IOException{
// jaxb 绑定请求GenDocument 响应GenDocumentResponse
JAXBContext ctxt = JAXBContext.newInstance(QueryReport.class, QueryReportResponse.class);
// 创建与生成的 JAXB 对象一起使用的 Dispatch 实例
Dispatch<Object> dispatchJAXB = service.createDispatch(portQName, ctxt, Service.Mode.PAYLOAD);
String visitNum = "2018061300005";
ReportWSReqMessage reqMessage = new ReportWSReqMessage();
reqMessage.setVisitNum(visitNum);
reqMessage.setClientType("1");
// reqMessage.setStartTime("20180612");
// reqMessage.setEndTime("20180614");
QueryReport query = new QueryReport();
query.setReportReqMessage(reqMessage);
QueryReportResponse response = (QueryReportResponse) dispatchJAXB.invoke(query);
ReportWSRespMessage respMsg = response.get_return();
System.out.println("************状态码: " + respMsg.getStatusCode());
System.out.println("************报告单信息: " + respMsg.getReportInfos());
}
@Test
public void testDownloadReport() throws JAXBException, IOException{
// jaxb 绑定请求GenDocument 响应GenDocumentResponse
JAXBContext ctxt = JAXBContext.newInstance(DownloadReport.class, DownloadReportResponse.class);
// 创建与生成的 JAXB 对象一起使用的 Dispatch 实例
Dispatch<Object> dispatchJAXB = service.createDispatch(portQName, ctxt, Service.Mode.PAYLOAD);
ReportWSReqMessage reqMessage = new ReportWSReqMessage();
String reportNum = "200000004";
reqMessage.setReportNum(reportNum);
reqMessage.setClientType("1");
DownloadReport download = new DownloadReport();
download.setReportReqMessage(reqMessage);
DownloadReportResponse response = (DownloadReportResponse) dispatchJAXB.invoke(download);
ReportWSRespMessage respMsg = response.get_return();
System.out.println(respMsg.getStatusCode());
System.out.println(respMsg.getReportFileBty());
}
@Test
public void testUndoReport() throws JAXBException, IOException{
// jaxb 绑定请求GenDocument 响应GenDocumentResponse
JAXBContext ctxt = JAXBContext.newInstance(DeleteReport.class, DeleteReportResponse.class);
// 创建与生成的 JAXB 对象一起使用的 Dispatch 实例
Dispatch<Object> dispatchJAXB = service.createDispatch(portQName, ctxt, Service.Mode.PAYLOAD);
ReportWSReqMessage reqMessage = new ReportWSReqMessage();
String reportNum = "200000003";
reqMessage.setReportNum(reportNum);
DeleteReport del = new DeleteReport();
del.setReportReqMessage(reqMessage);
DeleteReportResponse response = (DeleteReportResponse) dispatchJAXB.invoke(del);
ReportWSRespMessage respMsg = response.get_return();
System.out.println(respMsg.getStatusCode());
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>撤销请求</pre>
***************************************************************************/
@XmlRootElement(name = "undoReport", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "undoReport", namespace = "urn:edms:names:jaxws:ws", propOrder = {
"reportReqMessage"
})
public class DeleteReport {
@XmlElement(name = "reportReqMessage", namespace = "")
private ReportWSReqMessage reportReqMessage;
public ReportWSReqMessage getReportReqMessage() {
return reportReqMessage;
}
public void setReportReqMessage(ReportWSReqMessage reportReqMessage) {
this.reportReqMessage = reportReqMessage;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>撤销响应</pre>
***************************************************************************/
@XmlRootElement(name = "undoReportResponse", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "undoReportResponse", namespace = "urn:edms:names:jaxws:ws")
public class DeleteReportResponse {
@XmlElement(name = "return", namespace = "")
private ReportWSRespMessage _return;
public ReportWSRespMessage get_return() {
return _return;
}
public void set_return(ReportWSRespMessage _return) {
this._return = _return;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>下载请求</pre>
***************************************************************************/
@XmlRootElement(name = "downloadReport", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "downloadReport", namespace = "urn:edms:names:jaxws:ws", propOrder = {
"reportReqMessage"
})
public class DownloadReport {
@XmlElement(name = "reportReqMessage", namespace = "")
private ReportWSReqMessage reportReqMessage;
public ReportWSReqMessage getReportReqMessage() {
return reportReqMessage;
}
public void setReportReqMessage(ReportWSReqMessage reportReqMessage) {
this.reportReqMessage = reportReqMessage;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>下载响应</pre>
***************************************************************************/
@XmlRootElement(name = "downloadReportResponse", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "downloadReportResponse", namespace = "urn:edms:names:jaxws:ws")
public class DownloadReportResponse {
@XmlElement(name = "return", namespace = "")
private ReportWSRespMessage _return;
public ReportWSRespMessage get_return() {
return _return;
}
public void set_return(ReportWSRespMessage _return) {
this._return = _return;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>查询报告单</pre>
***************************************************************************/
@XmlRootElement(name = "queryReport", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "queryReport", namespace = "urn:edms:names:jaxws:ws", propOrder = {
"reportReqMessage"
})
public class QueryReport {
@XmlElement(name = "reportReqMessage", namespace = "")
private ReportWSReqMessage reportReqMessage;
public ReportWSReqMessage getReportReqMessage() {
return reportReqMessage;
}
public void setReportReqMessage(ReportWSReqMessage reportReqMessage) {
this.reportReqMessage = reportReqMessage;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>查询响应</pre>
***************************************************************************/
@XmlRootElement(name = "queryReportResponse", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "queryReportResponse", namespace = "urn:edms:names:jaxws:ws")
public class QueryReportResponse {
@XmlElement(name = "return", namespace = "")
private ReportWSRespMessage _return;
public ReportWSRespMessage get_return() {
return _return;
}
public void set_return(ReportWSRespMessage _return) {
this._return = _return;
}
}
package cn.org.bjca.treport.ws.demo.element;
import java.io.Serializable;
/***************************************************************************
* <pre>请求信息</pre>
***************************************************************************/
public class ReportWSReqMessage implements Serializable {
private static final long serialVersionUID = -4791087393335555937L;
private String reportNum;
private String reportTitle;
private String visitNum;
private String patientName;
private String clientType;
private String startTime;
private String endTime;
private String documentRuleNum;
private byte[] reportFileBty;
private String barcodeContent;
public String getReportNum() {
return reportNum;
}
public void setReportNum(String reportNum) {
this.reportNum = reportNum;
}
public String getReportTitle() {
return reportTitle;
}
public void setReportTitle(String reportTitle) {
this.reportTitle = reportTitle;
}
public String getVisitNum() {
return visitNum;
}
public void setVisitNum(String visitNum) {
this.visitNum = visitNum;
}
public String getPatientName() {
return patientName;
}
public void setPatientName(String patientName) {
this.patientName = patientName;
}
public String getClientType() {
return clientType;
}
public void setClientType(String clientType) {
this.clientType = clientType;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public String getDocumentRuleNum() {
return documentRuleNum;
}
public void setDocumentRuleNum(String documentRuleNum) {
this.documentRuleNum = documentRuleNum;
}
public byte[] getReportFileBty() {
return reportFileBty;
}
public void setReportFileBty(byte[] reportFileBty) {
this.reportFileBty = reportFileBty;
}
public String getBarcodeContent() {
return barcodeContent;
}
public void setBarcodeContent(String barcodeContent) {
this.barcodeContent = barcodeContent;
}
}
package cn.org.bjca.treport.ws.demo.element;
import java.io.Serializable;
/***************************************************************************
* <pre>响应信息</pre>
***************************************************************************/
public class ReportWSRespMessage implements Serializable {
private static final long serialVersionUID = 2737051535444407591L;
private String statusCode;
private String reportInfos;
private byte[] reportFileBty;
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public String getReportInfos() {
return reportInfos;
}
public void setReportInfos(String reportInfos) {
this.reportInfos = reportInfos;
}
public byte[] getReportFileBty() {
return reportFileBty;
}
public void setReportFileBty(byte[] reportFileBty) {
this.reportFileBty = reportFileBty;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>上传报告单请求</pre>
***************************************************************************/
@XmlRootElement(name = "uploadReport", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "uploadReport", namespace = "urn:edms:names:jaxws:ws", propOrder = {
"reportReqMessage"
})
public class UploadReport {
@XmlElement(name = "reportReqMessage", namespace = "")
private ReportWSReqMessage reportReqMessage;
public ReportWSReqMessage getReportReqMessage() {
return reportReqMessage;
}
public void setReportReqMessage(ReportWSReqMessage reportReqMessage) {
this.reportReqMessage = reportReqMessage;
}
}
package cn.org.bjca.treport.ws.demo.element;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
/***************************************************************************
* <pre>上传报告单响应</pre>
***************************************************************************/
@XmlRootElement(name = "uploadReportResponse", namespace = "urn:edms:names:jaxws:ws")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "uploadReportResponse", namespace = "urn:edms:names:jaxws:ws")
public class UploadReportResponse {
@XmlElement(name = "return", namespace = "")
private ReportWSRespMessage _return;
public ReportWSRespMessage get_return() {
return _return;
}
public void set_return(ReportWSRespMessage _return) {
this._return = _return;
}
}