联通VAC定制包解析userIdType和updateType数据碰到的一个问题解决

发布者:罗堃,发布时间:2009-5-15 上午6:33

因为没有使用java平台,也就没有使用建议的axis对提供的wsdl文件做处理,所有关于数据包的解析只能自己写程序做解析处理。
华为提供的vac请求样例包request.xml

  1. <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.bossagent.vac.unicom.com">
  2.    <soapenv:Header/>
  3.    <soapenv:Body>
  4.       <soap:orderRelationUpdateNotify soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  5.          <orderRelationUpdateNotifyRequest xsi:type="req:OrderRelationUpdateNotifyRequest" xmlns:req="http://req.sync.soap.bossagent.vac.unicom.com">
  6.             <recordSequenceId xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">11</recordSequenceId>
  7.             <userIdType xsi:type="soapenc:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</userIdType>
  8.             <userId xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</userId>
  9.             <serviceType xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</serviceType>
  10.             <spId xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</spId>
  11.             <productId xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">2</productId>
  12.             <updateType xsi:type="soapenc:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">3</updateType>
  13.             <updateTime xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">44444444</updateTime>
  14.             <updateDesc xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">444</updateDesc>
  15.             <linkId xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">44</linkId>
  16.             <content xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">?</content>
  17.             <effectiveDate xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">333333</effectiveDate>
  18.             <expireDate xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">2222222</expireDate>
  19.             <time_stamp xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">3333</time_stamp>
  20.             <encodeStr xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">111gg</encodeStr>
  21.          </orderRelationUpdateNotifyRequest>
  22.       </soap:orderRelationUpdateNotify>
  23.    </soapenv:Body>
  24. </soapenv:Envelope>

实际在网络上收到的数据包

  1. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  2.  <soapenv:Body>
  3.   <ns1:orderRelationUpdateNotify soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://soap.bossagent.vac.unicom.com">
  4.    <orderRelationUpdateNotifyRequest href="#id0"/>
  5.   </ns1:orderRelationUpdateNotify>
  6.   <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:OrderRelationUpdateNotifyRequest" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://req.sync.soap.bossagent.vac.unicom.com">
  7.    <recordSequenceId xsi:type="soapenc:string">200903181622360043</recordSequenceId>
  8.    <userIdType href="#id1"/>
  9.    <userId xsi:type="soapenc:string">8613004849965</userId>
  10.    <serviceType xsi:type="soapenc:string">5</serviceType>
  11.    <spId xsi:type="soapenc:string">90000001</spId>
  12.    <productId xsi:type="soapenc:string">050002</productId>
  13.    <updateType href="#id2"/>
  14.    <updateTime xsi:type="soapenc:string">20090313110400</updateTime>
  15.    <updateDesc xsi:type="soapenc:string"></updateDesc>
  16.    <linkId xsi:type="soapenc:string"></linkId>
  17.    <content xsi:type="soapenc:string"></content>
  18.    <effectiveDate xsi:type="soapenc:string">20080301000000</effectiveDate>
  19.    <expireDate xsi:type="soapenc:string">20100301000000</expireDate>
  20.    <time_stamp xsi:type="soapenc:string">0318162236</time_stamp>
  21.    <encodeStr xsi:type="soapenc:string"></encodeStr>
  22.   </multiRef>
  23.   <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</multiRef>
  24.   <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="soapenc:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">1</multiRef>
  25.  </soapenv:Body>
  26. </soapenv:Envelope>

通过对数据包的分析,可以看到在实际包里面,采用了multiRef方式,对userIdType和updateType数据的值使用了href引 用,这样在分析数据包时,就同时要根据节点的href属性值来判断处理所引用的值节点,然后再遍历multiRef的节点找匹配id属性值的,从而找出正 确的值所在。

——-
虽然现在解析正确了,但是没有使用标准的xml开发包工具开发,缺少开发包所做的类型验证,数据包还原等处理,如果以后接口数据格式有发生变化还是要再次 进行解析代码的修改处理,不过不想只为了一个xml解析目的就为服务器添加上java的一堆环境和东西,只好先忍受着自己手工分析xml数据吧。