source: TI12-security/trunk/python/Tests/Echo/EchoClient.py @ 1804

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/Echo/EchoClient.py@1804
Revision 1804, 2.5 KB checked in by pjkersha, 14 years ago (diff)

Changes for WebSphere? tests.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3# Exampe echo client, to show extended code generation in ZSI
4#
5# Import the client proxy object
6from EchoServer_client import EchoServerSOAP
7import sys
8
9import wsSecurity
10
11# Lambda used by WS-Security handler to check which operation has been
12# invoked
13isEchoRequest = lambda sw: sw.body.node.childNodes[0].localName=='Echo'
14isEchoEncrRequest = lambda sw: sw.body.node.childNodes[0].localName=='EchoEncr'
15
16isEchoResponse = lambda ps: \
17ps.dom.childNodes[1].childNodes[1].childNodes[0].localName == 'EchoResponse'
18isEchoEncrResponse = lambda ps: \
19ps.dom.childNodes[1].childNodes[1].childNodes[0].localName=='EchoEncrResponse'
20
21class WSSEhandler:
22    def __init__(self, sigHandler=None, encrHandler=None):
23        self.sigHandler = sigHandler
24        self.encrHandler = encrHandler
25       
26    def sign(self, sw):
27        if self.sigHandler:
28            self.sigHandler.sign(sw)
29           
30    def verify(self, ps):
31        if self.sigHandler:
32            self.sigHandler.verify(ps)
33       
34    def encrypt(self, sw):
35        if self.encrHandler:
36            self.encrHandler.encrypt(sw)
37           
38    def decrypt(self, ps):
39        if self.encrHandler:
40            self.encrHandler.decrypt(ps)
41
42
43#priKeyPwd = open('../tmp2').read().strip()
44#certFilePath = '../Junk-cert.pem'
45#priKeyFilePath = '../Junk-key.pem'
46priKeyPwd = None
47certFilePath = '../webSphereTestcert.pem'
48priKeyFilePath = '../webSphereTestkey.pem'
49
50# Signature handler object is passed to binding
51sigHandler = wsSecurity.SignatureHandler(certFilePath=certFilePath,
52                                         priKeyFilePath=priKeyFilePath,
53                                         priKeyPwd=priKeyPwd)
54
55encrHandler = wsSecurity.EncryptionHandler(certFilePath=certFilePath,
56                                           priKeyFilePath=priKeyFilePath,
57                                           priKeyPwd=priKeyPwd)
58
59# Test encryption only
60#wsseHandler = WSSEhandler(sigHandler, encrHandler)
61wsseHandler = WSSEhandler(encrHandler=encrHandler)
62   
63       
64# Instantiate a client proxy object, then call it
65#wsURL = "http://192.100.78.234:9081/EchoServiceWeb/services/EchoServer"
66#wsURL = "http://localhost:7000"
67wsURL = "http://192.100.78.135:7000"
68echoSrv = EchoServerSOAP(wsURL,
69                         sig_handler=sigHandler,
70                         encr_handler=encrHandler,
71                         tracefile=sys.stdout)
72try:
73    import pdb;pdb.set_trace()
74    print echoSrv.Echo("Test String")
75    #print echoSrv.EchoEncr("Test Secret")
76except Exception, e:
77    print "Failed to echo: ", e
78
Note: See TracBrowser for help on using the repository browser.