Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Ticket #482: wsdl_group_fix.patch

File wsdl_group_fix.patch, 6.9 kB (added by user, 6 months ago)

Patch to corrcet handling of group elements, including test.

  • test/wsdl/complexgroupcontent/test_echo.rb

    old new  
     1require 'test/unit' 
     2require 'wsdl/parser' 
     3require 'wsdl/soap/wsdl2ruby' 
     4require 'soap/rpc/standaloneServer' 
     5require 'soap/wsdlDriver' 
     6require File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'testutil.rb') 
     7 
     8#$DEBUG = true 
     9 
     10module WSDL; module ComplexContent 
     11 
     12class TestEcho < Test::Unit::TestCase 
     13  class Server < ::SOAP::RPC::StandaloneServer 
     14    Namespace = 'urn:complexGroupContent' 
     15 
     16    def on_init 
     17      add_document_method( 
     18        self, 
     19        nil, 
     20        'echo', 
     21        XSD::QName.new(Namespace, 'echo'), 
     22        XSD::QName.new(Namespace, 'echo') 
     23      ) 
     24    end 
     25   
     26    def echo(arg) 
     27      arg 
     28    end 
     29  end 
     30 
     31  DIR = File.dirname(File.expand_path(__FILE__)) 
     32  Port = 17171 
     33 
     34  def setup 
     35    setup_server 
     36    setup_classdef 
     37    @client = nil 
     38  end 
     39 
     40  def teardown 
     41    teardown_server if @server 
     42    unless $DEBUG 
     43      File.unlink(pathname('complexGroupContent.rb')) 
     44      File.unlink(pathname('complexGroupContentMappingRegistry.rb')) 
     45    end 
     46    @client.reset_stream if @client 
     47  end 
     48 
     49  def setup_server 
     50    @server = Server.new('Test', Server::Namespace, '0.0.0.0', Port) 
     51    @server.level = Logger::Severity::ERROR 
     52    @server_thread = TestUtil.start_server_thread(@server) 
     53  end 
     54 
     55  def setup_classdef 
     56    gen = WSDL::SOAP::WSDL2Ruby.new 
     57    gen.location = pathname("complexGroupContent.wsdl") 
     58    gen.basedir = DIR 
     59    gen.logger.level = Logger::FATAL 
     60    gen.opt['classdef'] = nil 
     61    gen.opt['mapping_registry'] = nil 
     62    gen.opt['force'] = true 
     63    gen.run 
     64    TestUtil.require(DIR, 'complexGroupContentMappingRegistry.rb', 'complexGroupContent.rb') 
     65  end 
     66 
     67  def teardown_server 
     68    @server.shutdown 
     69    @server_thread.kill 
     70    @server_thread.join 
     71  end 
     72 
     73  def pathname(filename) 
     74    File.join(DIR, filename) 
     75  end 
     76 
     77  def test_wsdl 
     78    wsdl = File.join(DIR, 'complexGroupContent.wsdl') 
     79    @client = ::SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver 
     80    @client.endpoint_url = "http://localhost:#{Port}/" 
     81    # We don't want to use the registry, because it masks the bug. 
     82    # @client.literal_mapping_registry = ComplexGroupContentMappingRegistry::LiteralRegistry 
     83    @client.wiredump_dev = STDOUT if $DEBUG 
     84    params = { 
     85      "item" => { 
     86        "Name" => "jerith", 
     87        "GCElem" => "foo", 
     88        "GSElem" => "bar", 
     89      } 
     90    } 
     91    resp = @client.send("echo", params) 
     92    assert_instance_of(::SOAP::Mapping::Object, resp) 
     93  end 
     94end 
     95 
     96 
     97end; end 
  • test/wsdl/complexgroupcontent/complexGroupContent.wsdl

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<definitions name="complexGroupContent" 
     3  targetNamespace="urn:complexGroupContent" 
     4  xmlns="http://schemas.xmlsoap.org/wsdl/" 
     5  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
     6  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     7  xmlns:tns="urn:complexGroupContent" 
     8  xmlns:txd="urn:complexGroupContent.type"> 
     9 
     10  <types> 
     11    <schema elementFormDefault="qualified" 
     12      xmlns="http://www.w3.org/2001/XMLSchema" 
     13      targetNamespace="urn:complexGroupContent.type"> 
     14      <complexType name="Base"> 
     15        <sequence> 
     16          <element name="Id" type="xsd:string" 
     17            nillable="false" minOccurs="0" maxOccurs="1"/> 
     18          <element name="Type" type="xsd:string" 
     19            nillable="true" minOccurs="0" maxOccurs="1"/> 
     20          <group ref="txd:GroupChoice"/> 
     21          <group ref="txd:GroupSequence"/> 
     22        </sequence> 
     23      </complexType> 
     24 
     25      <complexType name="Derived"> 
     26        <complexContent> 
     27          <extension base="txd:Base"> 
     28            <sequence> 
     29              <element name="Name" type="xsd:string"/> 
     30            </sequence> 
     31          </extension> 
     32        </complexContent> 
     33      </complexType> 
     34 
     35      <group name="GroupChoice" > 
     36        <choice> 
     37          <element name="GCElem" type="xsd:string"/> 
     38        </choice> 
     39      </group> 
     40 
     41      <group name="GroupSequence" > 
     42        <choice> 
     43          <element name="GSElem" type="xsd:string"/> 
     44        </choice> 
     45      </group> 
     46 
     47    </schema> 
     48 
     49    <schema elementFormDefault="qualified" 
     50      xmlns="http://www.w3.org/2001/XMLSchema" 
     51      targetNamespace="urn:complexGroupContent"> 
     52      <element name="Derived" type="txd:Derived"/> 
     53 
     54      <element name="echo"> 
     55        <complexType> 
     56          <sequence> 
     57            <element name="item" type="txd:Derived"/> 
     58          </sequence> 
     59        </complexType> 
     60      </element> 
     61    </schema> 
     62  </types> 
     63 
     64  <message name="echoRequest"> 
     65    <part element="tns:echo" name="parameters"/> 
     66  </message> 
     67 
     68  <message name="echoResponse"> 
     69    <part element="tns:echo" name="parameters"/> 
     70  </message> 
     71 
     72  <portType name="Soap"> 
     73    <operation name="echo"> 
     74      <input  message="tns:echoRequest"/> 
     75      <output message="tns:echoResponse"/> 
     76    </operation> 
     77  </portType>  
     78 
     79  <binding name="SoapBinding" type="tns:Soap"> 
     80    <soap:binding style="document" 
     81      transport="http://schemas.xmlsoap.org/soap/http"/> 
     82    <operation name="echo"> 
     83      <soap:operation soapAction=""/> 
     84      <input> 
     85        <soap:body parts="parameters" use="literal"/> 
     86      </input> 
     87      <output>  
     88        <soap:body use="literal"/> 
     89      </output> 
     90    </operation> 
     91  </binding> 
     92 
     93  <service name="complexGroupContentService"> 
     94    <port binding="tns:SoapBinding" name="Soap"> 
     95      <soap:address location="http://localhost:17171/"/> 
     96    </port> 
     97  </service> 
     98</definitions> 
  • lib/soap/mapping/wsdlliteralregistry.rb

    old new  
    140140    ele 
    141141  end 
    142142 
    143   def complexobj2sequencesoap(obj, soap, type, nillable, is_choice
     143  def complexobj2sequencesoap(obj, soap, type, nillable, is_choice, is_group = false
    144144    added = false 
    145     type.elements.each do |child_ele| 
     145    if is_group 
     146      elements = [type.content] 
     147    else 
     148      elements = type.elements 
     149    end 
     150    elements.each do |child_ele| 
    146151      case child_ele 
    147152      when WSDL::XMLSchema::Any 
    148153        any = Mapping.get_attributes_for_any(obj) 
     
    152157        ele_added = true 
    153158      when WSDL::XMLSchema::Element 
    154159        ele_added = complexobj2soapchildren(obj, soap, child_ele, nillable) 
     160      when WSDL::XMLSchema::Group 
     161        ele_added = complexobj2sequencesoap(obj, soap, child_ele, nillable, false, true) 
    155162      when WSDL::XMLSchema::Sequence 
    156163        ele_added = complexobj2sequencesoap(obj, soap, child_ele, nillable, false) 
    157164      when WSDL::XMLSchema::Choice