soap4r 1.5.6 → 1.5.7

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 (69) hide show
  1. data/bin/wsdl2ruby.rb +1 -1
  2. data/bin/xsd2ruby.rb +12 -4
  3. data/lib/soap/baseData.rb +3 -1
  4. data/lib/soap/encodingstyle/literalHandler.rb +3 -2
  5. data/lib/soap/encodingstyle/soapHandler.rb +7 -4
  6. data/lib/soap/filter.rb +4 -1
  7. data/lib/soap/filter/filterchain.rb +1 -1
  8. data/lib/soap/filter/streamhandler.rb +29 -0
  9. data/lib/soap/generator.rb +6 -0
  10. data/lib/soap/httpconfigloader.rb +21 -6
  11. data/lib/soap/mapping/encodedregistry.rb +2 -1
  12. data/lib/soap/mapping/literalregistry.rb +31 -16
  13. data/lib/soap/mapping/registry.rb +5 -1
  14. data/lib/soap/mapping/rubytypeFactory.rb +3 -0
  15. data/lib/soap/mapping/wsdlliteralregistry.rb +3 -3
  16. data/lib/soap/netHttpClient.rb +6 -0
  17. data/lib/soap/rpc/router.rb +26 -17
  18. data/lib/soap/soap.rb +4 -4
  19. data/lib/soap/streamHandler.rb +61 -26
  20. data/lib/wsdl/soap/classDefCreator.rb +4 -2
  21. data/lib/wsdl/soap/literalMappingRegistryCreator.rb +7 -2
  22. data/lib/wsdl/soap/mappingRegistryCreator.rb +0 -2
  23. data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +2 -0
  24. data/lib/wsdl/soap/methodDefCreator.rb +6 -3
  25. data/lib/wsdl/xmlSchema/element.rb +4 -0
  26. data/lib/wsdl/xmlSchema/importer.rb +21 -9
  27. data/lib/wsdl/xmlSchema/xsd2ruby.rb +56 -3
  28. data/lib/xsd/mapping.rb +30 -13
  29. data/test/interopR2/client.log +5 -0
  30. data/test/interopR2/client.rb +9 -3
  31. data/test/interopR2/server.rb +1 -0
  32. data/test/soap/asp.net/test_aspdotnet.rb +1 -1
  33. data/test/soap/auth/htdigest +2 -0
  34. data/test/soap/auth/htpasswd +2 -0
  35. data/test/soap/auth/test_basic.rb +116 -0
  36. data/test/soap/auth/test_digest.rb +117 -0
  37. data/test/soap/htpasswd +2 -0
  38. data/test/soap/ssl/README +1 -1
  39. data/test/soap/ssl/test_ssl.rb +9 -9
  40. data/test/soap/test_cookie.rb +112 -0
  41. data/test/soap/test_custom_ns.rb +63 -0
  42. data/test/soap/test_httpconfigloader.rb +20 -5
  43. data/test/soap/test_mapping.rb +62 -0
  44. data/test/soap/test_nil.rb +55 -0
  45. data/test/soap/test_no_indent.rb +1 -1
  46. data/test/soap/test_streamhandler.rb +26 -14
  47. data/test/wsdl/datetime/datetimeServant.rb +1 -0
  48. data/test/wsdl/datetime/test_datetime.rb +4 -0
  49. data/test/wsdl/document/array/double.wsdl +50 -0
  50. data/test/wsdl/document/array/test_array.rb +34 -7
  51. data/test/wsdl/qualified/test_qualified.rb +1 -1
  52. data/test/wsdl/qualified/test_unqualified.rb +2 -16
  53. data/test/wsdl/rpc/test_rpc.rb +3 -0
  54. data/test/wsdl/rpc/test_rpc_lit.rb +1 -1
  55. data/test/wsdl/simpletype/rpc/expectedMappingRegistry.rb +2 -2
  56. data/test/wsdl/soap/wsdl2ruby/expectedMappingRegistry.rb +2 -2
  57. data/test/wsdl/soap/wsdl2ruby/section/test_section.rb +1 -1
  58. data/test/xsd/xsd2ruby/expected_mysample.rb +54 -0
  59. data/test/xsd/xsd2ruby/expected_mysample_mapper.rb +11 -0
  60. data/test/xsd/xsd2ruby/expected_mysample_mapping_registry.rb +57 -0
  61. data/test/xsd/xsd2ruby/section.xsd +41 -0
  62. data/test/xsd/xsd2ruby/test_xsd2ruby.rb +90 -0
  63. metadata +31 -12
  64. data/lib/soap/mapping/encodedregistry.rb~ +0 -531
  65. data/lib/tags +0 -5144
  66. data/lib/xsd/classloader.rb +0 -26
  67. data/test/interopR2/result_client.NetRemoting.txt +0 -0
  68. data/test/wsdl/rpc/test-rpc-lit-qualified.wsdl +0 -74
  69. data/test/wsdl/rpc/test-rpc-lit12.wsdl +0 -455
