In order to template the discovery message in ruby we manipulate the template string using XML.
The following code convert the template from string to XML , manipulate the service name and name space and convert it back to string representation .
require 'rexml/document'
def TempalteProbeMsg (pMsg)
doc = REXML::Document.new(pMsg)
theElment = doc.root.elements['s:Body/Probe/d:Types']
theElment.text = 'dp0:IMyServiceToProbe'
theElment.attributes["xmlns:dp0"] ="Com.myCompany.Services"
return doc.root.to_s
end
The following code convert the template from string to XML , manipulate the service name and name space and convert it back to string representation .
require 'rexml/document'
def TempalteProbeMsg (pMsg)
doc = REXML::Document.new(pMsg)
theElment = doc.root.elements['s:Body/Probe/d:Types']
theElment.text = 'dp0:IMyServiceToProbe'
theElment.attributes["xmlns:dp0"] ="Com.myCompany.Services"
return doc.root.to_s
end
The probe message before templating
envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Hello</a:Action>
<h:AppSequence InstanceId="1369239226" MessageNumber="1" xmlns:h="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01"/>
<a:MessageID>urn:uuid:bc95d269-a20f-4d7b-b5bd-c31698dd9569</a:MessageID>
<a:To s:mustUnderstand="1">urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01</a:To>
</s:Header>
<s:Body>
<Hello xmlns="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01">
<a:EndpointReference>
<a:Address>http://localhost:8989/myService</a:Address>
</a:EndpointReference>
<d:Types xmlns:d="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01" xmlns:dp0="Com.myCompany.Services">dp0:IMyServiceAlias</d:Types>
<XAddrs>http://localhost:8989/myService</XAddrs>
<MetadataVersion>0</MetadataVersion>
</Hello>
</s:Body>
</s:Envelope>
<s:Header>
<a:Action s:mustUnderstand="1">http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01/Hello</a:Action>
<h:AppSequence InstanceId="1369239226" MessageNumber="1" xmlns:h="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01"/>
<a:MessageID>urn:uuid:bc95d269-a20f-4d7b-b5bd-c31698dd9569</a:MessageID>
<a:To s:mustUnderstand="1">urn:docs-oasis-open-org:ws-dd:ns:discovery:2009:01</a:To>
</s:Header>
<s:Body>
<Hello xmlns="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01">
<a:EndpointReference>
<a:Address>http://localhost:8989/myService</a:Address>
</a:EndpointReference>
<d:Types xmlns:d="http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01" xmlns:dp0="Com.myCompany.Services">dp0:IMyServiceAlias</d:Types>
<XAddrs>http://localhost:8989/myService</XAddrs>
<MetadataVersion>0</MetadataVersion>
</Hello>
</s:Body>
</s:Envelope>
The probe message after templating
<s:Envelope xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:s='http://www.w
3.org/2003/05/soap-envelope'>
<s:Header>
<a:Action s:mustUnderstand='1'>http://docs.oasis-open.org/ws-dd/ns/discove
ry/2009/01/Probe</a:Action>
<a:MessageID>urn:uuid:4faf9212-2449-43bd-9cfb-9cf8b12300d1</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand='1'>urn:docs-oasis-open-org:ws-dd:ns:discovery:2009
:01</a:To>
</s:Header>
<s:Body>
<Probe xmlns='http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01'>
<d:Types xmlns:d='http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01'
xmlns:dp0='Com.myCompany.Services'>dp0:IMyServiceToProbe</d:Types>
<Duration xmlns='http://schemas.microsoft.com/ws/2008/06/discovery'>PT5S
</Duration>
</Probe>
</s:Body>
</s:Envelope>
3.org/2003/05/soap-envelope'>
<s:Header>
<a:Action s:mustUnderstand='1'>http://docs.oasis-open.org/ws-dd/ns/discove
ry/2009/01/Probe</a:Action>
<a:MessageID>urn:uuid:4faf9212-2449-43bd-9cfb-9cf8b12300d1</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand='1'>urn:docs-oasis-open-org:ws-dd:ns:discovery:2009
:01</a:To>
</s:Header>
<s:Body>
<Probe xmlns='http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01'>
<d:Types xmlns:d='http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01'
xmlns:dp0='Com.myCompany.Services'>dp0:IMyServiceToProbe</d:Types>
<Duration xmlns='http://schemas.microsoft.com/ws/2008/06/discovery'>PT5S
</Duration>
</Probe>
</s:Body>
</s:Envelope>
אין תגובות:
הוסף רשומת תגובה