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

因为没有使用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数据吧。

Popularity: 32% [?]

Random Posts

使用postfix发邮件被拒(UBE)的处理

公司邮箱发出到QQ邮件有发不出,然后收到一份主题为Considered UNSOLICITED BULK EMAIL, apparently from you的邮件:

A message from  to:
-> 439386@qq.com

was considered unsolicited bulk e-mail (UBE).

Our internal reference code for your message is 14395-03/IiCsmVeSBHvn

The message carried your return address, so it was either a genuine mail
from you, or a sender address was faked and your e-mail address abused
by third party, in which case we apologize for undesired notification.

We do try to minimize backscatter for more prominent cases of UBE and
for infected mail, but for less obvious cases of UBE some balance
between losing genuine mail and sending undesired backscatter is sought,
and there can be some collateral damage on both sides.

First upstream SMTP client IP address: [127.0.0.1]
According to a ‘Received:’ trace, the message originated at: [127.0.0.1],
  localhost.localdomain mail.cn [127.0.0.1]

Return-Path: 
From: “=?GB2312?B?bWFzdGVy?=” 
Message-ID: <20090311013925.CBA7AB805@mail-corp.cn>
Subject: =?GB2312?B?v7S/tLLZ1/fPtc2z?=

Delivery of the email was stopped!

通过到提供邮件打包安装的 www.extmail.org 论坛上查找原因,发现如下解决方法。
论坛中的地址:http://www.extmail.org/forum/thread-8949-1-1.html
修改/etc/amavisd.conf配置文件

修改完以后,执行 amavisd reload 重新应用规则。

Popularity: 25% [?]

Random Posts

linux命令后面常见的>/dev/null 和 2>&1 的含义

为了避免在开发服务器使用ftp上传代码文件,导致文件不一致问题的现象。今天做一个从版本库中自动同步文件到开发服务器的脚本,同时可以规范版本库的使用。

简单编写了一下脚本,通过ssh登陆在命令行下运行正常,可是将脚本添加到crontab中就不正常。想记录一下输出信息,分析一下错误原因。
将脚本通过使用 > info.log 重定向输出,结果发现一些在命令行下可以看到的文本信息没有记录到 info.log 文件中,研究了一下,那些输出估计是输出到了标准错误上。

研究了一下通常添加命令后面几个输出含义

Popularity: 24% [?]

Random Posts

Nginx常见应用技术指南(Nginx Tips) - 转

发现一篇关于Nginx使用Tips的好文,特转载与此

Nginx 技术指南[NGINX TIPS]

转自:http://bbs.linuxtone.org/thread-1241-1-1.html

Nginx 常见应用技术指南(Nginx Tips)[定期更新]

作者:NetSeek http://www.linuxtone.org(IT运维专家网|集群架构|性能调优)
欢迎转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明.
更新时间:[2008-12-4] 第一版:[2008-11-25]

目录:
一. Nginx基础知识
二. Nginx安装配置
三. Nginx Rewrite
四. Nginx Redirect
五. Nginx 目录自动加斜线
六. Nginx 防盗链
七. Nginx expires
八. Nginx 访问控制
九. Nginx Location
十. Nginx 日志处理
十一.   Nginx Cache服务配置
十二.   Nginx 负载均衡
十三.   Nginx 优化
十四.   Nginx 相关参考文档

Read more

Popularity: 28% [?]

Related

Web中一些不利于做缓存的因素

Web中不利于做缓存的一些因素,以及怎样尽可能的减小这些不利因素对缓存处理的影响。

Popularity: 28% [?]

Related

http以trunked编码方式传输的数据表示规则

一般HTTP通信时会使用是Content-Length头信息性来指定小,但是有时候无法确定信息大小,就要使用trunked编码动态的提供body内容的长度。

进行Chunked编码传输的HTTP数据要在消息头部设置:

Transfer-Encoding: chunked

表示Content Body将用chunked编码传输内容。

