webservice 返回documentImpl 数据为空

来源:互联网 发布:snmp trap 接收 java 编辑:程序博客网 时间:2024/06/06 12:40

在做webservice上传的时候,返回值是map对象,但是通过

Client client = new Client(new URL(surl));// client.setProperty("mtom-enabled", "true");client.setProperty(HttpTransport.CHUNKING_ENABLED, "true");Object[] results = client.invoke(saction, objarr);return results;

这种方式调用之后,结果返回的都是一个documentImpl 对象,再跟踪进去的话会发现,里面所有的都是空值,找不到正确的返回值。

我的解决办法是使用w3c的document 将取回的值强制转换,然后在根据里面的tagname获取对应的值。

代码如下,

    Long start = System.currentTimeMillis();Object[] results ;long startpost = 0;int BUFFER_LENGTH = 1024 * 20;// 一次性读入大小int SLEEP_TIME = 250;// 循环读次数long filesize = 0;FileInputStream fis = null;try {File upfile = new File("d://xx.docx");filesize = upfile.length();if(filesize>5000000){System.out.println("上传文件大小不能超过5M");return; }fis = new FileInputStream(upfile);fis.skip(startpost);// 读文件前,先定位StringBuffer sb = new StringBuffer();int time = 0;byte[] buffer = new byte[BUFFER_LENGTH];int count = -1;while (time < SLEEP_TIME && (count = fis.read(buffer)) != -1) {sb.append(Base64.encode(buffer, 0, count));time++;}String ret = sb.toString();boolean uploadFlag = false;results = getWebService("http://localhost:8081/scysspjc1/webservice/WSSPWebServiceControllerPort?wsdl", "addFileContentDHS", new Object[] {"123","{AC132005-0000-0000-59D9-704F00000010}", ret });            org.w3c.dom.Document d = (org.w3c.dom.Document)results[0];            NodeList nl =d.getElementsByTagName("ns1:out");            NodeList n2 = nl.item(0).getChildNodes();            System.out.println(n2.getLength());            for (int i=0;i<n2.getLength();i++){ //                System.out.println(n2.item(i).getNodeName()+"::"+n2.item(i).getTextContent());                if(n2.item(i).getTextContent().contains("STATUS")){                if(n2.item(i).getTextContent().contains("1"))                uploadFlag = true;                }            }            if(uploadFlag){            System.out.println("文件上传成功!");            }Long end = System.currentTimeMillis();System.out.println("用时:" + (end - start));} catch (FileNotFoundException e) {e.printStackTrace();throw new Exception("出错啦!", e);} catch (IOException e) {e.printStackTrace();throw new Exception("出错啦!", e);} catch (Exception e) {} finally {if(fis!=null){fis.close();}}    


原创粉丝点击