00001
00002 import getopt, socket, sys
00003
00004 try:
00005 (opts, args) = getopt.getopt(sys.argv[1:],
00006 'h:p:s',
00007 ( 'host=', 'port=',
00008 'statusonly', 'help'))
00009 except getopt.GetoptError, e:
00010 print >>sys.stderr, sys.argv[0] + ': ' + str(e)
00011 sys.exit(1)
00012 if args:
00013 print sys.argv[0] + ': Usage error; try --help.'
00014 sys.exit(1)
00015
00016 hostname, portnum, verbose = 'localhost', 80, 1
00017 for opt, val in opts:
00018 if opt in [ '--help' ]:
00019 print '''Options include:
00020 --host HOST (-h HOST) Name of server host
00021 --port PORT (-p PORT) Port server is listening on
00022 --statusonly (-s) Do not output reply packets; just status code
00023 Default is -h%s -p%d -t%s''' % \
00024 (hostname, portnum, ','.join([str(x) for x in tests]))
00025 sys.exit(0)
00026 if opt in [ '-h', '--host' ]:
00027 hostname = val
00028 elif opt in [ '-p', '--port' ]:
00029 portnum = int(val)
00030 elif opt in [ '-s', '--statusonly' ]:
00031 verbose = 0
00032
00033
00034 IN = '''<SOAP-ENV:Envelope
00035 xmlns="http://www.example.com/schemas/TEST"
00036 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
00037 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
00038 <SOAP-ENV:Body>
00039 <hello/>
00040 </SOAP-ENV:Body>
00041 </SOAP-ENV:Envelope>
00042 '''
00043
00044 IN = '''<SOAP-ENV:Envelope
00045 xmlns="http://www.example.com/schemas/TEST"
00046 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
00047 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
00048 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
00049 <SOAP-ENV:Body>
00050 <echo>
00051 <SOAP-ENC:int>1</SOAP-ENC:int>
00052 <SOAP-ENC:int>2</SOAP-ENC:int>
00053 </echo>
00054 </SOAP-ENV:Body>
00055 </SOAP-ENV:Envelope>
00056 '''
00057
00058 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00059 s.connect((hostname, portnum))
00060 f = s.makefile('r+')
00061
00062 f.write('POST /cgi-bin/x HTTP/1.0\r\n')
00063 f.write('Content-type: text/xml; charset="utf-8"\r\n')
00064 f.write('Content-Length: %d\r\n\r\n' % len(IN))
00065 f.write(IN)
00066 f.flush()
00067
00068 status = f.readline()
00069 print status,
00070 while 1:
00071 l = f.readline()
00072 if l == '': break
00073 if verbose: print l,
00074
00075 f.close()