class SOAP::RPC::SOAPlet
Attributes
authenticator[RW]
options[R]
Public Class Methods
new(router = nil)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 47 def initialize(router = nil) @router = router || ::SOAP::RPC::Router.new(self.class.name) @options = {} @authenticator = nil @config = {} end
user()
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 113 def self.user get_variable(:User) end
user=(user)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 117 def self.user=(user) set_variable(:User, user) end
Private Class Methods
get_variable(name)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 123 def self.get_variable(name) if var = Thread.current[:SOAPlet] var[name] else nil end end
set_variable(name, value)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 131 def self.set_variable(name, value) var = Thread.current[:SOAPlet] ||= {} var[name] = value end
Public Instance Methods
allow_content_encoding_gzip=(allow)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 54 def allow_content_encoding_gzip=(allow) @options[:allow_content_encoding_gzip] = allow end
do_GET(req, res)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 70 def do_GET(req, res) res.header['Allow'] = 'POST' raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed" end
do_POST(req, res)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 75 def do_POST(req, res) logger.debug { "SOAP request: " + req.body } if logger if @authenticator @authenticator.authenticate(req, res) # you can check authenticated user with SOAP::RPC::SOAPlet.user end begin conn_data = ::SOAP::StreamHandler::ConnectionData.new setup_req(conn_data, req) @router.external_ces = @options[:external_ces] Mapping.protect_threadvars(:SOAPlet) do SOAPlet.user = req.user SOAPlet.cookies = req.cookies conn_data = @router.route(conn_data) setup_res(conn_data, req, res) end 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
get_instance(config, *options)
click to toggle source
Servlet interfaces for WEBrick
.
# File lib/soap/rpc/soaplet.rb, line 61 def get_instance(config, *options) @config = config self end
require_path_info?()
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 66 def require_path_info? false end
Private Instance Methods
encode_gzip(req, outstring)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 178 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
encode_gzip?(req)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 192 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
logger()
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 136 def logger @config[:Logger] end
parse_soapaction(soapaction)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 169 def parse_soapaction(soapaction) if !soapaction.nil? and !soapaction.empty? if /^"(.+)"$/ =~ soapaction return $1 end end nil end
setup_req(conn_data, req)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 140 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
setup_res(conn_data, req, res)
click to toggle source
# File lib/soap/rpc/soaplet.rb, line 146 def setup_res(conn_data, req, res) res['content-type'] = conn_data.send_contenttype cookies = SOAPlet.cookies unless cookies.empty? res['set-cookie'] = cookies.collect { |cookie| cookie.to_s } end if conn_data.is_nocontent res.status = WEBrick::HTTPStatus::RC_ACCEPTED res.body = '' return end 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