source: vanHelsing/trunk/src/VanHelsingServer.py@ 860

Last change on this file since 860 was 855, checked in by tobias, on Mar 26, 2010 at 6:42:38 PM

node replacement added.

File size: 3.3 KB
RevLine 
[824]1from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
[826]2from ZSI.schema import LocalElementDeclaration, ElementDeclaration, TypeDefinition, GTD, GED
[824]3from VanHelsing_server import VanHelsing
[836]4from VanHelsing_types import ns0
5import VanHelsingWrapper
6import sys
[824]7
[826]8ResourceInfo= GTD("http://www.dass-it.de/VanHelsing/", "ResourceInfo")(None).pyclass()
[836]9listResourcesType= GTD("http://www.dass-it.de/VanHelsing/", "listResourcesType")(None).pyclass()
10#print dir(ResourceInfo)
[826]11
[824]12class VanSOAPRequestHandler(SOAPRequestHandler):
13 def do_GET(self):
14 wsdl=open("VanHelsing.wsdl").read()
15 self.send_xml(wsdl)
16
17def 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
[826]25
26class RealVanHelsing(VanHelsing):
27 def soap_listResources(self, ps, **kw):
28 request,response=VanHelsing.soap_listResources(self,ps)
29
[836]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
[837]39 resInf=response.new_resource()
[836]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
[837]46 response.set_element_resource(rList)
[836]47
[826]48 return request,response
49
[839]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
[855]81 def soap_setSimpleResource(self, ps, **kw):
82 request,response=VanHelsing.soap_setSimpleResource(self, ps)
[839]83
[855]84 resInfo = request.get_element_resInfo()
85 resId = resInfo.get_element_resId()
86 director = resInfo.get_element_director()
87 attributes = request.get_element_resAttribute()
[839]88
[855]89 resId, status = VanHelsingWrapper.setResourceById(resId, director, attributes, resInfo)
90 response.set_element_resId(resId)
91 response.set_element_status(status)
[839]92
[855]93 return request, response
94
[824]95if 1:
[836]96 if len(sys.argv) < 2:
97 filename="test.conf"
98 else:
99 filename=sys.argv[1]
100
101 VanHelsingWrapper.loadDirectorConfig(filename)
102
[826]103 AsServer(port=8080,services=[ RealVanHelsing() ], RequestHandlerClass=VanSOAPRequestHandler)
[824]104
Note: See TracBrowser for help on using the repository browser.