Skip to content

Commit

Permalink
support automatic re-login when HTTP session expires
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Jan 12, 2014
1 parent 7b10a88 commit da84df5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/ooor/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def self.build(faultCode, faultString, method, *args)
return UnAuthorizedError.new(method, faultCode, faultString, *args)
elsif faultCode =~ /AuthenticationError: Credentials not provided/
return InvalidSessionError.new(method, faultCode, faultString, *args)
elsif faultCode =~ /SessionExpiredException/
return SessionExpiredError.new(method, faultCode, faultString, *args)
else
return new(method, faultCode, faultString, *args)
end
Expand Down Expand Up @@ -79,7 +81,7 @@ class UnAuthorizedError < OpenERPServerError; end
class TypeError < OpenERPServerError; end
class ValueError < OpenERPServerError; end
class InvalidSessionError < OpenERPServerError; end

class SessionExpiredError < OpenERPServerError; end

class ValidationError < OpenERPServerError
def extract_validation_error!(errors)
Expand Down
6 changes: 4 additions & 2 deletions lib/ooor/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def object_service(service, obj, method, *args)
uid = @session.config[:user_id]
db = @session.config[:database]
@session.logger.debug "OOOR object service: rpc_method: #{service}, db: #{db}, uid: #{uid}, pass: #, obj: #{obj}, method: #{method}, *args: #{args.inspect}"
begin
if @session.config[:force_xml_rpc]
pass = @session.config[:password]
send(service, db, uid, pass, obj, method, *args)
Expand All @@ -98,7 +97,10 @@ def object_service(service, obj, method, *args)
rescue InvalidSessionError
@session.config[:force_xml_rpc] = true #TODO set v6 version too
retry
end
rescue SessionExpiredError
@session.logger.debug "session for uid: #{uid} has expired, trying to login again"
@session.common.login(@session.config[:database], @session.config[:username], @session.config[:password])
retry
end

def inject_session_context(*args)
Expand Down

0 comments on commit da84df5

Please sign in to comment.