wsdl-reader 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/.gitignore +4 -0
  2. data/.idea/.name +1 -0
  3. data/.idea/.rakeTasks +7 -0
  4. data/.idea/encodings.xml +5 -0
  5. data/.idea/misc.xml +350 -0
  6. data/.idea/modules.xml +9 -0
  7. data/.idea/projectCodeStyle.xml +123 -0
  8. data/.idea/vcs.xml +7 -0
  9. data/.idea/workspace.xml +683 -0
  10. data/.idea/wsdl-reader.iml +25 -0
  11. data/.rspec +2 -0
  12. data/Gemfile +4 -0
  13. data/Guardfile +9 -0
  14. data/Rakefile +1 -0
  15. data/lib/wsdl-reader.rb +15 -0
  16. data/lib/wsdl-reader/binding.rb +148 -0
  17. data/lib/wsdl-reader/core_ext.rb +28 -0
  18. data/lib/wsdl-reader/error.rb +29 -0
  19. data/lib/wsdl-reader/message.rb +50 -0
  20. data/lib/wsdl-reader/parser.rb +105 -0
  21. data/lib/wsdl-reader/port_type.rb +106 -0
  22. data/lib/wsdl-reader/request.rb +213 -0
  23. data/lib/wsdl-reader/response.rb +72 -0
  24. data/lib/wsdl-reader/service.rb +56 -0
  25. data/lib/wsdl-reader/version.rb +5 -0
  26. data/lib/wsdl-reader/wsdl.rb +48 -0
  27. data/lib/wsdl-reader/xsd.rb +98 -0
  28. data/lib/wsdl-reader/xsd/complextype.rb +136 -0
  29. data/lib/wsdl-reader/xsd/convert.rb +142 -0
  30. data/lib/wsdl-reader/xsd/element.rb +168 -0
  31. data/lib/wsdl-reader/xsd/enumeration.rb +6 -0
  32. data/lib/wsdl-reader/xsd/restriction.rb +76 -0
  33. data/lib/wsdl-reader/xsd/sequence.rb +117 -0
  34. data/lib/wsdl-reader/xsd/simpletype.rb +83 -0
  35. data/spec/binding_spec.rb +67 -0
  36. data/spec/fixtures/OneFileUserService.wsdl +114 -0
  37. data/spec/fixtures/UserService.wsdl +63 -0
  38. data/spec/fixtures/UserService.xsd +56 -0
  39. data/spec/message_spec.rb +22 -0
  40. data/spec/parser_spec.rb +56 -0
  41. data/spec/port_type_spec.rb +32 -0
  42. data/spec/request_spec.rb +9 -0
  43. data/spec/spec_helper.rb +24 -0
  44. data/wsdl-reader.gemspec +27 -0
  45. metadata +122 -0
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="DBNavigator.Module.ConnectionManager">
4
+ <connections />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$" />
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.1.3, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
11
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.9.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.2.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v3.2.3, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="thor (v0.14.6, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.0.11, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.9.1, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.9.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.0.21, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v2.9.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="guard (v1.0.1, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="guard-rspec (v0.7.0, RVM: ruby-1.9.3-p0 [global]) [gem]" level="application" />
23
+ </component>
24
+ </module>
25
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+ gem 'activesupport'
3
+ # Specify your gem's dependencies in wsdl-reader.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/wsdl-reader/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ watch(%r{spec/fixtures/.+}) { "spec" }
9
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ require "active_support/core_ext/hash/keys"
2
+ require "wsdl-reader/version"
3
+ require "wsdl-reader/error"
4
+ require "wsdl-reader/parser"
5
+ require "wsdl-reader/request"
6
+
7
+ module WSDL
8
+ module Reader
9
+ def debugging?
10
+ false
11
+ end
12
+
13
+ module_function :debugging?
14
+ end
15
+ end
@@ -0,0 +1,148 @@
1
+ module WSDL
2
+ module Reader
3
+ class Bindings < Hash
4
+ def get_binding_for_operation_name(binding_name = nil, operation_name)
5
+ if binding_name.nil?
6
+ self.map do |_, binding|
7
+ binding if binding.operation?(operation_name)
8
+ end.flatten
9
+ else
10
+ [self[binding_name]] if self[binding_name].operation?(operation_name)
11
+ end
12
+ end
13
+
14
+ def get_operations(binding_name = nil)
15
+ if binding_name.nil?
16
+ all_operations
17
+ else
18
+ self[binding_name].operations.keys
19
+ end
20
+ end
21
+
22
+ def all_operations
23
+ self.map { |_, binding| binding.operations.keys }.flatten
24
+ end
25
+ end
26
+
27
+ class Binding
28
+ attr_reader :operations
29
+ attr_reader :name
30
+ attr_reader :type
31
+ attr_reader :style
32
+ attr_reader :transport
33
+
34
+ def initialize(element)
35
+ @operations = Hash.new
36
+ @name = element.attributes['name']
37
+ @type = element.attributes['type'] # because of Object#type
38
+ @style = nil
39
+ @transport = nil
40
+
41
+ # Process all binding and operation
42
+ element.find_all { |e| e.class == REXML::Element }.each { |operation|
43
+ case operation.name
44
+ when "binding" # soap:binding
45
+ store_style_and_transport(element, operation)
46
+
47
+ when "operation"
48
+ store_operation_name(element, operation)
49
+
50
+ operation.find_all { |e| e.class == REXML::Element }.each { |action|
51
+ store_action(action, element, operation)
52
+ }
53
+ else
54
+ warn "Ignoring element `#{operation.name}' in binding `#{element.attributes['name']}'"
55
+ end
56
+ }
57
+ end
58
+
59
+ def operation?(name)
60
+ operations.include? name
61
+ end
62
+
63
+ protected
64
+
65
+ def store_style_and_transport(element, operation)
66
+ operation.attributes.each do |name, value|
67
+ case name
68
+ when 'style'
69
+ @style = value
70
+ when 'transport'
71
+ @transport = value
72
+ else
73
+ warn "Ignoring attribute `#{name}' for wsdlsoap:binding in binding `#{element.attributes['name']}'"
74
+ end
75
+ end
76
+ end
77
+
78
+ def store_operation_name(element, operation)
79
+ operation.attributes.each do |name, value|
80
+ case name
81
+ when 'name'
82
+ current_operation(operation)[:name] = value
83
+ else
84
+ warn "Ignoring attribute `#{name}' for operation `#{operation.attributes['name']}' in binding `#{element.attributes['name']}'"
85
+ end
86
+ end
87
+ end
88
+
89
+ def fill_action(action, operation)
90
+ filling_action = { }
91
+
92
+ action.attributes.each do |name, value|
93
+ case name
94
+ when 'name'
95
+ filling_action[:name] = value
96
+ else
97
+ warn "Ignoring attribute `#{name}' in #{action.name} `#{action.attributes['name']}' in operation `#{operation.attributes['name']}' for binding `#{element.attributes['name']}'"
98
+ end
99
+ end
100
+
101
+ # Store body
102
+ action.find_all { |e| e.class == REXML::Element }.each do |body|
103
+ case body.name
104
+ when "body"
105
+ filling_action[:body] = { }
106
+
107
+ body.attributes.each { |name, value| filling_action[:body][name.to_sym] = value }
108
+ else
109
+ warn "Ignoring element `#{body.name}' in #{action.name} `#{action.attributes['name']}' in operation `#{operation.attributes['name']}' for binding `#{element.attributes['name']}'"
110
+ end
111
+ end
112
+ filling_action
113
+ end
114
+
115
+ def store_action(action, element, operation)
116
+ case action.name
117
+ when "operation" # soap:operation
118
+ action.attributes.each do |name, value|
119
+ case name
120
+ when 'soapAction'
121
+ current_operation(operation)[:soapAction] = value
122
+ when 'style'
123
+ current_operation(operation)[:style] = value
124
+ else
125
+ warn "Ignoring attribut `#{name}' for wsdlsoap:operation in operation `#{operation.attributes['name']}' in binding `#{element.attributes['name']}'"
126
+ end
127
+ end
128
+ when "input"
129
+ current_operation(operation)[:input] = fill_action(action, operation)
130
+
131
+ when "output"
132
+ current_operation(operation)[:output] = fill_action(action, operation)
133
+
134
+ when "fault"
135
+ current_operation(operation)[:fault] = fill_action(action, operation)
136
+
137
+ else
138
+ warn "Ignoring element `#{action.name}' in operation `#{operation.attributes['name']}' for binding `#{element.attributes['name']}'"
139
+ end
140
+ end
141
+
142
+ def current_operation(operation)
143
+ @operations[operation.attributes['name']] ||= { }
144
+ end
145
+
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,28 @@
1
+ class String #:nodoc:
2
+ def nns
3
+ self.gsub( /^[^:]*:/, "" )
4
+ end
5
+ end
6
+
7
+ class Hash #:nodoc:
8
+ def keys_to_sym!( )
9
+ self.each {|k, v|
10
+ self.delete(k)
11
+ self[k.to_sym] = v
12
+ }
13
+ end
14
+
15
+ def kvTable( k, v )
16
+ self[k] = v
17
+ # if( self.keys.include?(k) )
18
+ # if self[k].class == Array
19
+ # self[k] << v
20
+ # else
21
+ # self[k] = [self[k], v]
22
+ # end
23
+ # else
24
+ # self[k] = v
25
+ # end
26
+ end
27
+ end
28
+
@@ -0,0 +1,29 @@
1
+ module WSDL
2
+ module Reader
3
+ class ParserError < StandardError
4
+ end
5
+
6
+ class FileOpenError < ParserError
7
+ end
8
+ end
9
+ end
10
+
11
+ module SOAP
12
+ class LCError < RuntimeError
13
+ end
14
+
15
+ class LCWSDLError < NameError
16
+ end
17
+
18
+ class LCNoMethodError < NoMethodError
19
+ end
20
+
21
+ class LCArgumentError < ArgumentError
22
+ end
23
+
24
+ class LCElementError < NameError
25
+ end
26
+
27
+ class LCTypeError < NameError
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ module WSDL
2
+ module Reader
3
+ class Messages < Hash
4
+ end
5
+
6
+ class Message
7
+ attr_reader :parts
8
+ attr_reader :name
9
+
10
+ def initialize(element)
11
+ @parts = Hash.new
12
+ @name = element.attributes['name']
13
+
14
+ process_all_parts element
15
+ end
16
+
17
+ protected
18
+
19
+ def process_all_parts(element)
20
+ element.select { |e| e.class == REXML::Element }.each do |part|
21
+ case part.name
22
+ when "part"
23
+ @parts[part.attributes['name']] = Hash.new
24
+ store_part_attributes(part)
25
+ else
26
+ warn "Ignoring element `#{part.name}' in message `#{element.attributes['name']}'"
27
+ end
28
+ end
29
+ end
30
+
31
+ def store_part_attributes(part)
32
+ current_part = @parts[part.attributes['name']]
33
+ part.attributes.each do |name, value|
34
+ case name
35
+ when 'name'
36
+ current_part[:name] = value
37
+ when 'element'
38
+ current_part[:element] = value
39
+ current_part[:mode] = :element
40
+ when 'type'
41
+ current_part[:type] = value
42
+ current_part[:mode] = :type
43
+ else
44
+ warn "Ignoring attribute `#{name}' in part `#{part.attributes['name']}' for message `#{element.attributes['name']}'"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,105 @@
1
+ require 'open-uri'
2
+ require 'rexml/document'
3
+
4
+ require 'wsdl-reader/message'
5
+ require 'wsdl-reader/port_type'
6
+ require 'wsdl-reader/binding'
7
+ require 'wsdl-reader/service'
8
+ require 'wsdl-reader/xsd'
9
+
10
+ module WSDL
11
+ module Reader
12
+ class Parser
13
+ attr_reader :types, :messages, :port_types, :bindings, :services
14
+ attr_reader :prefixes, :target_namespace
15
+ attr_reader :document, :uri
16
+
17
+ def initialize(uri)
18
+ @uri = uri
19
+ @types = SOAP::XSD.new()
20
+ @messages = WSDL::Reader::Messages.new
21
+ @port_types = WSDL::Reader::PortTypes.new
22
+ @bindings = WSDL::Reader::Bindings.new
23
+ @services = SOAP::WSDL::Services.new
24
+
25
+ @prefixes = Hash.new
26
+ @target_namespace = ""
27
+
28
+ @document = REXML::Document.new(get_wsdl_source)
29
+
30
+ process_attributes @document.root.attributes
31
+ process_content @document.root.children
32
+ end
33
+
34
+ private
35
+
36
+ def get_wsdl_source
37
+ # Get WSDL
38
+ source = nil
39
+ begin
40
+ open(uri) { |f| source = f.read }
41
+ rescue Errno::ECONNREFUSED, Errno::ENOENT, OpenURI::HTTPError => e
42
+ raise WSDL::Reader::FileOpenError, "Can't open '#{uri}' : #{e.message}"
43
+ end
44
+ source
45
+ end
46
+
47
+ def process_attributes(attributes)
48
+ @target_namespace = attributes["targetNamespace"]
49
+
50
+ attributes.values.each do |attribute|
51
+ if attribute.prefix == "xmlns" then
52
+ @prefixes[attribute.name] = attribute.value
53
+ end
54
+ end
55
+
56
+ if (default_namespace = attributes["xmlns"]) then
57
+ @prefixes["__default__"] = default_namespace
58
+ end
59
+ end
60
+
61
+ def process_content(elements)
62
+ elements.find_all { |e| e.class == REXML::Element }.each do |element|
63
+ case element.name
64
+ when "types"
65
+ process_types(element)
66
+ when "message"
67
+ process_message(element)
68
+ when "portType"
69
+ process_port_type(element)
70
+ when "binding"
71
+ process_binding(element)
72
+ when "service"
73
+ process_service(element)
74
+ else
75
+ warn "Ignoring #{element} in #{__FILE__}:#{__LINE__}"
76
+ end
77
+ end
78
+ end
79
+
80
+ def process_types(element)
81
+ @types.add_schema(element)
82
+ end
83
+
84
+ def process_message(element)
85
+ name = element.attributes['name']
86
+ @messages[name] = WSDL::Reader::Message.new(element)
87
+ end
88
+
89
+ def process_port_type(element)
90
+ name = element.attributes['name']
91
+ @port_types[name] = WSDL::Reader::PortType.new(element)
92
+ end
93
+
94
+ def process_binding(element)
95
+ name = element.attributes['name']
96
+ @bindings[name] = WSDL::Reader::Binding.new(element)
97
+ end
98
+
99
+ def process_service(element)
100
+ name = element.attributes['name']
101
+ @services[name] = SOAP::WSDL::Service.new(element)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,106 @@
1
+ module WSDL
2
+ module Reader
3
+ class PortTypes < Hash
4
+ end
5
+
6
+ class PortType
7
+ attr_reader :operations
8
+ attr_reader :name
9
+
10
+ def initialize(element)
11
+ @operations = Hash.new
12
+ @name = element.attributes['name']
13
+
14
+ process_all_operations(element)
15
+ end
16
+
17
+ protected
18
+
19
+ def store_attributes(element, operation)
20
+ operation.attributes.each { |name, value|
21
+ case name
22
+ when 'name'
23
+ @operations[operation.attributes['name']][:name] = value
24
+ else
25
+ warn "Ignoring attribut '#{name}' in operation '#{operation.attributes['name']}' for portType '#{element.attributes['name']}'"
26
+ end
27
+ }
28
+ end
29
+
30
+ def store_input(action, element, operation)
31
+ @operations[operation.attributes['name']][:input] = Hash.new
32
+ action.attributes.each do |name, value|
33
+ case name
34
+ when 'name'
35
+ @operations[operation.attributes['name']][:input][:name] = value
36
+ when 'message'
37
+ @operations[operation.attributes['name']][:input][:message] = value
38
+ else
39
+ warn_ignoring(action, element, name, operation)
40
+ end
41
+ end
42
+ end
43
+
44
+ def store_output(action, element, operation)
45
+ @operations[operation.attributes['name']][:output] = Hash.new
46
+ action.attributes.each { |name, value|
47
+ case name
48
+ when 'name'
49
+ @operations[operation.attributes['name']][:output][:name] = value
50
+ when 'message'
51
+ @operations[operation.attributes['name']][:output][:message] = value
52
+ else
53
+ warn_ignoring(action, element, name, operation)
54
+ end
55
+ }
56
+ end
57
+
58
+ def store_fault(action, element, operation)
59
+ @operations[operation.attributes['name']][:fault] = Hash.new
60
+ action.attributes.each { |name, value|
61
+ case name
62
+ when 'name'
63
+ @operations[operation.attributes['name']][:fault][:name] = value
64
+ when 'message'
65
+ @operations[operation.attributes['name']][:fault][:message] = value
66
+ else
67
+ warn_ignoring(action, element, name, operation)
68
+ end
69
+ }
70
+ end
71
+
72
+ def process_all_operations(element)
73
+ element.find_all { |e| e.class == REXML::Element }.each do |operation|
74
+ case operation.name
75
+ when "operation"
76
+ @operations[operation.attributes['name']] = Hash.new
77
+
78
+ store_attributes(element, operation)
79
+
80
+ operation.find_all { |e| e.class == REXML::Element }.each do |action|
81
+ case action.name
82
+ when "input"
83
+ store_input(action, element, operation)
84
+
85
+ when "output"
86
+ store_output(action, element, operation)
87
+
88
+ when "fault"
89
+ store_fault(action, element, operation)
90
+
91
+ else
92
+ warn "Ignoring element '#{action.name}' in operation '#{operation.attributes['name']}' for portType '#{element.attributes['name']}'"
93
+ end
94
+ end
95
+ else
96
+ warn "Ignoring element '#{operation.name}' in portType '#{element.attributes['name']}'"
97
+ end
98
+ end
99
+ end
100
+
101
+ def warn_ignoring(action, element, name, operation)
102
+ warn "Ignoring attribute '#{name}' in #{action.name} '#{action.attributes['name']}' in operation '#{operation.attributes['name']}' for portType '#{element.attributes['name']}'"
103
+ end
104
+ end
105
+ end
106
+ end