Class: Rack::RPC::Endpoint::XMLRPC::Server
- Inherits:
-
XMLRPC::BasicServer
- Object
- XMLRPC::BasicServer
- Rack::RPC::Endpoint::XMLRPC::Server
- Defined in:
- lib/rack/rpc/endpoint/xmlrpc.rb
Overview
Instance Method Summary (collapse)
-
- add_capabilities(options = {})
Implements the
system.getCapabilities
standard method, enabling clients to determine whether a given capability is supported by this server. -
- (String) error_response(code, message)
Create a valid error response for a given code and message.
- - (Rack::Response) execute(request)
-
- (Server) initialize(server, options = {})
constructor
A new instance of Server.
-
- (void) process(request_body)
Process requests and ensure errors are handled properly.
Constructor Details
- (Server) initialize(server, options = {})
Returns a new instance of Server
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rack/rpc/endpoint/xmlrpc.rb', line 26 def initialize(server, = {}) @server = server super() add_multicall unless [:multicall] == false add_introspection unless [:introspection] == false add_capabilities unless [:capabilities] == false server.class.rpc.each do |rpc_name, method_name| add_handler(rpc_name, nil, nil, &server.method(method_name)) end end |
Instance Method Details
- add_capabilities(options = {})
This method returns an undefined value.
Implements the system.getCapabilities
standard method, enabling
clients to determine whether a given capability is supported by this
server.
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rack/rpc/endpoint/xmlrpc.rb', line 72 def add_capabilities( = {}) add_handler('system.getCapabilities', %w(struct), '') do capabilities = {} unless [:faults_interop] == false capabilities['faults_interop'] = { 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 'specVersion' => 20010516, } end capabilities end self end |
- (String) error_response(code, message)
Create a valid error response for a given code and message
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rack/rpc/endpoint/xmlrpc.rb', line 93 def error_response(code, ) xml = Builder::XmlMarkup.new xml.instruct! :xml, :version=>"1.0" xml.methodResponse{ xml.fault { xml.value{ xml.struct{ xml.member{ xml.name('faultCode') xml.value{ xml.int(code) } } xml.member{ xml.name('faultString') xml.value{ xml.string() } } } } } } end |
- (Rack::Response) execute(request)
40 41 42 43 44 45 46 47 |
# File 'lib/rack/rpc/endpoint/xmlrpc.rb', line 40 def execute(request) @server.request = request # Store the request so it can be accessed from the server methods request_body = request.body.read request_body.force_encoding(Encoding::UTF_8) if request_body.respond_to?(:force_encoding) # Ruby 1.9+ Rack::Response.new([process(request_body)], 200, { 'Content-Type' => (request.content_type || CONTENT_TYPE).to_s, }) end |
- (void) process(request_body)
Process requests and ensure errors are handled properly
53 54 55 56 57 58 59 |
# File 'lib/rack/rpc/endpoint/xmlrpc.rb', line 53 def process(request_body) begin super(request_body) rescue RuntimeError => e error_response(-32500, "application error - #{e.}") end end |