Changeset 219
- Timestamp:
- 12/05/06 16:27:01 (2 years ago)
- Files:
-
- branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb (modified) (9 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message.rb (modified) (9 diffs)
- branches/message-handling-refactor-branch/test/test-systems/Gnaraloo/trading_agreements/cpa_test.xml (added)
- branches/message-handling-refactor-branch/test/unit-tests/tc_hefeweizen_library_ebMS_message_test.rb (modified) (4 diffs)
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 2 2 3 3 Signal.trap("INT") do $stdout.puts "info : #{Time.now.to_s} - #{$$} - #{$$}: Big Ania caught INT signal. not exitting."; end … … 488 488 ######################### 489 489 ## process reponse 490 ## will be factored out! 490 491 ######################### 491 492 … … 579 580 # @logger.debug "The directive is a ebMS signal: #{directive.is_a_ebMS_signal?.to_s}" 580 581 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. 583 583 if !transaction.set_root_cause directive then 584 584 @logger.error "Unable to store the directive as root cause to the new transaction" … … 610 610 # CREATE ebXML MESSAGE 611 611 # -------------------- 612 # potential for a tasker 612 613 @logger.debug "Creating ebXML message" 613 614 ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.create_message @config, directive, ebMS_message_info … … 634 635 return false 635 636 end 636 637 637 638 transaction.attach_file ebXML_message_file_path, "outgoing ebXML message" 638 639 transaction.remember_file_to_remove ebXML_message_file_path 639 640 640 641 # create an ebXML message parameters file 641 642 ebXML_message_parameters_file_path = ebMS_message.create_ebXML_message_parameters_file ebMS_message_info, ebMS_message.is_multipart? … … 644 645 return false 645 646 end 646 647 647 648 transaction.attach_file ebXML_message_parameters_file_path, "outgoing ebXML message parameters" 648 649 transaction.remember_file_to_remove ebXML_message_parameters_file_path … … 650 651 # SEND ebXML MESSAGE 651 652 # ------------------ 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 661 670 662 671 @logger.debug "Call tasker to send ebXML message." 663 672 say_to_ania "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}" 664 673 665 674 # SET EXPECTED NEW STATE 666 675 transaction.set_next_expectation(expectation) 667 676 668 677 return true 669 678 else … … 685 694 transaction.set_root_cause command_hash['file_full'] 686 695 687 # TODO SMTP SUPPORT! there may be o SOAP ACTION!688 696 # maybe stuff this into ebMS class 689 697 if !(ebMS_message_header =~ /^.*SOAPAction: ebXML.*$/ or ebMS_message_header =~ /.*SOAPAction: \"ebXML\".*/) then … … 716 724 return true 717 725 end 718 726 719 727 # from here on we have to send back ebXML error messages. 720 728 branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message.rb
r203 r219 33 33 attr_reader :errors 34 34 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 35 47 private 36 48 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 38 98 39 99 # TODO requires smarter loading of ebXML message. eg not loading everything … … 64 124 end 65 125 66 67 126 @soap_only = raw_message_to_soap_only @raw_message 68 127 @payloads = raw_message_to_payloads @raw_message … … 72 131 73 132 message_header = @message['Header'].first['MessageHeader'].first 133 134 throw Exception.new("Error Reading ebXML message. Error accessing MessageHeader information") if message_header.nil? 74 135 75 136 # required elements … … 95 156 throw Exception.new("There is a mismatch between the payloads and the reference information in the Manifest") 96 157 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 97 164 end 98 165 … … 268 335 } 269 336 end 270 337 271 338 # Party Identities 272 339 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_s275 # file_path = "#{config['TEMP_FILE_DIR']}/#{file_name}"276 # my_command = "touch #{file_path}"277 # system my_command278 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 279 346 skeleton = <<EOF 280 347 --HefeWeizenBoundary … … 310 377 EOF 311 378 312 # my_command = "echo '#{header}' >> #{file_path}"313 # system my_command379 ## my_command = "echo '#{header}' >> #{file_path}" 380 ## system my_command 314 381 315 382 # ADDING PAYLOADS … … 336 403 EOF 337 404 338 # my_command = "echo '#{skeleton}' >> #{file_path}"339 # system my_command405 ## my_command = "echo '#{skeleton}' >> #{file_path}" 406 ## system my_command 340 407 341 408 if FileTest.exists? payload_path and FileTest.readable? payload_path then 342 409 343 # my_command = "cat #{payload_path} >> #{file_path}"344 # system my_command410 ## my_command = "cat #{payload_path} >> #{file_path}" 411 ## system my_command 345 412 file = File.open(payload_path, "r") 346 413 skeleton << file.read … … 356 423 --HefeWeizenBoundary-- 357 424 EOF 358 # my_command = "echo '#{msg_end}' >> #{file_path}"359 # system my_command425 ## my_command = "echo '#{msg_end}' >> #{file_path}" 426 ## system my_command 360 427 361 428 if errors then … … 444 511 file.sync = true 445 512 file.close 513 store_message_parameter_file file_path 446 514 return file_path 447 515 end branches/message-handling-refactor-branch/test/unit-tests/tc_hefeweizen_library_ebMS_message_test.rb
r203 r219 24 24 FileUtils.mkdir(@temp_dir) 25 25 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 26 34 @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 } 28 36 29 37 @sample_ping = <<END … … 39 47 </eb:To> 40 48 <eb:CPAId>Coronation::Gnaraloo::UBL 1.0 Invoice Notification::id47724</eb:CPAId> 41 <eb:ConversationId>116 2889683.13662</eb:ConversationId>49 <eb:ConversationId>1164207127.8254</eb:ConversationId> 42 50 <eb:Service>urn:oasis:names:tc:ebxml-msg:service</eb:Service> 43 51 <eb:Action>Ping</eb:Action> … … 463 471 def teardown 464 472 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 467 478 def test_valid_sample_message 468 479 assert_not_nil @sample_ping … … 586 597 assert_equal 2, error_message.errors.size, "ebXML Error Message must have two errors." 587 598 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 588 634 589 635 private
