Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Weird behaviour with complex types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sybren Stüvel  
View profile  
 More options Oct 15 2007, 7:00 am
From: Sybren Stüvel <syb...@stuvel.eu>
Date: Sun, 14 Oct 2007 23:00:10 +0200
Local: Mon, Oct 15 2007 7:00 am
Subject: [Pywebsvcs-talk] Weird behaviour with complex types
Hi folks,

I'm trying to get some complex types to work between a very simple ZSI
SOAP server and client. So you know what I'm talking about, I've
placed the code at the bottom of this email.

When running the server & client, I get this output on the server:
calling the only exported method 'transfer', I get this (wrapped for
email)

$ ./zsi_server.py
transfer:
    Positional: ({'dest': u'dst', 'source': u'src', 'Amount':
           {'currency': u'EUR',
            'value': u'5322',
            'fractional_digits': u'2'}},)
    Named: {}
localhost - - [14/Oct/2007 22:48:03] "POST / HTTP/1.1" 500 -
localhost - - [14/Oct/2007 22:48:03] "POST / HTTP/1.1" 200 -

On the client I get the following output, again wrapped & indented for
email readability:

_________________________________ Sun Oct 14 22:48:03 2007 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:Body>
    <transfer>
      <dest id="ob7d95860" xsi:type="xsd:string">dst</dest>
      <source id="ob7d95820" xsi:type="xsd:string">src</source>
      <Amount>
        <currency xsi:type="xsd:string">EUR</currency>
        <value>5322</value>
        <fractional_digits>2</fractional_digits>
      </Amount>
    </transfer>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
_________________________________ Sun Oct 14 22:48:03 2007 RESPONSE:
500
Internal Server Error
-------
Server: ZSI/1.1 BaseHTTP/0.3 Python/2.5.1
Date: Sun, 14 Oct 2007 20:48:03 GMT
Content-type: text/xml; charset="utf-8"
Content-Length: 701

<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:Body>
    <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Client</faultcode>
      <faultstring>Unparseable message</faultstring>
      <detail>
        <Eob7925758>&lt;ZSI:ParseFaultDetail&gt;
        &lt;ZSI:string&gt;'int' object has no attribute 'typecode'&lt;/ZSI:string&gt;
        &lt;ZSI:trace&gt;&lt;/ZSI:trace&gt;
        &lt;/ZSI:ParseFaultDetail&gt;
    </Eob7925758>
      </detail>
    </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Traceback (most recent call last):
  File "./zsi_client.py", line 10, in <module>
    result = b.transfer(source='src', dest='dst', quantity=amount)
  File "/usr/lib/python2.5/site-packages/ZSI/client.py", line 64, in __call__
    **kw)
  File "/usr/lib/python2.5/site-packages/ZSI/client.py", line 171, in RPC
    return self.Receive(replytype, **kw)
  File "/usr/lib/python2.5/site-packages/ZSI/client.py", line 503, in Receive
    return _Binding.Receive(self, replytype, **kw)
  File "/usr/lib/python2.5/site-packages/ZSI/client.py", line 431, in Receive
    raise FaultException(msg)
ZSI.FaultException: Unparseable message
<ZSI:ParseFaultDetail>
<ZSI:string>'int' object has no attribute 'typecode'</ZSI:string>
<ZSI:trace></ZSI:trace>
</ZSI:ParseFaultDetail>

There are a few things weird here. First of all, I pass the third
parameter using the name 'quantity', but it arrives named 'Amount'.
How did that happen? Second, why do I get the parameters in a single
dictionary, instead of passed as simply named parameters? And why
can't I even return an integer?

I hope someone can help me out here, since I'm completely at a loss
how to fix this. To run my code, save the files then start "python
zsi_server.py" and then "python zsi_client.py". I've done this using
Python 2.5 and ZSI 2.0.

Greetings,
Sybren

-v--v--v--v--v--v--v--v--v- complextypes.py -v--v--v--v--v--v--v--v--v-
from ZSI import TC

TC.TypeCode.typechecks = False

class Amount(object):
    def __init__(self, currency, value, fractional_digits):
        '''Constructor'''

        self.currency = currency
        self.value = value
        self.fractional_digits = fractional_digits

    def __unicode__(self):
        return '''%s %.2f''' % (self.currency, float(self))

    def __str__(self):
        return unicode(self).encode('utf-8')

    def __repr__(self):
        return '''Amount('%s', %i, %i)''' % (self.currency,
                self.value, self.fractional_digits)

Amount.typecode = TC.Struct(Amount, [
          TC.String('currency'),
          TC.Integer('value'),
          TC.Integer('fractional_digits')],
          'Amount')
-^--^--^--^--^--^--^--^--^- complextypes.py -^--^--^--^--^--^--^--^--^-

As you can see, the complex type isn't that complex after all. Here is
the module with the only exported function:

-v--v--v--v--v--v--v--v--v- exported.py -v--v--v--v--v--v--v--v--v-
from complextypes import Amount

def transfer(*args, **kwargs):
    print 'transfer:'
    print '\tPositional: %s' % repr(args)
    print '\tNamed: %s' % repr(kwargs)
    return 0

