Changeset 567

Show
Ignore:
Timestamp:
03/25/07 14:29:23 (2 years ago)
Author:
sacha
Message:

added logger functionality

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/taskers/hefeweizen_tasker_application_send_ebXML_message.rb

    r566 r567  
    106106        require "#{@config['LIB_DIR']}/hefeweizen_library_utils" 
    107107 
    108 =begin         
     108        @debug = @info = @warn = @error = true 
     109        case @config['LOG_LEVEL'] 
     110        when 'debug' then 
     111          @debug = @info = @warn = @error = true 
     112        when 'info' then 
     113          @info = @warn = @error = true  
     114          @debug = nil 
     115        when 'warn' then 
     116          @warn = @error = true 
     117          @debug = @info = nil  
     118        when 'error' then 
     119          @error = true 
     120          @debug = @info = @warn = nil 
     121        end 
     122 
    109123        begin 
    110 #          @logger = HefeWeizen::HefeWeizenLibrary::HefeWeizenLogger.new "#{@config['LOG_DIR']}/#{@config['LOG_FILE']}", @config['LOG_LEVEL'] 
    111 #          @logger.info "#{$0}: HefeWeizen Tasker HTTP Sender Starting with Process ID #{$$}." 
    112  
     124          @logger = HefeWeizen::HefeWeizenLibrary::HefeWeizenLogger.new "#{@config['LOG_DIR']}/#{@config['LOG_FILE']}", @config['LOG_LEVEL'] 
     125          @logger.info "#{$0}: HefeWeizen Tasker HTTP Sender Starting with Process ID #{$$}." 
    113126        rescue Exception => e 
    114127          $stderr.puts "Error creating logger. #{e.to_s}" 
     
    116129          return -1 
    117130        end 
    118 =end         
     131 
    119132      end 
    120133 
    121134      def me 
    122         "HefeWeizenHTTPClient
     135        "HefeWeizenSendEbXMLMessageTasker
    123136      end 
    124137 
    125138      def run 
    126          
    127139        if (FileTest.exists?(@parameters_file_path) && FileTest.readable?(@parameters_file_path) &&  
    128140            FileTest.exists?(@ebXML_message_file_path) && FileTest.readable?(@ebXML_message_file_path)) then 
     
    139151          # HTTP settings 
    140152          http_url = @ebXML_message_parameters['info']['transport-protocol-endpoint'] 
    141           number_of_retries = @ebXML_message_parameters['info']['reliable-messaging-retries'] || 5 
    142           seconds_to_wait_between_retries = @ebXML_message_parameters['info']['reliable-messaging-retry-interval'] || 10 
    143  
     153           
    144154          # HTTPS settings 
    145155          ssl_configurations = "" 
    146156          security_protocol = @ebXML_message_parameters['info']['transport-protocol-security-protocol'] 
    147157          if !security_protocol.nil? and security_protocol.upcase == 'SSL' then 
     158            @logger.debug "#{me}: Using SSL as transport level security protocol." if @debug 
    148159            # no certificate checkings for wget use argument --no-check-certificate 
    149160 
     
    155166            # --certificate = -> the client certificate file path 
    156167 
    157             # "/home/sacha/HefeWeizenHTTPS/test/test-systems/Gnaraloo/certificates/gnaraloo_ssl_server_cert/Gnaraloo_ssl_server_cacert.pem" 
    158             # "/home/sacha/HefeWeizenHTTPS/test/test-systems/Coronation/certificates/coronation_ssl_client_cert/Coronation_ssl_client_cacert.pem" 
    159  
    160168            ca_certificate = @ebXML_message_parameters['info']['transport-protocol-security-server-cert-file'] || "" 
    161169            ca_directory = @ebXML_message_parameters['info']['transport-protocol-security-server-cas-directory'] || "" 
     
    166174              msg = "Required SSL configuration information is missing. Check the values of the ca_certificate: '#{ca_certificate}', " + 
    167175                "ca_directory = '#{ca_directory}', client certificate: '#{client_certificate}', or priate key: '#{priate_key}'." 
    168               # @logger.error "#{me}: #{msg}" 
    169176              # ssl_configurations = "--no-check-certificate" 
    170               puts "Errro #{msg}"  
     177              @logger.error "#{me}: Errro #{msg}" if @error 
     178              # TODO exit -1? 
    171179            else 
    172180              ssl_configurations = "--ca-certificate=#{ca_certificate} --ca-directory=#{ca_directory} --certificate=#{client_certificate} --private-key=#{private_key}" 
     
    175183          end 
    176184 
    177           # FIX ME FOR TESTING PURPOSE SEND IT TO A LOCAL WEBSERVER 
     185          # FOR TESTING PURPOSE SEND IT TO A LOCAL WEBSERVER 
    178186          #        http_url = "localhost:5555/test" 
    179187 
    180           # FIX ME FOR TESTING PURPOSE SEND IT TO A LOCAL WEBSERVER 
     188          # FOR TESTING PURPOSE SEND IT TO A LOCAL WEBSERVER 
    181189          #        http_url = "192.168.1.49:8888/gnaraloo" 
    182190           
     
    187195          transfer_info_file_path = "#{@config['TEMP_FILE_DIR']}/#{@pid}_transfer_#{time}_#{time2}" 
    188196           
    189            
    190197          extra_header = nil 
    191198 
     
    195202            extra_header = 'Content-Type: text/xml' 
    196203          end 
    197            
    198           # TODO 
    199           # maybe do sending individually and keep track of retries. this would allow 
    200           # to send status information to big_ania to let the transaction know about 
    201           # individual failed attempts 
    202            
    203           #        command = "wget -S --user-agent=\"HefeWeizen\" --post-file=#{@ebXML_message_file_path} --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=#{response_file_path} --tries=#{number_of_retries} --wait=#{seconds_to_wait_between_retries} --quiet #{http_url}" 
    204           #          command = "wget -S --user-agent=\"HefeWeizen\" --post-file=#{@ebXML_message_file_path} --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=#{response_file_path} --tries=#{number_of_retries} --wait=#{seconds_to_wait_between_retries} --append-output=#{transfer_info_file_path} #{http_url} " 
    205           # no retries here! 
    206  
    207  
    208           #          puts command = "wget -S --user-agent=\"HefeWeizen\" --post-file=\"#{@ebXML_message_file_path}\" --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=\"#{response_file_path}\" --append-output=\"#{transfer_info_file_path}\" #{http_url} " 
    209  
     204 
     205          @logger.debug "#{me}: Extra headers for HTTP post: #{extra_header}" if @debug 
    210206          # added ignore-length ... had problems with it when using webrick and setting code 204 to it. 
    211  
    212207          command = "wget -S #{ssl_configurations} --ignore-length --user-agent=\"HefeWeizen\" --post-file=\"#{@ebXML_message_file_path}\" --header='#{extra_header}' --header='SOAPAction: \"ebXML\"' --output-document=\"#{response_file_path}\" --append-output=\"#{transfer_info_file_path}\" #{http_url} " 
    213  
     208           
     209          @logger.debug "#{me}: Complete HTTP post command: #{command}" if @debug 
    214210          system(command) 
    215  
    216211          success = $? 
    217212 
    218           #        puts "-----------------HTTP SENDER---response-------------------" 
    219           #        require 'pp' 
    220           #        pp File.read(response_file_path) 
    221           #        puts "-----------------HTTP SENDER---response-------------------" 
    222  
    223213        elsif @ebXML_message_parameters['info']['transport-protocol-name'].upcase == "SMTP" then 
    224           puts 'SMTP not implemented yet' 
     214          @logger.error "#{me}: SMTP not implemented yet " if @error 
    225215          success = -1 
    226           exit -1 
    227216        end 
    228217 
     
    241230 
    242231        test_response = false 
     232 
    243233        if @ebXML_message_parameters['info']['transport-protocol-name'].upcase == "HTTP" then 
    244234 
     235          # The code below will be used in the test environment. 
     236          # It will check if there is a directive that tells the client to throw away a response (usefule 
     237          # to test reliable messaging). 
    245238          if @config['BIG_ANIA_LOAD_TEST_ENVIRONMENT'] == 'true' then 
    246  
    247239            file_path = "#{@config['TEMP_FILE_DIR']}/client_throw_away_message_response_#{@b2b_system_name}" 
    248240            if File.exists?(file_path) then 
     
    252244              accepted_time_difference = 30*60 
    253245              if time_difference  > accepted_time_difference then 
    254                 puts "Time difference too big (#{time_difference} instead of #{accepted_time_difference}). Just in case someone forgot such a file in this place." 
     246                @logger.debug "Time difference too big (#{time_difference} instead of #{accepted_time_difference}). Just in case someone forgot such a file in this place." if @debug 
    255247              else 
    256248                test_response = true 
     
    296288        else 
    297289          command_hash['status'] = "FAILED" 
    298           command_hash['reason'] = "HTTP sender task was unable to deliver the message." 
     290          command_hash['reason'] = "ebXML message sender task was unable to deliver the message." 
    299291        end 
    300292         
    301293        my_command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}\" > #{@pipe_to_ania}" 
     294        @logger.debug "#{me}: Sending back result to Big Ania: #{my_command}" if @debug 
    302295        system my_command 
    303296