调用webservices服务一个异常处理:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in someth
2009-07-15 11:09
651 查看
今天调用一个webservices服务抛出一个异常:org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in someth ing it was trying to deserialize.
网上找资料花了一天才搞定.
调用webservices代码:
如果services返回的结果GetSubscriptionRsp类对象里面没有关联另外一个SubInfo类对象. 就不会报这样的异常. 服务返回结果的GetSubscriptionRsp类对象里关联另外一个SubInfo类对象25行就抛出这个异常. 异常的意思看似返回的结果中有个子元素不能反序列化. 估计是不能反序列为SubInfo. 到网上查了N久找到处理的方法, 国内一些留言的没找到相关解决办法. 参考了国外高人的留言,一个一个字的慢慢看(看来英语还是很重要.) 找到了处理方法:
增加了几行代码:
异常就再也没有抛出来了, 总算送了一口气. 虽然问题解决了. 但是还是不知道什么原因. 为什么要加这几行代码? 请各位高人指点.
网上找资料花了一天才搞定.
调用webservices代码:
GetSubscriptionReq input = new GetSubscriptionReq(); GetSubscriptionRsp output = null; Service service = new Service(); Call call = (Call)service.createCall(); call.setTimeout(new Integer(20000)); org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc(); oper.setName("getSubscription"); param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://portalEngine.ismp.chinatelecom.com", "getSubscriptionReq"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://req.portalEngine.ismp.chinatelecom.com", "GetSubscriptionReq"), GetSubscriptionReq.class, false, false); oper.addParameter(param); oper.setReturnType(new javax.xml.namespace.QName("http://rsp.portalEngine.ismp.chinatelecom.com", "GetSubscriptionRsp")); oper.setReturnClass(GetSubscriptionRsp.class); oper.setReturnQName(new javax.xml.namespace.QName("http://portalEngine.ismp.chinatelecom.com", "getSubscriptionRsp")); oper.setStyle(org.apache.axis.constants.Style.DOCUMENT); oper.setUse(org.apache.axis.constants.Use.LITERAL); call.setOperation(oper); call.setOperationName("getSubscription"); call.setTargetEndpointAddress("http://"+service_addr+"/PortalEngineService"); try{ output = (GetSubscriptionRsp)call.invoke(new Object[]{input});//调用webservices服务 }catch(Exception e) { throw new ServantException("core_invoke_webservices_failure",e.getMessage()); }
如果services返回的结果GetSubscriptionRsp类对象里面没有关联另外一个SubInfo类对象. 就不会报这样的异常. 服务返回结果的GetSubscriptionRsp类对象里关联另外一个SubInfo类对象25行就抛出这个异常. 异常的意思看似返回的结果中有个子元素不能反序列化. 估计是不能反序列为SubInfo. 到网上查了N久找到处理的方法, 国内一些留言的没找到相关解决办法. 参考了国外高人的留言,一个一个字的慢慢看(看来英语还是很重要.) 找到了处理方法:
增加了几行代码:
TypeMappingRegistry registry = service.getTypeMappingRegistry(); TypeMapping mapping = registry.createTypeMapping(); registerBeanMapping(mapping, GetSubscriptionReq.class,new javax.xml.namespace. QName("http://req.portalEngine.ismp.chinatelecom.com", "GetSubscriptionReq")); registerBeanMapping(mapping, GetSubscriptionRsp.class,new javax.xml.namespace. QName("http://rsp.portalEngine.ismp.chinatelecom.com", "GetSubscriptionRsp")); registerBeanMapping(mapping, SubInfo.class,new javax.xml.namespace. QName("http://rsp.portalEngine.ismp.chinatelecom.com", "SubInfo")); registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping); protected void registerBeanMapping(TypeMapping mapping, Class type, javax.xml.namespace.QName qname) { mapping.register(type, qname, new BeanSerializerFactory(type, qname), new BeanDeserializerFactory(type, qname)); }
异常就再也没有抛出来了, 总算送了一口气. 虽然问题解决了. 但是还是不知道什么原因. 为什么要加这几行代码? 请各位高人指点.
相关文章推荐
- 调用WebService 出现org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it
- org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in
- weblogic对xml中BOM处理异常——org.xml.sax.SAXParseException:Content is not allowed in prolog
- weblogic部署异常—org.xml.sax.SAXParseException: The string "--" is not permitted within comments
- org.xml.sax.SAXParseException: The prefix "context" for element "context:component-scan" is not boun
- Caused by: org.xml.sax.SAXParseException: The prefix "aop" for element "aop:config" is not bound
- org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog
- sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.3: Element 'beans' cannot have
- org.xml.sax.SAXParseException: Content is not allowed in prolog.
- Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决
- org.xml.sax.SAXParseException: Content is not allowed in prolog.
- org.xml.sax.SAXNotRecognizedException异常解析
- "org.xml.sax.SAXParseException: The content of element type "class" must match" 异常解决
- 转载:sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决
- 错误提示-ibatisorg.xml.sax.SAXParseException: The string "--" is not permitted within comments.
- nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.