soap4r-ng 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +15 -0
  2. data/bin/wsdl2ruby.rb +140 -0
  3. data/bin/xsd2ruby.rb +92 -0
  4. data/lib/soap/attachment.rb +109 -0
  5. data/lib/soap/attrproxy.rb +35 -0
  6. data/lib/soap/baseData.rb +1095 -0
  7. data/lib/soap/element.rb +278 -0
  8. data/lib/soap/encodingstyle/aspDotNetHandler.rb +208 -0
  9. data/lib/soap/encodingstyle/handler.rb +121 -0
  10. data/lib/soap/encodingstyle/literalHandler.rb +196 -0
  11. data/lib/soap/encodingstyle/soapHandler.rb +560 -0
  12. data/lib/soap/filter.rb +14 -0
  13. data/lib/soap/filter/filterchain.rb +52 -0
  14. data/lib/soap/filter/handler.rb +32 -0
  15. data/lib/soap/filter/streamhandler.rb +30 -0
  16. data/lib/soap/generator.rb +299 -0
  17. data/lib/soap/header/handler.rb +62 -0
  18. data/lib/soap/header/handlerset.rb +71 -0
  19. data/lib/soap/header/mappinghandler.rb +48 -0
  20. data/lib/soap/header/simplehandler.rb +45 -0
  21. data/lib/soap/httpconfigloader.rb +140 -0
  22. data/lib/soap/mapping.rb +13 -0
  23. data/lib/soap/mapping/encodedregistry.rb +541 -0
  24. data/lib/soap/mapping/factory.rb +389 -0
  25. data/lib/soap/mapping/literalregistry.rb +392 -0
  26. data/lib/soap/mapping/mapping.rb +577 -0
  27. data/lib/soap/mapping/registry.rb +296 -0
  28. data/lib/soap/mapping/rubytypeFactory.rb +446 -0
  29. data/lib/soap/mapping/schemadefinition.rb +171 -0
  30. data/lib/soap/mapping/typeMap.rb +107 -0
  31. data/lib/soap/mapping/wsdlencodedregistry.rb +212 -0
  32. data/lib/soap/mapping/wsdlliteralregistry.rb +249 -0
  33. data/lib/soap/marshal.rb +60 -0
  34. data/lib/soap/mimemessage.rb +243 -0
  35. data/lib/soap/nestedexception.rb +43 -0
  36. data/lib/soap/netHttpClient.rb +242 -0
  37. data/lib/soap/ns.rb +39 -0
  38. data/lib/soap/parser.rb +253 -0
  39. data/lib/soap/processor.rb +67 -0
  40. data/lib/soap/property.rb +330 -0
  41. data/lib/soap/proxy.rb +15 -0
  42. data/lib/soap/rpc/cgistub.rb +249 -0
  43. data/lib/soap/rpc/driver.rb +222 -0
  44. data/lib/soap/rpc/element.rb +375 -0
  45. data/lib/soap/rpc/httpserver.rb +144 -0
  46. data/lib/soap/rpc/methodDef.rb +69 -0
  47. data/lib/soap/rpc/proxy.rb +573 -0
  48. data/lib/soap/rpc/router.rb +663 -0
  49. data/lib/soap/rpc/rpc.rb +26 -0
  50. data/lib/soap/rpc/soaplet.rb +201 -0
  51. data/lib/soap/rpc/standaloneServer.rb +44 -0
  52. data/lib/soap/soap.rb +154 -0
  53. data/lib/soap/streamHandler.rb +302 -0
  54. data/lib/soap/version.rb +9 -0
  55. data/lib/soap/wsdlDriver.rb +165 -0
  56. data/lib/wsdl/binding.rb +66 -0
  57. data/lib/wsdl/data.rb +65 -0
  58. data/lib/wsdl/definitions.rb +237 -0
  59. data/lib/wsdl/documentation.rb +33 -0
  60. data/lib/wsdl/import.rb +81 -0
  61. data/lib/wsdl/importer.rb +39 -0
  62. data/lib/wsdl/info.rb +51 -0
  63. data/lib/wsdl/message.rb +55 -0
  64. data/lib/wsdl/operation.rb +152 -0
  65. data/lib/wsdl/operationBinding.rb +241 -0
  66. data/lib/wsdl/param.rb +94 -0
  67. data/lib/wsdl/parser.rb +180 -0
  68. data/lib/wsdl/part.rb +53 -0
  69. data/lib/wsdl/port.rb +67 -0
  70. data/lib/wsdl/portType.rb +76 -0
  71. data/lib/wsdl/service.rb +62 -0
  72. data/lib/wsdl/soap/address.rb +41 -0
  73. data/lib/wsdl/soap/binding.rb +50 -0
  74. data/lib/wsdl/soap/body.rb +59 -0
  75. data/lib/wsdl/soap/cgiStubCreator.rb +93 -0
  76. data/lib/wsdl/soap/classDefCreator.rb +434 -0
  77. data/lib/wsdl/soap/classDefCreatorSupport.rb +241 -0
  78. data/lib/wsdl/soap/classNameCreator.rb +55 -0
  79. data/lib/wsdl/soap/clientSkeltonCreator.rb +107 -0
  80. data/lib/wsdl/soap/complexType.rb +174 -0
  81. data/lib/wsdl/soap/data.rb +43 -0
  82. data/lib/wsdl/soap/definitions.rb +201 -0
  83. data/lib/wsdl/soap/driverCreator.rb +121 -0
  84. data/lib/wsdl/soap/element.rb +34 -0
  85. data/lib/wsdl/soap/encodedMappingRegistryCreator.rb +74 -0
  86. data/lib/wsdl/soap/fault.rb +57 -0
  87. data/lib/wsdl/soap/header.rb +87 -0
  88. data/lib/wsdl/soap/headerfault.rb +57 -0
  89. data/lib/wsdl/soap/literalMappingRegistryCreator.rb +116 -0
  90. data/lib/wsdl/soap/mappingRegistryCreator.rb +59 -0
  91. data/lib/wsdl/soap/mappingRegistryCreatorSupport.rb +377 -0
  92. data/lib/wsdl/soap/methodDefCreator.rb +200 -0
  93. data/lib/wsdl/soap/operation.rb +113 -0
  94. data/lib/wsdl/soap/servantSkeltonCreator.rb +92 -0
  95. data/lib/wsdl/soap/servletStubCreator.rb +105 -0
  96. data/lib/wsdl/soap/standaloneServerStubCreator.rb +101 -0
  97. data/lib/wsdl/soap/wsdl2ruby.rb +227 -0
  98. data/lib/wsdl/types.rb +45 -0
  99. data/lib/wsdl/wsdl.rb +25 -0
  100. data/lib/wsdl/xmlSchema/all.rb +25 -0
  101. data/lib/wsdl/xmlSchema/annotation.rb +35 -0
  102. data/lib/wsdl/xmlSchema/any.rb +62 -0
  103. data/lib/wsdl/xmlSchema/anyAttribute.rb +49 -0
  104. data/lib/wsdl/xmlSchema/attribute.rb +105 -0
  105. data/lib/wsdl/xmlSchema/attributeGroup.rb +69 -0
  106. data/lib/wsdl/xmlSchema/choice.rb +59 -0
  107. data/lib/wsdl/xmlSchema/complexContent.rb +98 -0
  108. data/lib/wsdl/xmlSchema/complexExtension.rb +120 -0
  109. data/lib/wsdl/xmlSchema/complexRestriction.rb +105 -0
  110. data/lib/wsdl/xmlSchema/complexType.rb +194 -0
  111. data/lib/wsdl/xmlSchema/content.rb +96 -0
  112. data/lib/wsdl/xmlSchema/data.rb +117 -0
  113. data/lib/wsdl/xmlSchema/element.rb +154 -0
  114. data/lib/wsdl/xmlSchema/enumeration.rb +37 -0
  115. data/lib/wsdl/xmlSchema/fractiondigits.rb +38 -0
  116. data/lib/wsdl/xmlSchema/group.rb +101 -0
  117. data/lib/wsdl/xmlSchema/import.rb +53 -0
  118. data/lib/wsdl/xmlSchema/importHandler.rb +45 -0
  119. data/lib/wsdl/xmlSchema/importer.rb +103 -0
  120. data/lib/wsdl/xmlSchema/include.rb +48 -0
  121. data/lib/wsdl/xmlSchema/length.rb +38 -0
  122. data/lib/wsdl/xmlSchema/list.rb +49 -0
  123. data/lib/wsdl/xmlSchema/maxexclusive.rb +38 -0
  124. data/lib/wsdl/xmlSchema/maxinclusive.rb +38 -0
  125. data/lib/wsdl/xmlSchema/maxlength.rb +38 -0
  126. data/lib/wsdl/xmlSchema/minexclusive.rb +38 -0
  127. data/lib/wsdl/xmlSchema/mininclusive.rb +38 -0
  128. data/lib/wsdl/xmlSchema/minlength.rb +38 -0
  129. data/lib/wsdl/xmlSchema/parser.rb +168 -0
  130. data/lib/wsdl/xmlSchema/pattern.rb +37 -0
  131. data/lib/wsdl/xmlSchema/ref.rb +34 -0
  132. data/lib/wsdl/xmlSchema/schema.rb +179 -0
  133. data/lib/wsdl/xmlSchema/sequence.rb +55 -0
  134. data/lib/wsdl/xmlSchema/simpleContent.rb +70 -0
  135. data/lib/wsdl/xmlSchema/simpleExtension.rb +63 -0
  136. data/lib/wsdl/xmlSchema/simpleRestriction.rb +133 -0
  137. data/lib/wsdl/xmlSchema/simpleType.rb +88 -0
  138. data/lib/wsdl/xmlSchema/totaldigits.rb +38 -0
  139. data/lib/wsdl/xmlSchema/union.rb +36 -0
  140. data/lib/wsdl/xmlSchema/unique.rb +35 -0
  141. data/lib/wsdl/xmlSchema/whitespace.rb +38 -0
  142. data/lib/wsdl/xmlSchema/xsd2ruby.rb +177 -0
  143. data/lib/xsd/charset.rb +190 -0
  144. data/lib/xsd/codegen.rb +13 -0
  145. data/lib/xsd/codegen/classdef.rb +209 -0
  146. data/lib/xsd/codegen/commentdef.rb +35 -0
  147. data/lib/xsd/codegen/gensupport.rb +277 -0
  148. data/lib/xsd/codegen/methoddef.rb +71 -0
  149. data/lib/xsd/codegen/moduledef.rb +209 -0
  150. data/lib/xsd/datatypes.rb +1465 -0
  151. data/lib/xsd/datatypes1999.rb +21 -0
  152. data/lib/xsd/iconvcharset.rb +33 -0
  153. data/lib/xsd/mapping.rb +69 -0
  154. data/lib/xsd/namedelements.rb +133 -0
  155. data/lib/xsd/ns.rb +183 -0
  156. data/lib/xsd/qname.rb +80 -0
  157. data/lib/xsd/xmlparser.rb +81 -0
  158. data/lib/xsd/xmlparser/libxmlparser.rb +135 -0
  159. data/lib/xsd/xmlparser/nokogiriparser.rb +58 -0
  160. data/lib/xsd/xmlparser/ogaparser.rb +63 -0
  161. data/lib/xsd/xmlparser/oxparser.rb +101 -0
  162. data/lib/xsd/xmlparser/parser.rb +101 -0
  163. data/lib/xsd/xmlparser/rexmlparser.rb +58 -0
  164. metadata +236 -0
