soap-lc 0.0.1 → 0.0.2

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.
@@ -1,5 +1,5 @@
1
- require 'rubygems'
2
- require 'active_support'
1
+ require 'rexml/document'
2
+ require 'soap/lc/error'
3
3
 
4
4
  module SOAP
5
5
  class Response
@@ -9,13 +9,34 @@ module SOAP
9
9
  attr_reader :to_h
10
10
 
11
11
  def initialize( request ) #:nodoc:
12
+ @request = request
12
13
  url = URI.parse( request[:uri] )
13
14
  @soap_response = Net::HTTP.new( url.host, url.port ).start { |http|
14
- http.post( url.request_uri, request[:envelope], request[:headers] )
15
+ http.post( url.request_uri, @request[:envelope], @request[:headers] )
15
16
  }
16
17
 
17
18
  @to_xml = @soap_response.body
18
- @to_h = Hash.from_xml( @soap_response.body )["Envelope"]["Body"][request[:response]]
19
+ @to_h = {}
20
+
21
+ if @request[:wsdl].nil? or @request[:response].nil?
22
+ require 'rubygems'
23
+ require 'active_support'
24
+
25
+ @to_h = Hash.from_xml( @soap_response.body )
26
+ else
27
+ processResponse()
28
+ end
29
+ end
30
+
31
+ def method_missing( id, *args )
32
+ get( id.id2name )
33
+ end
34
+
35
+ def [](name)
36
+ @to_h[name]
37
+ end
38
+ def get( name )
39
+ @to_h[name]
19
40
  end
20
41
 
21
42
  # Return SOAP error
@@ -23,8 +44,25 @@ module SOAP
23
44
  @soap_response.error!
24
45
  end
25
46
 
26
- def method_missing( id, *args ) #:nodoc:
27
- puts id.id2name
47
+ private
48
+ def processResponse
49
+ xml_result = REXML::Document.new( @to_xml )
50
+ # raise SOAP::LCElementError, "Invalide SOAP response!" if xml_result.root.children[0].children[0].name != "#{@request[:method]}Response"
51
+
52
+ xml_response = xml_result.root.children[0].children[0].children
53
+ @request[:wsdl].messages[@request[:response]].parts.each do |_, attrs|
54
+ case attrs[:mode]
55
+ when :element
56
+ @to_h = @request[:wsdl].types[attrs[:element].nns][:value].responseToHash( xml_response, @request[:wsdl].types )
57
+ when :type
58
+ if SOAP::XSD::ANY_SIMPLE_TYPE.include?( attrs[:type].nns )
59
+ # **************************** TODO ************************************
60
+ else
61
+ # **************************** TODO ************************************
62
+ end
63
+ else
64
+ end
65
+ end
28
66
  end
29
67
 
30
68
  end
@@ -0,0 +1,5 @@
1
+ module SOAP
2
+ class LC
3
+ SOAP::LC::VERSION = "0.0.2"
4
+ end
5
+ end
@@ -5,8 +5,9 @@ module SOAP
5
5
  class WSDL
6
6
  attr_reader :parse
7
7
 
8
- def initialize( uri ) #:nodoc:
8
+ def initialize( uri, binding ) #:nodoc:
9
9
  @parse = SOAP::WSDL::Parser.new( uri )
10
+ @binding = binding
10
11
  end
11
12
 
12
13
  # Call a method for the current WSDL and get the corresponding SOAP::Request
@@ -16,7 +17,7 @@ module SOAP
16
17
  # request = wsdl.myMethod( :param1 => "hello" )
17
18
  # # => #<SOAP::Request:0xNNNNNN>
18
19
  def method_missing( id, *args )
19
- return request.call( id.id2name, args[0] )
20
+ return request( @binding ).call( id.id2name, args[0] )
20
21
  end
21
22
 
22
23
  # Call a method for the current WSDL and get the corresponding SOAP::Request