data/lib/soap/soap.rb CHANGED
@@ -13,7 +13,7 @@ require 'xsd/charset'
13
13
  module SOAP
14
14
 
15
15
 
16
- VERSION = Version = '1.5.6'
16
+ VERSION = Version = '1.5.7'
17
17
  PropertyName = 'soap/property'
18
18
 
19
19
  EnvelopeNamespace = 'http://schemas.xmlsoap.org/soap/envelope/'
@@ -119,9 +119,9 @@ module Env
119
119
  ENV[name.downcase] || ENV[name.upcase]
120
120
  end
121
121
 
122
- use_proxy = getenv('soap_use_proxy') == 'on'
123
- HTTP_PROXY = use_proxy ? getenv('http_proxy') : nil
124
- NO_PROXY = use_proxy ? getenv('no_proxy') : nil
122
+ is_cgi = !getenv('request_method').nil?
123
+ HTTP_PROXY = is_cgi ? getenv('cgi_http_proxy') : getenv('http_proxy')
124
+ NO_PROXY = getenv('no_proxy')
125
125
  end
126
126
 
127
127
 
@@ -8,6 +8,7 @@
8
8
 
9
9
  require 'soap/soap'
10
10
  require 'soap/httpconfigloader'
11
+ require 'soap/filter/filterchain'
11
12
  begin
12
13
  require 'stringio'
13
14
  require 'zlib'
@@ -22,6 +23,8 @@ module SOAP
22
23
  class StreamHandler
23
24
  RUBY_VERSION_STRING = "ruby #{ RUBY_VERSION } (#{ RUBY_RELEASE_DATE }) [#{ RUBY_PLATFORM }]"
24
25
 
26
+ attr_reader :filterchain
27
+
25
28
  class ConnectionData
26
29
  attr_accessor :send_string
27
30
  attr_accessor :send_contenttype
@@ -42,6 +45,10 @@ class StreamHandler
42
45
  end
43
46
  end
44
47
 
48
+ def initialize
49
+ @filterchain = Filter::FilterChain.new
50
+ end
51
+
45
52
  def self.parse_media_type(str)
46
53
  if /^#{ MediaType }(?:\s*;\s*charset=([^"]+|"[^"]+"))?$/i !~ str
47
54
  return nil
@@ -55,13 +62,13 @@ class StreamHandler
55
62
  "#{ MediaType }; charset=#{ charset }"
56
63
  end
57
64
 
58
- def send(endpoint_url, conn_data, soapaction = nil, charset = nil)
59
- # send a ConnectionData to specified endpoint_url.
65
+ def send(url, conn_data, soapaction = nil, charset = nil)
66
+ # send a ConnectionData to specified url.
60
67
  # return value is a ConnectionData with receive_* property filled.
61
68
  # You can fill values of given conn_data and return it.
62
69
  end
63
70
 
64
- def reset(endpoint_url = nil)
71
+ def reset(url = nil)
65
72
  # for initializing connection status if needed.
66
73
  # return value is not expected.
67
74
  end
