summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2012-03-07 13:49:41 +0100
committerChristoph Helma <helma@in-silico.ch>2012-03-07 13:49:41 +0100
commitd6482ea41cceaa741dc47192dfea6e5482d17a30 (patch)
treea81eac2ef6711fae063dda7bedb178b72442f004
parent2d2b1a31e64e84ca65b4cb180a9d83d55ee2e0cf (diff)
environment cleanup, turtle error reports
-rw-r--r--lib/environment.rb13
-rw-r--r--lib/opentox.rb17
2 files changed, 13 insertions, 17 deletions
diff --git a/lib/environment.rb b/lib/environment.rb
index d164925..1af76f8 100644
--- a/lib/environment.rb
+++ b/lib/environment.rb
@@ -1,5 +1,4 @@
# set default environment
-
ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV']
# load/setup configuration
@@ -12,29 +11,25 @@ LOG_DIR = File.join(basedir, "log")
if File.exist?(config_file)
CONFIG = YAML.load_file(config_file)
- raise "could not load config, config file: "+config_file.to_s unless CONFIG
+ not_found_error "Could not load configuration from \"#{config_file.to_s}\"" unless CONFIG
else
FileUtils.mkdir_p TMP_DIR
FileUtils.mkdir_p LOG_DIR
FileUtils.mkdir_p config_dir
puts "Please edit #{config_file} and restart your application."
- #exit
+ exit
end
logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log"
+$logger = OTLogger.new(logfile)
-$logger = OTLogger.new(logfile) # no rotation
-$logger.formatter = Logger::Formatter.new #this is neccessary to restore the formating in case active-record is loaded
if CONFIG[:logger] and CONFIG[:logger] == "debug"
$logger.level = Logger::DEBUG
else
$logger.level = Logger::WARN
end
-# Regular expressions for parsing classification data
-TRUE_REGEXP = /^(true|active|1|1.0|tox|activating|carcinogen|mutagenic)$/i
-FALSE_REGEXP = /^(false|inactive|0|0.0|low tox|deactivating|non-carcinogen|non-mutagenic)$/i
-
+# TODO: move to opentox-client???
AA_SERVER = CONFIG[:authorization] ? (CONFIG[:authorization][:server] ? CONFIG[:authorization][:server] : nil) : nil
CONFIG[:authorization][:authenticate_request] = [""] unless CONFIG[:authorization][:authenticate_request]
CONFIG[:authorization][:authorize_request] = [""] unless CONFIG[:authorization][:authorize_request]
diff --git a/lib/opentox.rb b/lib/opentox.rb
index 73798ef..16646c1 100644
--- a/lib/opentox.rb
+++ b/lib/opentox.rb
@@ -1,18 +1,19 @@
require 'sinatra/base'
-# Error handling
-# Errors are logged as error and formated according to acccept-header
-# Non OpenTox::Errors (defined in error.rb) are handled as internal error (500), stacktrace is logged
-# IMPT: set sinatra settings :show_exceptions + :raise_errors to false in config.ru, otherwise Rack::Showexceptions takes over
module OpenTox
+ # Base class for OpenTox services
+ # Errors are formated according to acccept-header
+ # Non OpenTox::Errors (defined in error.rb) are handled as internal error (500), stacktrace is logged
class Service < Sinatra::Base
+
helpers Sinatra::UrlForHelper
+ # use OpenTox error handling
set :raise_errors, false
set :show_exceptions, false
+
error do
- #TODO: add actor to error report
- #actor = "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}"
error = request.env['sinatra.error']
+ error.report.actor = "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}"
case request.env['HTTP_ACCEPT']
when 'application/rdf+xml'
content_type 'application/rdf+xml'
@@ -21,7 +22,7 @@ module OpenTox
when "text/n3"
content_type "text/n3"
else
- content_type "text/n3"
+ content_type "text/turtle"
end
if error.respond_to? :report
code = error.report.http_code
@@ -33,7 +34,7 @@ module OpenTox
when "text/n3"
body = error.report.to_ntriples
else
- body = error.report.to_ntriples
+ body = error.report.to_turtle
end
else
content_type "text/plain"