soybean 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +15 -0
  4. data/Gemfile.lock +38 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +44 -0
  8. data/VERSION +1 -0
  9. data/bin/soybean +22 -0
  10. data/bin/xsd2ruby +90 -0
  11. data/lib/soybean.rb +11 -0
  12. data/lib/soybean/actions/generate_classes.rb +33 -0
  13. data/soybean.gemspec +236 -0
  14. data/spec/soybean_spec.rb +5 -0
  15. data/spec/spec_helper.rb +12 -0
  16. data/vendor/soap4r/soap/attachment.rb +109 -0
  17. data/vendor/soap4r/soap/attrproxy.rb +35 -0
  18. data/vendor/soap4r/soap/base_data.rb +1095 -0
  19. data/vendor/soap4r/soap/element.rb +278 -0
  20. data/vendor/soap4r/soap/encodingstyle/asp_dot_net_handler.rb +208 -0
  21. data/vendor/soap4r/soap/encodingstyle/handler.rb +121 -0
  22. data/vendor/soap4r/soap/encodingstyle/literal_handler.rb +196 -0
  23. data/vendor/soap4r/soap/encodingstyle/soap_handler.rb +560 -0
  24. data/vendor/soap4r/soap/filter.rb +14 -0
  25. data/vendor/soap4r/soap/filter/filterchain.rb +52 -0
  26. data/vendor/soap4r/soap/filter/handler.rb +32 -0
  27. data/vendor/soap4r/soap/filter/streamhandler.rb +30 -0
  28. data/vendor/soap4r/soap/generator.rb +299 -0
  29. data/vendor/soap4r/soap/header/handler.rb +62 -0
  30. data/vendor/soap4r/soap/header/handlerset.rb +71 -0
  31. data/vendor/soap4r/soap/header/mappinghandler.rb +48 -0
  32. data/vendor/soap4r/soap/header/simplehandler.rb +45 -0
  33. data/vendor/soap4r/soap/httpconfigloader.rb +140 -0
  34. data/vendor/soap4r/soap/mapping.rb +13 -0
  35. data/vendor/soap4r/soap/mapping/encodedregistry.rb +539 -0
  36. data/vendor/soap4r/soap/mapping/factory.rb +389 -0
  37. data/vendor/soap4r/soap/mapping/literalregistry.rb +392 -0
  38. data/vendor/soap4r/soap/mapping/mapping.rb +577 -0
  39. data/vendor/soap4r/soap/mapping/registry.rb +296 -0
  40. data/vendor/soap4r/soap/mapping/rubytype_factory.rb +446 -0
  41. data/vendor/soap4r/soap/mapping/schemadefinition.rb +171 -0
  42. data/vendor/soap4r/soap/mapping/type_map.rb +107 -0
  43. data/vendor/soap4r/soap/mapping/wsdlencodedregistry.rb +212 -0
  44. data/vendor/soap4r/soap/mapping/wsdlliteralregistry.rb +249 -0
  45. data/vendor/soap4r/soap/marshal.rb +60 -0
  46. data/vendor/soap4r/soap/mimemessage.rb +243 -0
  47. data/vendor/soap4r/soap/nestedexception.rb +43 -0
  48. data/vendor/soap4r/soap/net_http_client.rb +242 -0
  49. data/vendor/soap4r/soap/ns.rb +39 -0
  50. data/vendor/soap4r/soap/parser.rb +253 -0
  51. data/vendor/soap4r/soap/processor.rb +67 -0
  52. data/vendor/soap4r/soap/property.rb +340 -0
  53. data/vendor/soap4r/soap/proxy.rb +15 -0
  54. data/vendor/soap4r/soap/rpc/cgistub.rb +248 -0
  55. data/vendor/soap4r/soap/rpc/driver.rb +222 -0
  56. data/vendor/soap4r/soap/rpc/element.rb +375 -0
  57. data/vendor/soap4r/soap/rpc/httpserver.rb +143 -0
  58. data/vendor/soap4r/soap/rpc/method_def.rb +69 -0
  59. data/vendor/soap4r/soap/rpc/proxy.rb +573 -0
  60. data/vendor/soap4r/soap/rpc/router.rb +663 -0
  61. data/vendor/soap4r/soap/rpc/rpc.rb +26 -0
  62. data/vendor/soap4r/soap/rpc/soaplet.rb +201 -0
  63. data/vendor/soap4r/soap/rpc/standalone_server.rb +44 -0
  64. data/vendor/soap4r/soap/soap.rb +154 -0
  65. data/vendor/soap4r/soap/stream_handler.rb +302 -0
  66. data/vendor/soap4r/soap/version.rb +9 -0
  67. data/vendor/soap4r/soap/wsdl_driver.rb +165 -0
  68. data/vendor/soap4r/wsdl/binding.rb +66 -0
  69. data/vendor/soap4r/wsdl/data.rb +65 -0
  70. data/vendor/soap4r/wsdl/definitions.rb +237 -0
  71. data/vendor/soap4r/wsdl/documentation.rb +33 -0
  72. data/vendor/soap4r/wsdl/import.rb +81 -0
  73. data/vendor/soap4r/wsdl/importer.rb +39 -0
  74. data/vendor/soap4r/wsdl/info.rb +51 -0
  75. data/vendor/soap4r/wsdl/message.rb +55 -0
  76. data/vendor/soap4r/wsdl/operation.rb +152 -0
  77. data/vendor/soap4r/wsdl/operation_binding.rb +241 -0
  78. data/vendor/soap4r/wsdl/param.rb +94 -0
  79. data/vendor/soap4r/wsdl/parser.rb +165 -0
  80. data/vendor/soap4r/wsdl/part.rb +53 -0
  81. data/vendor/soap4r/wsdl/port.rb +67 -0
  82. data/vendor/soap4r/wsdl/port_type.rb +76 -0
  83. data/vendor/soap4r/wsdl/service.rb +62 -0
  84. data/vendor/soap4r/wsdl/soap/address.rb +41 -0
  85. data/vendor/soap4r/wsdl/soap/binding.rb +50 -0
  86. data/vendor/soap4r/wsdl/soap/body.rb +59 -0
  87. data/vendor/soap4r/wsdl/soap/cgi_stub_creator.rb +93 -0
  88. data/vendor/soap4r/wsdl/soap/class_def_creator.rb +437 -0
  89. data/vendor/soap4r/wsdl/soap/class_def_creator_support.rb +241 -0
  90. data/vendor/soap4r/wsdl/soap/class_name_creator.rb +55 -0
  91. data/vendor/soap4r/wsdl/soap/client_skelton_creator.rb +107 -0
  92. data/vendor/soap4r/wsdl/soap/complex_type.rb +174 -0
  93. data/vendor/soap4r/wsdl/soap/data.rb +43 -0
  94. data/vendor/soap4r/wsdl/soap/definitions.rb +201 -0
  95. data/vendor/soap4r/wsdl/soap/driver_creator.rb +121 -0
  96. data/vendor/soap4r/wsdl/soap/element.rb +34 -0
  97. data/vendor/soap4r/wsdl/soap/encoded_mapping_registry_creator.rb +74 -0
  98. data/vendor/soap4r/wsdl/soap/fault.rb +57 -0
  99. data/vendor/soap4r/wsdl/soap/header.rb +87 -0
  100. data/vendor/soap4r/wsdl/soap/headerfault.rb +57 -0
  101. data/vendor/soap4r/wsdl/soap/literal_mapping_registry_creator.rb +116 -0
  102. data/vendor/soap4r/wsdl/soap/mapping_registry_creator.rb +59 -0
  103. data/vendor/soap4r/wsdl/soap/mapping_registry_creator_support.rb +377 -0
  104. data/vendor/soap4r/wsdl/soap/method_def_creator.rb +200 -0
  105. data/vendor/soap4r/wsdl/soap/operation.rb +113 -0
  106. data/vendor/soap4r/wsdl/soap/servant_skelton_creator.rb +92 -0
  107. data/vendor/soap4r/wsdl/soap/servlet_stub_creator.rb +105 -0
  108. data/vendor/soap4r/wsdl/soap/standalone_server_stub_creator.rb +101 -0
  109. data/vendor/soap4r/wsdl/soap/wsdl2ruby.rb +226 -0
  110. data/vendor/soap4r/wsdl/types.rb +45 -0
  111. data/vendor/soap4r/wsdl/wsdl.rb +25 -0
  112. data/vendor/soap4r/wsdl/xml_schema/all.rb +25 -0
  113. data/vendor/soap4r/wsdl/xml_schema/annotation.rb +35 -0
  114. data/vendor/soap4r/wsdl/xml_schema/any.rb +62 -0
  115. data/vendor/soap4r/wsdl/xml_schema/any_attribute.rb +49 -0
  116. data/vendor/soap4r/wsdl/xml_schema/attribute.rb +105 -0
  117. data/vendor/soap4r/wsdl/xml_schema/attribute_group.rb +69 -0
  118. data/vendor/soap4r/wsdl/xml_schema/choice.rb +59 -0
  119. data/vendor/soap4r/wsdl/xml_schema/complex_content.rb +98 -0
  120. data/vendor/soap4r/wsdl/xml_schema/complex_extension.rb +120 -0
  121. data/vendor/soap4r/wsdl/xml_schema/complex_restriction.rb +105 -0
  122. data/vendor/soap4r/wsdl/xml_schema/complex_type.rb +194 -0
  123. data/vendor/soap4r/wsdl/xml_schema/content.rb +96 -0
  124. data/vendor/soap4r/wsdl/xml_schema/data.rb +117 -0
  125. data/vendor/soap4r/wsdl/xml_schema/element.rb +154 -0
  126. data/vendor/soap4r/wsdl/xml_schema/enumeration.rb +37 -0
  127. data/vendor/soap4r/wsdl/xml_schema/fractiondigits.rb +38 -0
  128. data/vendor/soap4r/wsdl/xml_schema/group.rb +101 -0
  129. data/vendor/soap4r/wsdl/xml_schema/import.rb +54 -0
  130. data/vendor/soap4r/wsdl/xml_schema/import_handler.rb +46 -0
  131. data/vendor/soap4r/wsdl/xml_schema/importer.rb +103 -0
  132. data/vendor/soap4r/wsdl/xml_schema/include.rb +49 -0
  133. data/vendor/soap4r/wsdl/xml_schema/length.rb +38 -0
  134. data/vendor/soap4r/wsdl/xml_schema/list.rb +49 -0
  135. data/vendor/soap4r/wsdl/xml_schema/maxexclusive.rb +38 -0
  136. data/vendor/soap4r/wsdl/xml_schema/maxinclusive.rb +38 -0
  137. data/vendor/soap4r/wsdl/xml_schema/maxlength.rb +38 -0
  138. data/vendor/soap4r/wsdl/xml_schema/minexclusive.rb +38 -0
  139. data/vendor/soap4r/wsdl/xml_schema/mininclusive.rb +38 -0
  140. data/vendor/soap4r/wsdl/xml_schema/minlength.rb +38 -0
  141. data/vendor/soap4r/wsdl/xml_schema/parser.rb +168 -0
  142. data/vendor/soap4r/wsdl/xml_schema/pattern.rb +37 -0
  143. data/vendor/soap4r/wsdl/xml_schema/ref.rb +34 -0
  144. data/vendor/soap4r/wsdl/xml_schema/schema.rb +179 -0
  145. data/vendor/soap4r/wsdl/xml_schema/sequence.rb +55 -0
  146. data/vendor/soap4r/wsdl/xml_schema/simple_content.rb +70 -0
  147. data/vendor/soap4r/wsdl/xml_schema/simple_extension.rb +63 -0
  148. data/vendor/soap4r/wsdl/xml_schema/simple_restriction.rb +133 -0
  149. data/vendor/soap4r/wsdl/xml_schema/simple_type.rb +88 -0
  150. data/vendor/soap4r/wsdl/xml_schema/totaldigits.rb +38 -0
  151. data/vendor/soap4r/wsdl/xml_schema/union.rb +36 -0
  152. data/vendor/soap4r/wsdl/xml_schema/unique.rb +35 -0
  153. data/vendor/soap4r/wsdl/xml_schema/whitespace.rb +38 -0
  154. data/vendor/soap4r/wsdl/xml_schema/xsd2ruby.rb +176 -0
  155. data/vendor/soap4r/xsd/charset.rb +190 -0
  156. data/vendor/soap4r/xsd/codegen.rb +13 -0
  157. data/vendor/soap4r/xsd/codegen/classdef.rb +209 -0
  158. data/vendor/soap4r/xsd/codegen/commentdef.rb +35 -0
  159. data/vendor/soap4r/xsd/codegen/gensupport.rb +277 -0
  160. data/vendor/soap4r/xsd/codegen/methoddef.rb +71 -0
  161. data/vendor/soap4r/xsd/codegen/moduledef.rb +209 -0
  162. data/vendor/soap4r/xsd/datatypes.rb +1466 -0
  163. data/vendor/soap4r/xsd/datatypes1999.rb +21 -0
  164. data/vendor/soap4r/xsd/iconvcharset.rb +34 -0
  165. data/vendor/soap4r/xsd/mapping.rb +69 -0
  166. data/vendor/soap4r/xsd/namedelements.rb +133 -0
  167. data/vendor/soap4r/xsd/ns.rb +183 -0
  168. data/vendor/soap4r/xsd/qname.rb +80 -0
  169. data/vendor/soap4r/xsd/xmlparser.rb +77 -0
  170. data/vendor/soap4r/xsd/xmlparser/libxmlparser.rb +116 -0
  171. data/vendor/soap4r/xsd/xmlparser/parser.rb +101 -0
  172. data/vendor/soap4r/xsd/xmlparser/rexmlparser.rb +59 -0
  173. data/vendor/soap4r/xsd/xmlparser/xmlparser.rb +51 -0
  174. data/vendor/soap4r/xsd/xmlparser/xmlscanner.rb +150 -0
  175. metadata +316 -0
