Pagina Principale/ZSI

Page last edited 1 924 giorni 22 ore fa
Da wiki.betaingegneria.it.

Zolera Server Infrasctructure[modifica]

Documentazione[modifica]

Nel PC:

  marcob@jsbach:~/Documenti/software/programming/Python/webservices
  marcob@jsbach:~/Documenti/software/programming/Python/webservices/client/ZSI-2.0$ sudo python setup.py install

Eseguire ZSI[modifica]

Server[modifica]

   #!/usr/bin/python
   
   # SOAP Array
   def hello():
       return ["Hello, world"]
   
   def echo(*args):
       return args
   
   def sum(*args):
       sum = 0
       for i in args: sum += i
       
       return [sum]
   
   def average(*args):
       return [sum(*args) / len(args)]
   
   from ZSI import dispatch
   dispatch.AsCGI(rpc=True)

Lo deposito in /var/www/cgi-bin/ e seguo le istruzioni in Apache#CGI

Client[modifica]

   #!/usr/bin/python
   
   # client.py
   import sys
   
   from ZSI.client import Binding
   myurl = 'http://127.0.0.1/cgi-bin/server.py'
   #print myurl
   b = Binding(url=myurl, tracefile=sys.stdout)
   #print b.hello()
   
   try:
       print b.hello(1)
   except Exception, ex:
       print "Fault: ", ex
   
   print b.echo("whatever", "hi", 1, 2)
   print b.sum(*[2*i for i in range(5)])
   print b.average(*[2*i for i in range(5)])

Lo eseguo: accade un bel cose di cose strane:

b.hello(1)[modifica]

   _________________________________ Wed Oct 24 17:24:18 2012 REQUEST:
   <SOAP-ENV:Envelope 
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAP-ENV:Header>
        </SOAP-ENV:Header>
        <SOAP-ENV:Body>
                <hello SOAP-ENC:arrayType="xsd:anyType[1]" xsi:type="SOAP-ENC:Array">
                        <element id="o221b7b8" xsi:type="xsd:int">1</element>
                </hello>
        </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   _________________________________ Wed Oct 24 17:24:18 2012 RESPONSE:
   500
   Internal Server Error
   -------
   Date: Wed, 24 Oct 2012 15:24:18 GMT
   Server: Apache/2.2.22 (Ubuntu)
   Content-Length: 690
   Vary: Accept-Encoding
   Connection: close
   Content-Type: text/xml; charset="utf-8"
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring>Processing Failure</faultstring>
         <detail>
           <ZSI:FaultDetail>
             <ZSI:string>
   hello() takes no arguments (1 given)</ZSI:string>
             <ZSI:trace>/usr/local/lib/python2.7/dist-packages/ZSI/dispatch.py:131:_Dispatch</ZSI:trace>
           </ZSI:FaultDetail>
         </detail>
       </SOAP-ENV:Fault>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   
   Fault:  Processing Failure
   hello() takes no arguments (1 given)
   [trace: /usr/local/lib/python2.7/dist-packages/ZSI/dispatch.py:131:_Dispatch]

Questo si capisce, ho invocato hello() passando un parametro, quando non se ne aspettava nemmeno 1.

b.hello()[modifica]

   _________________________________ Wed Oct 24 18:03:53 2012 REQUEST:
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <hello></hello>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   _________________________________ Wed Oct 24 18:03:53 2012 RESPONSE:
   200
   OK
   -------
   Date: Wed, 24 Oct 2012 16:03:53 GMT
   Server: Apache/2.2.22 (Ubuntu)
   Content-Length: 486
   Vary: Accept-Encoding
   Content-Type: text/xml; charset="utf-8"
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <helloResponse>
         <Eo7fe3876747a0 id="o7fe3876747a0" xsi:type="xsd:string">Hello, world</Eo7fe3876747a0>
       </helloResponse>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   
   {'Eo7fe3876747a0': u'Hello, world'}
   

Ecco, così va meglio

b.echo("whatever", "hi", 1, 2)[modifica]

   _________________________________ Wed Oct 24 17:24:18 2012 REQUEST:
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <echo SOAP-ENC:arrayType="xsd:anyType[4]" xsi:type="SOAP-ENC:Array">
         <element id="o7f958bc7f1e0" xsi:type="xsd:string">whatever</element>
         <element id="o7f958bcb8580" xsi:type="xsd:string">hi</element>
         <element id="o221b7b8" xsi:type="xsd:int">1</element>
         <element id="o221b7a0" xsi:type="xsd:int">2</element>
       </echo>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   _________________________________ Wed Oct 24 17:24:18 2012 RESPONSE:
   200
   OK
   -------
   Date: Wed, 24 Oct 2012 15:24:18 GMT
   Server: Apache/2.2.22 (Ubuntu)
   Content-Length: 670
   Vary: Accept-Encoding
   Content-Type: text/xml; charset="utf-8"
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <echoResponse>
         <Eo7f4b68454060 id="o7f4b68454060" xsi:type="xsd:string">whatever</Eo7f4b68454060>
         <Eo7f4b684541b0 id="o7f4b684541b0" xsi:type="xsd:string">hi</Eo7f4b684541b0>
         <Eo150e7b8 id="o150e7b8" xsi:type="xsd:int">1</Eo150e7b8>
         <Eo150e7a0 id="o150e7a0" xsi:type="xsd:int">2</Eo150e7a0>
       </echoResponse>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   {'Eo150e7a0': 2, 'Eo150e7b8': 1, 'Eo7f4b68454060': u'whatever', 'Eo7f4b684541b0': u'hi'}


