<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:method="http://www.topxml.com/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<!-- add.xsl : Kafka SOAP Endpoint Example, with modifications -->
<!-- Import soap.xsl to use the framework -->
<xsl:import href="kafka/soap.xsl"/>
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
<!-- Define the global variables for the framework -->
<xsl:variable name="Method">Add</xsl:variable>
<xsl:variable name="MethodNS">http://www.topxml.com/</xsl:variable>
<!-- Add : Add two numbers and return the sum -->
<!-- Function Add( A as Double, B as Double ) as Double -->
<xsl:template name="ProcessPayload">
<xsl:param name="Payload"/>
<xsl:for-each select="$Payload">
<!-- This is how to retrieve parameters from the input -->
<xsl:variable name="A" select="number(A|method:A)"/>
<xsl:variable name="B" select="number(B|method:B)"/>
<!-- The WriteParameter template takes the qualified name
for a response parameter as well as its value and
a QName specifying the tpe (for the xsi:type attribute) -->
<xsl:call-template name="WriteParameter">
<xsl:with-param name="p" select="'Result'"/>
<xsl:with-param name="v" select="$A + $B"/>
<xsl:with-param name="t" select="'xsd:double'"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
#HTTP Listener code for SOAP server
import BaseHTTPServer
#The processor class is the core of the XSLT API
from Ft.Xml.Xslt import Processor
#4XSLT uses an InputSource system for reading XML
from Ft.Xml import InputSource
SOAP_IMPL_FILE = "add.xsl"
class KafkaSoapHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def init(cls):
from Ft.Lib import Uri
#Set up a processor instance to use
KafkaSoapHandler.processor = Processor.Processor()
#Load it with add.xsl
add_uri = Uri.OsPathToUri(SOAP_IMPL_FILE, attemptAbsolute=1)
transform = InputSource.DefaultFactory.fromUri(add_uri)
KafkaSoapHandler.processor.appendStylesheet(transform)
#Now the processor is prepped with a transform and can be used
#over and over for the same transform
return
#Make init() a static method of the class
init = classmethod(init)
def do_POST(self):
clen = self.headers.getheader('content-length')
if clen:
clen = int(clen)
else:
print 'POST ERROR: missing content-length'
return
if self.path != '/add':
self.send_error(404)
input_body = self.rfile.read(clen)
#input_body is the request SOAP envelope and contents
response_body = self._run_through_kafka(input_body)
#response_body is the response SOAP envelope and contents
self._send_response(200, 'OK', response_body)
return
def _run_through_kafka(self, body):
#In 4Suite all InputSources have base URIs in case they refer to
#other URIs in some way and resolution is required.
#The SOAP messages will not have any such URI references,
#So use a dummy base URI
source = InputSource.DefaultFactory.fromString(body, "urn:dummy")
response = self.processor.run(source)
return response
def _send_response(self, code, msg, body):
#Prepare a normal response
self.send_response(200, 'OK')
#Send standard HTP headers
self.send_header('Content-type','text/html; charset=utf-8')
self.send_header("Connection", "close")
self.send_header("Accept-Ranges", "bytes")
self.send_header('Content-length', len(body)-1)
self.end_headers()
#Send the response prepared by the SOAP end point
self.wfile.write(body)
return
listen_on_port = 8888
#Set up to run on local machine
server_address = ('127.0.0.1', listen_on_port)
KafkaSoapHandler.init()
httpd = BaseHTTPServer.HTTPServer(server_address, KafkaSoapHandler)
print "Listening on port", listen_on_port
#Go into a the main event loop
httpd.serve_forever()
import SOAPpy ENDPOINT = "http://localhost:8888/add" ADD_NS = "http://www.topxml.com/" remote = SOAPpy.SOAPProxy(ENDPOINT, namespace=ADD_NS) print "Add result:", remote.Add(A=3, B=4)
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="adder"
targetNamespace="http://www.topxml.com/"
xmlns:tns="http://www.topxml.com/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="Add">
<part name="A" type="xsd:double" />
<part name="B" type="xsd:double" />
</message>
<message name="AddResponse">
<part name="param" type="xsd:double" />
</message>
<portType name="adder-port-type">
<operation name="Add">
<input message="tns:Add" />
<output message="tns:AddResponse" />
</operation>
</portType>
<binding name="adder-soap-binding" type="tns:adder-port-type"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="rpc"/>
<operation name="Add">
<soap:operation soapAction="http://tempuri.org/"/>
<input>
<soap:body use="encoded" namespace="http://www.topxml.com/"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="http://www.topxml.com/"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="adder-service">
<port name="adder-port" binding="tns:adder-soap-binding">
<soap:address location="http://127.0.0.1:8888/add"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/>
</port>
</service>
</definitions>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version='1.0'
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>
<xsl:output method='html'/>
<!-- Lookup tables for messages, portTypes, bindings and services -->
<xsl:key name='message' match="wsdl:definitions/wsdl:message"
use='@name'/>
<xsl:key name='port-type' match="wsdl:definitions/wsdl:portType"
use='@name'/>
<xsl:key name='binding' match="wsdl:definitions/wsdl:binding"
use='@name'/>
<xsl:key name='service' match="wsdl:definitions/wsdl:service"
use='@name'/>
<xsl:template match='/'>
<html>
<head>
<title>
Service summary: <xsl:value-of select='wsdl:definitions/@name'/>
</title>
<meta http-equiv="content-type" content="text/html"
charset="UTF-8"/>
</head>
<body>
<h1>
Service summary: <xsl:value-of select='wsdl:definitions/@name'/>
</h1>
<p><xsl:value-of select='wsdl:definitions/@documentation'/></p>
<xsl:apply-templates select="wsdl:definitions/wsdl:service"/>
</body>
</html>
</xsl:template>
<xsl:template match='wsdl:service'>
<div style="background: #ccffff">
Service "<xsl:value-of select='@name'/>" hosted at
<code>
<xsl:value-of select='wsdl:port/soap:address/@location'/>
</code>
<xsl:variable name="binding"
select="key('binding',
substring-after(wsdl:port/@binding, ':'))"
/>
<xsl:variable name="port-type"
select="key('port-type',
substring-after($binding/@type, ':'))"
/>
<xsl:apply-templates select="$port-type/wsdl:operation"/>
</div>
</xsl:template>
<xsl:template match='wsdl:operation'>
<p>Operation "<b><xsl:value-of select='@name'/></b>" message details:</p>
<!-- Yes, should sue CSS, but keep this example simple -->
<table border="1" width="50%">
<tbody>
<xsl:if test="wsdl:input">
<xsl:call-template name='message-role'>
<xsl:with-param name="role-node" select="wsdl:input"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="wsdl:output">
<xsl:call-template name='message-role'>
<xsl:with-param name="role-node" select="wsdl:output"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="wsdl:fault">
<xsl:call-template name='message-role'>
<xsl:with-param name="role-node" select="wsdl:fault"/>
</xsl:call-template>
</xsl:if>
</tbody>
</table>
</xsl:template>
<xsl:template name='message-role'>
<xsl:param name="role-node"/>
<xsl:variable name="role-name"
select="local-name($role-node)"/>
<xsl:variable name="message"
select="key('message',
substring-after($role-node/@message, ':'))"
/>
<tr>
<td><xsl:value-of select='$role-name'/></td>
<td>
<table width="100%">
<xsl:apply-templates select="$message/wsdl:part"/>
</table>
</td>
</tr>
</xsl:template>
<xsl:template match='wsdl:part'>
<tr>
<td width="50%"><b><xsl:value-of select='@name'/></b></td>
<td><xsl:value-of select='@type'/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
#HTTP Listener code for SOAP server
import BaseHTTPServer
#The processor class is the core of the XSLT API
from Ft.Xml.Xslt import Processor
#4XSLT uses an InputSource system for reading XML
from Ft.Xml import InputSource
SOAP_IMPL_FILE = "add.xsl"
WSDL_FILE = "listing4.xml"
HTML_VIEW_TRANSFORM = "listing5.xslt"
class KafkaSoapHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def init(cls):
from Ft.Lib import Uri
#Set up a processor instance to use
cls.processor = Processor.Processor()
#Load it with add.xsl
add_uri = Uri.OsPathToUri(SOAP_IMPL_FILE, attemptAbsolute=1)
transform = InputSource.DefaultFactory.fromUri(add_uri)
cls.processor.appendStylesheet(transform)
#Now the processor is prepped with a transform and can be used
#over and over for the same transform
#Prep for WSDL requests
cls.wsdl = open(WSDL_FILE).read()
return
#Make init() a static method of the class
init = classmethod(init)
def do_POST(self):
clen = self.headers.getheader('content-length')
if clen:
clen = int(clen)
else:
print 'POST ERROR: missing content-length'
return
if self.path != '/add':
self.send_error(404)
input_body = self.rfile.read(clen)
#input_body is the request SOAP envelope and contents
response_body = self._run_through_kafka(input_body)
#response_body is the response SOAP envelope and contents
_send_response(self, 200, 'OK', response_body)
return
def do_GET(self):
#response_body is the WSDL file
_send_response(self, 200, 'OK', self.wsdl)
return
def _run_through_kafka(self, body):
#In 4Suite all InputSources have base URIs in case they refer to
#other URIs in some way and resolution is required.
#The SOAP messages will not have any such URI references,
#So use a dummy base URI
source = InputSource.DefaultFactory.fromString(body, "urn:dummy")
response = self.processor.run(source)
return response
class HtmlHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def init(cls):
from Ft.Lib import Uri
#Perform the transform once and store the result
processor = Processor.Processor()
html_desc_uri = Uri.OsPathToUri(HTML_VIEW_TRANSFORM,
attemptAbsolute=1)
transform = InputSource.DefaultFactory.fromUri(html_desc_uri)
processor.appendStylesheet(transform)
wsdl_uri = Uri.OsPathToUri(WSDL_FILE, attemptAbsolute=1)
source = InputSource.DefaultFactory.fromUri(wsdl_uri)
cls.html_desc = processor.run(source)
return
#Make init() a static class method
init = classmethod(init)
def do_GET(self):
#response_body is the WSDL file
_send_response(self, 200, 'OK', self.html_desc)
return
#Turn _send_response into a global function
#for sharing between the classes
def _send_response(handler, code, msg, body):
#Prepare a normal response
handler.send_response(200, 'OK')
#Send standard HTP headers
handler.send_header('Content-type', 'text/html; charset=utf-8')
handler.send_header("Connection", "close")
handler.send_header("Accept-Ranges", "bytes")
handler.send_header('Content-length', len(body)-1)
handler.end_headers()
#Send the response prepared by the SOAP end point
handler.wfile.write(body)
return
def soap_listener_function():
listen_on_port = 8888
#Set up to run on local machine
server_address = ('127.0.0.1', listen_on_port)
KafkaSoapHandler.init()
httpd = BaseHTTPServer.HTTPServer(server_address, KafkaSoapHandler)
print "Listening for GET and POST on port", listen_on_port
#Go into a the main event loop
httpd.serve_forever()
def html_listener_function():
listen_on_port = 9000
#Set up to run on local machine
server_address = ('127.0.0.1', listen_on_port)
HtmlHandler.init()
httpd = BaseHTTPServer.HTTPServer(server_address, HtmlHandler)
print "Listening for GET on port", listen_on_port
#Go into a the main event loop
httpd.serve_forever()
return
import time
from threading import Thread
soap_thread = Thread(None, soap_listener_function)
html_thread = Thread(None, html_listener_function)
soap_thread.start()
#Pause before spawning the next thread
time.sleep(1)
html_thread.start()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有