public static List<String> getOperationList(String wsdlUrl) throws Exception {
Document document = getDefinitionDocument(wsdlUrl);
XPath xpath = getXpath(document);
NodeList operations = DOMUtil.findNodeList(document, "wsdl:definitions/wsdl:portType/wsdl:operation");
// 返回的结果集list
List<String> operationList = new ArrayList<String>();
for (int i = 0; i < operations.getLength(); i++) {
Node operation = operations.item(i);
String operationName = DOMUtil.getNodeName(operation);
if (operationName != null && !"".equals(operationName)) {
log.debug("解析" + wsdlUrl + "中的方法:" + operationName);
operationList.add(operationName);
}
}
//去除重复的operation(soap,get,post)
List<String> result = new ArrayList<String>();
for(int i=0;i<operationList.size()/3;i++){
String method = operationList.get(i);
result.add(i, method);
}
//返回最终结果result
return result;
}上面方法中用到的架包dom4j,jdom,wsdl4j
本文介绍了一种使用Java代码解析WSDL文件并提取其中的操作列表的方法。该方法利用了DOM技术,并通过XPath表达式定位到具体的操作节点,进而获取操作名称。为了确保操作列表的唯一性,还采取了措施去除重复项。
1749

被折叠的 条评论
为什么被折叠?



