SOAP/ZSI post/get for Java Web App

Jennifer Duerr jenn.duerr at gmail.com
Wed May 14 14:10:37 EDT 2008


On May 14, 12:59 pm, Waldemar Osuch <waldemar.os... at gmail.com> wrote:
> On May 13, 1:02 pm, Jennifer Duerr <jenn.du... at gmail.com> wrote:
>
>
>
>
>
> > All,
>
> > I need help concerning SOAP, Python and XML. I am very new to this, so
> > dumbing it down for me will not offend me!
>
> > I'm using Python and want to send a user-inputted string to an
> > existing Java web app that
> > will output results to XML. I need to capture elements of the XML and
> > put
> > the info into a table. (say I send a single/simple address string to
> > this
> > webservice/geocode, which then returns numerous possible matches with
> > XY
> > values and score values, and I want to capture that into a table)
>
> > How do I go about doing this? I'm told I need to use SOAP. I
> > discovered that
> > the best module to use is ZSI (please correct me if I'm wrong). I have
> > installed the necessary module. Examples I have seen are plenty and
> > all so different, its not clear to me how to go about.  I have been
> > spinning my wheels for too long on this!
>
> > Can someone provide some example code similar to what I need to do? Or
> > any
> > guidance would be appreciated.
>
> > Thanks!
>
> It looks like you have three tasks here:
>  - get data
>  - parse it
>  - store it
>
> SOAP could be the means to accomplish only the first one.
>
> If the service you use exposes the functionality using XML-RPC or some
> REST-ful methods I would try them first.  If it does not, then
> you are stuck with SOAP. Using SOAP in Python is currently
> not as straightforward as it could be.
>
> You have chosen to use ZSI and that is fine choice.
> In documentation look for "wsdl2py".
> Given a URL to a WSDL file it will generate stub class definition
> with methods corresponding to the SOAP service methods.
> In your code you would instantiate the class, call the method you want
> and grab the payload.  Your first task is done.
>
> From what I understand the payload will be XML that will need to be
> parsed.  For that you could use the excellent ElementTree
>
> If I were you I would investigate suds (https://fedorahosted.org/suds)
> It promises to be easier to use than ZSI.  The README has the usage
> example.
>
> Waldemar- Hide quoted text -
>
> - Show quoted text -

Thanks for your reply.
I got some help from a fellow co-worker.  We worked out this, so far.
Seems to be working...

[[my url is local, so use another, and also then choose an appropriate
value for the user_input var]]
import urllib, urllib2
from xml.dom import minidom

user_input = 'xyz'
url = 'http://xxx.....' #geocoding servlet url
values = {'address': user_input} #

data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
xmlResults = response.read()
#print xmlResults

xmldoc = minidom.parseString(xmlResults)
places = xmldoc.getElementsByTagName('Placemark')

nameTag = places[0].getElementsByTagName('name')
print nameTag[0].firstChild.wholeText

descriptionTag = places[0].getElementsByTagName('description')
print descriptionTag[0].firstChild.wholeText

coordinatesTag = places[0].getElementsByTagName('coordinates')
print coordinatesTag[0].firstChild.wholeText



More information about the Python-list mailing list