reidiculous-actionwebservice 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +320 -0
- data/MIT-LICENSE +21 -0
- data/README +381 -0
- data/Rakefile +180 -0
- data/TODO +32 -0
- data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
- data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
- data/examples/googlesearch/delegated/google_search_service.rb +108 -0
- data/examples/googlesearch/delegated/search_controller.rb +7 -0
- data/examples/googlesearch/direct/google_search_api.rb +50 -0
- data/examples/googlesearch/direct/search_controller.rb +58 -0
- data/examples/metaWeblog/apis/blogger_api.rb +60 -0
- data/examples/metaWeblog/apis/blogger_service.rb +34 -0
- data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
- data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
- data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
- data/generators/web_service/USAGE +28 -0
- data/generators/web_service/templates/api_definition.rb +5 -0
- data/generators/web_service/templates/controller.rb +8 -0
- data/generators/web_service/templates/functional_test.rb +19 -0
- data/generators/web_service/web_service_generator.rb +29 -0
- data/lib/action_web_service.rb +71 -0
- data/lib/action_web_service/api.rb +297 -0
- data/lib/action_web_service/base.rb +38 -0
- data/lib/action_web_service/casting.rb +149 -0
- data/lib/action_web_service/client.rb +3 -0
- data/lib/action_web_service/client/base.rb +28 -0
- data/lib/action_web_service/client/soap_client.rb +113 -0
- data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
- data/lib/action_web_service/container.rb +3 -0
- data/lib/action_web_service/container/action_controller_container.rb +93 -0
- data/lib/action_web_service/container/delegated_container.rb +86 -0
- data/lib/action_web_service/container/direct_container.rb +69 -0
- data/lib/action_web_service/dispatcher.rb +2 -0
- data/lib/action_web_service/dispatcher/abstract.rb +207 -0
- data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
- data/lib/action_web_service/invocation.rb +202 -0
- data/lib/action_web_service/protocol.rb +4 -0
- data/lib/action_web_service/protocol/abstract.rb +115 -0
- data/lib/action_web_service/protocol/discovery.rb +37 -0
- data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
- data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
- data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
- data/lib/action_web_service/scaffolding.rb +281 -0
- data/lib/action_web_service/soap/attachment.rb +107 -0
- data/lib/action_web_service/soap/baseData.rb +942 -0
- data/lib/action_web_service/soap/element.rb +258 -0
- data/lib/action_web_service/soap/encodingstyle/aspDotNetHandler.rb +213 -0
- data/lib/action_web_service/soap/encodingstyle/handler.rb +100 -0
- data/lib/action_web_service/soap/encodingstyle/literalHandler.rb +226 -0
- data/lib/action_web_service/soap/encodingstyle/soapHandler.rb +582 -0
- data/lib/action_web_service/soap/generator.rb +268 -0
- data/lib/action_web_service/soap/header/handler.rb +57 -0
- data/lib/action_web_service/soap/header/handlerset.rb +70 -0
- data/lib/action_web_service/soap/header/simplehandler.rb +44 -0
- data/lib/action_web_service/soap/httpconfigloader.rb +119 -0
- data/lib/action_web_service/soap/mapping.rb +10 -0
- data/lib/action_web_service/soap/mapping/factory.rb +355 -0
- data/lib/action_web_service/soap/mapping/mapping.rb +381 -0
- data/lib/action_web_service/soap/mapping/registry.rb +541 -0
- data/lib/action_web_service/soap/mapping/rubytypeFactory.rb +475 -0
- data/lib/action_web_service/soap/mapping/typeMap.rb +50 -0
- data/lib/action_web_service/soap/mapping/wsdlencodedregistry.rb +280 -0
- data/lib/action_web_service/soap/mapping/wsdlliteralregistry.rb +418 -0
- data/lib/action_web_service/soap/marshal.rb +59 -0
- data/lib/action_web_service/soap/mimemessage.rb +240 -0
- data/lib/action_web_service/soap/netHttpClient.rb +190 -0
- data/lib/action_web_service/soap/parser.rb +251 -0
- data/lib/action_web_service/soap/processor.rb +66 -0
- data/lib/action_web_service/soap/property.rb +333 -0
- data/lib/action_web_service/soap/rpc/cgistub.rb +206 -0
- data/lib/action_web_service/soap/rpc/driver.rb +254 -0
- data/lib/action_web_service/soap/rpc/element.rb +325 -0
- data/lib/action_web_service/soap/rpc/httpserver.rb +129 -0
- data/lib/action_web_service/soap/rpc/proxy.rb +497 -0
- data/lib/action_web_service/soap/rpc/router.rb +594 -0
- data/lib/action_web_service/soap/rpc/rpc.rb +25 -0
- data/lib/action_web_service/soap/rpc/soaplet.rb +162 -0
- data/lib/action_web_service/soap/rpc/standaloneServer.rb +43 -0
- data/lib/action_web_service/soap/soap.rb +140 -0
- data/lib/action_web_service/soap/streamHandler.rb +229 -0
- data/lib/action_web_service/soap/wsdlDriver.rb +575 -0
- data/lib/action_web_service/struct.rb +64 -0
- data/lib/action_web_service/support/class_inheritable_options.rb +28 -0
- data/lib/action_web_service/support/signature_types.rb +227 -0
- data/lib/action_web_service/test_invoke.rb +110 -0
- data/lib/action_web_service/version.rb +9 -0
- data/lib/action_web_service/wsdl/binding.rb +65 -0
- data/lib/action_web_service/wsdl/data.rb +64 -0
- data/lib/action_web_service/wsdl/definitions.rb +250 -0
- data/lib/action_web_service/wsdl/documentation.rb +32 -0
- data/lib/action_web_service/wsdl/import.rb +80 -0
- data/lib/action_web_service/wsdl/importer.rb +38 -0
- data/lib/action_web_service/wsdl/info.rb +39 -0
- data/lib/action_web_service/wsdl/message.rb +54 -0
- data/lib/action_web_service/wsdl/operation.rb +130 -0
- data/lib/action_web_service/wsdl/operationBinding.rb +108 -0
- data/lib/action_web_service/wsdl/param.rb +85 -0
- data/lib/action_web_service/wsdl/parser.rb +163 -0
- data/lib/action_web_service/wsdl/part.rb +52 -0
- data/lib/action_web_service/wsdl/port.rb +84 -0
- data/lib/action_web_service/wsdl/portType.rb +73 -0
- data/lib/action_web_service/wsdl/service.rb +61 -0
- data/lib/action_web_service/wsdl/soap/address.rb +40 -0
- data/lib/action_web_service/wsdl/soap/binding.rb +49 -0
- data/lib/action_web_service/wsdl/soap/body.rb +56 -0
- data/lib/action_web_service/wsdl/soap/cgiStubCreator.rb +76 -0
- data/lib/action_web_service/wsdl/soap/classDefCreator.rb +314 -0
- data/lib/action_web_service/wsdl/soap/classDefCreatorSupport.rb +126 -0
- data/lib/action_web_service/wsdl/soap/clientSkeltonCreator.rb +78 -0
- data/lib/action_web_service/wsdl/soap/complexType.rb +161 -0
- data/lib/action_web_service/wsdl/soap/data.rb +42 -0
- data/lib/action_web_service/wsdl/soap/definitions.rb +149 -0
- data/lib/action_web_service/wsdl/soap/driverCreator.rb +95 -0
- data/lib/action_web_service/wsdl/soap/element.rb +28 -0
- data/lib/action_web_service/wsdl/soap/fault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/header.rb +86 -0
- data/lib/action_web_service/wsdl/soap/headerfault.rb +56 -0
- data/lib/action_web_service/wsdl/soap/mappingRegistryCreator.rb +92 -0
- data/lib/action_web_service/wsdl/soap/methodDefCreator.rb +228 -0
- data/lib/action_web_service/wsdl/soap/operation.rb +122 -0
- data/lib/action_web_service/wsdl/soap/servantSkeltonCreator.rb +67 -0
- data/lib/action_web_service/wsdl/soap/standaloneServerStubCreator.rb +85 -0
- data/lib/action_web_service/wsdl/soap/wsdl2ruby.rb +176 -0
- data/lib/action_web_service/wsdl/types.rb +43 -0
- data/lib/action_web_service/wsdl/wsdl.rb +23 -0
- data/lib/action_web_service/wsdl/xmlSchema/all.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/annotation.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/any.rb +56 -0
- data/lib/action_web_service/wsdl/xmlSchema/attribute.rb +127 -0
- data/lib/action_web_service/wsdl/xmlSchema/choice.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexContent.rb +92 -0
- data/lib/action_web_service/wsdl/xmlSchema/complexType.rb +139 -0
- data/lib/action_web_service/wsdl/xmlSchema/content.rb +96 -0
- data/lib/action_web_service/wsdl/xmlSchema/data.rb +80 -0
- data/lib/action_web_service/wsdl/xmlSchema/element.rb +154 -0
- data/lib/action_web_service/wsdl/xmlSchema/enumeration.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/import.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/importer.rb +87 -0
- data/lib/action_web_service/wsdl/xmlSchema/include.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/length.rb +35 -0
- data/lib/action_web_service/wsdl/xmlSchema/parser.rb +166 -0
- data/lib/action_web_service/wsdl/xmlSchema/pattern.rb +36 -0
- data/lib/action_web_service/wsdl/xmlSchema/schema.rb +143 -0
- data/lib/action_web_service/wsdl/xmlSchema/sequence.rb +69 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleContent.rb +65 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleExtension.rb +54 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleRestriction.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/simpleType.rb +73 -0
- data/lib/action_web_service/wsdl/xmlSchema/unique.rb +34 -0
- data/lib/action_web_service/wsdl/xmlSchema/xsd2ruby.rb +107 -0
- data/lib/action_web_service/xsd/charset.rb +187 -0
- data/lib/action_web_service/xsd/codegen.rb +12 -0
- data/lib/action_web_service/xsd/codegen/classdef.rb +203 -0
- data/lib/action_web_service/xsd/codegen/commentdef.rb +34 -0
- data/lib/action_web_service/xsd/codegen/gensupport.rb +166 -0
- data/lib/action_web_service/xsd/codegen/methoddef.rb +63 -0
- data/lib/action_web_service/xsd/codegen/moduledef.rb +191 -0
- data/lib/action_web_service/xsd/datatypes.rb +1269 -0
- data/lib/action_web_service/xsd/datatypes1999.rb +20 -0
- data/lib/action_web_service/xsd/iconvcharset.rb +33 -0
- data/lib/action_web_service/xsd/mapping.rb +42 -0
- data/lib/action_web_service/xsd/namedelements.rb +95 -0
- data/lib/action_web_service/xsd/ns.rb +140 -0
- data/lib/action_web_service/xsd/qname.rb +78 -0
- data/lib/action_web_service/xsd/xmlparser.rb +61 -0
- data/lib/action_web_service/xsd/xmlparser/parser.rb +96 -0
- data/lib/action_web_service/xsd/xmlparser/rexmlparser.rb +54 -0
- data/lib/action_web_service/xsd/xmlparser/xmlparser.rb +50 -0
- data/lib/action_web_service/xsd/xmlparser/xmlscanner.rb +147 -0
- data/lib/actionwebservice.rb +1 -0
- data/setup.rb +1379 -0
- data/test/abstract_client.rb +183 -0
- data/test/abstract_dispatcher.rb +548 -0
- data/test/abstract_unit.rb +45 -0
- data/test/api_test.rb +103 -0
- data/test/apis/auto_load_api.rb +3 -0
- data/test/apis/broken_auto_load_api.rb +2 -0
- data/test/base_test.rb +42 -0
- data/test/casting_test.rb +95 -0
- data/test/client_soap_test.rb +156 -0
- data/test/client_xmlrpc_test.rb +153 -0
- data/test/container_test.rb +73 -0
- data/test/dispatcher_action_controller_soap_test.rb +139 -0
- data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
- data/test/fixtures/db_definitions/mysql.sql +8 -0
- data/test/fixtures/db_definitions/sqlite3.sql +8 -0
- data/test/fixtures/users.yml +12 -0
- data/test/gencov +3 -0
- data/test/invocation_test.rb +185 -0
- data/test/run +6 -0
- data/test/scaffolded_controller_test.rb +146 -0
- data/test/struct_test.rb +52 -0
- data/test/test_invoke_test.rb +112 -0
- metadata +281 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
module ActionWebService
|
2
|
+
# To send structured types across the wire, derive from ActionWebService::Struct,
|
3
|
+
# and use +member+ to declare structure members.
|
4
|
+
#
|
5
|
+
# ActionWebService::Struct should be used in method signatures when you want to accept or return
|
6
|
+
# structured types that have no Active Record model class representations, or you don't
|
7
|
+
# want to expose your entire Active Record model to remote callers.
|
8
|
+
#
|
9
|
+
# === Example
|
10
|
+
#
|
11
|
+
# class Person < ActionWebService::Struct
|
12
|
+
# member :id, :int
|
13
|
+
# member :firstnames, [:string]
|
14
|
+
# member :lastname, :string
|
15
|
+
# member :email, :string
|
16
|
+
# end
|
17
|
+
# person = Person.new(:id => 5, :firstname => 'john', :lastname => 'doe')
|
18
|
+
#
|
19
|
+
# Active Record model classes are already implicitly supported in method
|
20
|
+
# signatures.
|
21
|
+
class Struct
|
22
|
+
# If a Hash is given as argument to an ActionWebService::Struct constructor,
|
23
|
+
# it can contain initial values for the structure member.
|
24
|
+
def initialize(values={})
|
25
|
+
if values.is_a?(Hash)
|
26
|
+
values.map{|k,v| __send__('%s=' % k.to_s, v)}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# The member with the given name
|
31
|
+
def [](name)
|
32
|
+
send(name.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Iterates through each member
|
36
|
+
def each_pair(&block)
|
37
|
+
self.class.members.each do |name, type|
|
38
|
+
yield name, self.__send__(name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
# Creates a structure member with the specified +name+ and +type+. Generates
|
44
|
+
# accessor methods for reading and writing the member value.
|
45
|
+
def member(name, type)
|
46
|
+
name = name.to_sym
|
47
|
+
type = ActionWebService::SignatureTypes.canonical_signature_entry({ name => type }, 0)
|
48
|
+
write_inheritable_hash("struct_members", name => type)
|
49
|
+
class_eval <<-END
|
50
|
+
def #{name}; @#{name}; end
|
51
|
+
def #{name}=(value); @#{name} = value; end
|
52
|
+
END
|
53
|
+
end
|
54
|
+
|
55
|
+
def members # :nodoc:
|
56
|
+
read_inheritable_attribute("struct_members") || {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def member_type(name) # :nodoc:
|
60
|
+
members[name.to_sym]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/core_ext/class/inheritable_attributes'
|
2
|
+
|
3
|
+
class Class # :nodoc:
|
4
|
+
def class_inheritable_option(sym, default_value=nil)
|
5
|
+
write_inheritable_attribute sym, default_value
|
6
|
+
class_eval <<-EOS
|
7
|
+
def self.#{sym}(value=nil)
|
8
|
+
if !value.nil?
|
9
|
+
write_inheritable_attribute(:#{sym}, value)
|
10
|
+
else
|
11
|
+
read_inheritable_attribute(:#{sym})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.#{sym}=(value)
|
16
|
+
write_inheritable_attribute(:#{sym}, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def #{sym}
|
20
|
+
self.class.#{sym}
|
21
|
+
end
|
22
|
+
|
23
|
+
def #{sym}=(value)
|
24
|
+
self.class.#{sym} = value
|
25
|
+
end
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,227 @@
|
|
1
|
+
module ActionWebService # :nodoc:
|
2
|
+
# Action Web Service supports the following base types in a signature:
|
3
|
+
#
|
4
|
+
# [<tt>:int</tt>] Represents an integer value, will be cast to an integer using <tt>Integer(value)</tt>
|
5
|
+
# [<tt>:string</tt>] Represents a string value, will be cast to an string using the <tt>to_s</tt> method on an object
|
6
|
+
# [<tt>:base64</tt>] Represents a Base 64 value, will contain the binary bytes of a Base 64 value sent by the caller
|
7
|
+
# [<tt>:bool</tt>] Represents a boolean value, whatever is passed will be cast to boolean (<tt>true</tt>, '1', 'true', 'y', 'yes' are taken to represent true; <tt>false</tt>, '0', 'false', 'n', 'no' and <tt>nil</tt> represent false)
|
8
|
+
# [<tt>:float</tt>] Represents a floating point value, will be cast to a float using <tt>Float(value)</tt>
|
9
|
+
# [<tt>:time</tt>] Represents a timestamp, will be cast to a <tt>Time</tt> object
|
10
|
+
# [<tt>:datetime</tt>] Represents a timestamp, will be cast to a <tt>DateTime</tt> object
|
11
|
+
# [<tt>:date</tt>] Represents a date, will be cast to a <tt>Date</tt> object
|
12
|
+
#
|
13
|
+
# For structured types, you'll need to pass in the Class objects of
|
14
|
+
# ActionWebService::Struct and ActiveRecord::Base derivatives.
|
15
|
+
module SignatureTypes
|
16
|
+
def canonical_signature(signature) # :nodoc:
|
17
|
+
return nil if signature.nil?
|
18
|
+
unless signature.is_a?(Array)
|
19
|
+
raise(ActionWebServiceError, "Expected signature to be an Array")
|
20
|
+
end
|
21
|
+
i = -1
|
22
|
+
signature.map{ |spec| canonical_signature_entry(spec, i += 1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def canonical_signature_entry(spec, i) # :nodoc:
|
26
|
+
orig_spec = spec
|
27
|
+
name = "param#{i}"
|
28
|
+
if spec.is_a?(Hash)
|
29
|
+
name, spec = spec.keys.first, spec.values.first
|
30
|
+
end
|
31
|
+
type = spec
|
32
|
+
if spec.is_a?(Array)
|
33
|
+
ArrayType.new(orig_spec, canonical_signature_entry(spec[0], 0), name)
|
34
|
+
else
|
35
|
+
type = canonical_type(type)
|
36
|
+
if type.is_a?(Symbol)
|
37
|
+
BaseType.new(orig_spec, type, name)
|
38
|
+
else
|
39
|
+
StructuredType.new(orig_spec, type, name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def canonical_type(type) # :nodoc:
|
45
|
+
type_name = symbol_name(type) || class_to_type_name(type)
|
46
|
+
type = type_name || type
|
47
|
+
return canonical_type_name(type) if type.is_a?(Symbol)
|
48
|
+
type
|
49
|
+
end
|
50
|
+
|
51
|
+
def canonical_type_name(name) # :nodoc:
|
52
|
+
name = name.to_sym
|
53
|
+
case name
|
54
|
+
when :int, :integer, :fixnum, :bignum
|
55
|
+
:int
|
56
|
+
when :string, :text
|
57
|
+
:string
|
58
|
+
when :base64, :binary
|
59
|
+
:base64
|
60
|
+
when :bool, :boolean
|
61
|
+
:bool
|
62
|
+
when :float, :double
|
63
|
+
:float
|
64
|
+
when :decimal
|
65
|
+
:decimal
|
66
|
+
when :time, :timestamp
|
67
|
+
:time
|
68
|
+
when :datetime
|
69
|
+
:datetime
|
70
|
+
when :date
|
71
|
+
:date
|
72
|
+
else
|
73
|
+
raise(TypeError, "#{name} is not a valid base type")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def canonical_type_class(type) # :nodoc:
|
78
|
+
type = canonical_type(type)
|
79
|
+
type.is_a?(Symbol) ? type_name_to_class(type) : type
|
80
|
+
end
|
81
|
+
|
82
|
+
def symbol_name(name) # :nodoc:
|
83
|
+
return name.to_sym if name.is_a?(Symbol) || name.is_a?(String)
|
84
|
+
nil
|
85
|
+
end
|
86
|
+
|
87
|
+
def class_to_type_name(klass) # :nodoc:
|
88
|
+
klass = klass.class unless klass.is_a?(Class)
|
89
|
+
if derived_from?(Integer, klass) || derived_from?(Fixnum, klass) || derived_from?(Bignum, klass)
|
90
|
+
:int
|
91
|
+
elsif klass == String
|
92
|
+
:string
|
93
|
+
elsif klass == Base64
|
94
|
+
:base64
|
95
|
+
elsif klass == TrueClass || klass == FalseClass
|
96
|
+
:bool
|
97
|
+
# elsif derived_from?(Float, klass) || derived_from?(Precision, klass) || derived_from?(Numeric, klass)
|
98
|
+
elsif derived_from?(Float, klass) || derived_from?(Numeric, klass)
|
99
|
+
:float
|
100
|
+
elsif klass == Time
|
101
|
+
:time
|
102
|
+
elsif klass == DateTime
|
103
|
+
:datetime
|
104
|
+
elsif klass == Date
|
105
|
+
:date
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def type_name_to_class(name) # :nodoc:
|
112
|
+
case canonical_type_name(name)
|
113
|
+
when :int
|
114
|
+
Integer
|
115
|
+
when :string
|
116
|
+
String
|
117
|
+
when :base64
|
118
|
+
Base64
|
119
|
+
when :bool
|
120
|
+
TrueClass
|
121
|
+
when :float
|
122
|
+
Float
|
123
|
+
when :decimal
|
124
|
+
BigDecimal
|
125
|
+
when :time
|
126
|
+
Time
|
127
|
+
when :date
|
128
|
+
Date
|
129
|
+
when :datetime
|
130
|
+
DateTime
|
131
|
+
else
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def derived_from?(ancestor, child) # :nodoc:
|
137
|
+
child.ancestors.include?(ancestor)
|
138
|
+
end
|
139
|
+
|
140
|
+
module_function :type_name_to_class
|
141
|
+
module_function :class_to_type_name
|
142
|
+
module_function :symbol_name
|
143
|
+
module_function :canonical_type_class
|
144
|
+
module_function :canonical_type_name
|
145
|
+
module_function :canonical_type
|
146
|
+
module_function :canonical_signature_entry
|
147
|
+
module_function :canonical_signature
|
148
|
+
module_function :derived_from?
|
149
|
+
end
|
150
|
+
|
151
|
+
class BaseType # :nodoc:
|
152
|
+
include SignatureTypes
|
153
|
+
|
154
|
+
attr :spec
|
155
|
+
attr :type
|
156
|
+
attr :type_class
|
157
|
+
attr :name
|
158
|
+
|
159
|
+
def initialize(spec, type, name)
|
160
|
+
@spec = spec
|
161
|
+
@type = canonical_type(type)
|
162
|
+
@type_class = canonical_type_class(@type)
|
163
|
+
@name = name
|
164
|
+
end
|
165
|
+
|
166
|
+
def custom?
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
def array?
|
171
|
+
false
|
172
|
+
end
|
173
|
+
|
174
|
+
def structured?
|
175
|
+
false
|
176
|
+
end
|
177
|
+
|
178
|
+
def human_name(show_name=true)
|
179
|
+
type_type = array? ? element_type.type.to_s : self.type.to_s
|
180
|
+
str = array? ? (type_type + '[]') : type_type
|
181
|
+
show_name ? (str + " " + name.to_s) : str
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class ArrayType < BaseType # :nodoc:
|
186
|
+
attr :element_type
|
187
|
+
|
188
|
+
def initialize(spec, element_type, name)
|
189
|
+
super(spec, Array, name)
|
190
|
+
@element_type = element_type
|
191
|
+
end
|
192
|
+
|
193
|
+
def custom?
|
194
|
+
true
|
195
|
+
end
|
196
|
+
|
197
|
+
def array?
|
198
|
+
true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class StructuredType < BaseType # :nodoc:
|
203
|
+
def each_member
|
204
|
+
if @type_class.respond_to?(:members)
|
205
|
+
@type_class.members.each do |name, type|
|
206
|
+
yield name, type
|
207
|
+
end
|
208
|
+
elsif @type_class.respond_to?(:columns)
|
209
|
+
i = -1
|
210
|
+
@type_class.columns.each do |column|
|
211
|
+
yield column.name, canonical_signature_entry(column.type, i += 1)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def custom?
|
217
|
+
true
|
218
|
+
end
|
219
|
+
|
220
|
+
def structured?
|
221
|
+
true
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class Base64 < String # :nodoc:
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
module Test # :nodoc:
|
4
|
+
module Unit # :nodoc:
|
5
|
+
class TestCase # :nodoc:
|
6
|
+
private
|
7
|
+
# invoke the specified API method
|
8
|
+
def invoke_direct(method_name, *args)
|
9
|
+
prepare_request('api', 'api', method_name, *args)
|
10
|
+
@controller.process(@request, @response)
|
11
|
+
decode_rpc_response
|
12
|
+
end
|
13
|
+
alias_method :invoke, :invoke_direct
|
14
|
+
|
15
|
+
# invoke the specified API method on the specified service
|
16
|
+
def invoke_delegated(service_name, method_name, *args)
|
17
|
+
prepare_request(service_name.to_s, service_name, method_name, *args)
|
18
|
+
@controller.process(@request, @response)
|
19
|
+
decode_rpc_response
|
20
|
+
end
|
21
|
+
|
22
|
+
# invoke the specified layered API method on the correct service
|
23
|
+
def invoke_layered(service_name, method_name, *args)
|
24
|
+
prepare_request('api', service_name, method_name, *args)
|
25
|
+
@controller.process(@request, @response)
|
26
|
+
decode_rpc_response
|
27
|
+
end
|
28
|
+
|
29
|
+
# ---------------------- internal ---------------------------
|
30
|
+
|
31
|
+
def prepare_request(action, service_name, api_method_name, *args)
|
32
|
+
@request.recycle!
|
33
|
+
@request.request_parameters['action'] = action
|
34
|
+
@request.env['REQUEST_METHOD'] = 'POST'
|
35
|
+
@request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
|
36
|
+
@request.env['RAW_POST_DATA'] = encode_rpc_call(service_name, api_method_name, *args)
|
37
|
+
case protocol
|
38
|
+
when ActionWebService::Protocol::Soap::SoapProtocol
|
39
|
+
soap_action = "/#{@controller.controller_name}/#{service_name}/#{public_method_name(service_name, api_method_name)}"
|
40
|
+
@request.env['HTTP_SOAPACTION'] = soap_action
|
41
|
+
when ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
|
42
|
+
@request.env.delete('HTTP_SOAPACTION')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def encode_rpc_call(service_name, api_method_name, *args)
|
47
|
+
case @controller.web_service_dispatching_mode
|
48
|
+
when :direct
|
49
|
+
api = @controller.class.web_service_api
|
50
|
+
when :delegated, :layered
|
51
|
+
api = @controller.web_service_object(service_name.to_sym).class.web_service_api
|
52
|
+
end
|
53
|
+
protocol.register_api(api)
|
54
|
+
method = api.api_methods[api_method_name.to_sym]
|
55
|
+
raise ArgumentError, "wrong number of arguments for rpc call (#{args.length} for #{method.expects.length})" if method && method.expects && args.length != method.expects.length
|
56
|
+
protocol.encode_request(public_method_name(service_name, api_method_name), args.dup, method.expects)
|
57
|
+
end
|
58
|
+
|
59
|
+
def decode_rpc_response
|
60
|
+
public_method_name, return_value = protocol.decode_response(@response.body)
|
61
|
+
exception = is_exception?(return_value)
|
62
|
+
raise exception if exception
|
63
|
+
return_value
|
64
|
+
end
|
65
|
+
|
66
|
+
def public_method_name(service_name, api_method_name)
|
67
|
+
public_name = service_api(service_name).public_api_method_name(api_method_name)
|
68
|
+
if @controller.web_service_dispatching_mode == :layered && protocol.is_a?(ActionWebService::Protocol::XmlRpc::XmlRpcProtocol)
|
69
|
+
'%s.%s' % [service_name.to_s, public_name]
|
70
|
+
else
|
71
|
+
public_name
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def service_api(service_name)
|
76
|
+
case @controller.web_service_dispatching_mode
|
77
|
+
when :direct
|
78
|
+
@controller.class.web_service_api
|
79
|
+
when :delegated, :layered
|
80
|
+
@controller.web_service_object(service_name.to_sym).class.web_service_api
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def protocol
|
85
|
+
if @protocol.nil?
|
86
|
+
@protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
|
87
|
+
else
|
88
|
+
case @protocol
|
89
|
+
when :xmlrpc
|
90
|
+
@protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.create(@controller)
|
91
|
+
when :soap
|
92
|
+
@protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
|
93
|
+
else
|
94
|
+
@protocol
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_exception?(obj)
|
100
|
+
case protocol
|
101
|
+
when :soap, ActionWebService::Protocol::Soap::SoapProtocol
|
102
|
+
(obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
|
103
|
+
obj.detail.cause.is_a?(Exception)) ? obj.detail.cause : nil
|
104
|
+
when :xmlrpc, ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
|
105
|
+
obj.is_a?(XMLRPC::FaultException) ? obj : nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# WSDL4R - WSDL binding definition.
|
2
|
+
# Copyright (C) 2002, 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
3
|
+
|
4
|
+
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
5
|
+
# redistribute it and/or modify it under the same terms of Ruby's license;
|
6
|
+
# either the dual license version in 2003, or any later version.
|
7
|
+
|
8
|
+
|
9
|
+
require 'action_web_service/wsdl/info'
|
10
|
+
require 'action_web_service/xsd/namedelements'
|
11
|
+
|
12
|
+
|
13
|
+
module WSDL
|
14
|
+
|
15
|
+
|
16
|
+
class Binding < Info
|
17
|
+
attr_reader :name # required
|
18
|
+
attr_reader :type # required
|
19
|
+
attr_reader :operations
|
20
|
+
attr_reader :soapbinding
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
super
|
24
|
+
@name = nil
|
25
|
+
@type = nil
|
26
|
+
@operations = XSD::NamedElements.new
|
27
|
+
@soapbinding = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def targetnamespace
|
31
|
+
parent.targetnamespace
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_element(element)
|
35
|
+
case element
|
36
|
+
when OperationName
|
37
|
+
o = OperationBinding.new
|
38
|
+
@operations << o
|
39
|
+
o
|
40
|
+
when SOAPBindingName
|
41
|
+
o = WSDL::SOAP::Binding.new
|
42
|
+
@soapbinding = o
|
43
|
+
o
|
44
|
+
when DocumentationName
|
45
|
+
o = Documentation.new
|
46
|
+
o
|
47
|
+
else
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def parse_attr(attr, value)
|
53
|
+
case attr
|
54
|
+
when NameAttrName
|
55
|
+
@name = XSD::QName.new(targetnamespace, value.source)
|
56
|
+
when TypeAttrName
|
57
|
+
@type = value
|
58
|
+
else
|
59
|
+
nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|