Questo ha funzionato correttamente. Semplicemente fa eco di quello che gli scrivete, vi ritorna ciò che gli mandate.


b.sum(*[2*i for i in range(5)])[modifica]

Questo deve fare la somma dei doppi dei primi 5 numeri, ovvero il doppio della somma dei primi 5 numeri interi: 0+1+2+3+4 = 10: deve tornare 20.

   _________________________________ Wed Oct 24 17:24:18 2012 REQUEST:
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <sum SOAP-ENC:arrayType="xsd:anyType[5]" xsi:type="SOAP-ENC:Array">
         <element id="o221b7d0" xsi:type="xsd:int">0</element>
         <element id="o221b7a0" xsi:type="xsd:int">2</element>
         <element id="o221b770" xsi:type="xsd:int">4</element>
         <element id="o221b740" xsi:type="xsd:int">6</element>
         <element id="o221b710" xsi:type="xsd:int">8</element>
       </sum>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   
   _________________________________ Wed Oct 24 17:24:18 2012 RESPONSE:
   200
   OK
   -------
   Date: Wed, 24 Oct 2012 15:24:18 GMT
   Server: Apache/2.2.22 (Ubuntu)
   Content-Length: 454
   Vary: Accept-Encoding
   Content-Type: text/xml; charset="utf-8"
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <sumResponse>
         <Eo28bc5f0 id="o28bc5f0" xsi:type="xsd:int">20</Eo28bc5f0>
       </sumResponse>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   
   {'Eo28bc5f0': 20}

Funziona.

b.average(*[2*i for i in range(5)])[modifica]

Questo invece fa la media dei primi 5 interi da 0 a 5 e fa il doppio, quindi dovrebbe tornare 5, ma fallisce miseramente

  _________________________________ Wed Oct 24 17:24:18 2012 REQUEST:
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <average SOAP-ENC:arrayType="xsd:anyType[5]" xsi:type="SOAP-ENC:Array">
         <element id="o221b7d0" xsi:type="xsd:int">0</element>
         <element id="o221b7a0" xsi:type="xsd:int">2</element>
         <element id="o221b770" xsi:type="xsd:int">4</element>
         <element id="o221b740" xsi:type="xsd:int">6</element>
         <element id="o221b710" xsi:type="xsd:int">8</element>
       </average>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>
   
   _________________________________ Wed Oct 24 17:24:18 2012 RESPONSE:
   500
   Internal Server Error
   -------
   Date: Wed, 24 Oct 2012 15:24:18 GMT
   Server: Apache/2.2.22 (Ubuntu)
   Content-Length: 743
   Vary: Accept-Encoding
   Connection: close
   Content-Type: text/xml; charset="utf-8"
   
   <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <SOAP-ENV:Header></SOAP-ENV:Header>
     <SOAP-ENV:Body>
       <SOAP-ENV:Fault>
         <faultcode>SOAP-ENV:Server</faultcode>
         <faultstring>Processing Failure</faultstring>
         <detail>
           <ZSI:FaultDetail>
             <ZSI:string>
   unsupported operand type(s) for /: 'list' and 'int'</ZSI:string>
             <ZSI:trace>/usr/local/lib/python2.7/dist-packages/ZSI/dispatch.py:131:_Dispatch
   /var/www/cgi-bin/server.py:17:average</ZSI:trace>
           </ZSI:FaultDetail>
         </detail>
       </SOAP-ENV:Fault>
     </SOAP-ENV:Body>
   </SOAP-ENV:Envelope>

Caricare il modulo xml.dom.ext[modifica]

Provo così

 $ sudo apt-get install python-setuptools

Poi

 # easy_install pyxml

E ora funziona

 $ python
 >>> import xml.dom.ext
 >>>

No, non è finita, ora:

 xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 7, referer: http://jsbach/prova_zsi.php

Installare python3[modifica]

da Ubuntu Software Center o da apt-get install python3, poi

  marcob@jsbach:~/Documenti/clienti/ComunePd/2012/acsor$ ll /usr/bin/python
  lrwxrwxrwx 1 root root 9 mag 15 10:00 /usr/bin/python -> python2.7*

cambio il puntamento

  marcob@jsbach:~/Documenti/clienti/ComunePd/2012/acsor$ sudo rm /usr/bin/python
  marcob@jsbach:~/Documenti/clienti/ComunePd/2012/acsor$ sudo ln -s /usr/bin/python3 /usr/bin/python
  marcob@jsbach:~/Documenti/clienti/ComunePd/2012/acsor$ python
  Python 3.2.3 (default, Oct 19 2012, 20:10:41) 
  >>>