Changeset 1470
- Timestamp:
- 04/14/05 16:59:52 (4 years ago)
- Files:
-
- trunk/lib/soap/rpc/proxy.rb (modified) (9 diffs)
- trunk/lib/soap/rpc/router.rb (modified) (10 diffs)
- trunk/test/soap/test_styleuse.rb (modified) (4 diffs)
- trunk/test/soap/wsdlDriver/document.wsdl (modified) (2 diffs)
- trunk/test/soap/wsdlDriver/test_calc.rb (modified) (1 diff)
- trunk/test/soap/wsdlDriver/test_document.rb (modified) (1 diff)
- trunk/test/wsdl/document (added)
- trunk/test/wsdl/document/document.wsdl (added)
- trunk/test/wsdl/document/echo.rb (added)
- trunk/test/wsdl/document/test_rpc.rb (added)
- trunk/test/wsdl/ref/expectedProduct.rb (modified) (1 diff)
- trunk/test/wsdl/simpletype/simpletype.wsdl (modified) (3 diffs)
- trunk/test/wsdl/simpletype/test_simpletype.rb (modified) (2 diffs)
- trunk/test/wsdl/soap/wsdl2ruby/section/test_section.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/soap/rpc/proxy.rb
r1463 r1470 277 277 def request_body(values, mapping_registry, literal_mapping_registry) 278 278 if @request_style == :rpc 279 request_rpc(values, mapping_registry )280 else 281 request_doc(values, literal_mapping_registry)279 request_rpc(values, mapping_registry, literal_mapping_registry) 280 else 281 request_doc(values, mapping_registry, literal_mapping_registry) 282 282 end 283 283 end … … 285 285 def response_obj(body, mapping_registry, literal_mapping_registry) 286 286 if @response_style == :rpc 287 response_rpc(body, mapping_registry )288 else 289 response_doc(body, literal_mapping_registry)287 response_rpc(body, mapping_registry, literal_mapping_registry) 288 else 289 response_doc(body, mapping_registry, literal_mapping_registry) 290 290 end 291 291 end … … 305 305 end 306 306 307 def request_rpc(values, mapping_registry )307 def request_rpc(values, mapping_registry, literal_mapping_registry) 308 308 if @request_use == :encoded 309 309 request_rpc_enc(values, mapping_registry) 310 310 else 311 request_rpc_lit(values, mapping_registry)312 end 313 end 314 315 def request_doc(values, mapping_registry )311 request_rpc_lit(values, literal_mapping_registry) 312 end 313 end 314 315 def request_doc(values, mapping_registry, literal_mapping_registry) 316 316 if @request_use == :encoded 317 317 request_doc_enc(values, mapping_registry) 318 318 else 319 request_doc_lit(values, mapping_registry)319 request_doc_lit(values, literal_mapping_registry) 320 320 end 321 321 end … … 335 335 idx = 0 336 336 method.input_params.each do |name| 337 params[name] = SOAPElement.from_obj(values[idx]) 337 params[name] = Mapping.obj2soap(values[idx], mapping_registry, 338 XSD::QName.new(nil, name)) 338 339 idx += 1 339 340 end … … 344 345 def request_doc_enc(values, mapping_registry) 345 346 (0...values.size).collect { |idx| 346 ele = Mapping.obj2soap(values[idx], mapping_registry )347 ele.elename = @doc_request_qnames[idx]347 ele = Mapping.obj2soap(values[idx], mapping_registry, 348 @doc_request_qnames[idx]) 348 349 ele 349 350 } … … 352 353 def request_doc_lit(values, mapping_registry) 353 354 (0...values.size).collect { |idx| 354 ele = mapping_registry.obj2soap(values[idx], @doc_request_qnames[idx]) 355 ele = Mapping.obj2soap(values[idx], mapping_registry, 356 @doc_request_qnames[idx]) 355 357 ele.encodingstyle = LiteralNamespace 356 358 ele … … 358 360 end 359 361 360 def response_rpc(body, mapping_registry )362 def response_rpc(body, mapping_registry, literal_mapping_registry) 361 363 if @response_use == :encoded 362 364 response_rpc_enc(body, mapping_registry) 363 365 else 364 response_rpc_lit(body, mapping_registry)365 end 366 end 367 368 def response_doc(body, mapping_registry )366 response_rpc_lit(body, literal_mapping_registry) 367 end 368 end 369 370 def response_doc(body, mapping_registry, literal_mapping_registry) 369 371 if @response_use == :encoded 370 372 return *response_doc_enc(body, mapping_registry) 371 373 else 372 return *response_doc_lit(body, mapping_registry)374 return *response_doc_lit(body, literal_mapping_registry) 373 375 end 374 376 end … … 391 393 def response_rpc_lit(body, mapping_registry) 392 394 body.root_node.collect { |key, value| 393 value.respond_to?(:to_obj) ? value.to_obj : value.data395 Mapping.soap2obj(value, mapping_registry) 394 396 } 395 397 end … … 403 405 def response_doc_lit(body, mapping_registry) 404 406 body.collect { |key, value| 405 value.respond_to?(:to_obj) ? value.to_obj : value.data407 Mapping.soap2obj(value, mapping_registry) 406 408 } 407 409 end trunk/lib/soap/rpc/router.rb
r1463 r1470 140 140 141 141 def route(conn_data) 142 # we cannot set request_default_encodingsyle before parsing the content. 142 143 env = unmarshal(conn_data) 143 144 if env.nil? … … 154 155 soap_response = 155 156 op.call(env.body, @mapping_registry, @literal_mapping_registry) 157 default_encodingstyle = op.response_default_encodingstyle 156 158 rescue Exception 157 159 soap_response = fault($!) 158 end 159 conn_data.is_fault = true if soap_response.is_a?(SOAPFault) # To be fixed. 160 default_encodingstyle = nil 161 end 162 conn_data.is_fault = true if soap_response.is_a?(SOAPFault) 160 163 header = call_headers(headerhandler) 161 164 body = SOAPBody.new(soap_response) … … 342 345 end 343 346 347 def request_default_encodingstyle 348 (@request_use == :encoded) ? EncodingNamespace : LiteralNamespace 349 end 350 351 def response_default_encodingstyle 352 (@response_use == :encoded) ? EncodingNamespace : LiteralNamespace 353 end 354 344 355 def call(body, mapping_registry, literal_mapping_registry) 345 356 if @request_style == :rpc 346 values = request_rpc(body, mapping_registry )347 else 348 values = request_document(body, literal_mapping_registry)357 values = request_rpc(body, mapping_registry, literal_mapping_registry) 358 else 359 values = request_document(body, mapping_registry, literal_mapping_registry) 349 360 end 350 361 result = receiver.method(@name.intern).call(*values) 351 362 return result if result.is_a?(SOAPFault) 352 363 if @response_style == :rpc 353 response_rpc(result, mapping_registry )354 else 355 response_doc(result, literal_mapping_registry)364 response_rpc(result, mapping_registry, literal_mapping_registry) 365 else 366 response_doc(result, mapping_registry, literal_mapping_registry) 356 367 end 357 368 end … … 363 374 end 364 375 365 def request_rpc(body, mapping_registry )376 def request_rpc(body, mapping_registry, literal_mapping_registry) 366 377 request = body.request 367 378 unless request.is_a?(SOAPStruct) … … 371 382 request_rpc_enc(request, mapping_registry) 372 383 else 373 request_rpc_lit(request, mapping_registry)374 end 375 end 376 377 def request_document(body, mapping_registry )384 request_rpc_lit(request, literal_mapping_registry) 385 end 386 end 387 388 def request_document(body, mapping_registry, literal_mapping_registry) 378 389 # ToDo: compare names with @doc_request_qnames 379 390 if @request_use == :encoded 380 391 request_doc_enc(body, mapping_registry) 381 392 else 382 request_doc_lit(body, mapping_registry)393 request_doc_lit(body, literal_mapping_registry) 383 394 end 384 395 end … … 393 404 def request_rpc_lit(request, mapping_registry) 394 405 request.collect { |key, value| 395 value.respond_to?(:to_obj) ? value.to_obj : value.data406 Mapping.soap2obj(value, mapping_registry) 396 407 } 397 408 end … … 405 416 def request_doc_lit(body, mapping_registry) 406 417 body.collect { |key, value| 407 value.respond_to?(:to_obj) ? value.to_obj : value.data418 Mapping.soap2obj(value, mapping_registry) 408 419 } 409 420 end 410 421 411 def response_rpc(result, mapping_registry )422 def response_rpc(result, mapping_registry, literal_mapping_registry) 412 423 if @response_use == :encoded 413 424 response_rpc_enc(result, mapping_registry) 414 425 else 415 response_rpc_lit(result, mapping_registry)426 response_rpc_lit(result, literal_mapping_registry) 416 427 end 417 428 end 418 429 419 def response_doc(result, mapping_registry )430 def response_doc(result, mapping_registry, literal_mapping_registry) 420 431 if @doc_response_qnames.size == 1 and !result.is_a?(Array) 421 432 result = [result] … … 428 439 response_doc_enc(result, mapping_registry) 429 440 else 430 response_doc_lit(result, mapping_registry)441 response_doc_lit(result, literal_mapping_registry) 431 442 end 432 443 end … … 463 474 i = 1 464 475 soap_response.output_params.each do |outparam| 465 outparams[outparam] = SOAPElement.from_obj(result[i]) 476 outparams[outparam] = Mapping.obj2soap(result[i], mapping_registry, 477 XSD::QName.new(nil, outparam)) 466 478 i += 1 467 479 end 468 480 soap_response.set_outparam(outparams) 469 soap_response.retval = SOAPElement.from_obj(result[0]) 470 else 471 soap_response.retval = SOAPElement.from_obj(result) 481 soap_response.retval = Mapping.obj2soap(result[0], mapping_registry, 482 XSD::QName.new(nil, soap_response.elename)) 483 else 484 soap_response.retval = Mapping.obj2soap(result, mapping_registry, 485 XSD::QName.new(nil, soap_response.elename)) 472 486 end 473 487 soap_response … … 484 498 def response_doc_lit(result, mapping_registry) 485 499 (0...result.size).collect { |idx| 486 ele = mapping_registry.obj2soap(result[idx], @doc_response_qnames[idx]) 487 ele.encodingstyle = LiteralNamespace 488 ele 500 mapping_registry.obj2soap(result[idx], @doc_response_qnames[idx]) 489 501 } 490 502 end trunk/test/soap/test_styleuse.rb
r1414 r1470 8 8 9 9 class TestStyleUse < Test::Unit::TestCase 10 # rpc driver: obj in(Hash allowed for literal), obj out 11 # 12 # style: not visible from user 13 # rpc: wrapped element 14 # document: unwrappted element 15 # 16 # use: 17 # encoding: a graph (SOAP Data Model) 18 # literal: not a graph (SOAPElement) 19 # 20 # rpc stub: obj in, obj out(Hash is allowed for literal) 21 # 22 # style: not visible from user 23 # rpc: wrapped element 24 # document: unwrappted element 25 # 26 # use: 27 # encoding: a graph (SOAP Data Model) 28 # literal: not a graph (SOAPElement) 29 # 30 # document driver: SOAPElement in, SOAPElement out? [not implemented] 31 # 32 # style: ditto 33 # use: ditto 34 # 35 # 36 # document stub: SOAPElement in, SOAPElement out? [not implemented] 37 # 38 # style: ditto 39 # use: ditto 40 # 10 41 class GenericServant 11 42 # method name style: requeststyle_requestuse_responsestyle_responseuse … … 13 44 # 2 params -> array 14 45 def rpc_enc_rpc_enc(obj1, obj2) 46 [obj1, [obj1, obj2]] 47 end 48 49 # 2 objs -> array 50 def rpc_lit_rpc_enc(obj1, obj2) 51 [obj2, obj1] 52 end 53 54 # 2 params -> 2 params 55 def rpc_enc_rpc_lit(obj1, obj2) 56 klass = [obj1.class.name, obj2.class.name] 57 [obj2, obj1] 58 end 59 60 # 2 objs -> 2 objs 61 def rpc_lit_rpc_lit(obj1, obj2) 15 62 [obj1, obj2] 16 63 end 17 alias doc_enc_doc_enc rpc_enc_rpc_enc 18 19 # 2 hashes -> array 20 def rpc_lit_rpc_enc(obj1, obj2) 21 [obj1.keys, obj2.keys] 22 end 23 alias doc_lit_doc_enc rpc_lit_rpc_enc 64 65 # 2 params -> array 66 def doc_enc_doc_enc(obj1, obj2) 67 [obj1, [obj1, obj2]] 68 end 69 70 # 2 objs -> array 71 def doc_lit_doc_enc(obj1, obj2) 72 [obj2, obj1] 73 end 24 74 25 75 # 2 params -> 2 hashes 26 def rpc_enc_rpc_lit(obj1, obj2) 27 return {'obj1' => obj1.class.name}, {'obj2' => obj2.class.name} 28 end 29 alias doc_enc_doc_lit rpc_enc_rpc_lit 30 31 # 2 hashes -> 2 hashes 32 def rpc_lit_rpc_lit(obj1, obj2) 76 def doc_enc_doc_lit(obj1, obj2) 77 klass = [obj1.class.name, obj2.class.name] 78 return {'obj1' => {'klass' => klass}, 'misc' => 'hash does not have an order'}, 79 {'obj2' => {'klass' => klass}} 80 end 81 82 # 2 objs -> 2 objs 83 def doc_lit_doc_lit(obj1, obj2) 33 84 return obj1, obj2 34 85 end 35 alias doc_lit_doc_lit rpc_lit_rpc_lit36 86 end 37 87 … … 203 253 204 254 def test_rpc_enc_rpc_enc 255 o = "hello" 256 obj1 = o 257 obj2 = [1] 258 ret = @client.rpc_enc_rpc_enc(obj1, obj2) 259 # server returns [obj1, [obj1, obj2]] 260 assert_equal([obj1, [obj1, obj2]], ret) 261 assert_same(ret[0], ret[1][0]) 262 end 263 264 S1 = Struct.new(:a) 265 S2 = Struct.new(:c) 266 def test_rpc_lit_rpc_enc 267 ret1, ret2 = @client.rpc_lit_rpc_enc(S1.new('b'), S2.new('d')) 268 assert_equal('d', ret1.c) 269 assert_equal('b', ret2.a) 270 # Hash is allowed for literal 271 ret1, ret2 = @client.rpc_lit_rpc_enc({'a' => 'b'}, {'c' => 'd'}) 272 assert_equal('d', ret1.c) 273 assert_equal('b', ret2.a) 274 # simple value 205 275 assert_equal( 206 [1, [2]], 207 @client.rpc_enc_rpc_enc(1, [2]) 208 ) 209 end 210 211 def test_rpc_lit_rpc_enc 212 assert_equal( 213 [["a"], ["c"]], 214 @client.rpc_lit_rpc_enc({'a' => 'b'}, {'c' => 'd'}) 276 ['1', 'a'], 277 @client.rpc_lit_rpc_enc('a', 1) 215 278 ) 216 279 end … … 218 281 def test_rpc_enc_rpc_lit 219 282 assert_equal( 220 [ {'obj1' => 'String'}, {'obj2' => 'Fixnum'}],221 @client.rpc_enc_rpc_lit('a', 1)283 ['1', 'a'], 284 @client.rpc_enc_rpc_lit('a', '1') 222 285 ) 223 286 end 224 287 225 288 def test_rpc_lit_rpc_lit 289 ret1, ret2 = @client.rpc_lit_rpc_lit({'a' => 'b'}, {'c' => 'd'}) 290 assert_equal('b', ret1["a"]) 291 assert_equal('d', ret2["c"]) 292 end 293 294 def test_doc_enc_doc_enc 295 o = "hello" 296 obj1 = o 297 obj2 = [1] 298 ret = @client.rpc_enc_rpc_enc(obj1, obj2) 299 # server returns [obj1, [obj1, obj2]] 300 assert_equal([obj1, [obj1, obj2]], ret) 301 assert_same(ret[0], ret[1][0]) 302 end 303 304 def test_doc_lit_doc_enc 305 ret1, ret2 = @client.doc_lit_doc_enc({'a' => 'b'}, {'c' => 'd'}) 306 assert_equal('d', ret1.c) 307 assert_equal('b', ret2.a) 226 308 assert_equal( 227 [ {'a' => 'b'}, {'c' => 'd'}],228 @client. rpc_lit_rpc_lit({'a' => 'b'}, {'c' => 'd'})309 ['a', '1'], 310 @client.doc_lit_doc_enc(1, 'a') 229 311 ) 230 312 end 231 313 232 def test_doc_enc_doc_enc233 assert_equal(234 [1, [2]],235 @client.doc_enc_doc_enc(1, [2])236 )237 end238 239 def test_doc_lit_doc_enc240 assert_equal(241 [["a"], ["c"]],242 @client.doc_lit_doc_enc({'a' => 'b'}, {'c' => 'd'})243 )244 end245 246 314 def test_doc_enc_doc_lit 247 assert_equal( 248 [{'obj1' => 'String'}, {'obj2' => 'Fixnum'}], 249 @client.doc_enc_doc_lit('a', 1) 250 ) 315 ret1, ret2 = @client.doc_enc_doc_lit('a', 1) 316 # literal Array 317 assert_equal(['String', 'Fixnum'], ret1['obj1']['klass']) 318 # same value 319 assert_equal(ret1['obj1']['klass'], ret2['obj2']['klass']) 320 # not the same object (not encoded) 321 assert_not_same(ret1['obj1']['klass'], ret2['obj2']['klass']) 251 322 end 252 323 253 324 def test_doc_lit_doc_lit 254 assert_equal( 255 [{'a' => 'b'}, {'c' => 'd'}], 256 @client.doc_lit_doc_lit({'a' => 'b'}, {'c' => 'd'}) 257 ) 325 ret1, ret2 = @client.doc_lit_doc_lit({'a' => 'b'}, {'c' => 'd'}) 326 assert_equal('b', ret1["a"]) 327 assert_equal('d', ret2["c"]) 258 328 end 259 329 end trunk/test/soap/wsdlDriver/document.wsdl
r1415 r1470 11 11 <xsd:complexType> 12 12 <xsd:sequence> 13 <xsd:element minOccurs="1" maxOccurs="1" name=" version" type="tns:version"/>13 <xsd:element minOccurs="1" maxOccurs="1" name="myversion" type="tns:myversion"/> 14 14 <xsd:element minOccurs="0" maxOccurs="1" name="date" type="xsd:dateTime"/> 15 15 </xsd:sequence> … … 17 17 </xsd:element> 18 18 19 <xsd:simpleType name=" version">19 <xsd:simpleType name="myversion"> 20 20 <xsd:restriction base="xsd:string"> 21 21 <xsd:enumeration value="1.6"/> trunk/test/soap/wsdlDriver/test_calc.rb
r1465 r1470 14 14 15 15 def add(x, y) 16 x + y16 x.to_f + y.to_f 17 17 end 18 18 end trunk/test/soap/wsdlDriver/test_document.rb
r1415 r1470 66 66 67 67 def test_document 68 msg = {' version' => "1.9", 'date' => "2004-01-01T00:00:00Z"}68 msg = {'myversion' => "1.9", 'date' => "2004-01-01T00:00:00Z"} 69 69 reply_msg = @client.submit(msg) 70 assert_equal(msg, reply_msg) 70 assert_equal('1.9', reply_msg.myversion) 71 assert_equal('1.9', reply_msg['myversion']) 72 assert_equal('2004-01-01T00:00:00Z', reply_msg.date) 73 assert_equal('2004-01-01T00:00:00Z', reply_msg['date']) 71 74 end 72 75 end trunk/test/wsdl/ref/expectedProduct.rb
r1444 r1470 27 27 28 28 def attr_version 29 @__soap_attribute["version"]29 (@__soap_attribute ||= {})["version"] 30 30 end 31 31 32 32 def attr_version=(value) 33 @__soap_attribute["version"] = value33 (@__soap_attribute ||= {})["version"] = value 34 34 end 35 35 36 36 def attr_yesno 37 @__soap_attribute["yesno"]37 (@__soap_attribute ||= {})["yesno"] 38 38 end 39 39 40 40 def attr_yesno=(value) 41 @__soap_attribute["yesno"] = value41 (@__soap_attribute ||= {})["yesno"] = value 42 42 end 43 43 trunk/test/wsdl/simpletype/simpletype.wsdl
r1400 r1470 11 11 <xsd:complexType> 12 12 <xsd:sequence> 13 <xsd:element minOccurs="1" maxOccurs="1" name=" version" type="tns:version"/>13 <xsd:element minOccurs="1" maxOccurs="1" name="myversion" type="tns:myversion"/> 14 14 <xsd:element minOccurs="0" maxOccurs="1" name="date" type="xsd:dateTime"/> 15 15 </xsd:sequence> … … 17 17 </xsd:element> 18 18 19 <xsd:simpleType name=" version">19 <xsd:simpleType name="myversion"> 20 20 <xsd:restriction base="xsd:string"> 21 21 <xsd:enumeration value="1.6"/> … … 36 36 37 37 <message name="versionmsg"> 38 <part name=" version" element="tns:version"/>38 <part name="myversion" element="tns:myversion"/> 39 39 </message> 40 40 trunk/test/wsdl/simpletype/test_simpletype.rb
r1415 r1470 17 17 18 18 def ruby(ruby) 19 version = ruby[" version"]19 version = ruby["myversion"] 20 20 date = ruby["date"] 21 21 "#{version} (#{date})" … … 70 70 71 71 def test_ping 72 ret = @client.ping({: version => "1.9", :date => "2004-01-01T00:00:00Z"})72 ret = @client.ping({:myversion => "1.9", :date => "2004-01-01T00:00:00Z"}) 73 73 assert_equal("1.9 (2004-01-01T00:00:00Z)", ret) 74 74 end trunk/test/wsdl/soap/wsdl2ruby/section/test_section.rb
r1454 r1470 12 12 13 13 def teardown 14 File.unlink(pathname("mysample.rb")) 14 15 end 15 16 16 17 def test_classdef 17 18 compare("expectedClassdef.rb", "mysample.rb") 18 File.unlink(pathname("mysample.rb"))19 19 end 20 20