Chunked编码一般使用若干个chunk串连而成,最后由一个标明长度为0的chunk标示结束。
每个chunk分为头部正文两部分,
头部内容指定下一段正文的字符总数(非零开头的十六进制的数字)和数量单位(一般不写,表示字节).
正文部分就是指定长度的实际内容,两部分之间用回车换行(CRLF)隔开。
在最后一个长度为0的chunk中的内容是称为footer的内容,是一些附加的Header信息(通常可以直接忽略)。具体的chunk编码格式如下:

  1.   chunked-body = *chunk
  2.          "0" CRLF
  3.          footer
  4.          CRLF
  5.   chunk = chunk-size [ chunk-ext ] CRLF
  6.        chunk-data CRLF
  7.   hex-no-zero = <HEX excluding "0">
  8.   chunk-size = hex-no-zero *HEX
  9.   chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-value ] )
  10.   chunk-ext-name = token
  11.   chunk-ext-val = token | quoted-string
  12.   chunk-data = chunk-size(OCTET)
  13.   footer = *entity-header

RFC文档中的chunked解码过程如下:

  1.   length := 0
  2.   read chunk-size, chunk-ext (if any) and CRLF
  3.   while (chunk-size > 0) {
  4.       read chunk-data and CRLF
  5.       append chunk-data to entity-body
  6.       length := length + chunk-size
  7.       read chunk-size and CRLF
  8.   }
  9.   read entity-header
  10.   while (entity-header not empty) {
  11.       append entity-header to existing header fields
  12.       read entity-header
  13.   }
  14.   Content-Length := length
  15.   Remove "chunked" from Transfer-Encoding

Popularity: 26% [?]

Random Posts

IdHttp访问返回非2XX代码的地址后Response.Stream中无数据问题解决

直接使用IdHttp编写使用WebService方式交互数据的MMS客户端,发现在正常Post数据返回200错误代码时,Response中包含Xml Soap的数据包,但是当服务端返回Http 500这样有错误代码时,Response中没有数据。

是服务端真的没有返回数据吗?使用转包工具抓了一下数据包,发现服务器端在返回 Http 500错误代码后,仍然是返回了包含错误信息的xml soap数据包的。出现这样的情况应该是IdHttp在接收数据时出错。

打开idHttp文件分析了一下,发现其在 ProcessResponse 函数中存在如下一段判断处理

  1. if LResponseDigit <> 2 then
  2. begin
  3.   result := wnGoToURL;
  4.   case Response.ResponseCode of
  5.     401:
  6.        ….
  7.     407:
  8.        ….
  9.     else begin
  10.         RaiseException;
  11.     end;
  12.   end;
  13. end;

在返回值不是以2开头的时候,会直接抛掉后面接受到的数据,从而得不到想要的数据。
修改这个函数里面的子函数 RaiseException, 使其由原先的:

  1.   procedure RaiseException;
  2.   var
  3.     LRespStream: TStringStream;
  4.     LTempStream: TStream;
  5.     LTemp: Integer;
  6.   begin
  7.     LTemp := FHTTP.ReadTimeout;
  8.     FHTTP.ReadTimeout := 2000; // Lets wait 2 seconds for any kind of content
  9.     LRespStream := TStringStream.Create('');
  10.     LTempStream := Response.ContentStream;
  11.     Response.ContentStream := LRespStream;
  12.     try
  13.       FHTTP.ReadResult(Response);
  14.       raise EIdHTTPProtocolException.CreateError(Response.ResponseCode, FHTTP.ResponseText, LRespStream.DataString);
  15.     finally
  16.       Response.ContentStream := LTempStream;
  17.       LRespStream.Free;
  18.       FHTTP.ReadTimeout := LTemp;
  19.     end;
  20.   end;

变为

  1.   procedure RaiseException;
  2.   var
  3.     LTemp: Integer;
  4.   begin
  5.     LTemp := FHTTP.ReadTimeout;
  6.     FHTTP.ReadTimeout := 2000; // Lets wait 2 seconds for any kind of content
  7.     try
  8.       FHTTP.ReadResult(Response);
  9.       raise EIdHTTPProtocolException.CreateError(Response.ResponseCode, FHTTP.ResponseText, '');
  10.     finally
  11.       FHTTP.ReadTimeout := LTemp;
  12.     end;
  13.   end;

至此,Response.Stream中存放了返回后的数据,可以继续程序上的处理了。

Popularity: 30% [?]

Random Posts