@@ -25,8 +26,8 @@ module SOAP
25
26
  # wsdl = SOAP::LC.new( ).wsdl( "http://..." )
26
27
  # request = wsdl.call( "myMethod", { :param1 => "hello" } )
27
28
  # # => #<SOAP::Request:0xNNNNNN>
28
- def call( name, args )
29
- return request.call( name, args )
29
+ def call( name, args = {} )
30
+ return request( @binding ).call( name, args )
30
31
  end
31
32
 
32
33
  # Get a SOAP::Request object for the current WSDL
@@ -35,8 +36,8 @@ module SOAP
35
36
  # wsdl = SOAP::LC.new( ).wsdl( "http://..." )
36
37
  # request = wsdl.request( )
37
38
  # # => #<SOAP::Request:0xNNNNNN>
38
- def request( )
39
- return SOAP::Request.new( @parse )
39
+ def request( binding = nil )
40
+ return SOAP::Request.new( @parse, binding )
40
41
  end
41
42
  end
42
43
  end
@@ -1,11 +1,16 @@
1
1
  module SOAP
2
2
  class WSDL
3
3
  class Bindings < Hash
4
- def getBindingForOperationName( name )
5
- self.each do |binding_name, binding|
6
- return binding if binding.operations.keys.include?(name)
4
+ def getBindingForOperationName( binding, name )
5
+ r = []
6
+ if binding.nil?
7
+ self.each do |binding_name, binding|
8
+ r << binding if binding.operations.keys.include?(name)
9
+ end
10
+ else
11
+ r << self[binding] if self[binding].operations.keys.include?(name)
7
12
  end
8
- return nil
13
+ return r
9
14
  end
10
15
  end
11
16
 
@@ -61,6 +66,8 @@ module SOAP
61
66
  case name
62
67
  when 'soapAction'
63
68
  @operations[operation.attributes['name']][:soapAction] = value
69
+ when 'style'
70
+ @operations[operation.attributes['name']][:style] = value
64
71
  else
65
72
  warn "Ignoring attribut `#{name}' for wsdlsoap:operation in operation `#{operation.attributes['name']}' in binding `#{element.attributes['name']}'"
66
73
  end
@@ -1,5 +1,3 @@
1
- require 'soap/lc/error'
2
-
3
1
  module SOAP
4
2
  class WSDL
5
3
  class Messages < Hash
@@ -1,3 +1,14 @@
1
+ require 'soap/lc/error'
2
+ require 'soap/lc/core_ext'
3
+
4
+ require 'soap/lc/xsd/complextype'
5
+ require 'soap/lc/xsd/convert'
6
+ require 'soap/lc/xsd/element'
7
+ require 'soap/lc/xsd/enumeration'
8
+ require 'soap/lc/xsd/restriction'
9
+ require 'soap/lc/xsd/sequence'
10
+ require 'soap/lc/xsd/simpletype'
11
+
1
12
  module SOAP
2
13
  class XSD
3
14
  attr_reader :elements
@@ -77,442 +88,5 @@ module SOAP
77
88
  warn "Ignoring type `#{type.name}'"
78
89
  end
79
90
  end
