webservice 返回documentImpl 数据为空

在处理WebService上传并接收Map对象时遇到返回的DocumentImpl数据为空的状况。为了解决这个问题,采取了利用W3C的Document进行转换,通过tagName获取所需值的策略。具体实现代码文中未给出。

在做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();
			}
		}
    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值