@@ -85,19 +92,42 @@ class HTTPStreamHandler < StreamHandler
85
92
  include SOAP
86
93
 
87
94
  begin
88
- require 'http-access2'
89
- if HTTPAccess2::VERSION < "2.0"
90
- raise LoadError.new("http-access/2.0 or later is required.")
91
- end
92
- Client = HTTPAccess2::Client
95
+ require 'httpclient'
96
+ Client = HTTPClient
93
97
  RETRYABLE = true
94
98
  rescue LoadError
95
- warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
96
- require 'soap/netHttpClient'
97
- Client = SOAP::NetHttpClient
98
- RETRYABLE = false
99
+ begin
100
+ require 'http-access2'
101
+ if HTTPAccess2::VERSION < "2.0"
102
+ raise LoadError.new("http-access/2.0 or later is required.")
103
+ end
104
+ Client = HTTPAccess2::Client
105
+ RETRYABLE = true
106
+ rescue LoadError
107
+ warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
108
+ require 'soap/netHttpClient'
109
+ Client = SOAP::NetHttpClient
110
+ RETRYABLE = false
111
+ end
99
112
  end
100
113
 
114
+ class HttpPostRequestFilter
115
+ def initialize(filterchain)
116
+ @filterchain = filterchain
117
+ end
118
+
119
+ def filter_request(req)
120
+ @filterchain.each do |filter|
121
+ filter.on_http_outbound(req)
122
+ end
123
+ end
124
+
125
+ def filter_response(req, res)
126
+ @filterchain.each do |filter|
127
+ filter.on_http_inbound(req, res)
128
+ end
129
+ end
130
+ end
101
131
 
102
132
  public
103
133
 
@@ -113,6 +143,9 @@ public
113
143
  def initialize(options)
114
144
  super()
115
145
  @client = Client.new(nil, "SOAP4R/#{ Version }")
146
+ if @client.respond_to?(:request_filter)
147
+ @client.request_filter << HttpPostRequestFilter.new(@filterchain)
148
+ end
116
149
  @wiredump_file_base = nil
117
150
  @charset = @wiredump_dev = nil
118
151
  @options = options
@@ -134,18 +167,18 @@ public
134
167
  "#<#{self.class}>"
135
168
  end
136
169
 
137
- def send(endpoint_url, conn_data, soapaction = nil, charset = @charset)
170
+ def send(url, conn_data, soapaction = nil, charset = @charset)
138
171
  conn_data.soapaction ||= soapaction # for backward conpatibility
139
- conn_data = send_post(endpoint_url, conn_data, charset)
172
+ conn_data = send_post(url, conn_data, charset)
140
173
  @client.save_cookie_store if @cookie_store
141
174
  conn_data
142
175
  end
143
176
 
144
- def reset(endpoint_url = nil)
145
- if endpoint_url.nil?
177
+ def reset(url = nil)
178
+ if url.nil?
146
179
  @client.reset_all
147
180
  else
148
- @client.reset(endpoint_url)
181
+ @client.reset(url)
149
182
  end
150
183
  @client.save_cookie_store if @cookie_store
151
184
  end
@@ -170,9 +203,11 @@ private
170
203
  end
171
204
  ssl_config = @options["http.ssl_config"]
172
205
  basic_auth = @options["http.basic_auth"]
206
+ auth = @options["http.auth"]
173
207
  @options["http"].lock(true)
174
208
  ssl_config.unlock
175
209
  basic_auth.unlock
210
+ auth.unlock
176
211
  end
177
212
 
178
213
  def set_cookie_store_file(value)
@@ -181,7 +216,7 @@ private
181
216
  @client.set_cookie_store(@cookie_store) if @cookie_store
182
217
  end
183
218
 
184
- def send_post(endpoint_url, conn_data, charset)
219
+ def send_post(url, conn_data, charset)
185
220
  conn_data.send_contenttype ||= StreamHandler.create_media_type(charset)
186
221
 
187
222
  if @wiredump_file_base
@@ -191,29 +226,29 @@ private
191
226
  f.close
192
227
  end
