码迷,mamicode.com
首页 > 其他好文 > 详细

扫描soa并输出所有服务方法

时间:2016-10-26 20:04:49      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:站点   条件   测试自动化   ref   div   ext   文档   path   htm   

  现在,大多公司都采用soa架构。那么我们怎么知道soa提供哪些服务方法呢?是通过浏览器不断的点击尝试?还是通过wcf?还是通过阅读soa接口文档,在软件开发行业,总会有文档落后于代码的情况?这些手法都太拙劣了。其实我们可以通过一些更快捷高效的手段达到目的。

  萌生这个想法的背景是,我们公司部署了几个soa服务。然后我们测试自动化非常分散,形式各种各样,五花八门,简直就是八仙过海各显神通,非常不易于统计自动化覆盖率统计。于是乎,就想到了使用脚本扫描统计的办法。不多了,直接上代码,脚本如下:
#coding=utf-8
import requests
from lxml import etree
from suds.client import Client
import csv



preSoa = r"http://192.168.1.20:8085/"

soaurl =requests.get(preSoa)

detail_html = etree.HTML(soaurl.content)

links =detail_html.xpath(ur"//a")
hrefs = [preSoa +x.attrib["href"] for x in links if ".config" not in x.text and "bin" not in x.text and "Demo" not in x.text and ".asax" not in x.text ]

svclinks =[]

def getsvcurl(templink):
    tempsoaurlcontent = requests.get(templink).content
    temphtml = etree.HTML(tempsoaurlcontent)
    temphtmllink =temphtml.xpath(ur"//a/text()")
    svclink = [templink + x + "?singleWsdl" for x in  temphtmllink  if ".svc" in x]
    [svclinks.append(x) for x in svclink]

[getsvcurl(x) for x in hrefs]

getsvcurl(preSoa)

print "svc count:{0}".format(len(svclinks))


client = Client(svclinks[0])

svcfuns =[]

def dealsvcmethods(svclink):
    methods=[x[0] for x in Client(svclink).sd[0].ports[0][1]]
    [svcfuns.append({"funcname":x,"svc":svclink}) for x in methods]

[dealsvcmethods(x) for x in svclinks]


with open(ur"E:\主站soa2016-10-25.csv", ab+) as csvfile :
    writer = csv.DictWriter(csvfile,fieldnames = ["funcname","svc"])
    writer.writeheader()
    writer.writerows(svcfuns)

  当然,使用这种方式是有前提条件的。首先,soa站点必须要公开服务。有了这个,我们能够很容易找出前后版本新增的服务方法。

扫描soa并输出所有服务方法

标签:站点   条件   测试自动化   ref   div   ext   文档   path   htm   

原文地址:http://www.cnblogs.com/yicaifeitian/p/6001114.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!