Class: XMLRPC::RackServer
- Inherits:
-
BasicServer
- Object
- BasicServer
- XMLRPC::RackServer
- Defined in:
- lib/xmlrpc/rack_server.rb
Overview
Implements a Rack based XML-RPC server.
Extends the XMLRPC::BasicServer by implementing the Rack callback requirement, creating a Rack compatible XML-RPC server. It is used as a normal XML-RPC server:
server = XMLRPC::RackServer.new
server.add_introspection
server.add_handler("weblogUpdates", Ping)
The XMLRPC::RackServer instance may be mounted to a Rack chain.
Constant Summary collapse
- VERSION =
"0.0.2".freeze
Instance Method Summary collapse
-
#call(env) ⇒ Object
Implements the Rack callback requirement.
-
#initialize(*args) ⇒ RackServer
constructor
Creates a new XMLRPC::RackServer instance.
Constructor Details
#initialize(*args) ⇒ RackServer
Creates a new XMLRPC::RackServer instance.
All parameters given are by-passed to XMLRPC::BasicServer initializer.
23 24 25 |
# File 'lib/xmlrpc/rack_server.rb', line 23 def initialize(*args) super(*args) end |
Instance Method Details
#call(env) ⇒ Object
Implements the Rack callback requirement.
Responds to any bad requests with HTTP errors, parses the input and process it, responding with the output.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xmlrpc/rack_server.rb', line 31 def call(env) request = Rack::Request.new(env) return [405, {}, ["Method Not Allowed"]] unless request.post? return [400, {}, ["Bad Request"]] unless not request.content_type.nil? and ["application/xml", "text/xml"].include? parse_content_type(request.content_type).first length = request.content_length.to_i return [411, {}, ["Length Required"]] unless length > 0 data = request.body return [400, {}, ["Bad Request"]] if data.nil? or data.size != length input = data.read(length) output = nil begin output = process(input) rescue RuntimeError => e return [400, {}, ["Bad Request"]] if e. =~ /No valid method call/ end return [500, {}, ["Internal Server Error"]] if output.nil? or output.size <= 0 response = Rack::Response.new response.write output response["Content-Type"] = "text/xml; charset=utf-8" response.finish end |