Skip to content

Commit

Permalink
fix for service method getting to work with Google's soap service
Browse files Browse the repository at this point in the history
  • Loading branch information
mpclocal committed Aug 23, 2009
1 parent 62bb8f5 commit 300622e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
29 changes: 12 additions & 17 deletions lib/soap4r2ruby.rb
Expand Up @@ -72,12 +72,16 @@ def find_root_node_for_method(service_method_name)
# :faults => {"MySoap::InterfaceOne::DiscountServiceFault"=>{:encodingstyle=>"document", :use=>"literal", :ns=>"http://services.gid.gap.com/discountService/v1", :namespace=>nil, :name=>"DiscountServiceFault"}} }
# ]
# ]
m = get_method_descriptor_for_name(service_method_name)
m = Soap4r2RubyHelpers::get_method_descriptor_for_name(service_method_name, @service_method_descriptors)


io_methods = m.select{|e| e.class == Array}.first
input = io_methods.select{|e| e.first == "in"}.first
# io methods look something like this
# [ ["in", "input", ["::SOAP::SOAPElement", "http://schemas.gid.gap.com/discountService/v1", "DiscountServiceRequest"]],
# or
# [["in", "key", ["::SOAP::SOAPString"]], ["in", "url", ["::SOAP::SOAPString"]], ["retval", "return", ["::SOAP::SOAPBase64"]]]

# [ ["in", "input", ["::SOAP::SOAPElement", "http://schemas.gid.gap.com/discountService/v1", "DiscountServiceRequest"]],
input = io_methods.select{|e| e.first == "in"}.first

if input == nil || input.last == nil
#hack hack hack
Expand All @@ -88,22 +92,13 @@ def find_root_node_for_method(service_method_name)
# driver = eval(@namespace+"::"+@port_type).new
# name = driver.literal_mapping_registry.elename_schema_definition_from_class(obj.class).elename.name
schemadef = Soap4r2RubyHelpers::get_schemadef_for_class_name(root_node_name, @mapping_registry, @literal_mapping_registry)
@root_node = schemadef.last.class_for
if(schemadef.class == Array)
@root_node = schemadef.last.class_for
else
@root_node = schemadef
end
end

def get_method_descriptor_for_name(service_method_name)
@service_method_descriptors.select do |e|
element = e[1]
if element == nil or element == ""
element = e[0]
end
if (element.class.to_s.include?('XSD::QName'))
element.name == service_method_name
else
element == service_method_name
end
end.first
end
#
# def find_root_node_for_method(service_method_name)
# m = @port_type.operations.select{|e| e.operationname.name == service_method_name}.first
Expand Down
22 changes: 18 additions & 4 deletions lib/soap4r2ruby_helpers.rb
Expand Up @@ -74,21 +74,23 @@ def self.min_max_tagger(obj, driver)

def self.get_schemadef_for_class_name(node_name, mapping_registry, literal_mapping_registry)
search_path = ["@type_schema_definition", "@class_elename_schema_definition", "@elename_schema_definition", "@class_schema_definition"]
all = []
search_path.each do |path|
[mapping_registry, literal_mapping_registry].each do |registry|
schemadef = registry.instance_eval(path).select do |k,v|
v.elename != nil
end.select do |k, v|
all += [v.elename.name]
v.elename.name == node_name
end.first
if schemadef != nil
return schemadef
end
end
end
puts all.uniq
#if the node itself is a simple SOAP defined type return it
if (eval(node_name) !=nil)
return eval(node_name)
end
#if you ever get here finally throw a not found exception
throw Exception.new("can't find schemadef for #{node_name}")
end

Expand All @@ -106,7 +108,12 @@ def self.get_schemadef_for_type_name(node_name, mapping_registry, literal_mappin
end
end
end
nil
#if the node itself is a simple SOAP defined type return it
if eval"#{node_name}" !=nil
return eval"#{node_name}"
end
#if you ever get here finally throw a not found exception
throw Exception.new("can't find schemadef for #{node_name}")
end

def self.get_type_from_name_and_schemadef(name, schemadef)
Expand All @@ -126,4 +133,11 @@ def self.find_service_method_names(service_method_descriptors)
e[e.size-3]
end
end

def self.get_method_descriptor_for_name(service_method_name, service_method_descriptors)
service_method_descriptors.select do |e|
service_method_name == e[e.size-3]
end.first
end

end
6 changes: 3 additions & 3 deletions test/unit/tc_mpc1_service_names.rb
Expand Up @@ -95,9 +95,9 @@ def test_service_methods_and_names_for_google
assert_equal("doGetCachedPage", result.service_method_names[0].first)
assert_equal("doSpellingSuggestion", result.service_method_names[1].first)
assert_equal("doGoogleSearch", result.service_method_names[2].first)
assert_equal("a", result.find_root_node_for_method("doGetCachedPage"))
assert_equal("a", result.find_root_node_for_method("doSpellingSuggestion"))
assert_equal("a", result.find_root_node_for_method("doGoogleSearch"))
assert_equal(SOAP::SOAPString, result.find_root_node_for_method("doGetCachedPage"))
assert_equal(SOAP::SOAPString, result.find_root_node_for_method("doSpellingSuggestion"))
assert_equal(SOAP::SOAPString, result.find_root_node_for_method("doGoogleSearch"))
end

def test_service_methods_and_names_for_old_discount
Expand Down

0 comments on commit 300622e

Please sign in to comment.