Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

moved Savon::WSDLStream into its own file

  • Loading branch information...
commit 0d1e3bd20406f85e4ea71c8c24201eab4d34877a 1 parent be023be
Daniel Harrington rubiii authored
2  lib/savon.rb
@@ -29,6 +29,6 @@ class SOAPFault < StandardError; end
29 29 end
30 30
31 31 # core files
32   -%w(core_ext wsse soap request response wsdl client).each do |file|
  32 +%w(core_ext wsse soap request response wsdl_stream wsdl client).each do |file|
33 33 require File.dirname(__FILE__) + "/savon/#{file}"
34 34 end
89 lib/savon/wsdl.rb
@@ -62,93 +62,4 @@ def stream
62 62 end
63 63
64 64 end
65   -
66   - # Savon::WSDLStream
67   - #
68   - # Stream listener for parsing the WSDL document.
69   - class WSDLStream
70   -
71   - # The main sections of a WSDL document.
72   - Sections = %w(definitions types message portType binding service)
73   -
74   - def initialize
75   - @path, @operations = [], {}
76   - @namespaces = {}
77   - end
78   -
79   - # Returns the namespace URI.
80   - attr_reader :namespace_uri
81   -
82   - # Returns the SOAP operations.
83   - attr_reader :operations
84   -
85   - # Returns the SOAP endpoint.
86   - attr_reader :soap_endpoint
87   -
88   - # Hook method called when the stream parser encounters a starting tag.
89   - def tag_start(tag, attrs)
90   -
91   - # read xml namespaces if root element
92   - read_namespaces(attrs) if @path.empty?
93   -
94   - tag,namespace = tag.split(":").reverse
95   -
96   - @path << tag
97   -
98   - if @section == :binding && tag=="binding"
99   - # ensure that we are in an wsdl/soap namespace
100   - @section = nil unless @namespaces[namespace] == "http://schemas.xmlsoap.org/wsdl/soap/"
101   - end
102   -
103   - @section = tag.to_sym if Sections.include?(tag) if depth <= 2
104   -
105   - @namespace_uri ||= attrs["targetNamespace"] if @section == :definitions
106   - @soap_endpoint ||= URI(attrs["location"]) if @section == :service && tag == "address"
107   -
108   - operation_from tag, attrs if @section == :binding && tag == "operation"
109   - end
110   -
111   - def depth
112   - @path.size
113   - end
114   -
115   - # read namespace definitions from given hash
116   - def read_namespaces(attrs)
117   - for key, value in attrs
118   - if key.start_with?("xmlns:")
119   - @namespaces[key.split(':').last] = value
120   - end
121   - end
122   - end
123   -
124   - # Hook method called when the stream parser encounters a closing tag.
125   - def tag_end(tag)
126   - @path.pop
127   -
128   - if @section == :binding && @input && tag.strip_namespace == "operation"
129   - # no soapAction attribute found till now
130   - operation_from tag, "soapAction" => @input
131   - end
132   -
133   - end
134   -
135   - # Stores available operations from a given tag +name+ and +attrs+.
136   - def operation_from(tag, attrs)
137   - @input = attrs["name"] if attrs["name"]
138   -
139   - if attrs["soapAction"]
140   - @action = !attrs["soapAction"].blank? ? attrs["soapAction"] : @input
141   - @input = @action.split("/").last if !@input || @input.empty?
142   -
143   - @operations[@input.snakecase.to_sym] = { :action => @action, :input => @input }
144   - @input, @action = nil, nil
145   - @input = nil
146   - end
147   - end
148   -
149   - # Catches calls to unimplemented hook methods.
150   - def method_missing(method, *args)
151   - end
152   -
153   - end
154 65 end
88 lib/savon/wsdl_stream.rb
... ... @@ -0,0 +1,88 @@
  1 +module Savon
  2 +
  3 + # Savon::WSDLStream
  4 + #
  5 + # Stream listener for parsing the WSDL document.
  6 + class WSDLStream
  7 +
  8 + # The main sections of a WSDL document.
  9 + Sections = %w(definitions types message portType binding service)
  10 +
  11 + def initialize
  12 + @path, @operations = [], {}
  13 + @namespaces = {}
  14 + end
  15 +
  16 + # Returns the namespace URI.
  17 + attr_reader :namespace_uri
  18 +
  19 + # Returns the SOAP operations.
  20 + attr_reader :operations
  21 +
  22 + # Returns the SOAP endpoint.
  23 + attr_reader :soap_endpoint
  24 +
  25 + # Hook method called when the stream parser encounters a starting tag.
  26 + def tag_start(tag, attrs)
  27 + # read xml namespaces if root element
  28 + read_namespaces(attrs) if @path.empty?
  29 +
  30 + tag,namespace = tag.split(":").reverse
  31 + @path << tag
  32 +
  33 + if @section == :binding && tag == "binding"
  34 + # ensure that we are in an wsdl/soap namespace
  35 + @section = nil unless @namespaces[namespace] == "http://schemas.xmlsoap.org/wsdl/soap/"
  36 + end
  37 +
  38 + @section = tag.to_sym if Sections.include?(tag) && depth <= 2
  39 +
  40 + @namespace_uri ||= attrs["targetNamespace"] if @section == :definitions
  41 + @soap_endpoint ||= URI(attrs["location"]) if @section == :service && tag == "address"
  42 +
  43 + operation_from tag, attrs if @section == :binding && tag == "operation"
  44 + end
  45 +
  46 + # Returns our current depth in the WSDL document.
  47 + def depth
  48 + @path.size
  49 + end
  50 +
  51 + # Reads namespace definitions from a given +attrs+ Hash.
  52 + def read_namespaces(attrs)
  53 + attrs.each do |key, value|
  54 + @namespaces[key.split(":").last] = value if key.start_with? "xmlns:"
  55 + end
  56 + end
  57 +
  58 + # Hook method called when the stream parser encounters a closing tag.
  59 + def tag_end(tag)
  60 + @path.pop
  61 +
  62 + if @section == :binding && @input && tag.strip_namespace == "operation"
  63 + # no soapAction attribute found till now
  64 + operation_from tag, "soapAction" => @input
  65 + end
  66 +
  67 + end
  68 +
  69 + # Stores available operations from a given tag +name+ and +attrs+.
  70 + def operation_from(tag, attrs)
  71 + @input = attrs["name"] if attrs["name"]
  72 +
  73 + if attrs["soapAction"]
  74 + @action = !attrs["soapAction"].blank? ? attrs["soapAction"] : @input
  75 + @input = @action.split("/").last if !@input || @input.empty?
  76 +
  77 + @operations[@input.snakecase.to_sym] = { :action => @action, :input => @input }
  78 + @input, @action = nil, nil
  79 + @input = nil
  80 + end
  81 + end
  82 +
  83 + # Catches calls to unimplemented hook methods.
  84 + def method_missing(method, *args)
  85 + end
  86 +
  87 + end
  88 +end

0 comments on commit 0d1e3bd

Please sign in to comment.
Something went wrong with that request. Please try again.