Class: JsonRpcServer

Inherits:
Object
  • Object
show all
Includes:
JsonRpcConstants, JsonRpcErrors
Defined in:
lib/jsonrpc2.0/Server.rb

Constant Summary

Constants included from JsonRpcErrors

JsonRpcErrors::ApplicationErrors, JsonRpcErrors::ImplementationErrors

Constants included from JsonRpcConstants

JsonRpcConstants::VERSION

Instance Method Summary collapse

Methods included from JsonRpcErrors

add_application_errors, create_error_classes, error_from_hash

Instance Method Details

#handle_message(inMessage) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jsonrpc2.0/Server.rb', line 9

def handle_message(inMessage)
	begin
		begin
			message = JSON.parse inMessage
		rescue JSON::ParserError => e
			raise(ParseError, e.message)
		end

		if message.class == Array	
			response = message.map{ |e| handle_request(e) }.to_json
			response.compact!
		else
			response = handle_request(message).to_json
		end
	rescue BaseImplementationError => e
		id = nil
		id = message['id'] if (message.class == Hash)
		error = create_message(id)
		error['error'] = e
		response = error.to_json
	ensure
		response
	end
end