@@ -0,0 +1,144 @@
1
+ # encoding: UTF-8
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 'logger-application' unless defined?(Logger::Application)
12
+ require 'soap/attrproxy'
13
+ require 'soap/rpc/soaplet'
14
+ require 'soap/streamHandler'
15
+ require 'webrick'
16
+
17
+
18
+ module SOAP
19
+ module RPC
20
+
21
+
22
+ class HTTPServer < Logger::Application
23
+ include AttrProxy
24
+
25
+ attr_reader :server
26
+ attr_accessor :default_namespace
27
+
28
+ attr_proxy :mapping_registry, true
29
+ attr_proxy :literal_mapping_registry, true
30
+ attr_proxy :generate_explicit_type, true
31
+ attr_proxy :use_default_namespace, true
32
+
33
+ def initialize(config)
34
+ actor = config[:SOAPHTTPServerApplicationName] || self.class.name
35
+ super(actor)
36
+ @default_namespace = config[:SOAPDefaultNamespace]
37
+ @webrick_config = config.dup
38
+ self.level = Logger::Severity::ERROR # keep silent by default
39
+ @webrick_config[:Logger] ||= @log
40
+ @log = @webrick_config[:Logger] # sync logger of App and HTTPServer
41
+ @router = ::SOAP::RPC::Router.new(actor)
42
+ @soaplet = ::SOAP::RPC::SOAPlet.new(@router)
43
+ on_init
44
+ @server = WEBrick::HTTPServer.new(@webrick_config)
45
+ @server.mount('/soaprouter', @soaplet)
46
+ if wsdldir = config[:WSDLDocumentDirectory]
47
+ @server.mount('/wsdl', WEBrick::HTTPServlet::FileHandler, wsdldir)
48
+ end
49
+ @server.mount('/', @soaplet)
50
+ end
51
+
52
+ def on_init
53
+ # do extra initialization in a derived class if needed.
54
+ end
55
+
56
+ def status
57
+ @server.status if @server
58
+ end
59
+
60
+ def shutdown
61
+ @server.shutdown if @server
62
+ end
63
+
64
+ def authenticator
65
+ @soaplet.authenticator
66
+ end
67
+
68
+ def authenticator=(authenticator)
69
+ @soaplet.authenticator = authenticator
70
+ end
71
+
72
+ # servant entry interface
73
+
74
+ def add_rpc_request_servant(factory, namespace = @default_namespace)
75
+ @router.add_rpc_request_servant(factory, namespace)
76
+ end
77
+
78
+ def add_rpc_servant(obj, namespace = @default_namespace)
79
+ @router.add_rpc_servant(obj, namespace)
80
+ end
81
+
82
+ def add_request_headerhandler(factory)
83
+ @router.add_request_headerhandler(factory)
84
+ end
85
+
86
+ def add_headerhandler(obj)
87
+ @router.add_headerhandler(obj)
88
+ end
89
+ alias add_rpc_headerhandler add_headerhandler
90
+
91
+ def filterchain
92
+ @router.filterchain
93
+ end
94
+
95
+ # method entry interface
96
+
97
+ def add_rpc_method(obj, name, *param)
98
+ add_rpc_method_as(obj, name, name, *param)
99
+ end
100
+ alias add_method add_rpc_method
101
+
102
+ def add_rpc_method_as(obj, name, name_as, *param)
103
+ qname = XSD::QName.new(@default_namespace, name_as)
104
+ soapaction = nil
105
+ param_def = SOAPMethod.derive_rpc_param_def(obj, name, *param)
106
+ @router.add_rpc_operation(obj, qname, soapaction, name, param_def)
107
+ end
108
+ alias add_method_as add_rpc_method_as
109
+
110
+ def add_document_method(obj, soapaction, name, req_qnames, res_qnames)
111
+ param_def = SOAPMethod.create_doc_param_def(req_qnames, res_qnames)
112
+ @router.add_document_operation(obj, soapaction, name, param_def)
113
+ end
114
+
115
+ def add_rpc_operation(receiver, qname, soapaction, name, param_def, opt = {})
116
+ @router.add_rpc_operation(receiver, qname, soapaction, name, param_def, opt)
117
+ end
118
+
119
+ def add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt = {})
120
+ @router.add_rpc_request_operation(factory, qname, soapaction, name, param_def, opt)
121
+ end
122
+
123
+ def add_document_operation(receiver, soapaction, name, param_def, opt = {})
124
+ @router.add_document_operation(receiver, soapaction, name, param_def, opt)
125
+ end
126
+
127
+ def add_document_request_operation(factory, soapaction, name, param_def, opt = {})
128
+ @router.add_document_request_operation(factory, soapaction, name, param_def, opt)
129
+ end
130
+
131
+ private
132
+
133
+ def attrproxy
134
+ @router
135
+ end
136
+
137
+ def run
138
+ @server.start
139
+ end
140
+ end
141
+
142
+
143
+ end
144
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
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: UTF-8
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