Class: Handsoap::Parser::Wsdl
- Inherits:
-
Object
- Object
- Handsoap::Parser::Wsdl
- Defined in:
- lib/handsoap/parser.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #bindings ⇒ Object
- #endpoints ⇒ Object
-
#initialize(doc, url = "void://") ⇒ Wsdl
constructor
A new instance of Wsdl.
- #interface ⇒ Object
- #interfaces ⇒ Object
- #preferred_protocol ⇒ Object
- #service ⇒ Object
- #target_ns ⇒ Object
Constructor Details
#initialize(doc, url = "void://") ⇒ Wsdl
Returns a new instance of Wsdl.
67 68 69 70 |
# File 'lib/handsoap/parser.rb', line 67 def initialize(doc, url = "void://") @doc = doc @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
65 66 67 |
# File 'lib/handsoap/parser.rb', line 65 def url @url end |
Class Method Details
.read(url) ⇒ Object
72 73 74 |
# File 'lib/handsoap/parser.rb', line 72 def self.read(url) self.new(Nokogiri.XML(Kernel.open(url).read), url) end |
Instance Method Details
#bindings ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/handsoap/parser.rb', line 177 def bindings @doc.xpath("//wsdl1:binding|//wsdl2:binding", ns).map do |binding| raise "WSDL 2.0 not supported" if is_wsdl2?(binding) soap_binding = binding.xpath("./soap11:binding|./soap12:binding|./http:binding", ns).first protocol = protocol_from_ns(soap_binding) actions = [] style = nil encoding = nil actions = binding.xpath("./wsdl1:operation", ns).map do |operation| soap_operation = operation.xpath("./soap11:operation|./soap12:operation|./http:operation", ns).first if soap_operation[:style] raise "Mixed styles not supported" if style && style != soap_operation[:style] style = soap_operation[:style] end xquery = [] ['soap11', 'soap12', 'http'].each do |version| ['input', 'output'].each do || ['header', 'body'].each do |part_name| xquery << "./wsdl1:#{}/#{version}:#{part_name}" end end end operation.xpath(xquery.join('|'), ns).each do |thing| raise "Mixed encodings not supported" if encoding && encoding != thing[:use] encoding = thing[:use] end Action.new( operation[:name], :soap_action => soap_operation[:soapAction], :location => soap_operation[:location]) end Binding.new( binding[:name], :protocol => protocol, :interface => binding[:type], :transport => soap_binding[:transport], :style => style, :encoding => encoding, :verb => soap_binding[:verb], :actions => actions) end end |
#endpoints ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/handsoap/parser.rb', line 162 def endpoints @doc.xpath("//wsdl1:service/wsdl1:port|//wsdl2:service/wsdl2:endpoint", ns).map do |port| binding = port[:binding] if is_wsdl2?(port) location = port[:address] protocol = :binding else address = port.xpath("./soap11:address|./soap12:address|./http:address", ns).first location = address[:location] protocol = protocol_from_ns(address) end Endpoint.new(port[:name], protocol, binding, location) end end |
#interface ⇒ Object
121 122 123 124 125 |
# File 'lib/handsoap/parser.rb', line 121 def interface tmp = interfaces raise "Expected exactly 1 interface/portType in WSDL" if tmp.length != 1 tmp[0] end |
#interfaces ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/handsoap/parser.rb', line 142 def interfaces @doc.xpath("//wsdl1:portType|//wsdl2:interface", ns).map do |port_type| operations = port_type.xpath("./wsdl1:operation|./wsdl2:operation", ns).map do |operation| if is_wsdl2?(operation) input_node = operation.xpath("./wsdl2:input", ns).first input = input_node ? input_node[:element] : nil output_node = operation.xpath("./wsdl2:output", ns).first output = output_node ? output_node[:element] : nil else input_node = operation.xpath("./wsdl1:input", ns).first input = input_node ? input_node[:message] : nil output_node = operation.xpath("./wsdl1:output", ns).first output = output_node ? output_node[:message] : nil end Operation.new(operation[:name], :input => input, :output => output) end Interface.new(port_type[:name], operations) end end |
#preferred_protocol ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/handsoap/parser.rb', line 131 def preferred_protocol e = endpoints if e.select { |endpoint| endpoint.protocol == :soap12 }.any? :soap12 elsif e.select { |endpoint| endpoint.protocol == :soap11 }.any? :soap11 else raise "Can't find any soap 1.1 or soap 1.2 endpoints" end end |
#service ⇒ Object
115 116 117 118 119 |
# File 'lib/handsoap/parser.rb', line 115 def service services = @doc.xpath("//wsdl1:service|//wsdl2:service", ns) raise "Expected exactly 1 service in WSDL" if services.length != 1 services[0][:name] end |
#target_ns ⇒ Object
127 128 129 |
# File 'lib/handsoap/parser.rb', line 127 def target_ns @doc.root[:targetNamespace] || raise("Attribute targetNamespace not defined") end |