rubysl-soap 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/.travis.yml +8 -0
  4. data/README.md +2 -2
  5. data/Rakefile +0 -1
  6. data/lib/rubysl/soap.rb +1 -0
  7. data/lib/rubysl/soap/version.rb +5 -0
  8. data/lib/soap/attachment.rb +107 -0
  9. data/lib/soap/baseData.rb +942 -0
  10. data/lib/soap/element.rb +258 -0
  11. data/lib/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  12. data/lib/soap/encodingstyle/handler.rb +100 -0
  13. data/lib/soap/encodingstyle/literalHandler.rb +226 -0
  14. data/lib/soap/encodingstyle/soapHandler.rb +582 -0
  15. data/lib/soap/generator.rb +268 -0
  16. data/lib/soap/header/handler.rb +57 -0
  17. data/lib/soap/header/handlerset.rb +70 -0
  18. data/lib/soap/header/simplehandler.rb +44 -0
  19. data/lib/soap/httpconfigloader.rb +119 -0
  20. data/lib/soap/mapping.rb +10 -0
  21. data/lib/soap/mapping/factory.rb +355 -0
  22. data/lib/soap/mapping/mapping.rb +381 -0
  23. data/lib/soap/mapping/registry.rb +541 -0
  24. data/lib/soap/mapping/rubytypeFactory.rb +475 -0
  25. data/lib/soap/mapping/typeMap.rb +50 -0
  26. data/lib/soap/mapping/wsdlencodedregistry.rb +280 -0
  27. data/lib/soap/mapping/wsdlliteralregistry.rb +418 -0
  28. data/lib/soap/marshal.rb +59 -0
  29. data/lib/soap/mimemessage.rb +240 -0
  30. data/lib/soap/netHttpClient.rb +190 -0
  31. data/lib/soap/parser.rb +251 -0
  32. data/lib/soap/processor.rb +66 -0
  33. data/lib/soap/property.rb +333 -0
  34. data/lib/soap/rpc/cgistub.rb +206 -0
  35. data/lib/soap/rpc/driver.rb +254 -0
  36. data/lib/soap/rpc/element.rb +325 -0
  37. data/lib/soap/rpc/httpserver.rb +129 -0
  38. data/lib/soap/rpc/proxy.rb +497 -0
  39. data/lib/soap/rpc/router.rb +594 -0
  40. data/lib/soap/rpc/rpc.rb +25 -0
  41. data/lib/soap/rpc/soaplet.rb +162 -0
  42. data/lib/soap/rpc/standaloneServer.rb +43 -0
  43. data/lib/soap/soap.rb +140 -0
  44. data/lib/soap/streamHandler.rb +229 -0
  45. data/lib/soap/wsdlDriver.rb +575 -0
  46. data/rubysl-soap.gemspec +19 -18
  47. metadata +115 -86
  48. data/lib/rubysl-soap.rb +0 -7
  49. data/lib/rubysl-soap/version.rb +0 -5
