java解析wsdl文件转json_java 调用wsdl接口同时将返回数据解析成json

packagecom.haiersoft.ushequmobile.utils;importjava.io.ByteArrayInputStream;importjava.io.ByteArrayOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.StringReader;importjava.util.List;importjava.util.Map;importjavax.xml.soap.MessageFactory;importjavax.xml.soap.SOAPBody;importjavax.xml.soap.SOAPElement;importjavax.xml.soap.SOAPEnvelope;importjavax.xml.soap.SOAPException;importjavax.xml.soap.SOAPMessage;importjavax.xml.soap.SOAPPart;importorg.apache.commons.httpclient.HttpClient;importorg.apache.commons.httpclient.HttpStatus;importorg.apache.commons.httpclient.methods.InputStreamRequestEntity;importorg.apache.commons.httpclient.methods.PostMethod;importorg.apache.commons.httpclient.methods.RequestEntity;importorg.apache.log4j.Logger;importorg.jdom2.Document;importorg.jdom2.Element;importorg.jdom2.input.SAXBuilder;importorg.xml.sax.InputSource;importcom.alibaba.fastjson.JSONArray;importcom.alibaba.fastjson.JSONObject;public classWSWorker

{private static Logger logger = Logger.getLogger(WSWorker.class.getName());/*** 返回JSONArray格式的结果

*

* params中如果同一个层次有重名元素,需要将重名元素放到list中,key不变,value使用新的list

*@paramprefix 方法前缀

*@parammethodName 方法名

*@paramns 命名空间

*@paramparams 参数

*@paramwsdl wsdl

*@return*@throwsSOAPException 生成soap报文时发生异常*/

public static JSONArray performRequest(String prefix, String methodName, String ns, Map params, String wsdl) throwsSOAPException

{returnparseXML(getSOAPMessage(prefix, methodName, ns, params, wsdl));

}/***

*@paramprefix 方法前缀

*@parammethodName 方法名

*@paramns 命名空间

*@paramparams 参数

*@paramwsdl wsdl

*@return*@throwsSOAPException

*@throwsIOException*/@SuppressWarnings("unchecked")private static String getSOAPMessage(String prefix, String methodName, String ns, Map params, String wsdl) throwsSOAPException

{

MessageFactory messageFactory=MessageFactory.newInstance();

SOAPMessage message=messageFactory.createMessage();

message

你可能感兴趣的:(java解析wsdl文件转json_java 调用wsdl接口同时将返回数据解析成json)