Changeset 219

Show
Ignore:
Timestamp:
12/05/06 16:27:01 (2 years ago)
Author:
sacha
Message:

start of refactoring stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb

    r209 r219  
    1 #!/usr/bin/ruby 
     1#!/usr/bin/ruby -w 
    22 
    33Signal.trap("INT") do $stdout.puts "info : #{Time.now.to_s} - #{$$} - #{$$}: Big Ania caught INT signal. not exitting."; end 
     
    488488          ######################### 
    489489          ## process reponse 
     490          ## will be factored out! 
    490491          ######################### 
    491492 
     
    579580        # @logger.debug "The directive is a ebMS signal: #{directive.is_a_ebMS_signal?.to_s}" 
    580581         
    581         # This is a new transaction so we have to set the root cause 
    582         # of this new transaction. 
     582        # This is a new transaction so we have to set the root cause of this new transaction. 
    583583        if !transaction.set_root_cause directive then 
    584584          @logger.error "Unable to store the directive as root cause to the new transaction" 
     
    610610        # CREATE ebXML MESSAGE 
    611611        # -------------------- 
     612        # potential for a tasker 
    612613        @logger.debug "Creating ebXML message" 
    613614        ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.create_message @config, directive, ebMS_message_info 
     
    634635          return false 
    635636        end 
    636  
     637         
    637638        transaction.attach_file ebXML_message_file_path, "outgoing ebXML message" 
    638639        transaction.remember_file_to_remove ebXML_message_file_path 
    639  
     640         
    640641        # create an ebXML message parameters file 
    641642        ebXML_message_parameters_file_path = ebMS_message.create_ebXML_message_parameters_file ebMS_message_info, ebMS_message.is_multipart? 
     
    644645          return false 
    645646        end 
    646  
     647         
    647648        transaction.attach_file ebXML_message_parameters_file_path, "outgoing ebXML message parameters" 
    648649        transaction.remember_file_to_remove ebXML_message_parameters_file_path 
     
    650651        # SEND ebXML MESSAGE 
    651652        # ------------------ 
    652         expectation = "send_ebXML_message_http_done" 
    653         command_hash = { 
    654           "from" => "big_ania",  
    655           "to" => "ania",  
    656           "command" => "start_tasker", 
    657           "tasker" => "#{@config['BIN_DIR']}/hefeweizen_tasker_application_send_ebXML_message_http.rb", 
    658           "tasker arguments" => "--b2b-system-name #{b2b_system.system_name} --pipe-to-ania #{@config['PIPE_TO_ANIA']} --config #{@config['CONFIG_DIR']}/hefeweizen.conf --ebXML-message-file-path #{ebXML_message_file_path} --parameters-file-path #{ebXML_message_parameters_file_path} --transaction-id #{transaction.transaction_id} --state-expectation #{expectation}", 
    659           "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    660         } 
     653        if ebMS_message_info['info']['transport-protocol-name'].upcase == "HTTP" then 
     654          expectation = "send_ebXML_message_done" 
     655          command_hash = { 
     656            "from" => "big_ania",  
     657            "to" => "ania",  
     658            "command" => "start_tasker", 
     659            "tasker" => "#{@config['BIN_DIR']}/hefeweizen_tasker_application_send_ebXML_message_http.rb", 
     660            "tasker arguments" => "--b2b-system-name #{b2b_system.system_name} --pipe-to-ania #{@config['PIPE_TO_ANIA']} --config #{@config['CONFIG_DIR']}/hefeweizen.conf --ebXML-message-file-path #{ebXML_message_file_path} --parameters-file-path #{ebXML_message_parameters_file_path} --transaction-id #{transaction.transaction_id} --state-expectation #{expectation}", 
     661            "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
     662          } 
     663        elsif ebMS_message_info['info']['transport-protocol-name'].upcase == "SMTP" then 
     664          @logger.error "Message expected to be sent via SMTP but SMTP is not yet implemented." 
     665          return false 
     666        else 
     667          @logger.error "Message expected to be sent via #{ebMS_message_info['info']['transport-protocol-name']} which is unknwn and not supported." 
     668          return false 
     669        end 
    661670 
    662671        @logger.debug "Call tasker to send ebXML message." 
    663672        say_to_ania "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}" 
    664  
     673         
    665674        # SET EXPECTED NEW STATE 
    666675        transaction.set_next_expectation(expectation) 
    667  
     676         
    668677        return true 
    669678      else 
     
    685694      transaction.set_root_cause command_hash['file_full'] 
    686695       
    687       # TODO SMTP SUPPORT! there may be o SOAP ACTION! 
    688696      # maybe stuff this into ebMS class 
    689697      if !(ebMS_message_header =~ /^.*SOAPAction: ebXML.*$/ or ebMS_message_header =~ /.*SOAPAction: \"ebXML\".*/) then 
     
    716724        return true 
    717725      end   
    718  
     726       
    719727      # from here on we have to send back ebXML error messages. 
    720728 
  • branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message.rb

    r203 r219  
    3333      attr_reader :errors 
    3434 
     35      public 
     36 
     37      # This method gets an ebXML message from the message store. 
     38      def EBMSMessage.get_message_by_message_id config, id 
     39        path = "#{config['MESSAGE_DIR']}/#{id}" 
     40        if FileTest.exists? path then 
     41          return EBMSMessage.new( config, "#{path}/ebXML_message", false, (do_register = false) ) 
     42        else 
     43          return nil 
     44        end 
     45      end 
     46       
    3547      private 
    3648       
    37       def initialize config, ebXML_message, validate = false 
     49      # TODO what todo when a message is already there? 
     50      def register_message_id 
     51        target = "#{@config['MESSAGE_DIR']}/#{self.message_id}" 
     52        if FileTest.exists? target then 
     53          @logger.warn "There is already an ebXML message with message_id #{self.message_id} in the data store." 
     54          return nil 
     55        else 
     56          FileUtils.mkdir(target) 
     57          FileUtils.mv(create_ebXML_message_file, "#{target}/ebXML_message") 
     58          register_message_id_with_conversation_id 
     59          return true 
     60        end 
     61      end 
     62 
     63      def store_message_parameter_file file_path 
     64        target = "#{@config['MESSAGE_DIR']}/#{self.message_id}" 
     65        if !FileTest.exists? target then 
     66          @logger.warn "There is no ebXML message with given message id '#{self.message_id}' stored in the message store." 
     67          return nil 
     68        else 
     69          FileUtils.cp(file_path, "#{target}/ebXML_message_parameters_file") 
     70          return true 
     71        end 
     72         
     73      end 
     74 
     75      # TODO 
     76      # -> shall there be a file with the filename of the message id instead of a soft link (with absolute path!)? 
     77      def register_message_id_with_conversation_id 
     78        target = "#{@config['CONVERSATION_DIR']}/#{self.conversation_id}" 
     79        # conversation id first 
     80        if FileTest.exists? target then 
     81          @logger.debug "There is already a conversation with id #{self.conversation_id} registered." 
     82        else 
     83          FileUtils.mkdir(target) 
     84        end 
     85         
     86        # registering message for conversation next 
     87        source = "#{@config['MESSAGE_DIR']}/#{self.message_id}" 
     88        if FileTest.exists? "#{target}/#{self.message_id}" then 
     89          @logger.warn "Message with message id '#{self.message_id}' is already registered with conversation id '#{self.conversation_id}'." 
     90          return nil 
     91        else 
     92          FileUtils.ln_s(source, target) 
     93          return true 
     94        end 
     95      end 
     96 
     97      def initialize config, ebXML_message, validate = false, do_register_message = true 
    3898         
    3999        # TODO requires smarter loading of ebXML message. eg not loading everything 
     
    64124        end 
    65125 
    66          
    67126        @soap_only = raw_message_to_soap_only @raw_message 
    68127        @payloads = raw_message_to_payloads @raw_message 
     
    72131         
    73132        message_header = @message['Header'].first['MessageHeader'].first 
     133         
     134        throw Exception.new("Error Reading ebXML message. Error accessing MessageHeader information") if message_header.nil? 
    74135         
    75136        # required elements 
     
    95156            throw Exception.new("There is a mismatch between the payloads and the reference information in the Manifest") 
    96157          end 
     158        end 
     159 
     160        # TODO 
     161        # what to do if there is an already registered message? 
     162        if do_register_message then 
     163          register_message_id 
    97164        end 
    98165 
     
    268335            } 
    269336          end 
    270  
     337           
    271338          # Party Identities 
    272339          from_id, from_id_type, to_id, to_id_type = get_party_ids directive, ebMS_message_info 
    273  
    274 #          file_name = Time.now.to_f.to_s 
    275 #          file_path = "#{config['TEMP_FILE_DIR']}/#{file_name}" 
    276 #          my_command = "touch #{file_path}" 
    277 #          system my_command 
    278  
     340           
     341          ##          file_name = Time.now.to_f.to_s 
     342          ##          file_path = "#{config['TEMP_FILE_DIR']}/#{file_name}" 
     343          ##          my_command = "touch #{file_path}" 
     344          ##          system my_command 
     345           
    279346          skeleton = <<EOF 
    280347--HefeWeizenBoundary 
     
    310377EOF 
    311378 
    312 #          my_command = "echo '#{header}' >> #{file_path}" 
    313 #          system my_command 
     379          ##          my_command = "echo '#{header}' >> #{file_path}" 
     380          ##          system my_command 
    314381 
    315382          # ADDING PAYLOADS 
     
    336403EOF 
    337404 
    338 #            my_command = "echo '#{skeleton}' >> #{file_path}" 
    339 #            system my_command 
     405            ##            my_command = "echo '#{skeleton}' >> #{file_path}" 
     406            ##            system my_command 
    340407             
    341408            if FileTest.exists? payload_path and FileTest.readable? payload_path then 
    342409               
    343 #              my_command = "cat #{payload_path} >> #{file_path}" 
    344 #              system my_command 
     410              ##              my_command = "cat #{payload_path} >> #{file_path}" 
     411              ##              system my_command 
    345412              file = File.open(payload_path, "r") 
    346413              skeleton << file.read 
     
    356423--HefeWeizenBoundary-- 
    357424EOF 
    358 #          my_command = "echo '#{msg_end}' >> #{file_path}" 
    359 #          system my_command 
     425          ##          my_command = "echo '#{msg_end}' >> #{file_path}" 
     426          ##          system my_command 
    360427 
    361428          if errors then 
     
    444511        file.sync = true 
    445512        file.close 
     513        store_message_parameter_file file_path 
    446514        return file_path 
    447515      end 
  • branches/message-handling-refactor-branch/test/unit-tests/tc_hefeweizen_library_ebMS_message_test.rb

    r203 r219  
    2424    FileUtils.mkdir(@temp_dir) 
    2525 
     26    @message_dir = "#{FileUtils.pwd}/messages" 
     27    FileUtils.rm_rf(@message_dir) if FileTest.exists?(@message_dir) 
     28    FileUtils.mkdir(@message_dir) 
     29 
     30    @conversation_dir = "#{FileUtils.pwd}/conversations" 
     31    FileUtils.rm_rf(@conversation_dir) if FileTest.exists?(@conversation_dir) 
     32    FileUtils.mkdir(@conversation_dir) 
     33 
    2634    @logger = Logger.new(STDOUT) 
    27     @mock_config = { 'TEMP_FILE_DIR' => @temp_dir, 'LOGGER' => @logger
     35    @mock_config = { 'TEMP_FILE_DIR' => @temp_dir, 'LOGGER' => @logger, 'MESSAGE_DIR' => @message_dir, 'CONVERSATION_DIR' => @conversation_dir
    2836 
    2937    @sample_ping = <<END 
     
    3947      </eb:To> 
    4048      <eb:CPAId>Coronation::Gnaraloo::UBL 1.0 Invoice Notification::id47724</eb:CPAId> 
    41       <eb:ConversationId>1162889683.13662</eb:ConversationId> 
     49      <eb:ConversationId>1164207127.8254</eb:ConversationId> 
    4250      <eb:Service>urn:oasis:names:tc:ebxml-msg:service</eb:Service> 
    4351      <eb:Action>Ping</eb:Action> 
     
    463471  def teardown 
    464472    FileUtils.rm_rf(@temp_dir) 
    465   end 
    466  
     473    #    FileUtils.rm_rf(@message_dir) 
     474    #    FileUtils.rm_rf(@conversation_dir) 
     475  end 
     476 
     477=begin 
    467478  def test_valid_sample_message 
    468479    assert_not_nil @sample_ping 
     
    586597    assert_equal 2, error_message.errors.size, "ebXML Error Message must have two errors." 
    587598  end 
     599=end 
     600   
     601  def test_message_store_when_create_ebMS_message_from_file_path 
     602    file_path = "#{@temp_dir}/sample.xml" 
     603    file = File.open(file_path, "w") 
     604    file << @sample_ping 
     605    file.sync = true 
     606    file.close 
     607    assert_equal 0, Dir.glob("#{@mock_config['CONVERSATION_DIR']}/*").size, "There must be exactly no directory in the conversation dir at this time." 
     608    ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.new @mock_config, file_path 
     609    assert_not_nil ebMS_message 
     610    assert_equal 1, Dir.glob("#{@mock_config['MESSAGE_DIR']}/*").size, "There must be exactly one message" 
     611    assert_equal 1, Dir.glob("#{@mock_config['CONVERSATION_DIR']}/*").size, "There must be exactly one directory in the conversation dir." 
     612    assert FileTest.exists?("#{@conversation_dir}/1164207127.8254"), "Conversation Directory must exist." 
     613    assert_equal 1, Dir.glob("#{@conversation_dir}/1164207127.8254/*").size, "There must be one message for this conversation id." 
     614 
     615    ping = HefeWeizen::HefeWeizenLibrary::EBMSMessage.new @mock_config, @sample_ping 
     616    assert_not_nil ping 
     617    assert_equal 1, Dir.glob("#{@mock_config['MESSAGE_DIR']}/*").size, "Ping is already created." 
     618    assert_equal 1, Dir.glob("#{@mock_config['CONVERSATION_DIR']}/*").size, "There must be exactly one directory in the conversation dir." 
     619    assert FileTest.exists?("#{@conversation_dir}/1164207127.8254"), "Conversation Directory must exist." 
     620    assert_equal 1, Dir.glob("#{@conversation_dir}/1164207127.8254/*").size, "There must be one message for this conversation id." 
     621 
     622    pong = HefeWeizen::HefeWeizenLibrary::EBMSMessage.new @mock_config, @sample_hermes_nice_pong 
     623    assert_not_nil pong 
     624    assert_equal 2, Dir.glob("#{@mock_config['MESSAGE_DIR']}/*").size, "There must be now 2 messages." 
     625    assert_equal 1, Dir.glob("#{@mock_config['CONVERSATION_DIR']}/*").size, "There must still be exactly one directory in the conversation dir." 
     626    assert FileTest.exists?("#{@conversation_dir}/1164207127.8254"), "Conversation Directory must still exist." 
     627    assert_equal 2, Dir.glob("#{@conversation_dir}/1164207127.8254/*").size, "There must be two messages for this conversation id." 
     628 
     629    new_from_data_store = HefeWeizen::HefeWeizenLibrary::EBMSMessage.get_message_by_message_id @mock_config, ebMS_message.message_id 
     630    assert_not_nil new_from_data_store, "A new message must have been created from the message store." 
     631 
     632  end 
     633 
    588634 
    589635  private