80
-
81
- class Restriction < Hash
82
- def initialize( content )
83
- content.attributes.each { |name, value|
84
- self[name.to_sym] = value
85
- }
86
- content.find_all{ |e| e.class == REXML::Element }.each { |restrictions|
87
- case restrictions.name
88
- when "annotation"
89
- ###############################################################################
90
- warn "xsd:annotation in xsd:restriction is not yet supported!"
91
- ###############################################################################
92
- when "fractionDigits"
93
- ###############################################################################
94
- warn "xsd:fractionDigits in xsd:restriction is not yet supported!"
95
- ###############################################################################
96
- when "enumeration"
97
- self[:enumeration] = SOAP::XSD::Enumeration.new unless self.has_key?( :enumeration )
98
- self[:enumeration] << restrictions.attributes['value']
99
- when "length"
100
- ###############################################################################
101
- warn "xsd:length in xsd:restriction is not yet supported!"
102
- ###############################################################################
103
- when "maxExclusive"
104
- ###############################################################################
105
- warn "xsd:maxExclusive in xsd:restriction is not yet supported!"
106
- ###############################################################################
107
- when "maxInclusive"
108
- ###############################################################################
109
- warn "xsd:maxInclusive in xsd:restriction is not yet supported!"
110
- ###############################################################################
111
- when "maxLength"
112
- ###############################################################################
113
- warn "xsd:maxLength in xsd:restriction is not yet supported!"
114
- ###############################################################################
115
- when "minExclusive"
116
- ###############################################################################
117
- warn "xsd:minExclusive in xsd:restriction is not yet supported!"
118
- ###############################################################################
119
- when "minInclusive"
120
- ###############################################################################
121
- warn "xsd:minInclusive in xsd:restriction is not yet supported!"
122
- ###############################################################################
123
- when "minLength"
124
- ###############################################################################
125
- warn "xsd:minLength in xsd:restriction is not yet supported!"
126
- ###############################################################################
127
- when "pattern"
128
- ###############################################################################
129
- warn "xsd:pattern in xsd:restriction is not yet supported!"
130
- ###############################################################################
131
- when "simpleType"
132
- ###############################################################################
133
- warn "xsd:simpleType in xsd:restriction is not yet supported!"
134
- ###############################################################################
135
- when "totalDigits"
136
- ###############################################################################
137
- warn "xsd:totalDigits in xsd:restriction is not yet supported!"
138
- ###############################################################################
139
- when "whiteSpace"
140
- ###############################################################################
141
- warn "xsd:whiteSpace in xsd:restriction is not yet supported!"
142
- ###############################################################################
143
- else
144
- warn "Ignoring `#{restrictions.name}' in xsd:restriction for xsd:simpleType `#{type.attributes['name']}'"
145
- end
146
- }
147
- end
148
- end
149
-
150
- class Enumeration < Array
151
- end
152
-
153
- class Sequence < Hash
154
- def initialize( type )
155
- type.attributes.each { |name, value|
156
- self[name.to_sym] = value
157
- }
158
-
159
- type.find_all{ |e| e.class == REXML::Element }.each { |content|
160
- case content.name
161
- when "annotation"
162
- ###############################################################################
163
- warn "xsd:annotation in xsd:sequence is not yet supported!"
164
- ###############################################################################
165
- when "element"
166
- raise SOAP::LCElementError, "Malformated sequence" unless self[:type].nil? or self[:type] = :element
167
- if self[:type].nil?
168
- self[:type] = :element
169
- self[:element] = Array.new
170
- end
171
- self[:element] << SOAP::XSD::Element.new( content )
172
- when "choice"
173
- raise SOAP::LCElementError, "Malformated sequence" unless self[:type].nil? or self[:type] = :choice
174
- self[:type] = :choice
175
- ###############################################################################
176
- warn "xsd:choice in xsd:sequence is not yet supported!"
177
- ###############################################################################
178
- when "group"
179
- raise SOAP::LCElementError, "Malformated sequence" unless self[:type].nil? or self[:type] = :group
180
- self[:type] = :group
181
- ###############################################################################
182
- warn "xsd:group in xsd:sequence is not yet supported!"
183
- ###############################################################################
184
- when "sequence"
185
- raise SOAP::LCElementError, "Malformated sequence" unless self[:type].nil? or self[:type] = :sequence
186
- self[:type] = :sequence
187
- ###############################################################################
188
- warn "xsd:sequence in xsd:sequence is not yet supported!"
189
- ###############################################################################
190
- when "any"
191
- raise SOAP::LCElementError, "Malformated sequence" unless self[:type].nil? or self[:type] = :any
192
- self[:type] = :any
193
- ###############################################################################
194
- warn "xsd:any in xsd:sequence is not yet supported!"
195
- ###############################################################################
196
- else
197
- raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:sequence"
198
- end
199
- }
200
- end
201
-
202
- def display( types, args )
203
- r = ""
204
-
205
- case self[:type]
206
- when :element
207
- self[:element].each { |element|
208
- r << element.display( types, args )
209
- }
210
- when :choice
211
- ###############################################################################
212
- warn "xsd:choice in xsd:sequence is not yet supported!"
213
- ###############################################################################
214
- when :group
215
- ###############################################################################
216
- warn "xsd:group in xsd:sequence is not yet supported!"
217
- ###############################################################################
218
- when :sequence
219
- ###############################################################################
220
- warn "xsd:sequence in xsd:sequence is not yet supported!"
221
- ###############################################################################
222
- when :any
223
- ###############################################################################
224
- warn "xsd:any in xsd:sequence is not yet supported!"
225
- ###############################################################################
226
- else
227
- raise SOAP::LCWSDLError, "Malformated sequence `#{self[:name]}'"
228
- end
229
-
230
- return r
231
- end
232
- end
233
-
234
- class SimpleType < Hash
235
- def initialize( type )
236
- type.attributes.each { |name, value|
237
- self[name.to_sym] = value
238
- }
239
-
240
- type.find_all{ |e| e.class == REXML::Element }.each { |content|
241
- case content.name
242
- when "list"
243
- raise SOAP::LCElementError, "Malformated simpleType `#{type.attributes['name']}'" unless self[:type].nil?
244
- self[:type] = :list
245
- self[:list] = nil
246
- ###############################################################################
247
- warn "xsd:list in xsd:simpleType is not yet supported!"
248
- ###############################################################################
249
- when "union"
250
- raise SOAP::LCElementError, "Malformated simpleType `#{type.attributes['name']}'" unless self[:type].nil?
251
- self[:type] = :union
252
- self[:union] = nil
253
- ###############################################################################
254
- warn "xsd:union in xsd:simpleType is not yet supported!"
255
- ###############################################################################
256
- when "restriction"
257
- raise SOAP::LCElementError, "Malformated simpleType `#{type.attributes['name']}'" unless self[:type].nil?
258
- self[:type] = :restriction
259
- self[:restriction] = SOAP::XSD::Restriction.new( content )
260
- when "annotation"
261
- ###############################################################################
262
- warn "xsd:annotation in xsd:simpleType is not yet supported!"
263
- ###############################################################################
264
- else
265
- raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:simpleType `#{type.attributes['name']}'"
266
- end
267
- }
268
- end
269
-
270
- def display( types, args )
271
- r = ""
272
-
273
- case self[:type]
274
- when :restriction
275
- # TODO ########################################################################
276
- # TODO ########################################################################
277
- # TODO ########################################################################
278
- # TODO ########################################################################
279
- when :list
280
- ###############################################################################
281
- warn "xsd:list in xsd:simpleType is not yet supported!"
282
- ###############################################################################
283
- when :union
284
- ###############################################################################
285
- warn "xsd:union in xsd:simpleType is not yet supported!"
286
- ###############################################################################
287
- else
288
- raise SOAP::LCWSDLError, "Malformated simpleType `#{self[:name]}'"
289
- end
290
-
291
- return r
292
- end
293
-
294
- end
295
-
296
- class ComplexType < Hash
297
- def initialize( type )
298
- type.attributes.each { |name, value|
299
- self[name.to_sym] = value
300
- }
301
-
302
- type.find_all{ |e| e.class == REXML::Element }.each { |content|
303
- case content.name
304
- when "simpleContent"
305
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
306
- self[:type] = :simpleContent
307
- ###############################################################################
308
- warn "xsd:simpleContent in xsd:complexType (global definition) is not yet supported!"
309
- ###############################################################################
310
- when "complexContent"
311
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
312
- self[:type] = :complexContent
313
- ###############################################################################
314
- warn "xsd:complexContent in xsd:complexType (global definition) is not yet supported!"
315
- ###############################################################################
316
- when "group"
317
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
318
- self[:type] = :group
319
- ###############################################################################
320
- warn "xsd:group in xsd:complexType (global definition) is not yet supported!"
321
- ###############################################################################
322
- when "all"
323
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
324
- self[:type] = :all
325
- ###############################################################################
326
- warn "xsd:all in xsd:complexType (global definition) is not yet supported!"
327
- ###############################################################################
328
- when "choise"
329
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
330
- self[:type] = :choise
331
- ###############################################################################
332
- warn "xsd:choise in xsd:complexType (global definition) is not yet supported!"
333
- ###############################################################################
334
- when "sequence"
335
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" unless self[:type].nil?
336
- self[:type] = :sequence
337
- self[:sequence] = SOAP::XSD::Sequence.new( content )
338
- when "attribute"
339
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if (not(self[:attributes_type].nil?) and self[:attributes_type] != :attribute) or [:simpleContent, :complexContent].include?(self[:type])
340
- self[:attributes_type] = :attribute
341
- ###############################################################################
342
- warn "xsd:attribute in xsd:complexType (global definition) is not yet supported!"
343
- ###############################################################################
344
- when "attributeGroup"
345
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if (not(self[:attributes_type].nil?) and self[:attributes_type] != :attributeGroup) or [:simpleContent, :complexContent].include?(self[:type])
346
- self[:attributes_type] = :attributeGroup
347
- ###############################################################################
348
- warn "xsd:attributeGroup in xsd:complexType (global definition) is not yet supported!"
349
- ###############################################################################
350
- when "anyAttribute"
351
- raise SOAP::LCElementError, "Malformated complexType `#{type.attributes['name']}'" if not(self[:any_attributes].nil?) or [:simpleContent, :complexContent].include?(self[:type])
352
- self[:any_attributes] = :anyAttribute
353
- ###############################################################################
354
- warn "xsd:anyAttribute in xsd:complexType (global definition) is not yet supported!"
355
- ###############################################################################
356
- when "annotation"
357
- ###############################################################################
358
- warn "xsd:annotation in xsd:complexType (global definition) (global definition) is not yet supported!"
359
- ###############################################################################
360
- else
361
- raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:complexType `#{type.attributes['name']}'"
362
- end
363
- }
364
- end
365
-
366
- def display( types, args )
367
- r = ""
368
-
369
- case self[:type]
370
- when :simpleContent
371
- ###############################################################################
372
- warn "xsd:simpleContent in xsd:complexType (global definition) is not yet supported!"
373
- ###############################################################################
374
- when :complexContent
375
- ###############################################################################
376
- warn "xsd:complexContent in xsd:complexType (global definition) is not yet supported!"
377
- ###############################################################################
378
- when :group
379
- ###############################################################################
380
- warn "xsd:group in xsd:complexType (global definition) is not yet supported!"
381
- ###############################################################################
382
- when :all
383
- ###############################################################################
384
- warn "xsd:all in xsd:complexType (global definition) is not yet supported!"
385
- ###############################################################################
386
- when :choise
387
- ###############################################################################
388
- warn "xsd:choise in xsd:complexType (global definition) is not yet supported!"
389
- ###############################################################################
390
- when :sequence
391
- r << self[:sequence].display( types, args )
392
- else
393
- raise SOAP::LCWSDLError, "Malformated complexType `#{self[:name]}'"
394
- end
395
-
396
- return r
397
- end
398
- end
399
-
400
- class Element < Hash
401
- def initialize( type )
402
- type.attributes.each { |name, value|
403
- self[name.to_sym] = value
404
- }
405
-
406
- type.find_all{ |e| e.class == REXML::Element }.each { |content|
407
- case content.name
408
- when "simpleType"
409
- raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil?
410
- self[:type] = :simpleType
411
- ###############################################################################
412
- warn "xsd:simpleType in xsd:element is not yet supported!"
413
- ###############################################################################
414
- when "complexType"
415
- raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:type].nil?
416
- self[:type] = :complexType
417
- self[:complexType] = SOAP::XSD::ComplexType.new( content )
418
- when "unique"
419
- raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
420
- self[:key] = :unique
421
- ###############################################################################
422
- warn "xsd:unique in xsd:element is not yet supported!"
423
- ###############################################################################
424
- when "key"
425
- raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
426
- self[:key] = :key
427
- ###############################################################################
428
- warn "xsd:unique in xsd:element is not yet supported!"
429
- ###############################################################################
430
- when "keyref"
431
- raise SOAP::LCElementError, "Malformated element `#{type.attributes['name']}'" unless self[:key].nil?
432
- self[:key] = :keyref
433
- ###############################################################################
434
- warn "xsd:unique in xsd:element is not yet supported!"
435
- ###############################################################################
436
- when "annotation"
437
- ###############################################################################
438
- warn "xsd:annotation in xsd:complexType (global definition) (global definition) is not yet supported!"
439
- ###############################################################################
440
- else
441
- raise SOAP::LCElementError, "Invalid element `#{content.name}' in xsd:element `#{type.attributes['name']}'"
442
- end
443
- }
444
- end
445
-
446
- def display( types, args )
447
- r = ""
448
-
449
- min, max = getOccures( args )
450
- if SOAP::XSD::ANY_SIMPLE_TYPE.include?( self[:type].nns )
451
- r << SOAP::XSD.displayBuiltinType( self[:name], args, min, max )
452
- else
453
- case types[self[:type].nns][:type]
454
- when :simpleType
455
- if args.keys.include?( self[:name].to_sym )
456
- args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array
457
- if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max
458
- raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'"
459
- end
460
- args[self[:name].to_sym].each { |v|
461
- r << "<#{self[:name]}>"
462
- r << "#{v}" ############ CHECK !!!
463
- r << "</#{self[:name]}>\n"
464
- }
465
- elsif min > 0
466
- raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0
467
- end
468
- when :complexType
469
- if args.keys.include?( self[:name].to_sym )
470
- if args.keys.include?( self[:name].to_sym )
471
- args[self[:name].to_sym] = [args[self[:name].to_sym]] unless args[self[:name].to_sym].class == Array
472
- if args[self[:name].to_sym].size < min or args[self[:name].to_sym].size > max
473
- raise SOAP::LCArgumentError, "Wrong number or values for parameter `#{name}'"
474
- end
475
- args[self[:name].to_sym].each { |v|
476
- r << "<#{self[:name]}>"
477
- r << types[self[:type].nns][:value].display( types, v )
478
- r << "</#{self[:name]}>\n"
479
- }
480
- elsif min > 0
481
- raise SOAP::LCArgumentError, "Missing parameter `#{name}'" if min > 0
482
- end
483
- else
484
- r << "<#{self[:name]}>\n"
485
- r << types[self[:type].nns][:value].display( types, args )
486
- r << "</#{self[:name]}>\n"
487
- end
488
- else
489
- raise SOAL::LCWSDLError, "Malformated element `#{self[:name]}'"
490
- end
491
- end
492
-
493
- return r
494
- end
495
-
496
- def getOccures( args )
497
- element_min = self[:minOccurs].to_i || 1
498
- element_max = self[:maxOccurs] || "1"
499
- if element_max == "unbounded"
500
- if args.keys.include?(self[:name].to_sym)
501
- if args[self[:name].to_sym].class == Array
502
- element_max = args[self[:name].to_sym].size
503
- else
504
- element_max = 1
505
- end
506
- else
507
- element_max = 1
508
- end
509
- else
510
- element_max = element_max.to_i
511
- end
512
-
513
- return( [element_min, element_max] )
514
- end
515
-
516
- end
517
91
  end
518
92
  end