source: vanHelsing/trunk/webservice/VanHelsingServer.py@ 1100

Last change on this file since 1100 was 877, checked in by slederer, on May 27, 2010 at 3:02:19 PM

VanHelsingServer: anderen Port verwenden (8082)

File size: 3.5 KB
Line 
1from ZSI.ServiceContainer import ServiceContainer, SOAPRequestHandler
2from ZSI.schema import LocalElementDeclaration, ElementDeclaration, TypeDefinition, GTD, GED
3from VanHelsing_server import VanHelsing
4from VanHelsing_types import ns0
5import VanHelsingWrapper
6import sys
7
8ResourceInfo= GTD("http://www.dass-it.de/VanHelsing/", "ResourceInfo")(None).pyclass()
9listResourcesType= GTD("http://www.dass-it.de/VanHelsing/", "listResourcesType")(None).pyclass()
10#print dir(ResourceInfo)
11
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
25
26class 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 resource=VanHelsingWrapper.getResourceById(resDirector,resId)
58 attributes=VanHelsingWrapper.keyValueList(resource)
59
60 resInf=response.new_resInfo()
61 print dir(response)
62 resInf.set_element_director(resDirector)
63 resInf.set_element_resId(resId)
64 resInf.set_element_resType("type")
65 resInf.set_element_resName("name")
66
67 response.set_element_resInfo(resInf)
68
69 attrlist=[]
70
71 for k,v in attributes:
72 resAttr=response.new_resAttribute()
73 resAttr.set_element_key(k)
74 resAttr.set_element_value(v)
75 attrlist.append(resAttr)
76 response.set_element_resAttribute(attrlist)
77
78 return request,response
79
80 def soap_setSimpleResource(self, ps, **kw):
81 request,response=VanHelsing.soap_setSimpleResource(self, ps)
82
83 resInfo = request.get_element_resInfo()
84 resId = resInfo.get_element_resId()
85 director = resInfo.get_element_director()
86 attributes = request.get_element_resAttribute()
87
88 resId, status = VanHelsingWrapper.setResourceById(resId, director, attributes, resInfo)
89 #response.set_element_resId(resId)
90 response.set_element_status(status)
91
92 return request, response
93
94 def soap_setFileSetResource(self, ps, **kw):
95 request,response=VanHelsing.soap_setFileSetResource(self, ps)
96
97
98 return request, response
99
100if 1:
101 if len(sys.argv) < 2:
102 filename="test.conf"
103 else:
104 filename=sys.argv[1]
105
106 VanHelsingWrapper.loadDirectorConfig(filename)
107
108 AsServer(port=8082,services=[ RealVanHelsing() ], RequestHandlerClass=VanSOAPRequestHandler)
109
Note: See TracBrowser for help on using the repository browser.