mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

#nnn is a ticket number at http://dev.ctor.org/soap4r * SOAP * allow to configure an envelope namespace of SOAP request. (#124) TemporaryNamespace = 'http://www.w3.org/2003/05/soap-envelope' @client.options["soap.envelope.requestnamespace"] = TemporaryNamespace @client.options["soap.envelope.responsenamespace"] = TemporaryNamespace @client.do_proc(...) * let SOAP request XML indent space configuable. see "soap.envelope.no_indent" option. (#130) * let external CES configuable. ex. client["soap.mapping.external_ces"] = 'SJIS'. $KCODE is used by default. (#133) external CES ::= CES used in Ruby object of client and server internal CES ::= CES used in SOAP/OM * add iso-8859-1 external CES support. (#106) * fixed illegal 'qualified' handling of elements. it caused ASP.NET inteoperability problem. (#144) * added 'soap.envelope.use_numeric_character_reference' (boolean) option to let query XML use numeric character reference in XML, not plain UTF-8 character. !GoogleSearch server seems to not allow plain UTF-8 character since 2005-08-15 update. (#147) * SOAP::Header::SimpleHeader (de)serialization throws an exception on !SimpleHeader.on_(in|out)bound when header is a String. so we could not use a simple single element headerItem. fixed. thanks to emil. (#129) * out parameter of rpc operation did not work. (#132) * follow HTTP redirect only if using http-access2. (#125) (#145) * add a workaround for importing an WSDL whose path begins with drive letter. (#115) * WSDL * SOAP Data which is defined as a simpletype was not mapped correctly to Ruby obj when using wsdl2ruby.rb generated classdef file. (#123) * rpc/literal support. (#118) * re-implemented local element qualify/unqualify control. handles elementFormDefault and form in WSDL. (#119) * Array of an element which has simpleType causes a crash. (#128) * prarmeterOrder may not contain return part so it can be shorter than parts size. Thanks to Hugh. (#139) * Samples * added !BasicAuth client sample. (#117) * added Base64 client/server sample. * added Flickr SOAP interface client sample. (#122) * added !SalesForce client sample. (#135) * updated Thawte CA certificate for !GoogleAdWords sample. * updated a client script with the newer version made by Johan. thanks! * shortened long file names. (#120) * fixed typo in authheader sample. (#129) * updated deprecated method usage. (#138) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9171 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
162 lines
3.7 KiB
Ruby
162 lines
3.7 KiB
Ruby
# SOAP4R - SOAP handler servlet for WEBrick
|
|
# Copyright (C) 2001-2005 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
|
|
|
|
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
|
# redistribute it and/or modify it under the same terms of Ruby's license;
|
|
# either the dual license version in 2003, or any later version.
|
|
|
|
|
|
require 'webrick/httpservlet/abstract'
|
|
require 'webrick/httpstatus'
|
|
require 'soap/rpc/router'
|
|
require 'soap/streamHandler'
|
|
begin
|
|
require 'stringio'
|
|
require 'zlib'
|
|
rescue LoadError
|
|
warn("Loading stringio or zlib failed. No gzipped response supported.") if $DEBUG
|
|
end
|
|
|
|
|
|
warn("Overriding WEBrick::Log#debug") if $DEBUG
|
|
require 'webrick/log'
|
|
module WEBrick
|
|
class Log < BasicLog
|
|
alias __debug debug
|
|
def debug(msg = nil)
|
|
if block_given? and msg.nil?
|
|
__debug(yield)
|
|
else
|
|
__debug(msg)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
module SOAP
|
|
module RPC
|
|
|
|
|
|
class SOAPlet < WEBrick::HTTPServlet::AbstractServlet
|
|
public
|
|
attr_reader :options
|
|
|
|
def initialize(router = nil)
|
|
@router = router || ::SOAP::RPC::Router.new(self.class.name)
|
|
@options = {}
|
|
@config = {}
|
|
end
|
|
|
|
# for backward compatibility
|
|
def app_scope_router
|
|
@router
|
|
end
|
|
|
|
# for backward compatibility
|
|
def add_servant(obj, namespace)
|
|
@router.add_rpc_servant(obj, namespace)
|
|
end
|
|
|
|
def allow_content_encoding_gzip=(allow)
|
|
@options[:allow_content_encoding_gzip] = allow
|
|
end
|
|
|
|
###
|
|
## Servlet interfaces for WEBrick.
|
|
#
|
|
def get_instance(config, *options)
|
|
@config = config
|
|
self
|
|
end
|
|
|
|
def require_path_info?
|
|
false
|
|
end
|
|
|
|
def do_GET(req, res)
|
|
res.header['Allow'] = 'POST'
|
|
raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed"
|
|
end
|
|
|
|
def do_POST(req, res)
|
|
logger.debug { "SOAP request: " + req.body } if logger
|
|
begin
|
|
conn_data = ::SOAP::StreamHandler::ConnectionData.new
|
|
setup_req(conn_data, req)
|
|
@router.external_ces = @options[:external_ces]
|
|
conn_data = @router.route(conn_data)
|
|
setup_res(conn_data, req, res)
|
|
rescue Exception => e
|
|
conn_data = @router.create_fault_response(e)
|
|
res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
|
|
res.body = conn_data.send_string
|
|
res['content-type'] = conn_data.send_contenttype || "text/xml"
|
|
end
|
|
if res.body.is_a?(IO)
|
|
res.chunked = true
|
|
logger.debug { "SOAP response: (chunked response not logged)" } if logger
|
|
else
|
|
logger.debug { "SOAP response: " + res.body } if logger
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def logger
|
|
@config[:Logger]
|
|
end
|
|
|
|
def setup_req(conn_data, req)
|
|
conn_data.receive_string = req.body
|
|
conn_data.receive_contenttype = req['content-type']
|
|
conn_data.soapaction = parse_soapaction(req.meta_vars['HTTP_SOAPACTION'])
|
|
end
|
|
|
|
def setup_res(conn_data, req, res)
|
|
res['content-type'] = conn_data.send_contenttype
|
|
if conn_data.is_fault
|
|
res.status = WEBrick::HTTPStatus::RC_INTERNAL_SERVER_ERROR
|
|
end
|
|
if outstring = encode_gzip(req, conn_data.send_string)
|
|
res['content-encoding'] = 'gzip'
|
|
res['content-length'] = outstring.size
|
|
res.body = outstring
|
|
else
|
|
res.body = conn_data.send_string
|
|
end
|
|
end
|
|
|
|
def parse_soapaction(soapaction)
|
|
if !soapaction.nil? and !soapaction.empty?
|
|
if /^"(.+)"$/ =~ soapaction
|
|
return $1
|
|
end
|
|
end
|
|
nil
|
|
end
|
|
|
|
def encode_gzip(req, outstring)
|
|
unless encode_gzip?(req)
|
|
return nil
|
|
end
|
|
begin
|
|
ostream = StringIO.new
|
|
gz = Zlib::GzipWriter.new(ostream)
|
|
gz.write(outstring)
|
|
ostream.string
|
|
ensure
|
|
gz.close
|
|
end
|
|
end
|
|
|
|
def encode_gzip?(req)
|
|
@options[:allow_content_encoding_gzip] and defined?(::Zlib) and
|
|
req['accept-encoding'] and
|
|
req['accept-encoding'].split(/,\s*/).include?('gzip')
|
|
end
|
|
end
|
|
|
|
|
|
end
|
|
end
|