1 | from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
|
---|
2 | from ZSI.schema import LocalElementDeclaration, ElementDeclaration, TypeDefinition, GTD, GED
|
---|
3 | from VanHelsing_server import VanHelsing
|
---|
4 | from VanHelsing_types import ns0
|
---|
5 | import VanHelsingWrapper
|
---|
6 | import sys
|
---|
7 |
|
---|
8 | ResourceInfo= GTD("http://www.dass-it.de/VanHelsing/", "ResourceInfo")(None).pyclass()
|
---|
9 | listResourcesType= GTD("http://www.dass-it.de/VanHelsing/", "listResourcesType")(None).pyclass()
|
---|
10 | #print dir(ResourceInfo)
|
---|
11 |
|
---|
12 | class VanSOAPRequestHandler(SOAPRequestHandler):
|
---|
13 | def do_GET(self):
|
---|
14 | wsdl=open("VanHelsing.wsdl").read()
|
---|
15 | self.send_xml(wsdl)
|
---|
16 |
|
---|
17 | def AsServer(port=80, services=(), RequestHandlerClass=SOAPRequestHandler):
|
---|
18 | address = ("127.0.0.1",port)
|
---|
19 | sc = ServiceContainer(address, RequestHandlerClass=RequestHandlerClass)
|
---|
20 | for service in services:
|
---|
21 | path = service.getPost()
|
---|
22 | sc.setNode(service,path)
|
---|
23 | sc.serve_forever()
|
---|
24 |
|
---|
25 |
|
---|
26 | class RealVanHelsing(VanHelsing):
|
---|
27 | def soap_listResources(self, ps, **kw):
|
---|
28 | request,response=VanHelsing.soap_listResources(self,ps)
|
---|
29 |
|
---|
30 | resType=request.get_element_resourceType()
|
---|
31 | resDirector=request.get_element_director()
|
---|
32 |
|
---|
33 | result=VanHelsingWrapper.getResources(resDirector,resType)
|
---|
34 |
|
---|
35 | rList=[]
|
---|
36 |
|
---|
37 | for rid,name in result:
|
---|
38 |
|
---|
39 | resInf=response.new_resource()
|
---|
40 | resInf.set_element_director(resDirector)
|
---|
41 | resInf.set_element_resId(rid)
|
---|
42 | resInf.set_element_resType(resType)
|
---|
43 | resInf.set_element_resName(name)
|
---|
44 | rList.append(resInf)
|
---|
45 |
|
---|
46 | response.set_element_resource(rList)
|
---|
47 |
|
---|
48 | return request,response
|
---|
49 |
|
---|
50 | def soap_getSimpleResource(self, ps, **kw):
|
---|
51 | request,response=VanHelsing.soap_getSimpleResource(self,ps)
|
---|
52 |
|
---|
53 | resId=request.get_element_resId()
|
---|
54 | resDirector=request.get_element_director()
|
---|
55 |
|
---|
56 | print resId
|
---|
57 |
|
---|
58 | resource=VanHelsingWrapper.getResourceById(resDirector,resId)
|
---|
59 | attributes=VanHelsingWrapper.keyValueList(resource)
|
---|
60 |
|
---|
61 | resInf=response.new_resInfo()
|
---|
62 | print dir(response)
|
---|
63 | resInf.set_element_director(resDirector)
|
---|
64 | resInf.set_element_resId(resId)
|
---|
65 | resInf.set_element_resType("type")
|
---|
66 | resInf.set_element_resName("name")
|
---|
67 |
|
---|
68 | response.set_element_resInfo(resInf)
|
---|
69 |
|
---|
70 | attrlist=[]
|
---|
71 |
|
---|
72 | for k,v in attributes:
|
---|
73 | resAttr=response.new_resAttribute()
|
---|
74 | resAttr.set_element_key(k)
|
---|
75 | resAttr.set_element_value(v)
|
---|
76 | attrlist.append(resAttr)
|
---|
77 | response.set_element_resAttribute(attrlist)
|
---|
78 |
|
---|
79 | return request,response
|
---|
80 |
|
---|
81 | def soap_setSimpleResource(self, ps, **kw):
|
---|
82 | request,response=VanHelsing.soap_setSimpleResource(self, ps)
|
---|
83 |
|
---|
84 | resInfo = request.get_element_resInfo()
|
---|
85 | resId = resInfo.get_element_resId()
|
---|
86 | director = resInfo.get_element_director()
|
---|
87 | attributes = request.get_element_resAttribute()
|
---|
88 |
|
---|
89 | resId, status = VanHelsingWrapper.setResourceById(resId, director, attributes, resInfo)
|
---|
90 | response.set_element_resId(resId)
|
---|
91 | response.set_element_status(status)
|
---|
92 |
|
---|
93 | return request, response
|
---|
94 |
|
---|
95 | if 1:
|
---|
96 | if len(sys.argv) < 2:
|
---|
97 | filename="test.conf"
|
---|
98 | else:
|
---|
99 | filename=sys.argv[1]
|
---|
100 |
|
---|
101 | VanHelsingWrapper.loadDirectorConfig(filename)
|
---|
102 |
|
---|
103 | AsServer(port=8080,services=[ RealVanHelsing() ], RequestHandlerClass=VanSOAPRequestHandler)
|
---|
104 |
|
---|