Google

星期五, 五月 15, 2009

soapUI; the Web Services Testing tool

soapUI is a free and open source desktop application for

It is mainly aimed at developers and testers providing or consuming WSDL or REST based Web Services (Java, .net, etc). Functional and Load Testing can be done both interactively in soapUI or within an automated build or integration process using the soapUI command line tools.

Mock Web Services can easily be created for any WSDL and hosted from within soapUI or using the command-line MockService runner. IDE-plugins are available for

soapUI requires Java 1.5 and is licensed under the LGPL license.

http://www.soapui.org/

标签: ,

星期二, 四月 07, 2009

Python XMLRPC with GBK encoding

一句话,简直是噩梦,如果实在是没有什么理由非要用GBK编码不可,我的建议,还是改用utf-8这样更国际化的标准吧。说实在的,Python下面折腾GBK编码的XMLRPC实在是没有什么意思,没有任何乐趣,只有浪费时间。

  言归正传,当你没有办法非要使用GBK编码的xmlrpc服务,体会一下恶梦,那我们就开始吧。首先明确一下革命形势:标准的Python xmlrpclib库,就是不支持GBK编码的。换而言之,指望通过给ServerProxy指定encoding参数的做法,是解决不了什么问题的。问题的关键在于,Python XML模块的底层,依赖的expat这个东东,对GBK支持是有问题的(我是想说更本就不支持,不过不能确定,就暂且定义为有问题),所以只要是依赖这个东西的XML模块,都是不能很好的处理GBK编码下的XML数据的。解决问题的大体方向就出来了,一个是绕过expat,干脆不用这个东西,其二就是认命妥协了,把数据转换成utf-8编码再塞给expat吧。前面一个方案,可联想到的就是libxml2-python。我是采用第二种方案了,这里也有两种可参考的做法,一种是自己定义一个Parser,然后覆盖ServerProxy那个getParser,生成支持转码功能的XMLParser给xmlrpc proxy使用。另外一个办法,就是干脆跳过ServerProxy,自己做一个。考虑到我的实际使用情况,不会有太大的数据传输,没有必要做一个支持流接口的XMLParser,所以就干脆自己重新做了一个代替ServerProxy的东西。下面是简单的代码示例。

  PYTHON:

  importxmlrpclib

  importhttplib

  

  defXMLRPCCall0(URI, methodname, param):

  body = xmlrpclib.dumps(

  param, methodname, False, 'GBK')

  

  (protocl, host, path,

  query, fragment)= httplib.urlsplit(URI)

  h = httplib.HTTPConnection(host)

  headers = {

  'Content-Type': 'text/xml'

  }

  h.request('POST', URI, body, headers)

  res = h.getresponse()

  resbody = res.read()

  h.close()

  resbody = resbody.replace(' encoding="GBK"', '')

  returnxmlrpclib.loads(

  resbody.decode('GBK').encode('utf-8'))[0][0]

http://www.cnscn.org/htm_data/369/0810/17233.html

标签: , ,

xmlrpc for python

使用python处理xmlrpc太简单了,又一次感受到了python的力量!
下面以使用python调用wordpress提供的xmlrpc方法为例简单介绍一下:

1) how to call xmlrpc method in python
>>> import xmlrpclib
>>> from pprint import pprint
>>> server = xmlrpclib.ServerProxy("http://localhost/wordpress/xmlrpc.php")
>>> pprint(server.system.listMethods() )

['system.multicall',
'system.listMethods',
'system.getCapabilities',
'demo.addTwoNumbers',
'demo.sayHello',
'pingback.extensions.getPingbacks',
'pingback.ping',
'mt.publishPost'......]

>>> blogs = server.metaWeblog.getRecentPosts('','admin','passwd',5)
>>> pprint(blogs)
>>> print(blogs[2]['permaLink'])

http://localhost/wordpress/?p=135

2)how to setup a xmlrpc server in python

import calendar, SimpleXMLRPCServer
#The server object
class Calendar:
def getMonth(self, year, month):
return calendar.month(year, month)

def getYear(self, year):
return calendar.calendar(year)
calendar_object = Calendar()
server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
server.register_instance(calendar_object)
#Go into the main listener loop
print "Listening on port 8888"
server.serve_forever()

3)write a client to test server above
import xmlrpclib
server = xmlrpclib.ServerProxy("http://localhost:8888")
month = server.getMonth( 2002, 8 )
print month

August 2002
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

PS:
pprint means pretty print. A cool tool too.

Reference:
1 http://docs.python.org/lib/module-xmlrpclib.html
2 http://www-128.ibm.com/developerworks/library/ws-pyth10.html
3 http://groovy.codehaus.org/XMLRPC

http://zeaster.blogspot.com/2007/01/xmlrpc-for-python.html

标签: , ,

辽ICP备05003652号
流风洄雪听天籁,轻云蔽日看落花

Powered by Blogger