-^--^--^--^--^--^--^--^--^- exported.py -^--^--^--^--^--^--^--^--^-

Here are the server and client applications:

-v--v--v--v--v--v--v--v--v- zsi_server.py -v--v--v--v--v--v--v--v--v-
#!/usr/bin/env python

import ZSI.dispatch

import complextypes
import exported

server = ZSI.dispatch.AsServer(
        port=8081,
        modules=[exported],
        typesmodule=complextypes)
server.server_forever()
-^--^--^--^--^--^--^--^--^- zsi_server.py -^--^--^--^--^--^--^--^--^-

-v--v--v--v--v--v--v--v--v- zsi_client.py -v--v--v--v--v--v--v--v--v-
#!/usr/bin/env python

from ZSI.client import NamedParamBinding as NPBinding
import sys

from complextypes import Amount

b = NPBinding(url='http://localhost:8081/', tracefile=sys.stdout)
amount = Amount('EUR', 5322, 2)
result = b.transfer(source='src', dest='dst', quantity=amount)

print "Result: %s" % result
-^--^--^--^--^--^--^--^--^- zsi_client.py -^--^--^--^--^--^--^--^--^-

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Pywebsvcs-talk mailing list
Pywebsvcs-t...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
Also archived at http://groups.google.com/group/pywebsvcs


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sybren Stüvel  
View profile  
 More options Oct 20 2007, 8:00 pm
From: Sybren Stüvel <syb...@stuvel.eu>
Date: Sat, 20 Oct 2007 12:00:49 +0200
Local: Sat, Oct 20 2007 8:00 pm
Subject: Re: [Pywebsvcs-talk] Weird behaviour with complex types
Hi Folks,

Is there nobody who can help me with this more or less trivial
bit of code?

Greetings,
Sybren

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Pywebsvcs-talk mailing list
Pywebsvcs-t...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
Also archived at http://groups.google.com/group/pywebsvcs

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joshua Boverhof  
View profile  
 More options Oct 21 2007, 7:42 am
From: Joshua Boverhof <jrbover...@lbl.gov>
Date: Sat, 20 Oct 2007 14:42:59 -0700
Local: Sun, Oct 21 2007 7:42 am
Subject: Re: [Pywebsvcs-talk] Weird behaviour with complex types
Looks like you need to change a couple things.  I think all of this  
is covered in the zsi developers guide, although probably not the 3rd  
point I make.  Please provide specific comments if you don't think it  
adequately or clearly dealt with these issues.

So with "zsi_server.py", unless everything you return has a typecode  
to describe it you need to use "rpc=True"

Secondly, with "exported.py" the return value needs to be either a  
list or a dict.

        return {'myInt':0}

is probably what you want.

Third, the complextypes.  If a typecode's pyclass is used to parse  
messages, it must have constructors that take only optional arguments.

        def __init__(self, currency=None, value=None, fractional_digits=None):

-josh

On Oct 20, 2007, at 3:00 AM, Sybren Stüvel wrote:

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Pywebsvcs-talk mailing list
Pywebsvcs-t...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
Also archived at http://groups.google.com/group/pywebsvcs

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sybren Stüvel  
View profile  
 More options Oct 22 2007, 2:45 am
From: Sybren Stüvel <syb...@stuvel.eu>
Date: Sun, 21 Oct 2007 18:45:39 +0200
Local: Mon, Oct 22 2007 2:45 am
Subject: Re: [Pywebsvcs-talk] Weird behaviour with complex types
Hi Josh & rest of the list,

Thanks for helping me out.

> I think all of this  is covered in the zsi developers guide,

You mean guide-zsi-2.0.pdf? It only covers cases concerning WSDL.
Since I'm not working from a WSDL file, I didn't read it. If there is
information in there that does apply in cases that don't use WSDL, I
recommend a change in chapter titles. Perhaps it should be merged with
zsi-2.0.pdf.

> So with "zsi_server.py", unless everything you return has a typecode
> to describe it you need to use "rpc=True"

Why isn't this described in any of the examples on the website nor in
zsi-2.0.pdf? I find the documentation lacking in describing *why*
something is done. It just gives examples without much explanation.

> Secondly, with "exported.py" the return value needs to be either a
> list or a dict.

This also isn't described. It is done as such, but it isn't explained
nor is any attention drawn to the fact that only lists or dicts can be
used. And why can Java SOAP services return integers, booleans and
strings, but is ZSI limited to lists or dicts?

> Third, the complextypes.  If a typecode's pyclass is used to parse
> messages, it must have constructors that take only optional
> arguments.

There is an example with a constructor that only takes optional
argument, but the documentation doesn't actually tell anyone that this
is *required*.

The documentation and ZSI software can be really improved if those
things are explained in the documentation and tested in the software.
For instance, the typecode class could check that the pyclass has a
constructor that can be called without arguments, for example by
introspection via ClassName.__init__.func_defaults or by simply
creating an instance of the class.

Greetings,
--
Sybren Stüvel
http://www.stuvel.eu/
http://www.flickr.com/photos/sybrenstuvel

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Pywebsvcs-talk mailing list
Pywebsvcs-t...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pywebsvcs-talk
Also archived at http://groups.google.com/group/pywebsvcs


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google