193
228
 
194
- extra = {}
195
- extra['Content-Type'] = conn_data.send_contenttype
196
- extra['SOAPAction'] = "\"#{ conn_data.soapaction }\""
197
- extra['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip?
229
+ extheader = {}
230
+ extheader['Content-Type'] = conn_data.send_contenttype
231
+ extheader['SOAPAction'] = "\"#{ conn_data.soapaction }\""
232
+ extheader['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip?
198
233
  send_string = conn_data.send_string
199
234
  @wiredump_dev << "Wire dump:\n\n" if @wiredump_dev
200
235
  begin
201
236
  retry_count = 0
202
237
  while true
203
- res = @client.post(endpoint_url, send_string, extra)
238
+ res = @client.post(url, send_string, extheader)
204
239
  if RETRYABLE and HTTP::Status.redirect?(res.status)
205
240
  retry_count += 1
206
241
  if retry_count >= MAX_RETRY_COUNT
207
242
  raise HTTPStreamError.new("redirect count exceeded")
208
243
  end
209
- endpoint_url = res.header["location"][0]
210
- puts "redirected to #{endpoint_url}" if $DEBUG
244
+ url = res.header["location"][0]
245
+ puts "redirected to #{url}" if $DEBUG
211
246
  else
212
247
  break
213
248
  end
214
249
  end
215
250
  rescue
216
- @client.reset(endpoint_url)
251
+ @client.reset(url)
217
252
  raise
218
253
  end
219
254
  @wiredump_dev << "\n\n" if @wiredump_dev
@@ -84,6 +84,8 @@ private
84
84
  dump_complextypedef(ele.name, ele.local_complextype, qualified)
85
85
  elsif ele.local_simpletype
86
86
  dump_simpletypedef(ele.name, ele.local_simpletype, qualified)
87
+ elsif ele.empty?
88
+ dump_simpleclassdef(ele.name, nil)
87
89
  else
88
90
  nil
89
91
  end
@@ -198,7 +200,7 @@ private
198
200
  c = ClassDef.new(classname, '::String')
199
201
  c.comment = "#{qname}"
200
202
  init_lines = []
201
- unless type_or_element.attributes.empty?
203
+ if type_or_element and !type_or_element.attributes.empty?
202
204
  define_attribute(c, type_or_element.attributes)
203
205
  init_lines << "@__xmlattr = {}"
204
206
  end
@@ -363,7 +365,7 @@ private
363
365
  end
364
366
 
365
367
  def check_classname(classname)
366
- if @modulepath.nil? and Module.constants.include?(classname)
368
+ if @modulepath.nil? and Object.constants.include?(classname)
367
369
  warn("created definition re-opens an existing toplevel class: #{classname}")
368
370
  end
369
371
  end
@@ -160,8 +160,13 @@ private
160
160
  child_element = typedef.find_aryelement
161
161
  if child_type == XSD::AnyTypeName
162
162
  type = nil
163
- elsif child_element and (klass = element_basetype(child_element))
164
- type = klass.name
163
+ elsif child_element
164
+ if klass = element_basetype(child_element)
165
+ type = klass.name
166
+ else
167
+ typename = child_element.type || child_element.name
168
+ type = create_class_name(typename, @modulepath)
169
+ end
165
170
  elsif child_type
166
171
  type = create_class_name(child_type, @modulepath)
167
172
  else
@@ -38,11 +38,9 @@ class MappingRegistryCreator
38
38
  m = XSD::CodeGen::ModuleDef.new(module_name)
39
39
  m.def_require("soap/mapping")
40
40
  varname = 'EncodedRegistry'
41
- methodname = 'define_encoded_mapping'
42
41
  m.def_const(varname, '::SOAP::Mapping::EncodedRegistry.new')
43
42
  m.def_code(encoded_creator.dump(varname))
44
43
  varname = 'LiteralRegistry'
45
- methodname = 'define_literal_mapping'
46
44
  m.def_const(varname, '::SOAP::Mapping::LiteralRegistry.new')
47
45
  m.def_code(literal_creator.dump(varname))
48
46
  m.dump
@@ -78,6 +78,8 @@ module MappingRegistryCreatorSupport
78
78
  when XMLSchema::Element
79
79
  if element.type == XSD::AnyTypeName
80
80
  type = nil
81
+ elsif @simpletypes[element.type]
82
+ type = create_class_name(element.type, @modulepath)
81
83
  elsif klass = element_basetype(element)
82
84
  type = klass.name
83
85
  elsif element.type
@@ -161,15 +161,18 @@ __EOD__
161
161
  when :TYPE_STRUCT, :TYPE_EMPTY # ToDo: empty should be treated as void.
162
162
  type = create_class_name(part.type, @modulepath)
163
163
  [type, part.type.namespace, part.type.name]
164
- when :TYPE_MAP
165
- [Hash.name, part.type.namespace, part.type.name]
166
164
  when :TYPE_ARRAY
167
165
  arytype = definedtype.find_arytype || XSD::AnyTypeName
168
166
  arytypename = arytype.name.sub(/\[(?:,)*\]$/, '')
169
167
  arytypedef = create_class_name(XSD::QName.new(nil, arytypename), @modulepath)
170
168
  [arytypedef + '[]', part.type.namespace, part.type.name]
169
+ when :TYPE_SIMPLE
170
+ type = create_class_name(part.type, @modulepath)
171
+ [type, part.type.namespace, part.type.name]
172
+ when :TYPE_MAP
173
+ [Hash.name, part.type.namespace, part.type.name]
171
174
  else
172
- raise NotImplementedError.new("must not reach here")
175
+ raise NotImplementedError.new("must not reach here: #{definedtype.compoundtype}")
173
176
  end
174
177
  elsif part.type == XSD::AnyTypeName
175
178
  [nil]
@@ -69,6 +69,10 @@ class Element < Info
69
69
  @refelement = nil
70
70
  end
71
71
 
72
+ def empty?
73
+ !(local_simpletype || local_complextype || constraint || type)
74
+ end
75
+
72
76
  def refelement
73
77
  @refelement ||= (@ref ? root.collect_elements[@ref] : nil)
74
78
  end
@@ -6,6 +6,7 @@
6
6
  # either the dual license version in 2003, or any later version.
7
7
 
8
8
 
9
+ require 'soap/soap'
9
10
  require 'soap/httpconfigloader'
10
11
  require 'wsdl/xmlSchema/parser'
11
12
 
@@ -15,6 +16,8 @@ module XMLSchema
15
16
 
16
17
 
17
18
  class Importer
19
+ DO_NOT_IMPORT = [::SOAP::EncodingNamespace]
20
+
18
21
  def self.import(location, originalroot = nil)
19
22
  new.import(location, originalroot)
20
23
  end
@@ -24,6 +27,9 @@ class Importer
24
27
  end
25
28
 
26
29
  def import(location, originalroot = nil)
30
+ if DO_NOT_IMPORT.include?(location.to_s)
31
+ return nil
32
+ end
27
33
  unless location.is_a?(URI)
28
34
  location = URI.parse(location)
29
35
  end
@@ -70,17 +76,23 @@ private
70
76
  end
71
77
 
72
78
  def web_client
73
- @web_client ||= begin
74
- require 'http-access2'
75
- if HTTPAccess2::VERSION < "2.0"
76
- raise LoadError.new("http-access/2.0 or later is required.")
77
- end
78
- HTTPAccess2::Client
79
+ return @web_client if @web_client
80
+ begin
81
+ require 'httpclient'
82
+ @web_client = HTTPClient
83
+ rescue LoadError
84
+ begin
85
+ require 'http-access2'
86
+ if HTTPAccess2::VERSION < "2.0"
87
+ raise LoadError.new("http-access/2.0 or later is required.")
88
+ end
89
+ @web_client = HTTPAccess2::Client
79
90
  rescue LoadError
80
- warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
81
- require 'soap/netHttpClient'
82
- ::SOAP::NetHttpClient
91
+ warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
92
+ require 'soap/netHttpClient'
93
+ @web_client = ::SOAP::NetHttpClient
83
94
  end
95
+ end
84
96
  @web_client
85
97
  end
86
98
  end
@@ -9,6 +9,8 @@
9
9
  require 'xsd/codegen/gensupport'
10
10
  require 'wsdl/xmlSchema/importer'
11
11
  require 'wsdl/soap/classDefCreator'
12
+ require 'wsdl/soap/literalMappingRegistryCreator'
13
+ require 'logger'
12
14
 
13
15
 
14
16
  module WSDL
@@ -26,7 +28,7 @@ class XSD2Ruby
26
28
  raise RuntimeError, "XML Schema location not given"
27
29
  end
28
30
  @xsd = import(@location)
29
- @name = create_classname(@xsd)
31
+ @name = @opt['classdef'] || create_classname(@xsd)
30
32
  create_file
31
33
  end
32
34
 
@@ -42,7 +44,10 @@ private
42
44
  end
43
45
 
44
46
  def create_file
45
- create_classdef
47
+ @modulepath = @opt['module_path']
48
+ create_classdef if @opt.key?('classdef')
49
+ create_mapping_registry if @opt.key?('mapping_registry')
50
+ create_mapper if @opt.key?('mapper')
46
51
  end
47
52
 
48
53
  def create_classdef
@@ -50,10 +55,58 @@ private
50
55
  @classdef_filename = @name + '.rb'
51
56
  check_file(@classdef_filename) or return
52
57
  write_file(@classdef_filename) do |f|
53
- f << WSDL::SOAP::ClassDefCreator.new(@xsd).dump
58
+ f << WSDL::SOAP::ClassDefCreator.new(@xsd, @modulepath).dump
54
59
  end
55
60
  end
56
61
 
62
+ def create_mapping_registry
63
+ @logger.info { "Creating mapping registry definition." }
64
+ @mr_filename = @name + '_mapping_registry.rb'
65
+ check_file(@mr_filename) or return
66
+ write_file(@mr_filename) do |f|
67
+ f << dump_mapping_registry
68
+ end
69
+ end
70
+
71
+ def create_mapper
72
+ @logger.info { "Creating mapper definition." }
73
+ @mapper_filename = @name + '_mapper.rb'
74
+ check_file(@mapper_filename) or return
75
+ write_file(@mapper_filename) do |f|
76
+ f << dump_mapper
77
+ end
78
+ end
79
+
80
+ def dump_mapping_registry
81
+ creator = WSDL::SOAP::LiteralMappingRegistryCreator.new(@xsd, @modulepath)
82
+ module_name = XSD::CodeGen::GenSupport.safeconstname(
83
+ @name + 'MappingRegistry')
84
+ if @modulepath
85
+ module_name = [@modulepath, module_name].join('::')
86
+ end
87
+ m = XSD::CodeGen::ModuleDef.new(module_name)
88
+ m.def_require("xsd/mapping")
89
+ m.def_require("#{@classdef_filename}")
90
+ varname = 'Registry'
91
+ m.def_const(varname, '::SOAP::Mapping::LiteralRegistry.new')
92
+ m.def_code(creator.dump(varname))
93
+ m.dump
94
+ end
95
+
96
+ def dump_mapper
97
+ class_name = XSD::CodeGen::GenSupport.safeconstname(@name + 'Mapper')
98
+ if @modulepath
99
+ class_name = [@modulepath, class_name].join('::')
100
+ end
101
+ mr_name = XSD::CodeGen::GenSupport.safeconstname(@name + 'MappingRegistry')
102
+ c = XSD::CodeGen::ClassDef.new(class_name, 'XSD::Mapping::Mapper')
103
+ c.def_require("#{@mr_filename}")
104
+ c.def_method("initialize") do
105
+ "super(#{mr_name}::Registry)"
106
+ end
107
+ c.dump
108
+ end
109
+
57
110
  def write_file(filename)
58
111
  if @basedir
59
112
  filename = File.join(basedir, filename)