NutzCN Logo
问答 webservice rpc方式调用cxf服务端,入参就是一个xmlParam字符串,可是调用之后,服务端那边还是接收参数为null?求救中
发布于 2558天前 作者 qq_6427b776 3727 次浏览 复制 上一个帖子 下一个帖子
标签:

public class WsClient {

public static void testRPCClient() {
    try {
       // axis2 服务端
       String url = "http://localhost:8080/sa/services/updateAlertStatus?wsdl";

       // 使用RPC方式调用WebService
       RPCServiceClient serviceClient = new RPCServiceClient();
       // 指定调用WebService的URL
       EndpointReference targetEPR = new EndpointReference(url);
       Options options = serviceClient.getOptions();
       // 确定目标服务地址
       options.setTo(targetEPR);
       // 确定调用方法
       options.setAction("urn:updateStatus");

       /**
        * 指定要调用的getPrice方法及WSDL文件的命名空间 如果 webservice 服务端由axis2编写 命名空间
        * 不一致导致的问题 org.apache.axis2.AxisFault: java.lang.RuntimeException:
        * Unexpected subelement arg0
        */
       QName qname = new QName("http://www.w3.org/2001/XMLSchema", "updateStatus");
       // 指定getPrice方法的参数值
       String xmlParam = "<?xml version=\"1.0\" ?><alertCode>148368863803747</alertCode><alertType>1</alertType>";
       Object[] parameters = new Object[] { xmlParam.toString() };

       // 指定getPrice方法返回值的数据类型的Class对象
       // Class[] returnTypes = new Class[] { String.class };
       // 调用方法一 传递参数,调用服务,获取服务返回结果集
       OMElement element = serviceClient.invokeBlocking(qname, parameters);
       // 值得注意的是,返回结果就是一段由OMElement对象封装的xml字符串。
       // 我们可以对之灵活应用,下面我取第一个元素值,并打印之。因为调用的方法返回一个结果
       String result = element.getFirstElement().getText();
       System.out.println(result);
       // 调用方法二 getPrice方法并输出该方法的返回值
       /*
        * Object[] response = serviceClient.invokeBlocking(qname,
        * parameters, returnTypes); // String r = (String) response[0];
        * WsUpdateAlertRes r = (WsUpdateAlertRes) response[0];
        * System.out.println(r);
        */

    } catch (AxisFault e) {
       e.printStackTrace();
    }
}

public static void main(String[] args) {
    WsClient.testRPCClient();
}

}

3 回复

updateAlertStatus的定义是怎样的?

public WsUpdateAlertRes updateStatus(String xmlParam) {
WsUpdateAlertRes reqBean = new WsUpdateAlertRes();
Document doc = UpdateAlertStatusService.parseXML(xmlParam);
Element rootElement = doc.getRootElement();
String alertCode = rootElement.getAttributeValue("alertCode");
String alertType = rootElement.getAttributeValue("alertType");
Long alertCodeL = Long.parseLong(alertCode);
int alertTypeI = Integer.parseInt(alertType);
// 1--校验入参
if (!validateParam(alertCodeL, alertTypeI)) {
reqBean.setMsg("调用服务接口入参参数不合规");
reqBean.setMsgCode(3);
return reqBean;
}
Dao baseDao = Mvcs.getIoc().get(Dao.class);
// 2--插入安全平台推送告警状态记录表
long insertUpdateStatusRecordId = this.insertUpdateStatus(baseDao,
TblMaxIdHelper.getTblMaxIdWithUpdate(baseDao, WsUpdateAlertStaus.class), alertTypeI, alertCodeL);
// 3--检查当前告警是否在SA平台存在,存在而更新状态
if (this.isExistAlert(baseDao, alertCodeL)) {
// 将安全平台的告警状态转换成SA告警状态
int destAlertStatus = this.getConvertAlertStatus(alertTypeI);
// 同步更新SA告警状态
int updateRecords = this.updateAlertStatus(baseDao, alertCodeL, destAlertStatus);
if (updateRecords > 0) {
reqBean.setMsg("更新SA告警状态成功");
reqBean.setMsgCode(1);
// 4--更新安全平台推送告警状态记录表的标识符,1为未完成,2为完成
this.updateAlertRecordFlag(baseDao, insertUpdateStatusRecordId);
}

    } else {
       reqBean.setMsg("告警流水号不存在,更新状态失败");
       reqBean.setMsgCode(2);
    }
    return reqBean;
}

不知道了

珍爱生命,远离axis2

添加回复
请先登陆
回到顶部