def handle_single(req)
      method = req["method"]
      if !method
        return err_resp(req, -32600, "No method provided on request")
      end

      # Special case - client is requesting the IDL bound to this server, so
      # we return it verbatim.  No further validation is needed in this case.
      if method == "barrister-idl"
        return ok_resp(req, @contract.idl)
      end

      # Make sure we can find an interface and function on the IDL for this
      # request method string
      err_resp, iface, func = @contract.resolve_method(req)
      if err_resp != nil
        return err_resp
      end
      
      # Make sure that the params on the request match the IDL types
      err_resp = @contract.validate_params(req, func)
      if err_resp != nil
        return err_resp
      end
      
      params = [ ]
      if req["params"]
        params = req["params"]
      end

      # Make sure we have a handler bound to this Server for the interface.
      # If not, that means `server.add_handler` was not called for this interface
      # name.  That's likely a misconfiguration.
      handler = @handlers[iface.name]
      if !handler
        return err_resp(req, -32000, "Server error. No handler is bound to interface #{iface.name}")
      end

      # Make sure that the handler has a method for the given function.
      if !handler.respond_to?(func.name)
        return err_resp(req, -32000, "Server error. Handler for #{iface.name} does not implement #{func.name}")
      end

      begin 
        # Call the handler function. This is where your code gets invoked.
        result  = handler.send(func.name, *params)
        
        # Verify that the handler function's return value matches the
        # correct type as specified in the IDL
        err_resp = @contract.validate_result(req, result, func)
        if err_resp != nil
            return err_resp
        else
          return ok_resp(req, result)
        end
      rescue RpcException => e
        # If the handler raised a RpcException, that's ok - return it unmodified.
        return err_resp(req, e.code, e.message, e.data)
      rescue => e
        # If any other error was raised, print it and return a generic error to the client
        puts e.inspect
        puts e.backtrace
        return err_resp(req, -32000, "Unknown error: #{e}")
      end
    end
def handle_single(req)
      method = req["method"]
      if !method
        return err_resp(req, -32600, "No method provided on request")
      end

      # Special case - client is requesting the IDL bound to this server, so
      # we return it verbatim.  No further validation is needed in this case.
      if method == "barrister-idl"
        return ok_resp(req, @contract.idl)
      end

      # Make sure we can find an interface and function on the IDL for this
      # request method string
      err_resp, iface, func = @contract.resolve_method(req)
      if err_resp != nil
        return err_resp
      end
      
      # Make sure that the params on the request match the IDL types
      err_resp = @contract.validate_params(req, func)
      if err_resp != nil
        return err_resp
      end
      
      params = [ ]
      if req["params"]
        params = req["params"]
      end

      # Make sure we have a handler bound to this Server for the interface.
      # If not, that means `server.add_handler` was not called for this interface
      # name.  That's likely a misconfiguration.
      handler = @handlers[iface.name]
      if !handler
        return err_resp(req, -32000, "Server error. No handler is bound to interface #{iface.name}")
      end

      # Make sure that the handler has a method for the given function.
      if !handler.respond_to?(func.name)
        return err_resp(req, -32000, "Server error. Handler for #{iface.name} does not implement #{func.name}")
      end

      begin 
        # Call the handler function. This is where your code gets invoked.
        result  = handler.send(func.name, *params)
        
        # Verify that the handler function's return value matches the
        # correct type as specified in the IDL
        err_resp = @contract.validate_result(req, result, func)
        if err_resp != nil
            return err_resp
        else
          return ok_resp(req, result)
        end
      rescue RpcException => e
        # If the handler raised a RpcException, that's ok - return it unmodified.
        return err_resp(req, e.code, e.message, e.data)
      rescue => e
        # If any other error was raised, print it and return a generic error to the client
        puts e.inspect
        puts e.backtrace
        return err_resp(req, -32000, "Unknown error: #{e}")
      end
    end
Internal method that validates and executes a single request.