@@ -0,0 +1,143 @@
1
+ # encoding: ASCII-8BIT
2
+ # SOAP4R - WEBrick HTTP Server
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'logger'
11
+ require 'soap/attrproxy'
12
+ require 'soap/rpc/soaplet'
13
+ require 'soap/streamHandler'
14
+ require 'webrick'
15
+
16
+
17
+ module SOAP
18
+ module RPC
19
+
20
+
21
+ class HTTPServer < Logger::Application
22
+ include AttrProxy
23
+
24
+ attr_reader :server
25
+ attr_accessor :default_namespace
26
+
27
+ attr_proxy :mapping_registry, true
28
+ attr_proxy :literal_mapping_registry, true
29
+ attr_proxy :generate_explicit_type, true
30
+ attr_proxy :use_default_namespace, true
31
+
32
+ def initialize(config)
33
+ actor = config[:SOAPHTTPServerApplicationName] || self.class.name
34
+ super(actor)
35
+ @default_namespace = config[:SOAPDefaultNamespace]
36
+ @webrick_config = config.dup
37
+ self.level = Logger::Severity::ERROR # keep silent by default
38
+ @webrick_config[:Logger] ||= @log
39
+ @log = @webrick_config[:Logger] # sync logger of App and HTTPServer
40
+ @router = ::SOAP::RPC::Router.new(actor)
41
+ @soaplet = ::SOAP::RPC::SOAPlet.new(@router)
42
+ on_init
43
+ @server = WEBrick::HTTPServer.new(@webrick_config)
44
+ @server.mount('/soaprouter', @soaplet)
45
+ if wsdldir = config[:WSDLDocumentDirectory]
46
+ @server.mount('/wsdl', WEBrick::HTTPServlet::FileHandler, wsdldir)
47
+ end
48
+ @server.mount('/', @soaplet)
49
+ end
50
+
51
+ def on_init
52
+ # do extra initialization in a derived class if needed.
53
+ end
54
+
55
+ def status
56
+ @server.status if @server
57
+ end
58
+
59
+ def shutdown
60
+ @server.shutdown if @server
61
+ end
62
+
63
+ def authenticator
64
+ @soaplet.authenticator
65
+ end
66
+
67
+ def authenticator=(authenticator)
68
+ @soaplet.authenticator = authenticator
69
+ end
70
+
71
+ # servant entry interface
72
+
73
+ def add_rpc_request_servant(factory, namespace = @default_namespace)
74
+ @router.add_rpc_request_servant(factory, namespace)
75
+ end
76
+
77
+ def add_rpc_servant(obj, namespace = @default_namespace)
78
+ @router.add_rpc_servant(obj, namespace)
79
+ end
80
+
81
+ def add_request_headerhandler(factory)
82
+ @router.add_request_headerhandler(factory)
83
+ end
84
+
85
+ def add_headerhandler(obj)
86
+ @router.add_headerhandler(obj)
87
+ end
88
+ alias add_rpc_headerhandler add_headerhandler
89
+
90
+ def filterchain
91
+ @router.filterchain
92
+ end
93
+
94
+ # method entry interface
95
+
96
+ def add_rpc_method(obj, name, *param)
97
+ add_rpc_method_as(obj, name, name, *param)
98
+ end
99
+ alias add_method add_rpc_method
100
+
101
+ def add_rpc_method_as(obj, name, name_as, *param)
102
+ qname = XSD::QName.new(@default_namespace, name_as)
103
+ soapaction = nil
104
+ param_def = SOAPMethod.derive_rpc_param_def(obj, name, *param)
105
+ @router.add_rpc_operation(obj, qname, soapaction, name, param_def)
106
+ end
107
+ alias add_method_as add_rpc_method_as
108
+
109
+ def add_document_method(obj, soapaction, name, req_qnames, res_qnames)
110
+ param_def = SOAPMethod.create_doc_param_def(req_qnames, res_qnames)
111
+ @router.add_document_operation(obj, soapaction, name, param_def)
112
+ end
113
+
114
+ def add_rpc_operation(receiver, qname, soapaction, name, param_def, opt = {})
115
+ @router.add_rpc_operation(receiver, qname, soapaction, name, param_def, opt)
116
+ end
117
+
118
+ def add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt = {})
119
+ @router.add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt)
120
+ end
121
+
122
+ def add_document_operation(receiver, soapaction, name, param_def, opt = {})
123
+ @router.add_document_operation(receiver, soapaction, name, param_def, opt)
124
+ end
125
+
126
+ def add_document_request_operation(factory, soapaction, name, param_def, opt = {})
127
+ @router.add_document_request_operation(factory, soapaction, name, param_def, opt)
128
+ end
129
+
130
+ private
131
+
132
+ def attrproxy
133
+ @router
134
+ end
135
+
136
+ def run
137
+ @server.start
138
+ end
139
+ end
140
+
141
+
142
+ end
143
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: ASCII-8BIT
2
+ # SOAP4R - A method definition
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ module SOAP
11
+ module RPC
12
+
13
+
14
+ class MethodDef
15
+ attr_reader :name
16
+ attr_reader :soapaction
17
+ attr_reader :qname
18
+ attr_accessor :style
19
+ attr_accessor :inputuse
20
+ attr_accessor :outputuse
21
+ attr_reader :parameters
22
+ attr_reader :faults
23
+
24
+ def initialize(name, soapaction, qname)
25
+ @name = name
26
+ @soapaction = soapaction
27
+ @qname = qname
28
+ @style = @inputuse = @outputuse = nil
29
+ @parameters = []
30
+ @faults = {}
31
+ end
32
+
33
+ def add_parameter(io_type, name, qname, mapped_class)
34
+ @parameters << Parameter.new(io_type, name, qname, mapped_class)
35
+ end
36
+
37
+ def self.to_param(param)
38
+ if param.respond_to?(:io_type)
39
+ param
40
+ else
41
+ io_type, name, param_type = param
42
+ mapped_class_str, nsdef, namedef = param_type
43
+ if nsdef && namedef
44
+ qname = XSD::QName.new(nsdef, namedef)
45
+ else
46
+ qname = nil
47
+ end
48
+ MethodDef::Parameter.new(io_type.to_sym, name, qname, mapped_class_str)
49
+ end
50
+ end
51
+
52
+ class Parameter
53
+ attr_reader :io_type
54
+ attr_reader :name
55
+ attr_reader :qname
56
+ attr_reader :mapped_class
57
+
58
+ def initialize(io_type, name, qname, mapped_class)
59
+ @io_type = io_type
60
+ @name = name
61
+ @qname = qname
62
+ @mapped_class = mapped_class
63
+ end
64
+ end
65
+ end
66
+
67
+
68
+ end
69
+ end
@@ -0,0 +1,573 @@
1
+ # encoding: ASCII-8BIT
2
+ # SOAP4R - RPC Proxy library.
3
+ # Copyright (C) 2000-2007 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
4
+
5
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
6
+ # redistribute it and/or modify it under the same terms of Ruby's license;
7
+ # either the dual license version in 2003, or any later version.
8
+
9
+
10
+ require 'soap/soap'
11
+ require 'soap/processor'
12
+ require 'soap/mapping'
13
+ require 'soap/mapping/literalregistry'
14
+ require 'soap/rpc/rpc'
15
+ require 'soap/rpc/element'
16
+ require 'soap/header/handlerset'
17
+ require 'soap/filter'
18
+ require 'soap/streamHandler'
19
+ require 'soap/mimemessage'
20
+
21
+
22
+ module SOAP
23
+ module RPC
24
+
25
+
26
+ class Proxy
27
+ include SOAP
28
+
29
+ public
30
+
31
+ attr_accessor :soapaction
32
+ attr_accessor :mandatorycharset
33
+ attr_accessor :allow_unqualified_element
34
+ attr_accessor :default_encodingstyle
35
+ attr_accessor :generate_explicit_type
36
+ attr_accessor :use_default_namespace
37
+ attr_accessor :return_response_as_xml
38
+ attr_reader :headerhandler
39
+ attr_reader :filterchain
40
+ attr_reader :streamhandler
41
+
42
+ attr_accessor :mapping_registry
43
+ attr_accessor :literal_mapping_registry
44
+
45
+ attr_reader :operation
46
+
47
+ def initialize(endpoint_url, soapaction, options)
48
+ @endpoint_url = endpoint_url
49
+ @soapaction = soapaction
50
+ @options = options
51
+ @protocol_option = options["protocol"] ||= ::SOAP::Property.new
52
+ initialize_streamhandler(@protocol_option)
53
+ @operation = {}
54
+ @operation_by_qname = {}
55
+ @operation_by_soapaction = {}
56
+ @mandatorycharset = nil
57
+ # TODO: set to false by default or drop thie option in 1.6.0
58
+ @allow_unqualified_element = true
59
+ @default_encodingstyle = nil
60
+ @generate_explicit_type = nil
61
+ @use_default_namespace = false
62
+ @return_response_as_xml = false
63
+ @headerhandler = Header::HandlerSet.new
64
+ @filterchain = Filter::FilterChain.new
65
+ @mapping_registry = nil
66
+ @literal_mapping_registry = ::SOAP::Mapping::LiteralRegistry.new
67
+ end
68
+
69
+ def inspect
70
+ "#<#{self.class}:#{@endpoint_url}>"
71
+ end
72
+
73
+ def endpoint_url
74
+ @endpoint_url
75
+ end
76
+
77
+ def endpoint_url=(endpoint_url)
78
+ @endpoint_url = endpoint_url
79
+ reset_stream
80
+ end
81
+
82
+ def reset_stream
83
+ @streamhandler.reset(@endpoint_url)
84
+ end
85
+
86
+ def set_wiredump_file_base(wiredump_file_base)
87
+ @streamhandler.wiredump_file_base = wiredump_file_base
88
+ end
89
+
90
+ def test_loopback_response
91
+ @streamhandler.test_loopback_response
92
+ end
93
+
94
+ def add_rpc_operation(qname, soapaction, name, param_def, opt = {})
95
+ ensure_styleuse_option(opt, :rpc, :encoded)
96
+ opt[:request_qname] = qname
97
+ op = Operation.new(soapaction, param_def, opt)
98
+ assign_operation(name, qname, soapaction, op)
99
+ end
100
+
101
+ def add_document_operation(soapaction, name, param_def, opt = {})
102
+ ensure_styleuse_option(opt, :document, :literal)
103
+ op = Operation.new(soapaction, param_def, opt)
104
+ assign_operation(name, nil, soapaction, op)
105
+ end
106
+
107
+ # add_method is for shortcut of typical rpc/encoded method definition.
108
+ alias add_method add_rpc_operation
109
+ alias add_rpc_method add_rpc_operation
110
+ alias add_document_method add_document_operation
111
+
112
+ def invoke(req_header, req_body, opt = nil)
113
+ opt ||= create_encoding_opt
114
+ env = route(req_header, req_body, opt, opt)
115
+ if @return_response_as_xml
116
+ opt[:response_as_xml]
117
+ else
118
+ env
119
+ end
120
+ end
121
+
122
+ def call(name, *params)
123
+ # name must be used only for lookup
124
+ op_info = lookup_operation(name)
125
+ mapping_opt = create_mapping_opt
126
+ req_header = create_request_header
127
+ req_body = SOAPBody.new(
128
+ op_info.request_body(params, @mapping_registry,
129
+ @literal_mapping_registry, mapping_opt)
130
+ )
131
+ reqopt = create_encoding_opt(
132
+ :soapaction => op_info.soapaction || @soapaction,
133
+ :envelopenamespace => @options["soap.envelope.requestnamespace"],
134
+ :default_encodingstyle =>
135
+ @default_encodingstyle || op_info.request_default_encodingstyle,
136
+ :use_default_namespace =>
137
+ op_info.use_default_namespace || @use_default_namespace
138
+ )
139
+ resopt = create_encoding_opt(
140
+ :envelopenamespace => @options["soap.envelope.responsenamespace"],
141
+ :default_encodingstyle =>
142
+ @default_encodingstyle || op_info.response_default_encodingstyle
143
+ )
144
+ if reqopt[:generate_explicit_type].nil?
145
+ reqopt[:generate_explicit_type] = (op_info.request_use == :encoded)
146
+ end
147
+ if resopt[:generate_explicit_type].nil?
148
+ resopt[:generate_explicit_type] = (op_info.response_use == :encoded)
149
+ end
150
+ env = route(req_header, req_body, reqopt, resopt)
151
+ if op_info.response_use.nil?
152
+ return nil
153
+ end
154
+ raise EmptyResponseError unless env
155
+ receive_headers(env.header)
156
+ begin
157
+ check_fault(env.body)
158
+ rescue ::SOAP::FaultError => e
159
+ op_info.raise_fault(e, @mapping_registry, @literal_mapping_registry)
160
+ end
161
+ if @return_response_as_xml
162
+ resopt[:response_as_xml]
163
+ else
164
+ op_info.response_obj(env.body, @mapping_registry,
165
+ @literal_mapping_registry, mapping_opt)
166
+ end
167
+ end
168
+
169
+ def route(req_header, req_body, reqopt, resopt)
170
+ req_env = ::SOAP::SOAPEnvelope.new(req_header, req_body)
171
+ unless reqopt[:envelopenamespace].nil?
172
+ set_envelopenamespace(req_env, reqopt[:envelopenamespace])
173
+ end
174
+ reqopt[:external_content] = nil
175
+ conn_data = marshal(req_env, reqopt)
176
+ if ext = reqopt[:external_content]
177
+ mime = MIMEMessage.new
178
+ ext.each do |k, v|
179
+ mime.add_attachment(v.data)
180
+ end
181
+ mime.add_part(conn_data.send_string + "\r\n")
182
+ mime.close
183
+ conn_data.send_string = mime.content_str
184
+ conn_data.send_contenttype = mime.headers['content-type'].str
185
+ end
186
+ conn_data.soapaction = reqopt[:soapaction]
187
+ conn_data = @streamhandler.send(@endpoint_url, conn_data)
188
+ if conn_data.receive_string.empty?
189
+ return nil
190
+ end
191
+ unmarshal(conn_data, resopt)
192
+ end
193
+
194
+ def check_fault(body)
195
+ if body.fault
196
+ raise SOAP::FaultError.new(body.fault)
197
+ end
198
+ end
199
+
200
+ private
201
+
202
+ def ensure_styleuse_option(opt, style, use)
203
+ if opt[:request_style] || opt[:response_style] || opt[:request_use] || opt[:response_use]
204
+ # do not edit
205
+ else
206
+ opt[:request_style] ||= style
207
+ opt[:response_style] ||= style
208
+ opt[:request_use] ||= use
209
+ opt[:response_use] ||= use
210
+ end
211
+ end
212
+
213
+ def initialize_streamhandler(options)
214
+ value = options["streamhandler"]
215
+ if value and !value.empty?
216
+ factory = Property::Util.const_from_name(value)
217
+ else
218
+ factory = HTTPStreamHandler
219
+ end
220
+ @streamhandler = factory.create(options)
221
+ options.add_hook("streamhandler") do |key, value|
222
+ @streamhandler.reset
223
+ if value.respond_to?(:create)
224
+ factory = value
225
+ elsif value and !value.to_str.empty?
226
+ factory = Property::Util.const_from_name(value.to_str)
227
+ else
228
+ factory = HTTPStreamHandler
229
+ end
230
+ options.unlock(true)
231
+ @streamhandler = factory.create(options)
232
+ end
233
+ end
234
+
235
+ def set_envelopenamespace(env, namespace)
236
+ env.elename = XSD::QName.new(namespace, env.elename.name)
237
+ if env.header
238
+ env.header.elename = XSD::QName.new(namespace, env.header.elename.name)
239
+ end
240
+ if env.body
241
+ env.body.elename = XSD::QName.new(namespace, env.body.elename.name)
242
+ end
243
+ end
244
+
245
+ def create_request_header
246
+ header = ::SOAP::SOAPHeader.new
247
+ items = @headerhandler.on_outbound(header)
248
+ items.each do |item|
249
+ header.add(item.elename.name, item)
250
+ end
251
+ header
252
+ end
253
+
254
+ def receive_headers(header)
255
+ @headerhandler.on_inbound(header) if header
256
+ end
257
+
258
+ def marshal(env, opt)
259
+ @filterchain.each do |filter|
260
+ env = filter.on_outbound(env, opt)
261
+ break unless env
262
+ end
263
+ send_string = Processor.marshal(env, opt)
264
+ StreamHandler::ConnectionData.new(send_string)
265
+ end
266
+
267
+ def unmarshal(conn_data, opt)
268
+ contenttype = conn_data.receive_contenttype
269
+ xml = nil
270
+ if /#{MIMEMessage::MultipartContentType}/i =~ contenttype
271
+ opt[:external_content] = {}
272
+ mime = MIMEMessage.parse("Content-Type: " + contenttype,
273
+ conn_data.receive_string)
274
+ mime.parts.each do |part|
275
+ value = Attachment.new(part.content)
276
+ value.contentid = part.contentid
277
+ obj = SOAPAttachment.new(value)
278
+ opt[:external_content][value.contentid] = obj if value.contentid
279
+ end
280
+ opt[:charset] = @mandatorycharset ||
281
+ StreamHandler.parse_media_type(mime.root.headers['content-type'].str)
282
+ xml = mime.root.content
283
+ else
284
+ opt[:charset] = @mandatorycharset ||
285
+ ::SOAP::StreamHandler.parse_media_type(contenttype)
286
+ xml = conn_data.receive_string
287
+ end
288
+ @filterchain.reverse_each do |filter|
289
+ xml = filter.on_inbound(xml, opt)
290
+ break unless xml
291
+ end
292
+ env = Processor.unmarshal(xml, opt)
293
+ if @return_response_as_xml
294
+ opt[:response_as_xml] = xml
295
+ end
296
+ unless env.is_a?(::SOAP::SOAPEnvelope)
297
+ raise ResponseFormatError.new("response is not a SOAP envelope: #{env}")
298
+ end
299
+ env
300
+ end
301
+
302
+ def create_encoding_opt(hash = nil)
303
+ opt = {}
304
+ opt[:default_encodingstyle] = @default_encodingstyle
305
+ opt[:allow_unqualified_element] = @allow_unqualified_element
306
+ opt[:generate_explicit_type] = @generate_explicit_type
307
+ opt[:no_indent] = @options["soap.envelope.no_indent"]
308
+ opt[:use_numeric_character_reference] =
309
+ @options["soap.envelope.use_numeric_character_reference"]
310
+ opt.update(hash) if hash
311
+ opt
312
+ end
313
+
314
+ def create_mapping_opt(hash = nil)
315
+ opt = {
316
+ :external_ces => @options["soap.mapping.external_ces"]
317
+ }
318
+ opt.update(hash) if hash
319
+ opt
320
+ end
321
+
322
+ def assign_operation(name, qname, soapaction, op)
323
+ assigned = false
324
+ if name and !name.empty?
325
+ @operation[name] = op
326
+ assigned = true
327
+ end
328
+ if qname
329
+ @operation_by_qname[qname] = op
330
+ assigned = true
331
+ end
332
+ if soapaction and !soapaction.empty?
333
+ @operation_by_soapaction[soapaction] = op
334
+ assigned = true
335
+ end
336
+ unless assigned
337
+ raise MethodDefinitionError.new("cannot assign operation")
338
+ end
339
+ end
340
+
341
+ def lookup_operation(name_or_qname_or_soapaction)
342
+ if op = @operation[name_or_qname_or_soapaction]
343
+ return op
344
+ end
345
+ if op = @operation_by_qname[name_or_qname_or_soapaction]
346
+ return op
347
+ end
348
+ if op = @operation_by_soapaction[name_or_qname_or_soapaction]
349
+ return op
350
+ end
351
+ raise MethodDefinitionError.new(
352
+ "operation: #{name_or_qname_or_soapaction} not supported")
353
+ end
354
+
355
+ class Operation
356
+ attr_reader :soapaction
357
+ attr_reader :request_style
358
+ attr_reader :response_style
359
+ attr_reader :request_use
360
+ attr_reader :response_use
361
+ attr_reader :use_default_namespace
362
+
363
+ def initialize(soapaction, param_def, opt)
364
+ @soapaction = soapaction
365
+ @request_style = opt[:request_style]
366
+ @response_style = opt[:response_style]
367
+ @request_use = opt[:request_use]
368
+ @response_use = opt[:response_use]
369
+ @use_default_namespace =
370
+ opt[:use_default_namespace] || opt[:elementformdefault]
371
+ if opt.key?(:elementformdefault)
372
+ warn("option :elementformdefault is deprecated. use :use_default_namespace instead")
373
+ end
374
+ check_style(@request_style)
375
+ check_style(@response_style)
376
+ check_use(@request_use)
377
+ check_use(@response_use)
378
+ if @request_style == :rpc
379
+ @rpc_request_qname = opt[:request_qname]
380
+ if @rpc_request_qname.nil?
381
+ raise MethodDefinitionError.new("rpc_request_qname must be given")
382
+ end
383
+ @rpc_method_factory =
384
+ RPC::SOAPMethodRequest.new(@rpc_request_qname, param_def, @soapaction)
385
+ else
386
+ @doc_request_qnames = []
387
+ @doc_response_qnames = []
388
+ param_def.each do |param|
389
+ param = MethodDef.to_param(param)
390
+ case param.io_type
391
+ when SOAPMethod::IN
392
+ @doc_request_qnames << param.qname
393
+ when SOAPMethod::OUT
394
+ @doc_response_qnames << param.qname
395
+ else
396
+ raise MethodDefinitionError.new(
397
+ "illegal inout definition for document style: #{param.io_type}")
398
+ end
399
+ end
400
+ end
401
+ end
402
+
403
+ def request_default_encodingstyle
404
+ (@request_use == :encoded) ? EncodingNamespace : LiteralNamespace
405
+ end
406
+
407
+ def response_default_encodingstyle
408
+ (@response_use == :encoded) ? EncodingNamespace : LiteralNamespace
409
+ end
410
+
411
+ def request_body(values, mapping_registry, literal_mapping_registry, opt)
412
+ if @request_style == :rpc
413
+ request_rpc(values, mapping_registry, literal_mapping_registry, opt)
414
+ else
415
+ request_doc(values, mapping_registry, literal_mapping_registry, opt)
416
+ end
417
+ end
418
+
419
+ def response_obj(body, mapping_registry, literal_mapping_registry, opt)
420
+ if @response_style == :rpc
421
+ response_rpc(body, mapping_registry, literal_mapping_registry, opt)
422
+ else
423
+ unique_result_for_one_element_array(
424
+ response_doc(body, mapping_registry, literal_mapping_registry, opt))
425
+ end
426
+ end
427
+
428
+ def raise_fault(e, mapping_registry, literal_mapping_registry)
429
+ if @response_style == :rpc
430
+ Mapping.fault2exception(e, mapping_registry)
431
+ else
432
+ Mapping.fault2exception(e, literal_mapping_registry)
433
+ end
434
+ end
435
+
436
+ private
437
+
438
+ # nil for [] / 1 for [1] / [1, 2] for [1, 2]
439
+ def unique_result_for_one_element_array(ary)
440
+ ary.size <= 1 ? ary[0] : ary
441
+ end
442
+
443
+ def check_style(style)
444
+ unless [:rpc, :document].include?(style)
445
+ raise MethodDefinitionError.new("unknown style: #{style}")
446
+ end
447
+ end
448
+
449
+ # nil means oneway
450
+ def check_use(use)
451
+ unless [:encoded, :literal, nil].include?(use)
452
+ raise MethodDefinitionError.new("unknown use: #{use}")
453
+ end
454
+ end
455
+
456
+ def request_rpc(values, mapping_registry, literal_mapping_registry, opt)
457
+ if @request_use == :encoded
458
+ request_rpc_enc(values, mapping_registry, opt)
459
+ else
460
+ request_rpc_lit(values, literal_mapping_registry, opt)
461
+ end
462
+ end
463
+
464
+ def request_doc(values, mapping_registry, literal_mapping_registry, opt)
465
+ if @request_use == :encoded
466
+ request_doc_enc(values, mapping_registry, opt)
467
+ else
468
+ request_doc_lit(values, literal_mapping_registry, opt)
469
+ end
470
+ end
471
+
472
+ def request_rpc_enc(values, mapping_registry, opt)
473
+ method = @rpc_method_factory.dup
474
+ names = method.input_params
475
+ types = method.input_param_types
476
+ ary = Mapping.objs2soap(values, mapping_registry, types, opt)
477
+ soap = {}
478
+ 0.upto(ary.length - 1) do |idx|
479
+ soap[names[idx]] = ary[idx]
480
+ end
481
+ method.set_param(soap)
482
+ method
483
+ end
484
+
485
+ def request_rpc_lit(values, mapping_registry, opt)
486
+ method = @rpc_method_factory.dup
487
+ names = method.input_params
488
+ types = method.get_paramtypes(names)
489
+ params = {}
490
+ idx = 0
491
+ names.each do |name|
492
+ params[name] = Mapping.obj2soap(values[idx], mapping_registry,
493
+ types[idx], opt)
494
+ params[name].elename = XSD::QName.new(nil, name)
495
+ idx += 1
496
+ end
497
+ method.set_param(params)
498
+ method
499
+ end
500
+
501
+ def request_doc_enc(values, mapping_registry, opt)
502
+ (0...values.size).collect { |idx|
503
+ ele = Mapping.obj2soap(values[idx], mapping_registry, nil, opt)
504
+ ele.elename = @doc_request_qnames[idx]
505
+ ele
506
+ }
507
+ end
508
+
509
+ def request_doc_lit(values, mapping_registry, opt)
510
+ (0...values.size).collect { |idx|
511
+ ele = Mapping.obj2soap(values[idx], mapping_registry,
512
+ @doc_request_qnames[idx], opt)
513
+ ele.encodingstyle = LiteralNamespace
514
+ ele
515
+ }
516
+ end
517
+
518
+ def response_rpc(body, mapping_registry, literal_mapping_registry, opt)
519
+ if @response_use == :encoded
520
+ response_rpc_enc(body, mapping_registry, opt)
521
+ else
522
+ response_rpc_lit(body, literal_mapping_registry, opt)
523
+ end
524
+ end
525
+
526
+ def response_doc(body, mapping_registry, literal_mapping_registry, opt)
527
+ if @response_use == :encoded
528
+ response_doc_enc(body, mapping_registry, opt)
529
+ else
530
+ response_doc_lit(body, literal_mapping_registry, opt)
531
+ end
532
+ end
533
+
534
+ def response_rpc_enc(body, mapping_registry, opt)
535
+ ret = nil
536
+ if body.response
537
+ ret = Mapping.soap2obj(body.response, mapping_registry,
538
+ @rpc_method_factory.retval_class_name, opt)
539
+ end
540
+ if body.outparams
541
+ outparams = body.outparams.collect { |outparam|
542
+ Mapping.soap2obj(outparam, mapping_registry, nil, opt)
543
+ }
544
+ [ret].concat(outparams)
545
+ else
546
+ ret
547
+ end
548
+ end
549
+
550
+ def response_rpc_lit(body, mapping_registry, opt)
551
+ body.root_node.collect { |key, value|
552
+ Mapping.soap2obj(value, mapping_registry,
553
+ @rpc_method_factory.retval_class_name, opt)
554
+ }
555
+ end
556
+
557
+ def response_doc_enc(body, mapping_registry, opt)
558
+ body.collect { |key, value|
559
+ Mapping.soap2obj(value, mapping_registry, nil, opt)
560
+ }
561
+ end
562
+
563
+ def response_doc_lit(body, mapping_registry, opt)
564
+ body.collect { |key, value|
565
+ Mapping.soap2obj(value, mapping_registry)
566
+ }
567
+ end
568
+ end
569
+ end
570
+
571
+
572
+ end
573
+ end