@@ -0,0 +1,206 @@
1
+ # SOAP4R - CGI/mod_ruby stub library
2
+ # Copyright (C) 2001, 2003-2005 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 'soap/streamHandler'
10
+ require 'webrick/httpresponse'
11
+ require 'webrick/httpstatus'
12
+ require 'logger'
13
+ require 'soap/rpc/soaplet'
14
+
15
+
16
+ module SOAP
17
+ module RPC
18
+
19
+
20
+ ###
21
+ # SYNOPSIS
22
+ # CGIStub.new
23
+ #
24
+ # DESCRIPTION
25
+ # To be written...
26
+ #
27
+ class CGIStub < Logger::Application
28
+ include SOAP
29
+ include WEBrick
30
+
31
+ class SOAPRequest
32
+ attr_reader :body
33
+
34
+ def [](var); end
35
+
36
+ def meta_vars; end
37
+ end
38
+
39
+ class SOAPStdinRequest < SOAPRequest
40
+ attr_reader :body
41
+
42
+ def initialize(stream)
43
+ size = ENV['CONTENT_LENGTH'].to_i || 0
44
+ @body = stream.read(size)
45
+ end
46
+
47
+ def [](var)
48
+ ENV[var.gsub(/-/, '_').upcase]
49
+ end
50
+
51
+ def meta_vars
52
+ {
53
+ 'HTTP_SOAPACTION' => ENV['HTTP_SOAPAction']
54
+ }
55
+ end
56
+ end
57
+
58
+ class SOAPFCGIRequest < SOAPRequest
59
+ attr_reader :body
60
+
61
+ def initialize(request)
62
+ @request = request
63
+ @body = @request.in.read
64
+ end
65
+
66
+ def [](var)
67
+ @request.env[var.gsub(/-/, '_').upcase]
68
+ end
69
+
70
+ def meta_vars
71
+ {
72
+ 'HTTP_SOAPACTION' => @request.env['HTTP_SOAPAction']
73
+ }
74
+ end
75
+ end
76
+
77
+ def initialize(appname, default_namespace)
78
+ super(appname)
79
+ set_log(STDERR)
80
+ self.level = ERROR
81
+ @default_namespace = default_namespace
82
+ @remote_host = ENV['REMOTE_HOST'] || ENV['REMOTE_ADDR'] || 'unknown'
83
+ @router = ::SOAP::RPC::Router.new(self.class.name)
84
+ @soaplet = ::SOAP::RPC::SOAPlet.new(@router)
85
+ on_init
86
+ end
87
+
88
+ def on_init
89
+ # do extra initialization in a derived class if needed.
90
+ end
91
+
92
+ def mapping_registry
93
+ @router.mapping_registry
94
+ end
95
+
96
+ def mapping_registry=(value)
97
+ @router.mapping_registry = value
98
+ end
99
+
100
+ def generate_explicit_type
101
+ @router.generate_explicit_type
102
+ end
103
+
104
+ def generate_explicit_type=(generate_explicit_type)
105
+ @router.generate_explicit_type = generate_explicit_type
106
+ end
107
+
108
+ # servant entry interface
109
+
110
+ def add_rpc_servant(obj, namespace = @default_namespace)
111
+ @router.add_rpc_servant(obj, namespace)
112
+ end
113
+ alias add_servant add_rpc_servant
114
+
115
+ def add_headerhandler(obj)
116
+ @router.add_headerhandler(obj)
117
+ end
118
+ alias add_rpc_headerhandler add_headerhandler
119
+
120
+ # method entry interface
121
+
122
+ def add_rpc_method(obj, name, *param)
123
+ add_rpc_method_with_namespace_as(@default_namespace, obj, name, name, *param)
124
+ end
125
+ alias add_method add_rpc_method
126
+
127
+ def add_rpc_method_as(obj, name, name_as, *param)
128
+ add_rpc_method_with_namespace_as(@default_namespace, obj, name, name_as, *param)
129
+ end
130
+ alias add_method_as add_rpc_method_as
131
+
132
+ def add_rpc_method_with_namespace(namespace, obj, name, *param)
133
+ add_rpc_method_with_namespace_as(namespace, obj, name, name, *param)
134
+ end
135
+ alias add_method_with_namespace add_rpc_method_with_namespace
136
+
137
+ def add_rpc_method_with_namespace_as(namespace, obj, name, name_as, *param)
138
+ qname = XSD::QName.new(namespace, name_as)
139
+ soapaction = nil
140
+ param_def = SOAPMethod.derive_rpc_param_def(obj, name, *param)
141
+ @router.add_rpc_operation(obj, qname, soapaction, name, param_def)
142
+ end
143
+ alias add_method_with_namespace_as add_rpc_method_with_namespace_as
144
+
145
+ def add_rpc_operation(receiver, qname, soapaction, name, param_def, opt = {})
146
+ @router.add_rpc_operation(receiver, qname, soapaction, name, param_def, opt)
147
+ end
148
+
149
+ def add_document_operation(receiver, soapaction, name, param_def, opt = {})
150
+ @router.add_document_operation(receiver, soapaction, name, param_def, opt)
151
+ end
152
+
153
+ def set_fcgi_request(request)
154
+ @fcgi = request
155
+ end
156
+
157
+ private
158
+
159
+ HTTPVersion = WEBrick::HTTPVersion.new('1.0') # dummy; ignored
160
+
161
+ def run
162
+ res = WEBrick::HTTPResponse.new({:HTTPVersion => HTTPVersion})
163
+ begin
164
+ @log.info { "received a request from '#{ @remote_host }'" }
165
+ if @fcgi
166
+ req = SOAPFCGIRequest.new(@fcgi)
167
+ else
168
+ req = SOAPStdinRequest.new($stdin)
169
+ end
170
+ @soaplet.do_POST(req, res)
171
+ rescue HTTPStatus::EOFError, HTTPStatus::RequestTimeout => ex
172
+ res.set_error(ex)
173
+ rescue HTTPStatus::Error => ex
174
+ res.set_error(ex)
175
+ rescue HTTPStatus::Status => ex
176
+ res.status = ex.code
177
+ rescue StandardError, NameError => ex # for Ruby 1.6
178
+ res.set_error(ex, true)
179
+ ensure
180
+ if defined?(MOD_RUBY)
181
+ r = Apache.request
182
+ r.status = res.status
183
+ r.content_type = res.content_type
184
+ r.send_http_header
185
+ buf = res.body
186
+ else
187
+ buf = ''
188
+ res.send_response(buf)
189
+ buf.sub!(/^[^\r]+\r\n/, '') # Trim status line.
190
+ end
191
+ @log.debug { "SOAP CGI Response:\n#{ buf }" }
192
+ if @fcgi
193
+ @fcgi.out.print buf
194
+ @fcgi.finish
195
+ @fcgi = nil
196
+ else
197
+ print buf
198
+ end
199
+ end
200
+ 0
201
+ end
202
+ end
203
+
204
+
205
+ end
206
+ end
@@ -0,0 +1,254 @@
1
+ # SOAP4R - SOAP RPC driver
2
+ # Copyright (C) 2000, 2001, 2003-2005 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 'soap/soap'
10
+ require 'soap/mapping'
11
+ require 'soap/mapping/wsdlliteralregistry'
12
+ require 'soap/rpc/rpc'
13
+ require 'soap/rpc/proxy'
14
+ require 'soap/rpc/element'
15
+ require 'soap/streamHandler'
16
+ require 'soap/property'
17
+ require 'soap/header/handlerset'
18
+
19
+
20
+ module SOAP
21
+ module RPC
22
+
23
+
24
+ class Driver
25
+ class << self
26
+ if RUBY_VERSION >= "1.7.0"
27
+ def __attr_proxy(symbol, assignable = false)
28
+ name = symbol.to_s
29
+ define_method(name) {
30
+ @proxy.__send__(name)
31
+ }
32
+ if assignable
33
+ aname = name + '='
34
+ define_method(aname) { |rhs|
35
+ @proxy.__send__(aname, rhs)
36
+ }
37
+ end
38
+ end
39
+ else
40
+ def __attr_proxy(symbol, assignable = false)
41
+ name = symbol.to_s
42
+ module_eval <<-EOS
43
+ def #{name}
44
+ @proxy.#{name}
45
+ end
46
+ EOS
47
+ if assignable
48
+ module_eval <<-EOS
49
+ def #{name}=(value)
50
+ @proxy.#{name} = value
51
+ end
52
+ EOS
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ __attr_proxy :endpoint_url, true
59
+ __attr_proxy :mapping_registry, true
60
+ __attr_proxy :default_encodingstyle, true
61
+ __attr_proxy :generate_explicit_type, true
62
+ __attr_proxy :allow_unqualified_element, true
63
+ __attr_proxy :headerhandler
64
+ __attr_proxy :streamhandler
65
+ __attr_proxy :test_loopback_response
66
+ __attr_proxy :reset_stream
67
+
68
+ attr_reader :proxy
69
+ attr_reader :options
70
+ attr_accessor :soapaction
71
+
72
+ def inspect
73
+ "#<#{self.class}:#{@proxy.inspect}>"
74
+ end
75
+
76
+ def httpproxy
77
+ options["protocol.http.proxy"]
78
+ end
79
+
80
+ def httpproxy=(httpproxy)
81
+ options["protocol.http.proxy"] = httpproxy
82
+ end
83
+
84
+ def wiredump_dev
85
+ options["protocol.http.wiredump_dev"]
86
+ end
87
+
88
+ def wiredump_dev=(wiredump_dev)
89
+ options["protocol.http.wiredump_dev"] = wiredump_dev
90
+ end
91
+
92
+ def mandatorycharset
93
+ options["protocol.mandatorycharset"]
94
+ end
95
+
96
+ def mandatorycharset=(mandatorycharset)
97
+ options["protocol.mandatorycharset"] = mandatorycharset
98
+ end
99
+
100
+ def wiredump_file_base
101
+ options["protocol.wiredump_file_base"]
102
+ end
103
+
104
+ def wiredump_file_base=(wiredump_file_base)
105
+ options["protocol.wiredump_file_base"] = wiredump_file_base
106
+ end
107
+
108
+ def initialize(endpoint_url, namespace = nil, soapaction = nil)
109
+ @namespace = namespace
110
+ @soapaction = soapaction
111
+ @options = setup_options
112
+ @wiredump_file_base = nil
113
+ @proxy = Proxy.new(endpoint_url, @soapaction, @options)
114
+ end
115
+
116
+ def loadproperty(propertyname)
117
+ unless options.loadproperty(propertyname)
118
+ raise LoadError.new("No such property to load -- #{propertyname}")
119
+ end
120
+ end
121
+
122
+ def add_rpc_method(name, *params)
123
+ add_rpc_method_with_soapaction_as(name, name, @soapaction, *params)
124
+ end
125
+
126
+ def add_rpc_method_as(name, name_as, *params)
127
+ add_rpc_method_with_soapaction_as(name, name_as, @soapaction, *params)
128
+ end
129
+
130
+ def add_rpc_method_with_soapaction(name, soapaction, *params)
131
+ add_rpc_method_with_soapaction_as(name, name, soapaction, *params)
132
+ end
133
+
134
+ def add_rpc_method_with_soapaction_as(name, name_as, soapaction, *params)
135
+ param_def = SOAPMethod.create_rpc_param_def(params)
136
+ qname = XSD::QName.new(@namespace, name_as)
137
+ @proxy.add_rpc_method(qname, soapaction, name, param_def)
138
+ add_rpc_method_interface(name, param_def)
139
+ end
140
+
141
+ # add_method is for shortcut of typical rpc/encoded method definition.
142
+ alias add_method add_rpc_method
143
+ alias add_method_as add_rpc_method_as
144
+ alias add_method_with_soapaction add_rpc_method_with_soapaction
145
+ alias add_method_with_soapaction_as add_rpc_method_with_soapaction_as
146
+
147
+ def add_document_method(name, soapaction, req_qname, res_qname)
148
+ param_def = SOAPMethod.create_doc_param_def(req_qname, res_qname)
149
+ @proxy.add_document_method(soapaction, name, param_def)
150
+ add_document_method_interface(name, param_def)
151
+ end
152
+
153
+ def add_rpc_operation(qname, soapaction, name, param_def, opt = {})
154
+ @proxy.add_rpc_operation(qname, soapaction, name, param_def, opt)
155
+ add_rpc_method_interface(name, param_def)
156
+ end
157
+
158
+ def add_document_operation(soapaction, name, param_def, opt = {})
159
+ @proxy.add_document_operation(soapaction, name, param_def, opt)
160
+ add_document_method_interface(name, param_def)
161
+ end
162
+
163
+ def invoke(headers, body)
164
+ if headers and !headers.is_a?(SOAPHeader)
165
+ headers = create_header(headers)
166
+ end
167
+ set_wiredump_file_base(body.elename.name)
168
+ env = @proxy.invoke(headers, body)
169
+ if env.nil?
170
+ return nil, nil
171
+ else
172
+ return env.header, env.body
173
+ end
174
+ end
175
+
176
+ def call(name, *params)
177
+ set_wiredump_file_base(name)
178
+ @proxy.call(name, *params)
179
+ end
180
+
181
+ private
182
+
183
+ def set_wiredump_file_base(name)
184
+ if @wiredump_file_base
185
+ @proxy.set_wiredump_file_base("#{@wiredump_file_base}_#{name}")
186
+ end
187
+ end
188
+
189
+ def create_header(headers)
190
+ header = SOAPHeader.new()
191
+ headers.each do |content, mustunderstand, encodingstyle|
192
+ header.add(SOAPHeaderItem.new(content, mustunderstand, encodingstyle))
193
+ end
194
+ header
195
+ end
196
+
197
+ def setup_options
198
+ if opt = Property.loadproperty(::SOAP::PropertyName)
199
+ opt = opt["client"]
200
+ end
201
+ opt ||= Property.new
202
+ opt.add_hook("protocol.mandatorycharset") do |key, value|
203
+ @proxy.mandatorycharset = value
204
+ end
205
+ opt.add_hook("protocol.wiredump_file_base") do |key, value|
206
+ @wiredump_file_base = value
207
+ end
208
+ opt["protocol.http.charset"] ||= XSD::Charset.xml_encoding_label
209
+ opt["protocol.http.proxy"] ||= Env::HTTP_PROXY
210
+ opt["protocol.http.no_proxy"] ||= Env::NO_PROXY
211
+ opt
212
+ end
213
+
214
+ def add_rpc_method_interface(name, param_def)
215
+ param_count = RPC::SOAPMethod.param_count(param_def,
216
+ RPC::SOAPMethod::IN, RPC::SOAPMethod::INOUT)
217
+ add_method_interface(name, param_count)
218
+ end
219
+
220
+ def add_document_method_interface(name, param_def)
221
+ param_count = RPC::SOAPMethod.param_count(param_def, RPC::SOAPMethod::IN)
222
+ add_method_interface(name, param_count)
223
+ end
224
+
225
+ if RUBY_VERSION > "1.7.0"
226
+ def add_method_interface(name, param_count)
227
+ ::SOAP::Mapping.define_singleton_method(self, name) do |*arg|
228
+ unless arg.size == param_count
229
+ raise ArgumentError.new(
230
+ "wrong number of arguments (#{arg.size} for #{param_count})")
231
+ end
232
+ call(name, *arg)
233
+ end
234
+ self.method(name)
235
+ end
236
+ else
237
+ def add_method_interface(name, param_count)
238
+ instance_eval <<-EOS
239
+ def #{name}(*arg)
240
+ unless arg.size == #{param_count}
241
+ raise ArgumentError.new(
242
+ "wrong number of arguments (\#{arg.size} for #{param_count})")
243
+ end
244
+ call(#{name.dump}, *arg)
245
+ end
246
+ EOS
247
+ self.method(name)
248
+ end
249
+ end
250
+ end
251
+
252
+
253
+ end
254
+ end