lib/marilyn-rpc/client.rb in marilyn-rpc-0.0.2 vs lib/marilyn-rpc/client.rb in marilyn-rpc-0.0.3

- old
+ new

@@ -1,14 +1,15 @@ require 'socket' require 'thread' module MarilynRPC - class BlankSlate + # A class with nothing but `__send__` and `__id__` + class ClientBlankSlate instance_methods.each { |m| undef_method m unless m =~ /^__/ } end - class NativeClientProxy < BlankSlate + class NativeClientProxy < ClientBlankSlate # Creates a new Native client proxy, were the calls get send to the remote # side. # @param [Object] path the path that is used to identify the service # @param [NativeClient] client the client to use for communication def initialize(path, client) @@ -60,10 +61,20 @@ # Disconnect the client from the remote. def disconnect @socket.close end + + # authenicate the client to call methods that require authentication + # @param [String] username the username of the client + # @param [String] password the password of the client + # @param [Symbol] method the method to use for authentication, currently + # only plain is supported. So make sure you are using a secure socket. + def authenticate(username, password, method = :plain) + execute(MarilynRPC::Service::AUTHENTICATION_PATH, + "authenticate_#{method}".to_sym, [username, password]) + end # Creates a new Proxy Object for the connection. # @param [Object] path the path were the service is registered on the remote # site # @return [MarilynRPC::NativeClientProxy] the proxy obejct that will serve @@ -137,10 +148,17 @@ mail = @semaphore.synchronize { @responses.delete(tag) } if mail.is_a? MarilynRPC::CallResponseMail mail.result else - raise mail.exception + raise MarilynError.new # raise exception to capture the client backtrace end + rescue MarilynError => exception + # add local and remote trace together and reraise the original exception + backtrace = [] + backtrace += exception.backtrace + backtrace += mail.exception.backtrace + mail.exception.set_backtrace(backtrace) + raise mail.exception end end end