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

Last change on this file since 850 was 839, checked in by slederer, on Mar 12, 2010 at 5:11:50 PM

neue SOAP-Operation getSimpleResource implementiert

File size: 2.8 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
81
82
83
[824]84if 1:
[836]85 if len(sys.argv) < 2:
86 filename="test.conf"
87 else:
88 filename=sys.argv[1]
89
90 VanHelsingWrapper.loadDirectorConfig(filename)
91
[826]92 AsServer(port=8080,services=[ RealVanHelsing() ], RequestHandlerClass=VanSOAPRequestHandler)
[824]93
Note: See TracBrowser for help on using the repository browser.