summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-29 14:50:03 +0200
committerChristoph Helma <helma@in-silico.ch>2012-03-29 14:50:03 +0200
commit97f9367b05a9a665022adc5c3f0a988acb1c4fa3 (patch)
tree0a716fa05fc4c8beacde349b13e7d749c1b23b9e
parent0d457e40c005ba4209ec7e3093aa06d73d65a442 (diff)
RestClientWrapper follows redirects
-rw-r--r--lib/error.rb11
-rw-r--r--lib/opentox.rb6
-rw-r--r--lib/rest-client-wrapper.rb13
3 files changed, 14 insertions, 16 deletions
diff --git a/lib/error.rb b/lib/error.rb
index e12f140..579f42b 100644
--- a/lib/error.rb
+++ b/lib/error.rb
@@ -52,11 +52,12 @@ module OpenTox
# Errors received from RestClientWrapper calls
class RestCallError < Error
- attr_accessor :request, :response
- def initialize request, response, message
+ attr_accessor :request#, :response
+ def initialize message, request, uri
+ #def initialize request, response, message
@request = request
- @response = response
- super 502, message, request.url
+ #@response = response
+ super 502, message, uri
end
end
@@ -78,7 +79,7 @@ module OpenTox
cut_index = backtrace.size-1 if cut_index < 0
@report[RDF::OT.errorDetails] = backtrace[0..cut_index].join("\n")
@report[RDF::OT.errorDetails] += "REST paramenters:\n#{error.request.args.inspect}" if defined? error.request
- @report[RDF::OT.message] += "\n" + error.response.body.to_s if defined? error.response
+ #@report[RDF::OT.message] += "\n" + error.response.body.to_s if defined? error.response
# TODO fix Error cause
# should point to another errorReport, but errorReports do not have URIs
# create a separate service?
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 2232063..187eb08 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -70,12 +70,6 @@ module OpenTox
end
end
-# def to_hash
-# hash = {}
-# metadata.each{|k,v| v.is_a?(Array) ? hash[k.to_s] = v.collect{|i| i.to_s} : hash[k.to_s] = v.to_s}
-# hash
-# end
-
def to_yaml
@rdf.to_hash.to_yaml
end
diff --git a/lib/rest-client-wrapper.rb b/lib/rest-client-wrapper.rb
index 30292de..aa5d9c4 100644
--- a/lib/rest-client-wrapper.rb
+++ b/lib/rest-client-wrapper.rb
@@ -34,13 +34,16 @@ module OpenTox
headers.each{ |k,v| headers.delete(k) if v==nil } if headers #remove keys with empty values, as this can cause problems
args[:headers] = headers
- # perform request
@request = RestClient::Request.new(args)
- # do not throw RestClient exceptions in order to create a @response object (needed for error reports) in every case
- @response = @request.execute { |response, request, result| return response }
# ignore error codes from Task services (may return error codes >= 400 according to API, which causes exceptions in RestClient and RDF::Reader)
- raise OpenTox::RestCallError.new @request, @response, "Response code is #{@response.code}." unless @response.code < 400 or URI.task? uri
- @response
+ @response = @request.execute do |response, request, result|
+ if [301, 302, 307].include? response.code and request.method == :get
+ response.follow_redirection(request, result)
+ else
+ raise OpenTox::RestCallError.new response.to_s, request, uri unless response.code < 400 or URI.task? uri
+ response
+ end
+ end
end
end