Changeset 555
- Timestamp:
- 03/24/07 14:39:47 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/taskers/hefeweizen_tasker_application_http_server.rb
r553 r555 64 64 # the thread can exit. 65 65 class EBMSServlet < WEBrick::HTTPServlet::AbstractServlet 66 66 67 def me 68 "EBMSServlet" 69 end 70 67 71 def do_POST(req, resp) 68 72 … … 76 80 accepted_time_difference = 30*60 77 81 if time_difference > accepted_time_difference then 78 puts "Time difference too big (#{time_difference} instead of #{accepted_time_difference}). Just in case someone forgot such a file in this place."82 @logger.debug "#{me}: Time difference too big (#{time_difference} instead of #{accepted_time_difference}). Just in case someone forgot such a file in this place." if @debug 79 83 else 80 84 resp.body = "" … … 110 114 111 115 if @is_https then 112 puts '-------------------------------' 113 puts 'General Request information ' 114 puts req.meta_vars.class 115 puts req.meta_vars 116 puts '-------------------------------' 117 puts 'The Client Certificate' 118 puts req.meta_vars['SSL_CLIENT_CERT'] 119 puts '-------------------------------' 116 if @debug then 117 @logger.debug "#{me}: -------------------------------" 118 @logger.debug "#{me}: General Request information" 119 @logger.debug "#{me}: #{req.meta_vars.class}" 120 @logger.debug "#{me}: #{req.meta_vars}" 121 @logger.debug "#{me}: -------------------------------" 122 @logger.debug "#{me}: The Client Certificate" 123 @logger.debug "#{me}: #{req.meta_vars['SSL_CLIENT_CERT']}" 124 @logger.debug "#{me}: -------------------------------" 125 end 120 126 end 121 127 … … 166 172 exit = true 167 173 rescue EOFError => error 168 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 169 puts "HTTP SERVER ERROR: #{error.to_s}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 170 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 174 @logger.error "#{warn}: HTTP SERVER ERROR: '#{error.to_s}', '#{error.inspect}', '#{error.backtrace}'" if @error 171 175 sleep (0.1) 172 176 end … … 178 182 # send response on HTTP response leg. 179 183 if command.nil? then 180 puts 'HTTP Server. Received empty command. This is bad.'184 @logger.warn 'HTTP Server. Received empty command. This is bad.' if @warn 181 185 resp['Content-Type'] = "plain/text" 186 # TODO probably a soap fault has to be returned. 182 187 resp.body = "ERROR here :( sorry dude." 183 188 elsif command.strip == 'system shutdown' 184 puts 'HTTP Server. Received shutdown command.'189 @logger.info "HTTP Server. Received shutdown command. Closing open connection of '#{req.meta_vars}'." if @info 185 190 resp['Content-Type'] = 'plain/text' 186 191 resp.body = "Server shutdown." … … 245 250 246 251 class InitializedEBMSServlet < EBMSServlet 247 def initialize server, b2b_system_name, config, pipe_to_ania252 def initialize server, b2b_system_name, config, logger, debug, info, warn, error, pipe_to_ania 248 253 super(server) 249 254 @b2b_system_name = b2b_system_name 250 255 @config = config 256 @logger = logger 257 @debug = debug 258 @info = info 259 @warn = warn 260 @error = error 251 261 @pipe_to_ania = pipe_to_ania 252 262 end … … 323 333 log_file = "#{@config['LOG_DIR']}/#{@config['LOG_FILE']}" 324 334 log_level = @config['LOG_LEVEL'] 335 case @config['LOG_LEVEL'] 336 when 'debug' then 337 @debug = @info = @warn = @error = true 338 when 'info' then 339 @info = @warn = @error = true 340 @debug = nil 341 when 'warn' then 342 @warn = @error = true 343 @debug = @info = nil 344 when 'error' then 345 @error = true 346 @debug = @info = @warn = nil 347 end 325 348 326 349 if !FileTest.exists?(log_file) then … … 340 363 if @is_https then 341 364 if !(!@server_cert_dir.nil? and FileTest.exists? @server_cert_dir and FileTest.directory? @server_cert_dir) then 342 @logger.error "#{me}: Unable to locate server certificate directory '#{@server_cert_dir}'." 365 @logger.error "#{me}: Unable to locate server certificate directory '#{@server_cert_dir}'." if @error 343 366 # exit -1 ? 344 367 else … … 348 371 # @private_key_password_file = Dir.glob("#{@server_cert_dir}/*private_key.password").first 349 372 if !(FileTest.exists? @cert_file and FileTest.readable? @cert_file) then 350 @logger.error "#{me}: The HTTP servers SSL certificate does not exist or is not readable. Please fix this first." 373 @logger.error "#{me}: The HTTP servers SSL certificate does not exist or is not readable. Please fix this first." if @error 351 374 exit -1 352 375 end 353 376 if !(!@private_key_file.nil? and FileTest.exists? @private_key_file and FileTest.readable? @private_key_file) then 354 @logger.error "#{me}: The HTTP Server's private key file does not exist or is not readable. Please fix this first." 377 @logger.error "#{me}: The HTTP Server's private key file does not exist or is not readable. Please fix this first." if @error 355 378 exit -1 356 379 end 357 380 358 381 if !(!@client_ca_path.nil? and FileTest.exists? @client_ca_path and FileTest.directory? @client_ca_path) then 359 @logger.error "#{me}: The value of client-ca-path of '#{@client_ca_path}' does not exist or ist not a directory. Please fix this first." 382 @logger.error "#{me}: The value of client-ca-path of '#{@client_ca_path}' does not exist or ist not a directory. Please fix this first." if @eror 360 383 exit -1 361 384 end … … 385 408 server_private_key = server_certificate = nil 386 409 387 puts "Private key file: #{@private_key_file}"388 puts "Sever cert file: #{@cert_file}"389 puts "Client CA path: #{@client_ca_path}"410 @logger.debug "#{me}: Private key file: #{@private_key_file}" if @debug 411 @logger.debug "#{me}: Sever cert file: #{@cert_file}" if @debug 412 @logger.debug "#{me}: Client CA path: #{@client_ca_path}" if @debug 390 413 391 414 begin … … 396 419 # ssl_ca_certificate_file = "/home/sacha/HefeWeizenHTTPS/test/test-systems/Coronation/certificates/coronation_ssl_client_cert/Coronation_ssl_client_cacert.pem", 397 420 rescue 398 @logger.error "#{me}: Unable to create HTTPs server." 421 @logger.error "#{me}: Unable to create HTTPs server." if @error 399 422 exit -1 400 423 end … … 456 479 end 457 480 458 server.mount @path, InitializedEBMSServlet, @b2b_system_name, @config, @ pipe_to_ania481 server.mount @path, InitializedEBMSServlet, @b2b_system_name, @config, @logger, @debug, @info, @warn, @error, @pipe_to_ania 459 482 trap("INT"){ server.shutdown } 460 483 server.start
