diff options
author | Christoph Helma <helma@in-silico.ch> | 2012-03-02 18:22:32 +0000 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2012-03-02 18:22:32 +0000 |
commit | e911f80feb92b26dace1bd93835e0e72c21bfbf5 (patch) | |
tree | 89c56849ad5c0d499e7987f3ef515eeb2bb5fcb0 | |
parent | af9a688c2e5a214ec6dccc61aee2e063a5899794 (diff) |
environment readjusted for ~/.opentox, new OpenTox::Service class derived from Sinatra::Base
-rw-r--r-- | lib/environment.rb | 36 | ||||
-rw-r--r-- | lib/opentox-server.rb | 2 | ||||
-rw-r--r-- | lib/opentox.rb | 47 |
3 files changed, 50 insertions, 35 deletions
diff --git a/lib/environment.rb b/lib/environment.rb index 6c3523b..d164925 100644 --- a/lib/environment.rb +++ b/lib/environment.rb @@ -3,7 +3,7 @@ ENV['RACK_ENV'] = 'production' unless ENV['RACK_ENV'] # load/setup configuration -basedir = File.join(ENV['HOME'], ".toxbank") +basedir = File.join(ENV['HOME'], ".opentox") config_dir = File.join(basedir, "config") config_file = File.join(config_dir, "#{ENV['RACK_ENV']}.yaml") @@ -22,7 +22,7 @@ else end logfile = "#{LOG_DIR}/#{ENV["RACK_ENV"]}.log" -#$logger = OTLogger.new(logfile,'daily') # daily rotation + $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" @@ -35,40 +35,8 @@ end 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 -# OWL Namespaces -=begin -class OwlNamespace - - attr_accessor :uri - def initialize(uri) - @uri = uri - end - - def [](property) - @uri+property.to_s - end - - def type # for RDF.type - "#{@uri}type" - end - - def method_missing(property) - @uri+property.to_s - end - -end -=end - 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] CONFIG[:authorization][:free_request] = [""] unless CONFIG[:authorization][:free_request] -#RDF = OwlNamespace.new 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' -#OWL = OwlNamespace.new 'http://www.w3.org/2002/07/owl#' -#DC = OwlNamespace.new 'http://purl.org/dc/elements/1.1/' -#OT = OwlNamespace.new 'http://www.opentox.org/api/1.1#' -#OTA = OwlNamespace.new 'http://www.opentox.org/algorithmTypes.owl#' -#XSD = OwlNamespace.new 'http://www.w3.org/2001/XMLSchema#' - - diff --git a/lib/opentox-server.rb b/lib/opentox-server.rb index fa8a37f..c8aae1b 100644 --- a/lib/opentox-server.rb +++ b/lib/opentox-server.rb @@ -4,4 +4,4 @@ require 'rack/contrib' require 'sinatra' require 'sinatra/url_for' require File.join(File.dirname(__FILE__),"environment.rb") - +require File.join(File.dirname(__FILE__),"opentox.rb") diff --git a/lib/opentox.rb b/lib/opentox.rb new file mode 100644 index 0000000..1ba77dc --- /dev/null +++ b/lib/opentox.rb @@ -0,0 +1,47 @@ +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 + class Service < Sinatra::Base + 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'] + case request.env['HTTP_ACCEPT'] + when 'application/rdf+xml' + content_type 'application/rdf+xml' + when /html/ + content_type 'text/html' + when "text/n3" + content_type "text/n3" + else + content_type "text/n3" + end + if error.respond_to? :report + code = error.report.http_code + case request.env['HTTP_ACCEPT'] + when 'application/rdf+xml' + body = error.report.to_rdfxml + when /html/ + body = error.report.to_yaml + when "text/n3" + body = error.report.to_ntriples + else + body = error.report.to_ntriples + end + else + content_type "text/plain" + body = error.message + body += "\n#{error.backtrace}" + end + + halt code, body + end + end +end + |