Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

The Python Web services developer, Part 3: Web services software repository, Part 2

A Web service for content updating

Return to article


Listing 5: A custom SOAP handler in 4Suite Server

import base64
from xml import xpath
from xml.dom import implementation, ext
from FtServer.Protocols.Http import SoapHandler

SOFTREPO_SOAP_NS = 'http://spam.com/softrepo'
DOCDEF = 'dublin_core'
URI_STEM = 'softrepo/incoming'
TEMPLATE = """<rdf:RDF
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1"
 xmlns="http://namespaces.4suite.org/www/software-map"
>
 <Software rdf:ID="%s">
 <dc:Title>%s</dc:Title>
 <dc:Creator>%s</dc:Creator>
 <Home rdf:resource="%s"/>
 <CurrentVersion>%s</CurrentVersion>
 <dc:Description>%s</dc:Description>
 </Software>
</rdf:RDF>
"""

def AddEntry(repo, reqbody, respbody):
 context = xpath.Context.Context(reqbody,
 processorNss={'s': SOFTREPO_SOAP_NS})
 title = xpath.Evaluate('string(s:Title)', context=context)
 creator = xpath.Evaluate('string(s:Creator)', context=context)
 home = xpath.Evaluate('string(s:Home)', context=context)
 version = xpath.Evaluate('string(s:Version)', context=context)
 desc = xpath.Evaluate('string(s:Description)', context=context)

 source = TEMPLATE%(title, title, creator, home, version, desc)
 uri = '%s/%s-%s.xml'%(URI_STEM, title, version)

 res = repo.createDocument(DOCDEF, uri, source)
 imt = res.getImt()
 result = respbody.ownerDocument.createElementNS(SOFTREPO_SOAP_NS, 'ftsoap:Document')
 result.setAttributeNS('', 'uri', res.getUri())
 result.setAttributeNS('', 'imt', res.getImt())
 result.appendChild(respbody.ownerDocument.createTextNode(base64.encodestring(source)))
 respbody.appendChild(result)
 return 1


class SoftRepoSoapHandler(SoapHandler.SoapHandler):
 NS_TO_HANDLER_MAPPING = {
 SOFTREPO_SOAP_NS: {'Add': AddEntry,
 },
 }


def Register(props):
 handler = SoftRepoSoapHandler()
 return [(handler.handle, 'POST')]

Return to article