Axis2调用webservice

/**
* Axis2 调用webservice
* Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物。
* Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持Spring、JSON等技术
* @param url webservice 地址
* @param method  调用方法名
* @param selectNode 指定节点名
* @param namespace webservice命名空间
* @param param 参数
* @param page 分页参数
* @return
* @throws AxisFault
*/
private JSONObject axis2Webservice(String url,String method,String selectNode,String namespace,Map<String,String> param,Page<?> page) throws AxisFault {

//定义一个json对象,接收解析后的数据
JSONObject json = new JSONObject();

//webservice 命名空间
String webservice_namespace = "http://WebXml.com.cn/";

if(StringUtils.isNotBlank(url) && StringUtils.isNotBlank(method)){

ServiceClient sender = new ServiceClient();

//
Options options = sender.getOptions();

EndpointReference targetEPR = new EndpointReference(url);

options.setTo(targetEPR);
options.setTimeOutInMilliSeconds(10000);
//如果不设置Action,会提示无法找到http action等错误
options.setAction(webservice_namespace+method);
//如果为true,调用.net发布的Webservice会出现不兼容异常
options.setProperty(HTTPConstants.CHUNKED, "false");

sender.setOptions(options);

//
OMFactory fac = OMAbstractFactory.getOMFactory();

OMNamespace omNs = fac.createOMNamespace(webservice_namespace, "tns");

OMElement data = fac.createOMElement(method, omNs);

//封装WebService参数条件
if(param.entrySet() != null && param.entrySet().size() > 0 ){

for(Map.Entry<String, String> entry: param.entrySet()){

OMElement inner = fac.createOMElement(entry.getKey(), omNs);

inner.setText(entry.getValue());

data.addChild(inner);

}

}

// 调用服务
OMElement result = sender.sendReceive(data);

//取到指定节点内容,并封装成集合返回
json = this.readStringXml(result.toString(), selectNode, namespace, page);

}

        return json;
       
}

猜你喜欢

转载自htl26260.iteye.com/blog/2101406