Liferay7.1调用Axis2服务
1.配置axis1的依赖:在当前module工程的build.gradle文件添加 implementation 'axis:axis:1.4'
2.gradle刷新工程加载依赖配置
3.编写java代码:
此处我重写了serveResource方法,其他方法也可以
需要导入的包:圈出来的包注意不要导错了
@Override
public void serveResource(ResourceRequest Request,ResourceResponse Response) throws IOException, PortletException {
String PatientInfo = null;
String data = null;
//从session中获取患者ID
PortletSession session = Request.getPortletSession();
String []getInpatInfo = (String []) session.getAttribute("getInpatInfo", PortletSession.APPLICATION_SCOPE);
String patid = getInpatInfo[0];
//获取
try {
//axis2的WSDL地址
String endpoint ="http://192.168.10.183:8080/DHYXWebServiceCDR/services/CDRPortlet?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
//命名空间地址及接口方法名称
call.setOperationName(new QName("http://unifiedport.dhyx.com", "PortletUnifiedPortImpl"));
//设置字符集
call.setEncodingStyle("UTF-8");
//设置webservice方法名和入参
call.addParameter("methodName", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("parameters", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
//此处入参是一个String数组
String[] args = {patid, "999"};
//调用webservice服务得到返回的数据
PatientInfo = (String) call.invoke(new Object[] { "getPatientInfo", args});
System.out.println(PatientInfo);
//处理返回的数据
data = PatientInfo.substring(1,PatientInfo.length()-1);
System.out.println(PatientInfo.substring(1,PatientInfo.length()-1));
} catch (Exception e) {
System.err.println(e.toString());
}
Response.getWriter().write(data);
}