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,25 @@
1
+ # SOAP4R - RPC utility.
2
+ # Copyright (C) 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
+ module SOAP
10
+
11
+
12
+ module RPC
13
+ ServerException = Mapping::MappedException
14
+
15
+ def self.defined_methods(obj)
16
+ if obj.is_a?(Module)
17
+ obj.methods - Module.methods
18
+ else
19
+ obj.methods - Object.instance_methods(true)
20
+ end
21
+ end
22
+ end
23
+
24
+
25
+ end
@@ -0,0 +1,162 @@
1
+ # SOAP4R - SOAP handler servlet for WEBrick
2
+ # Copyright (C) 2001-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 'webrick/httpservlet/abstract'
10
+ require 'webrick/httpstatus'
11
+ require 'soap/rpc/router'
12
+ require 'soap/streamHandler'
13
+ begin
14
+ require 'stringio'
15
+ require 'zlib'
16
+ rescue LoadError
17
+ warn("Loading stringio or zlib failed. No gzipped response supported.") if $DEBUG
18
+ end
19
+
20
+
21
+ warn("Overriding WEBrick::Log#debug") if $DEBUG
22
+ require 'webrick/log'
23
+ module WEBrick
24
+ class Log < BasicLog
25
+ alias __debug debug
26
+ def debug(msg = nil)
27
+ if block_given? and msg.nil?
28
+ __debug(yield)
29
+ else
30
+ __debug(msg)
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ module SOAP
38
+ module RPC
39
+
40
+
41
+ class SOAPlet < WEBrick::HTTPServlet::AbstractServlet
42
+ public
43
+ attr_reader :options
44
+
45
+ def initialize(router = nil)
46
+ @router = router || ::SOAP::RPC::Router.new(self.class.name)
47
+ @options = {}
48
+ @config = {}
49
+ end
50
+
51
+ # for backward compatibility
52
+ def app_scope_router
53
+ @router
54
+ end
55
+
56
+ # for backward compatibility
57
+ def add_servant(obj, namespace)
58
+ @router.add_rpc_servant(obj, namespace)
59
+ end
60
+
61
+ def allow_content_encoding_gzip=(allow)
62
+ @options[:allow_content_encoding_gzip] = allow
63
+ end
64
+
65
+ ###
66
+ ## Servlet interfaces for WEBrick.
67
+ #
68
+ def get_instance(config, *options)
69
+ @config = config
70
+ self
71
+ end
72
+
73
+ def require_path_info?
74
+ false
75
+ end
76
+
77
+ def do_GET(req, res)
78
+ res.header['Allow'] = 'POST'
79
+ raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed"
80
+ end
81
+
82
+ def do_POST(req, res)
83
+ logger.debug { "SOAP request: " + req.body } if logger
84
+ begin
85
+ conn_data = ::SOAP::StreamHandler::ConnectionData.new
86
+ setup_req(conn_data, req)
87
+ @router.external_ces = @options[:external_ces]
88
+ conn_data = @router.route(conn_data)
89
+ setup_res(conn_data, req, res)
90
+ rescue Exception => e
91
+ conn_data = @router.create_fault_response(e)
92
+ res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
93
+ res.body = conn_data.send_string
94
+ res['content-type'] = conn_data.send_contenttype || "text/xml"
95
+ end
96
+ if res.body.is_a?(IO)
97
+ res.chunked = true
98
+ logger.debug { "SOAP response: (chunked response not logged)" } if logger
99
+ else
100
+ logger.debug { "SOAP response: " + res.body } if logger
101
+ end
102
+ end
103
+
104
+ private
105
+
106
+ def logger
107
+ @config[:Logger]
108
+ end
109
+
110
+ def setup_req(conn_data, req)
111
+ conn_data.receive_string = req.body
112
+ conn_data.receive_contenttype = req['content-type']
113
+ conn_data.soapaction = parse_soapaction(req.meta_vars['HTTP_SOAPACTION'])
114
+ end
115
+
116
+ def setup_res(conn_data, req, res)
117
+ res['content-type'] = conn_data.send_contenttype
118
+ if conn_data.is_fault
119
+ res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
120
+ end
121
+ if outstring = encode_gzip(req, conn_data.send_string)
122
+ res['content-encoding'] = 'gzip'
123
+ res['content-length'] = outstring.size
124
+ res.body = outstring
125
+ else
126
+ res.body = conn_data.send_string
127
+ end
128
+ end
129
+
130
+ def parse_soapaction(soapaction)
131
+ if !soapaction.nil? and !soapaction.empty?
132
+ if /^"(.+)"$/ =~ soapaction
133
+ return $1
134
+ end
135
+ end
136
+ nil
137
+ end
138
+
139
+ def encode_gzip(req, outstring)
140
+ unless encode_gzip?(req)
141
+ return nil
142
+ end
143
+ begin
144
+ ostream = StringIO.new
145
+ gz = Zlib::GzipWriter.new(ostream)
146
+ gz.write(outstring)
147
+ ostream.string
148
+ ensure
149
+ gz.close
150
+ end
151
+ end
152
+
153
+ def encode_gzip?(req)
154
+ @options[:allow_content_encoding_gzip] and defined?(::Zlib) and
155
+ req['accept-encoding'] and
156
+ req['accept-encoding'].split(/,\s*/).include?('gzip')
157
+ end
158
+ end
159
+
160
+
161
+ end
162
+ end
@@ -0,0 +1,43 @@
1
+ # SOAP4R - WEBrick Server
2
+ # Copyright (C) 2003 by 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/rpc/httpserver'
10
+
11
+
12
+ module SOAP
13
+ module RPC
14
+
15
+
16
+ class StandaloneServer < HTTPServer
17
+ def initialize(appname, default_namespace, host = "0.0.0.0", port = 8080)
18
+ @appname = appname
19
+ @default_namespace = default_namespace
20
+ @host = host
21
+ @port = port
22
+ super(create_config)
23
+ end
24
+
25
+ alias add_servant add_rpc_servant
26
+ alias add_headerhandler add_rpc_headerhandler
27
+
28
+ private
29
+
30
+ def create_config
31
+ {
32
+ :BindAddress => @host,
33
+ :Port => @port,
34
+ :AccessLog => [],
35
+ :SOAPDefaultNamespace => @default_namespace,
36
+ :SOAPHTTPServerApplicationName => @appname,
37
+ }
38
+ end
39
+ end
40
+
41
+
42
+ end
43
+ end
@@ -0,0 +1,140 @@
1
+ # soap/soap.rb: SOAP4R - Base definitions.
2
+ # Copyright (C) 2000-2004 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 'xsd/qname'
10
+ require 'xsd/charset'
11
+
12
+
13
+ module SOAP
14
+
15
+
16
+ VERSION = Version = '1.5.5'
17
+ PropertyName = 'soap/property'
18
+
19
+ EnvelopeNamespace = 'http://schemas.xmlsoap.org/soap/envelope/'
20
+ EncodingNamespace = 'http://schemas.xmlsoap.org/soap/encoding/'
21
+ LiteralNamespace = 'http://xml.apache.org/xml-soap/literalxml'
22
+
23
+ NextActor = 'http://schemas.xmlsoap.org/soap/actor/next'
24
+
25
+ EleEnvelope = 'Envelope'
26
+ EleHeader = 'Header'
27
+ EleBody = 'Body'
28
+ EleFault = 'Fault'
29
+ EleFaultString = 'faultstring'
30
+ EleFaultActor = 'faultactor'
31
+ EleFaultCode = 'faultcode'
32
+ EleFaultDetail = 'detail'
33
+
34
+ AttrMustUnderstand = 'mustUnderstand'
35
+ AttrEncodingStyle = 'encodingStyle'
36
+ AttrActor = 'actor'
37
+ AttrRoot = 'root'
38
+ AttrArrayType = 'arrayType'
39
+ AttrOffset = 'offset'
40
+ AttrPosition = 'position'
41
+ ValueArray = 'Array'
42
+
43
+ EleEnvelopeName = XSD::QName.new(EnvelopeNamespace, EleEnvelope).freeze
44
+ EleHeaderName = XSD::QName.new(EnvelopeNamespace, EleHeader).freeze
45
+ EleBodyName = XSD::QName.new(EnvelopeNamespace, EleBody).freeze
46
+ EleFaultName = XSD::QName.new(EnvelopeNamespace, EleFault).freeze
47
+ EleFaultStringName = XSD::QName.new(nil, EleFaultString).freeze
48
+ EleFaultActorName = XSD::QName.new(nil, EleFaultActor).freeze
49
+ EleFaultCodeName = XSD::QName.new(nil, EleFaultCode).freeze
50
+ EleFaultDetailName = XSD::QName.new(nil, EleFaultDetail).freeze
51
+ AttrMustUnderstandName = XSD::QName.new(EnvelopeNamespace, AttrMustUnderstand).freeze
52
+ AttrEncodingStyleName = XSD::QName.new(EnvelopeNamespace, AttrEncodingStyle).freeze
53
+ AttrRootName = XSD::QName.new(EncodingNamespace, AttrRoot).freeze
54
+ AttrArrayTypeName = XSD::QName.new(EncodingNamespace, AttrArrayType).freeze
55
+ AttrOffsetName = XSD::QName.new(EncodingNamespace, AttrOffset).freeze
56
+ AttrPositionName = XSD::QName.new(EncodingNamespace, AttrPosition).freeze
57
+ ValueArrayName = XSD::QName.new(EncodingNamespace, ValueArray).freeze
58
+
59
+ Base64Literal = 'base64'
60
+
61
+ SOAPNamespaceTag = 'env'
62
+ XSDNamespaceTag = 'xsd'
63
+ XSINamespaceTag = 'xsi'
64
+
65
+ MediaType = 'text/xml'
66
+
67
+ class Error < StandardError; end
68
+
69
+ class StreamError < Error; end
70
+ class HTTPStreamError < StreamError; end
71
+ class PostUnavailableError < HTTPStreamError; end
72
+ class MPostUnavailableError < HTTPStreamError; end
73
+
74
+ class ArrayIndexOutOfBoundsError < Error; end
75
+ class ArrayStoreError < Error; end
76
+
77
+ class RPCRoutingError < Error; end
78
+ class EmptyResponseError < Error; end
79
+ class ResponseFormatError < Error; end
80
+
81
+ class UnhandledMustUnderstandHeaderError < Error; end
82
+
83
+ class FaultError < Error
84
+ attr_reader :faultcode
85
+ attr_reader :faultstring
86
+ attr_reader :faultactor
87
+ attr_accessor :detail
88
+
89
+ def initialize(fault)
90
+ @faultcode = fault.faultcode
91
+ @faultstring = fault.faultstring
92
+ @faultactor = fault.faultactor
93
+ @detail = fault.detail
94
+ super(self.to_s)
95
+ end
96
+
97
+ def to_s
98
+ str = nil
99
+ if @faultstring and @faultstring.respond_to?('data')
100
+ str = @faultstring.data
101
+ end
102
+ str || '(No faultstring)'
103
+ end
104
+ end
105
+
106
+
107
+ module Env
108
+ def self.getenv(name)
109
+ ENV[name.downcase] || ENV[name.upcase]
110
+ end
111
+
112
+ use_proxy = getenv('soap_use_proxy') == 'on'
113
+ HTTP_PROXY = use_proxy ? getenv('http_proxy') : nil
114
+ NO_PROXY = use_proxy ? getenv('no_proxy') : nil
115
+ end
116
+
117
+
118
+ end
119
+
120
+
121
+ unless Object.respond_to?(:instance_variable_get)
122
+ class Object
123
+ def instance_variable_get(ivarname)
124
+ instance_eval(ivarname)
125
+ end
126
+
127
+ def instance_variable_set(ivarname, value)
128
+ instance_eval("#{ivarname} = value")
129
+ end
130
+ end
131
+ end
132
+
133
+
134
+ unless Kernel.respond_to?(:warn)
135
+ module Kernel
136
+ def warn(msg)
137
+ STDERR.puts(msg + "\n") unless $VERBOSE.nil?
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,229 @@
1
+ # SOAP4R - Stream handler.
2
+ # Copyright (C) 2000, 2001, 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 'soap/soap'
10
+ require 'soap/httpconfigloader'
11
+ begin
12
+ require 'stringio'
13
+ require 'zlib'
14
+ rescue LoadError
15
+ warn("Loading stringio or zlib failed. No gzipped response support.") if $DEBUG
16
+ end
17
+
18
+
19
+ module SOAP
20
+
21
+
22
+ class StreamHandler
23
+ RUBY_VERSION_STRING = "ruby #{ RUBY_VERSION } (#{ RUBY_RELEASE_DATE }) [#{ RUBY_PLATFORM }]"
24
+
25
+ class ConnectionData
26
+ attr_accessor :send_string
27
+ attr_accessor :send_contenttype
28
+ attr_accessor :receive_string
29
+ attr_accessor :receive_contenttype
30
+ attr_accessor :is_fault
31
+ attr_accessor :soapaction
32
+
33
+ def initialize(send_string = nil)
34
+ @send_string = send_string
35
+ @send_contenttype = nil
36
+ @receive_string = nil
37
+ @receive_contenttype = nil
38
+ @is_fault = false
39
+ @soapaction = nil
40
+ end
41
+ end
42
+
43
+ def self.parse_media_type(str)
44
+ if /^#{ MediaType }(?:\s*;\s*charset=([^"]+|"[^"]+"))?$/i !~ str
45
+ return nil
46
+ end
47
+ charset = $1
48
+ charset.gsub!(/"/, '') if charset
49
+ charset || 'us-ascii'
50
+ end
51
+
52
+ def self.create_media_type(charset)
53
+ "#{ MediaType }; charset=#{ charset }"
54
+ end
55
+ end
56
+
57
+
58
+ class HTTPStreamHandler < StreamHandler
59
+ include SOAP
60
+
61
+ begin
62
+ require 'http-access2'
63
+ if HTTPAccess2::VERSION < "2.0"
64
+ raise LoadError.new("http-access/2.0 or later is required.")
65
+ end
66
+ Client = HTTPAccess2::Client
67
+ RETRYABLE = true
68
+ rescue LoadError
69
+ warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
70
+ require 'soap/netHttpClient'
71
+ Client = SOAP::NetHttpClient
72
+ RETRYABLE = false
73
+ end
74
+
75
+
76
+ public
77
+
78
+ attr_reader :client
79
+ attr_accessor :wiredump_file_base
80
+
81
+ MAX_RETRY_COUNT = 10 # [times]
82
+
83
+ def initialize(options)
84
+ super()
85
+ @client = Client.new(nil, "SOAP4R/#{ Version }")
86
+ @wiredump_file_base = nil
87
+ @charset = @wiredump_dev = nil
88
+ @options = options
89
+ set_options
90
+ @client.debug_dev = @wiredump_dev
91
+ @cookie_store = nil
92
+ @accept_encoding_gzip = false
93
+ end
94
+
95
+ def test_loopback_response
96
+ @client.test_loopback_response
97
+ end
98
+
99
+ def accept_encoding_gzip=(allow)
100
+ @accept_encoding_gzip = allow
101
+ end
102
+
103
+ def inspect
104
+ "#<#{self.class}>"
105
+ end
106
+
107
+ def send(endpoint_url, conn_data, soapaction = nil, charset = @charset)
108
+ conn_data.soapaction ||= soapaction # for backward conpatibility
109
+ send_post(endpoint_url, conn_data, charset)
110
+ end
111
+
112
+ def reset(endpoint_url = nil)
113
+ if endpoint_url.nil?
114
+ @client.reset_all
115
+ else
116
+ @client.reset(endpoint_url)
117
+ end
118
+ @client.save_cookie_store if @cookie_store
119
+ end
120
+
121
+ private
122
+
123
+ def set_options
124
+ HTTPConfigLoader.set_options(@client, @options)
125
+ @charset = @options["charset"] || XSD::Charset.xml_encoding_label
126
+ @options.add_hook("charset") do |key, value|
127
+ @charset = value
128
+ end
129
+ @wiredump_dev = @options["wiredump_dev"]
130
+ @options.add_hook("wiredump_dev") do |key, value|
131
+ @wiredump_dev = value
132
+ @client.debug_dev = @wiredump_dev
133
+ end
134
+ set_cookie_store_file(@options["cookie_store_file"])
135
+ @options.add_hook("cookie_store_file") do |key, value|
136
+ set_cookie_store_file(value)
137
+ end
138
+ ssl_config = @options["ssl_config"]
139
+ basic_auth = @options["basic_auth"]
140
+ @options.lock(true)
141
+ ssl_config.unlock
142
+ basic_auth.unlock
143
+ end
144
+
145
+ def set_cookie_store_file(value)
146
+ value = nil if value and value.empty?
147
+ @cookie_store = value
148
+ @client.set_cookie_store(@cookie_store) if @cookie_store
149
+ end
150
+
151
+ def send_post(endpoint_url, conn_data, charset)
152
+ conn_data.send_contenttype ||= StreamHandler.create_media_type(charset)
153
+
154
+ if @wiredump_file_base
155
+ filename = @wiredump_file_base + '_request.xml'
156
+ f = File.open(filename, "w")
157
+ f << conn_data.send_string
158
+ f.close
159
+ end
160
+
161
+ extra = {}
162
+ extra['Content-Type'] = conn_data.send_contenttype
163
+ extra['SOAPAction'] = "\"#{ conn_data.soapaction }\""
164
+ extra['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip?
165
+ send_string = conn_data.send_string
166
+ @wiredump_dev << "Wire dump:\n\n" if @wiredump_dev
167
+ begin
168
+ retry_count = 0
169
+ while true
170
+ res = @client.post(endpoint_url, send_string, extra)
171
+ if RETRYABLE and HTTP::Status.redirect?(res.status)
172
+ retry_count += 1
173
+ if retry_count >= MAX_RETRY_COUNT
174
+ raise HTTPStreamError.new("redirect count exceeded")
175
+ end
176
+ endpoint_url = res.header["location"][0]
177
+ puts "redirected to #{endpoint_url}" if $DEBUG
178
+ else
179
+ break
180
+ end
181
+ end
182
+ rescue
183
+ @client.reset(endpoint_url)
184
+ raise
185
+ end
186
+ @wiredump_dev << "\n\n" if @wiredump_dev
187
+ receive_string = res.content
188
+ if @wiredump_file_base
189
+ filename = @wiredump_file_base + '_response.xml'
190
+ f = File.open(filename, "w")
191
+ f << receive_string
192
+ f.close
193
+ end
194
+ case res.status
195
+ when 405
196
+ raise PostUnavailableError.new("#{ res.status }: #{ res.reason }")
197
+ when 200, 500
198
+ # Nothing to do.
199
+ else
200
+ raise HTTPStreamError.new("#{ res.status }: #{ res.reason }")
201
+ end
202
+ if res.respond_to?(:header) and !res.header['content-encoding'].empty? and
203
+ res.header['content-encoding'][0].downcase == 'gzip'
204
+ receive_string = decode_gzip(receive_string)
205
+ end
206
+ conn_data.receive_string = receive_string
207
+ conn_data.receive_contenttype = res.contenttype
208
+ conn_data
209
+ end
210
+
211
+ def send_accept_encoding_gzip?
212
+ @accept_encoding_gzip and defined?(::Zlib)
213
+ end
214
+
215
+ def decode_gzip(instring)
216
+ unless send_accept_encoding_gzip?
217
+ raise HTTPStreamError.new("Gzipped response content.")
218
+ end
219
+ begin
220
+ gz = Zlib::GzipReader.new(StringIO.new(instring))
221
+ gz.read
222
+ ensure
223
+ gz.close
224
+ end
225
+ end
226
+ end
227
+
228
+
229
+ end