Changeset 232
- Timestamp:
- 12/14/06 13:55:12 (2 years ago)
- Files:
-
- branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb (modified) (15 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_b2b_system.rb (modified) (5 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_cpa.rb (modified) (2 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message2.rb (modified) (23 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_transactions.rb (modified) (1 diff)
- branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_http_server.rb (modified) (3 diffs)
- branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_send_ebXML_message.rb (modified) (2 diffs)
- branches/message-handling-refactor-branch/test/tools/hefeweizen_tool_tester.rb (modified) (2 diffs)
- branches/message-handling-refactor-branch/test/unit-tests/tc_hefeweizen_library_cpa_test.rb (modified) (5 diffs)
- branches/message-handling-refactor-branch/test/unit-tests/tc_hefeweizen_library_ebMS_message_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb
r229 r232 7 7 require 'yaml' 8 8 require 'xsd/mapping' 9 10 11 =begin 12 todo: 13 14 check ebXML message validation in b2b system 15 16 -> problem of ebXML message ... to find the right ebMS info. eg if error message is coming back as a http sync response then we need the ebMS info of the orignal action. i think transport information must be passed on to the validator. 17 18 -> if transport protocol async then no problem. 19 -> if transport protocol sync then message receiver must provide info whether it is on the request or the response leg. 20 21 o proper delivery preparation for sending ebxml message 22 o proper delivery preparation for incoming ebxml message 23 o create response (ebxml ack, http ok, nothing, error message) 24 o no user message response, yet 25 o produce directive of incoming ebxml message 26 27 --------------------------> set status of ebXML message (specially user message) 28 ---------------------------------> link ebXML messages 29 30 31 =end 9 32 10 33 module HefeWeizen … … 426 449 if result == true 427 450 @logger.debug "Successfully processed new directive." 451 428 452 @logger.debug "Its time to deliver the ebXML message." 429 453 command, expectation = start_delivery( transaction, command_hash['b2b_system_name'] ) 430 transaction.set_next_expectation(expectation) 431 say_to_ania command 432 return true 454 if command.nil? then 455 @logger.warn "Unable to proceed with start deliervy." 456 transaction.fail "Error starting delivery" 457 return true 458 else 459 transaction.set_next_expectation(expectation) 460 say_to_ania command 461 return true 462 end 433 463 elsif result == false then 434 464 @logger.debug "Problems processing new directive xx." … … 455 485 456 486 command, expectation = start_an_encrypting_tasker metadata, transaction.transaction_id, command_hash['b2b_system_name'] 487 if command.nil? then 488 @logger.warn "Unable to proceed with start deliervy." 489 transaction.fail "Error starting delivery" 490 return true 491 else 492 # SET EXPECTED NEW STATE 493 transaction.set_next_expectation(expectation) 494 say_to_ania command 495 return true 496 end 497 else 498 @logger.debug "ebXML message must NOT be encrypted." 499 end 500 501 @logger.debug "Its time to deliver the ebXML message." 502 command, expectation = start_delivery( transaction, command_hash['b2b_system_name'] ) 503 if command.nil? then 504 @logger.warn "Unable to proceed with start deliervy." 505 transaction.fail "Error starting delivery" 506 return true 507 else 457 508 # SET EXPECTED NEW STATE 458 509 transaction.set_next_expectation(expectation) 459 510 say_to_ania command 460 511 return true 461 else 462 @logger.debug "ebXML message must NOT be encrypted." 463 end 464 @logger.debug "Its time to deliver the ebXML message." 465 command, expectation = start_delivery( transaction, command_hash['b2b_system_name'] ) 466 transaction.set_next_expectation(expectation) 467 say_to_ania command 468 return true 469 512 end 470 513 elsif command == 'encrypt ebXML message done' then 471 514 @logger.debug "Received encrypt ebXML message is done." 472 515 transaction.transition_to_new_state "encrypt ebXML message done" 516 473 517 @logger.debug "Its time to deliver the ebXML message." 474 518 command, expectation = start_delivery( transaction, command_hash['b2b_system_name'] ) 475 transaction.set_next_expectation(expectation) 476 say_to_ania command 477 return true 519 if command.nil? then 520 @logger.warn "Unable to proceed with start deliervy." 521 transaction.fail "Error starting delivery" 522 return true 523 else 524 # SET EXPECTED NEW STATE 525 transaction.set_next_expectation(expectation) 526 say_to_ania command 527 return true 528 end 478 529 479 530 elsif command == 'start ebXML message delivery' then 480 531 @logger.debug "Received start ebXML message delivery command." 481 @logger.debug "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx this far is OK" 482 return true 483 transaction.transition_to_new_state command 484 ebXML_message_id = transaction.get_ebXML_message_reference 485 if !ebXML_message_id.nil? 486 @logger.debug "Start of delivery of ebXML message with id: #{ebXML_message_id}" 487 command, expectation = deliver_ebXML_message transaction, ebXML_message_id, command_hash['b2b_system_name'] 488 if command == false then 489 msg = "It is not possible to start the delivery process." 490 @logger.warn msg 491 transaction.fail msg 492 return false 493 else 494 @logger.debug "Start of delivery of ebXML message can start." 495 transaction.set_next_expectation(expectation) 496 say_to_ania command 497 return true 498 end 499 else 500 msg = "Error getting the ebXML message id. Unable to find ebXML message from transaction with id #{transaction.transaction_id}" 501 @logger.debug "Error getting the ebXML message id. Unable to find ebXML message from transaction with id #{transaction.transaction_id}" 532 command, expectation = deliver_ebXML_message transaction, command, command_hash 533 if command == false then 534 msg = "It is not possible to start the delivery process." 535 @logger.warn msg 502 536 transaction.fail msg 537 return false 538 else 539 @logger.debug "Start of delivery of ebXML message can start." 540 transaction.set_next_expectation(expectation) 541 say_to_ania command 503 542 return true 504 543 end 544 505 545 elsif command == 'send ebXML message done' 506 546 @logger.debug "Send ebXML message done." … … 509 549 # o synchronous or asynchronous ebXML error message for this ebXML message is received. 510 550 # o an acknowledgment may be required for the ebXML message. 511 @logger.debug 'yesssssssssssssssssssssssss' 512 @logger.debug 'impementation stopps here' 551 success, comment = process_send_ebXML_message_response transaction, command, command_hash 552 if command == false then 553 msg = "It is not possible to process response of sending an ebXML message." 554 @logger.warn msg + comment 555 transaction.fail msg + comment 556 return false 557 else 558 @logger.debug "Successfully processed response of sending an ebXML message." 559 transaction.succeed comment 560 return true 561 end 562 563 elsif command == 'send ebXML message response done' then 564 @logger.debug "sending response (could be empty) done." 565 transaction.succeed "job done" 566 513 567 elsif command == 'new ebXML message received' then 568 @logger.debug "Received new ebXML message!" 514 569 if !transaction.open_and_new? then 515 @logger.warn "A transaction must be new and open for command '#{command}'." 516 return false 517 else 518 @logger.debug "Received new ebXML message!" 570 @logger.warn "A transaction must be new and open for a new ebXML message." 571 return false 572 else 519 573 result = process_new_ebXML_message2 command, command_hash, transaction 520 574 if result == false then 521 @logger.error "Error processing ebXML Message"522 transaction. close_transaction('failed', "Failed to process ebXML message.")if transaction.is_open?575 @logger.error "Error processing incoming ebXML Message" 576 transaction.fail "Failed to process ebXML message." if transaction.is_open? 523 577 return false 524 578 else … … 541 595 end 542 596 543 def store_ebMS_info ebMS_info 544 path = "#{ ebMS_info['ebXML_message']['ebXML_message_dir']}/#{ebMS_info['ebXML_message']['ebXML_message_parameters_file_name']}"597 def store_ebMS_info ebMS_info, b2b_system_name 598 path = "#{@config['MESSAGE_DIR']}/#{b2b_system_name}/#{ebMS_info['ebXML_message']['ebXML_message_id']}/ebXML_message_parameters.yml" 545 599 file = File.new(path, "w") 546 600 YAML.dump ebMS_info, file … … 557 611 end 558 612 559 def deliver_ebXML_message transaction, ebXML_message_id, b2b_system_name 613 =begin 614 def get_delivery_info ebMS_info 615 ebMS_delivery_info = get_delivery_info ebMS_info 616 if ebMS_info['delivery'].nil? then 617 dev = ebMS_info['delivery'] = Hash.new 618 dev['delivery_process_started'] = Time.now.to_s 619 tries = dev['delivery_tries'] = Array.new 620 tries[0] = Time.now.to_s 621 else 622 ebMS_info['delivery']['delivery_tries'] << Time.now.to_s 623 end 624 end 625 =end 626 627 def deliver_ebXML_message transaction, command, command_hash 628 @logger.debug "Starting ebXML message delivery process." 629 transaction.transition_to_new_state command 630 b2b_system_name = command_hash['b2b_system_name'] 631 ebXML_message_id = transaction.get_ebXML_message_reference 632 if ebXML_message_id.nil? then 633 @logger.debug "Unable to get ebXML message reference from transaction with id '#{transaction.transaction_id}'." 634 return false 635 end 636 @logger.debug "Start of delivery of ebXML message with id: #{ebXML_message_id}" 560 637 ebMS_info = get_ebMS_info ebXML_message_id, b2b_system_name 561 638 if ebMS_info.nil? then … … 564 641 end 565 642 @logger.debug "Successfully read the ebXML message info structure for ebXML message with id #{ebXML_message_id}." 566 567 # adding delivery informationn to the ebMS_info 568 if ebMS_info['delivery'].nil? then 569 dev = ebMS_info['delivery'] = Hash.new 570 dev['delivery_process_started'] = Time.now.to_s 571 tries = dev['delivery_tries'] = Array.new 572 tries[0] = Time.now.to_s 573 else 574 ebMS_info['delivery']['delivery_tries'] << Time.now.to_s 575 end 576 577 store_ebMS_info ebMS_info 643 644 # # adding delivery informationn to the ebMS_info 645 # ebMS_info.merge! = get_delivery_info ebMS_info 646 647 # store_ebMS_info ebMS_info, b2b_system_name 648 649 ebXML_message_file_path = "#{@config['MESSAGE_DIR']}/#{b2b_system_name}/#{ebMS_info['ebXML_message']['ebXML_message_id']}/ebXML_message.ebMS2" 650 ebXML_message_parameters_file_path = "#{@config['MESSAGE_DIR']}/#{b2b_system_name}/#{ebMS_info['ebXML_message']['ebXML_message_id']}/ebXML_message_parameters.yml" 578 651 579 652 #call tasker to send ebXML message … … 586 659 "command" => "start_tasker", 587 660 "tasker" => "#{@config['BIN_DIR']}/hefeweizen_tasker_application_send_ebXML_message.rb", 588 "tasker arguments" => "--b2b-system-name #{b2b_system_name} --pipe-to-ania #{@config['PIPE_TO_ANIA']} --config #{@config['CONFIG_DIR']}/hefeweizen.conf --ebXML-message-file-path #{eb MS_info['ebXML_message']['ebXML_message_dir']}/#{ebMS_info['ebXML_message']['ebXML_message_file_name']} --parameters-file-path #{ebMS_info['ebXML_message']['ebXML_message_dir']}/#{ebMS_info['ebXML_message']['ebXML_message_parameters_file_name']} --transaction-id #{transaction.transaction_id} --state-expectation #{expectation}",661 "tasker arguments" => "--b2b-system-name #{b2b_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}", 589 662 "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 590 663 } 591 664 592 @logger.debug "Call tasker to send ebXML message." 593 say_to_ania "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}" 594 595 # SET EXPECTED NEW STATE 596 transaction.set_next_expectation(expectation) 597 598 return true 599 600 665 return HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_hash), expectation 601 666 end 602 667 668 def temp_close_connection command, command_hash, transaction 669 puts 'xxxxxxxxxxxxxxxxxxxx' 670 end 671 603 672 def delivery_ack_requested? ebMS_info 604 673 (ebMS_info['info']['mc-ackRequested'] == 'always' or ( ebMS_info['info']['mc-ackRequested'] == 'perMessage' and !ebMS_info['directive']['ackRequested'].nil? ) ) ? true : false … … 609 678 end 610 679 680 # This method starts the delivery of an ebXML message. 611 681 def start_delivery transaction, b2b_system_name 612 @logger.debug " Lets beam us to the ebXML message deliver state"682 @logger.debug "Starting the delivery process." 613 683 transaction.transition_to_new_state "ebXML message delivery process started" 684 614 685 expectation = "start_ebXML_message_delivery" 615 686 command_hash = { … … 626 697 end 627 698 699 # This meesage processes the response of sending an ebXML message. 700 # o when the message was sent via SMTP then there is no info here. 701 # o when the message was sent via HTTP and there was no sync response then there is no info here. 702 # o when the message was sent via HTPT and there was a sync response then we have to process the response. 703 def process_send_ebXML_message_response transaction, command, command_hash 704 @logger.debug "sending of ebXML message done. received answer from sending tasker." 705 transaction.transition_to_new_state "ebXML message sent. processing response." 706 transaction.attach_file command_hash['transfer_info_path'], "transfer information" if command_hash['transfer_info_path'] 707 transaction.remember_file_to_remove command_hash['transfer_info_path'] if command_hash['transfer_info_path'] 708 transaction.attach_file command_hash['response_file_path'], "outgoing ebXML message response" if command_hash['response_file_path'] 709 transaction.remember_file_to_remove command_hash['response_file_path'] if command_hash['response_file_path'] 710 711 if command_hash['status'].upcase == "OK" then 712 @logger.debug "Received Success OK from the ebXML message sending tasker." 713 else 714 msg = "Received a FAILURE as status from the ebXML message sending tasker." 715 @logger.warn msg 716 return false, msg 717 end 718 719 if command_hash['transport_protocol'].upcase == "SMTP" then 720 @logger.debug "The SMTP transport protocol was used so no direct response (ebXML MS signal) possible." 721 722 # TODO set ebXML message to delivered! 723 return true, "Successfully completed transaction." 724 else 725 transfer_info_file = command_hash['transfer_info_path'] 726 response_file = command_hash['response_file_path'] 727 728 has_content = true 729 if FileTest.exists? transfer_info_file and FileTest.readable? transfer_info_file then 730 transfer_info = File.read transfer_info_file 731 transfer_info.each_line{ | line | 732 if line =~ /.*HTTP\/1\.1 204 No Content/ then 733 has_content = false 734 break 735 end 736 } 737 738 if has_content == false then 739 if FileTest.exists? response_file and !FileTest.zero? response_file then 740 @logger.warn "HTTP response indicates that there is no content (response code 204) but the response file exists and is not empty." 741 @logger.debug "Continuing with processing response file." 742 result = process_new_ebXML_message2 command, command_hash, transaction 743 if result == false then 744 msg = "Error processing response from sending an ebXML Message." 745 @logger.warn msg 746 return false, msg 747 end 748 return true, "Succesfully processed response ebXML message." 749 else 750 @logger.debug 'There was no response from sending ebXML message.' 751 # TODO validate if that is OK. 752 return true, "I ASSUME THIS FUCKER IS OKEY." 753 end 754 755 elsif has_content == true then 756 if FileTest.exists? response_file and FileTest.zero? response_file then 757 msg = "HTTP response indicates that there is content but the resposne file is empty." 758 @logger.warn msg 759 @logger.debug "Failing transction" 760 return false, msg 761 else 762 @logger.debug "Processing response from sending ebXMl message." 763 result = process_new_ebXML_message2 command, command_hash, transaction 764 if result == false then 765 msg = "Error processing response from sending an ebXML Message." 766 @logger.warn msg 767 return false, msg 768 end 769 return true, "Succesfully processed response ebXML message." 770 end 771 end 772 773 else 774 msg = "Unable to read transfer log of HTTP ebXML sending tasker to determine if there is a response." 775 @logger.warn msg 776 return false, msg 777 end 778 779 780 end 781 782 end 783 784 628 785 def process_new_directive2 command, command_hash, transaction 629 786 … … 674 831 end 675 832 833 # Some transaction stuff 676 834 path = "#{@config['MESSAGE_DIR']}/#{b2b_system.system_name}/#{ebMS_info['ebXML_message']['ebXML_message_id']}" 677 putscomplete_ebXML_message_file_path = "#{path}/ebXML_message.ebMS2"678 putscomplete_ebXML_message_parameters_file_path = "#{path}/ebXML_message_parameters.yml"835 complete_ebXML_message_file_path = "#{path}/ebXML_message.ebMS2" 836 complete_ebXML_message_parameters_file_path = "#{path}/ebXML_message_parameters.yml" 679 837 680 838 transaction.attach_file complete_ebXML_message_file_path, "outgoing ebXML message" … … 682 840 683 841 # attach the ebXML message to the transaction 684 transaction.transition_to_new_state "plain ebXML message created"842 transaction.transition_to_new_state "plain outgoing ebXML message created" 685 843 @logger.debug "Setting ebXML message id '#{ebMS_info['ebXML_message']['ebXML_message_id']}' to transaction." 686 844 transaction.add_ebXML_message_id_reference ebMS_info['ebXML_message']['ebXML_message_id'] 845 687 846 688 847 # ebXML message is created. … … 753 912 def process_new_ebXML_message2 command, command_hash, transaction 754 913 @logger.debug "Reading received ebXML message." 755 756 # TODO transport dependent header reading 757 # SMTP / HTTP independent 758 ebMS_message_header = File.read(command_hash['file_header']) 759 760 # setting root cause of this new transaction. 761 transaction.set_root_cause command_hash['file_full'] 762 763 # maybe stuff this into ebMS class 764 # SMTP / HTTP independent 765 if !(ebMS_message_header =~ /^.*SOAPAction: ebXML.*$/ or ebMS_message_header =~ /.*SOAPAction: \"ebXML\".*/) then 766 msg = "Received a message but the received message does not have a \"SOAPAction: ebXML\" HTTP header, so it is not an ebXML message." 767 @logger.warn msg 914 915 # depends whether this is received on server or is a response from a client. 916 if command_hash['file_full'] then 917 # setting root cause of this new transaction. 918 transaction.set_root_cause command_hash['file_full'] 919 920 # DUPLICATE! ok for now. -> add link_to in transaction class 921 transaction.attach_file command_hash['file_full'], "incoming ebXML message" 922 768 923 transaction.remember_file_to_remove [command_hash['file_full'], command_hash['file_body'], command_hash['file_header']] 769 #?? send_error "Bad Request", transaction, command_hash 770 transaction.close_transaction('failed', msg) 771 return true 772 end 773 @logger.debug "Message header indicates that it is an ebXML message." 774 775 # DUPLICATE! ok for now. -> add link_to in transaction class 776 transaction.attach_file command_hash['file_full'], "incoming ebXML message" 777 778 transaction.remember_file_to_remove command_hash['file_full'] 779 transaction.remember_file_to_remove command_hash['file_body'] 780 transaction.remember_file_to_remove command_hash['file_header'] 924 else 925 # setting root cause of this new transaction. 926 transaction.set_root_cause command_hash['response_file_path'] 927 928 # DUPLICATE! ok for now. -> add link_to in transaction class 929 transaction.attach_file command_hash['response_file_path'], "incoming ebXML message response" 930 931 transaction.remember_file_to_remove command_hash['response_file_path'] 932 end 781 933 782 934 b2b_system = @b2b_systems[command_hash['b2b_system_name']] … … 785 937 return false 786 938 end 787 788 begin 789 @logger.debug "Creating an ebXML message object from the received ebXML message. Provides basic ebXML message parsing." 790 # this parses the incoming message and creates an ebXML message object 791 ebXML_message_object = b2b_system.process_incoming_ebXML_message command_hash 792 if ebXML_message_object.nil? then 793 @logger.warn "Error creating an ebXML object from the ebXML message from file #{command_hash['file_full']}." 794 return false 795 end 796 @logger.debug "Successfully created ebXML message object: #{ebXML_message_object.summary}" 797 rescue Exception => e 798 msg = "It is not possible to create an ebXML Message object from the incoming ebXML message: #{e.to_s}" 799 @logger.warn msg 800 #?? send_error "Bad Request", transaction, command_hash 801 transaction.close_transaction('failed', msg) 939 940 @logger.debug "Creating an ebXML message object from the received ebXML message." 941 # this parses the incoming message and creates an ebXML message object 942 # this includes to validate the ebXML message against the CPA. 943 ebXML_message_object, ebMS_info, validation_errors = b2b_system.create_and_process_incoming_ebXML_message command_hash 944 if ebXML_message_object.nil? then 945 @logger.warn "Error creating an ebXML object from the ebXML message from file #{command_hash['file_full']}." 946 return false 947 end 948 949 # Some transaction stuff 950 path = "#{@config['MESSAGE_DIR']}/#{b2b_system.system_name}/#{ebMS_info['ebXML_message']['ebXML_message_id']}" 951 complete_ebXML_message_file_path = "#{path}/ebXML_message.ebMS2" 952 complete_ebXML_message_parameters_file_path = "#{path}/ebXML_message_parameters.yml" 953 954 transaction.attach_file complete_ebXML_message_file_path, "incoming ebXML message" 955 transaction.attach_file complete_ebXML_message_parameters_file_path, "incoming ebXML message parameters" 956 957 # attach the ebXML message to the transaction 958 transaction.transition_to_new_state "plain incoming ebXML message created." 959 @logger.debug "Setting ebXML message id '#{ebMS_info['ebXML_message']['ebXML_message_id']}' to transaction." 960 transaction.add_ebXML_message_id_reference ebMS_info['ebXML_message']['ebXML_message_id'] 961 962 if ebXML_message_object.is_user_message? then 963 # decrypt if encrypted if encrypted 964 # start tasker 965 966 # validate signature if signature 967 # start tasker 968 969 # -> may need an ebXML Error Message in case decryption or signature validation fails 970 end 971 972 if ebXML_message_object.is_ebMS_signal? then 973 # validate signature if signature 974 # start tasker 975 end 976 977 978 979 # CONTINUE WITH PROCESSING 980 # ------------------------ 981 982 new_ebXML_message_object = nil 983 new_ebXML_message_info = nil 984 new_delivery = false 985 986 if !validation_errors.nil? and validation_errors.class == Array and validation_errors.size > 0 then 987 @logger.debug "WARNING there are validation errors so an error message must be created." 988 # an ebXML Error Message must be created. 989 new_ebXML_message_object, new_ebXML_message_info = b2b_system.create_and_process_new_ebXML_signal_message ebXML_message_object, "MessageError", validation_errors 990 if new_ebXML_message_object.nil? then 991 @logger.warn "Error creating an ebXML Error message for the ebXML message: #{ebXML_message_object.summary}. The erros are: #{validation_errors.to_s}" 992 # TODO delete stuff?? 993 return false 994 end 995 996 # Interesting point here: 997 # o we have an ebXML message (the one recieved) 998 # o we create an new ebXML message (one that responds to the one received) 999 # -> so we will have two ebXML messages! 1000 1001 # Some transaction stuff 1002 path = "#{@config['MESSAGE_DIR']}/#{b2b_system.system_name}/#{new_ebXML_message_object.message_id}" 1003 complete_ebXML_message_file_path = "#{path}/ebXML_MessageError_message.ebMS2" 1004 complete_ebXML_message_parameters_file_path = "#{path}/ebXML_MessageError_message_parameters.yml" 1005 1006 transaction.attach_file complete_ebXML_message_file_path, "error message for incoming ebXML message" 1007 transaction.attach_file complete_ebXML_message_parameters_file_path, "error message parameters for incoming ebXML message" 1008 1009 # attach the ebXML message to the transaction 1010 transaction.add_ebXML_message_id_reference new_ebXML_message_object.message_id, "ErrorMessage" 1011 1012 new_delivery = true 1013 1014 elsif !validation_errors.nil? and validation_errors.class == String then 1015 # I must create a HTTP fault or something!!! 1016 # ?????????????? 1017 @logger.error validation_errors 1018 @logger.error '!!!!!!!!!!!!!!!! fix me' 802 1019 return true 803 end 804 805 puts 'yesssssssssssssssssssssssss ebxml message processed.' 806 807 # decrypt 808 809 # validate signature 810 811 # start delivery job 812 813 end 814 1020 1021 else 1022 1023 # no validation errors 1024 1025 if ebXML_message_object.is_user_message? or ebXML_message_object.is_pig? then 1026 # creating HefeWeizenDirective about new incoming ebXML message. 1027 @logger.debug "No errors processing incoming ebXML message. so we produce a directive for the user." 1028 path = HefeWeizen::HefeWeizenLibrary::HefeWeizenDirective.create_user_message_directive_and_save( b2b_system.get_incoming_directive_directory, 1029 b2b_system.get_incoming_payloads_directory, 1030 ebXML_message_object) 1031 transaction.transition_to_new_state "Receiving ebXML user message information sent to integration point." 1032 @logger.debug "Created incoming directive at : #{path}" 1033 end 1034 1035 # CONTINUE PROCESSING 1036 1037 # Check if there is something else to do. 1038 action_required, action = action_required? ebXML_message_object, ebMS_info 1039 1040 if action_required == true then 1041 @logger.debug "Requires further action: #{action}" 1042 new_ebXML_message_object, new_ebXML_message_info = b2b_system.create_and_process_new_ebXML_signal_message ebXML_message_object, action 1043 if new_ebXML_message_object.nil? then 1044 @logger.warn "Error creating an ebXML Acknowledgment Message for the ebXML message: #{ebXML_message_object.summary}." 1045 # TODO delete stuff?? 1046 return false 1047 end 1048 1049 # Interesting point here: 1050 # o we have an ebXML message (the one recieved) 1051 # o we create an new ebXML message (one that responds to the one received) 1052 # -> so we will have two ebXML messages! 1053 1054 # some transaction stuff 1055 path = "#{@config['MESSAGE_DIR']}/#{b2b_system.system_name}/#{new_ebXML_message_object.message_id}" 1056 complete_ebXML_message_file_path = "#{path}/ebXML_#{action}_message.ebMS2" 1057 complete_ebXML_message_parameters_file_path = "#{path}/ebXML_#{action}_message_parameters.yml" 1058 1059 transaction.attach_file complete_ebXML_message_file_path, "#{action} message for incoming ebXML message" 1060 transaction.attach_file complete_ebXML_message_parameters_file_path, "#{action} message parameters for incoming ebXML message" 1061 1062 # attach the ebXML message to the transaction 1063 transaction.add_ebXML_message_id_reference new_ebXML_message_object.message_id, "Acknowledgment" 1064 1065 new_delivery = true 1066 1067 else 1068 @logger.debug "No futher action required for ebXML message '#{ebXML_message_object.summary}'." 1069 end 1070 1071 instruction_pipe = command_hash['pipe_for_instructions'] 1072 1073 if new_delivery == true then 1074 1075 @logger.debug "There are responses to be delivered." 1076 1077 if ebMS_info['info']['transport-protocol-name'].upcase != "HTTP" then 1078 close_open_connection instruction_pipe, transaction 1079 # start new sending tasker. 1080 1081 else 1082 1083 # new_ebXML_message_object 1084 # new_ebXML_message_info 1085 1086 # -> sign messages? 1087 # start delivery? command? 1088 1089 if new_ebXML_message_object.is_ebMS_signal? then 1090 # <enumeration value="mshSignalsOnly"/> 1091 # <enumeration value="responseOnly"/> 1092 # <enumeration value="signalsAndResponse"/> 1093 # <enumeration value="signalsOnly"/> 1094 # <enumeration value="none"/> 1095 1096 if ebMS_info['info']['mc-syncReplyMode'] == 'none' then 1097 close_open_connection instruction_pipe, transaction 1098 #start new sending tasker. 1099 @logger.error "Not implemented yet to asynchronously send an ebXML response message" 1100 # xxxxxxxxxxxxxxxx 1101 elsif ebMS_info['info']['mc-syncReplyMode'] == 'mshSignalsOnly' 1102 @logger.debug "Sending msh signal synchronously back over HTTP transport protocol." 1103 send_sync_response new_ebXML_message_object.raw_ebXML_message, transaction, instruction_pipe 1104 1105 elsif ebMS_info['info']['mc-syncReplyMode'] == 'signalsOnly' 1106 @logger.warn "signalsAndResponse as syncReplyMode not implemented." 1107 close_open_connection instruction_pipe, transaction 1108 # ???? 1109 return false 1110 1111 elsif ebMS_info['info']['mc-syncReplyMode'] == 'signalsAndResponse' 1112 @logger.warn "signalsAndResponse as syncReplyMode not implemented." 1113 close_open_connection instruction_pipe, transaction 1114 # ???? 1115 return false 1116 1117 elsif ebMS_info['info']['mc-syncReplyMode'] == 'responseOnly' 1118 @logger.warn "signalsAndResponse as syncReplyMode not implemented." 1119 close_open_connection instruction_pipe, transaction 1120 # ???? 1121 return false 1122 1123 else 1124 @logger.debug "Unknown syncReplyMode '#{ebMS_info['info']['mc-syncReplyMode']}'. Not returning new responses." 1125 close_open_connection instruction_pipe, transaction 1126 # ???? 1127 return false 1128 end 1129 1130 else 1131 end 1132 1133 end 1134 1135 1136 else 1137 @logger.debug "There are no responses to be delivered. Closing any open connection" 1138 close_open_connection instruction_pipe, transaction 1139 end 1140 1141 # o if sync protocol and no sync response expected. 1142 1143 1144 end 1145 1146 1147 1148 return true 1149 1150 1151 end 1152 1153 def send_sync_response ebXML_message_file_path, transaction, instruction_pipe 1154 @logger.debug "Sending command to send the ebXML response message." 1155 command_to_http_server = { 1156 "from" => "big_ania", 1157 "to" => "http server", 1158 "response_file_name" => ebXML_message_file_path, 1159 "transaction_id" => transaction.transaction_id, 1160 "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 1161 } 1162 1163 command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 1164 system command 1165 1166 end 1167 1168 def close_open_connection instruction_pipe, transaction 1169 command_to_http_server = { 1170 "from" => "big_ania", 1171 "to" => "http server", 1172 "close_connection" => true, 1173 "transaction_id" => transaction.transaction_id, 1174 "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 1175 } 1176 command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 1177 system command 1178 end 1179 1180 def action_required? ebXML_message_object, ebXML_message_info 1181 if ebXML_message_object.is_pig? then 1182 @logger.warn "Piggybacking not implemented. No action taken." 1183 return false 1184 1185 elsif ebXML_message_object.is_user_message? then 1186 # user message. 1187 create_ack = false 1188 create_signed_ack = false 1189 1190 create_ack = ebXML_message_object.has_ack_requested? ? true : false 1191 1192 if create_ack then 1193 create_signed_ack = ebXML_message_object.has_ack_signature_requested? ? true : false 1194 end 1195 1196 if create_ack == true and create_signed_ack == false then 1197 return true, "Acknowledgment" 1198 elsif create_ack == true and create_signed_ack == true then 1199 return true, "SignedAcknowledgment" 1200 end 1201 1202 elsif ebXML_message_object.is_ebMS_signal? then 1203 # an ebMS signal 1204 if ebXML_message_object.is_ping? then 1205 @logger.debug "The ebXML message is a ping so we have to create an pong" 1206 return true, "Pong" 1207 elsif ebXML_message_object.is_status_request? 1208 @logger.warn "Status Request is not yet implemented. No action taken." 1209 return false 1210 else 1211 @logger.warn "Unkown type of ebXML message '#{ebXML_message_object.summary}'. No action taken." 1212 end 1213 else 1214 @logger. warn "Unknown type of ebXML message #{ebXML_message_object.summary}'. No action taken." 1215 return false 1216 end 1217 end 815 1218 816 1219 ################# rewrite … … 819 1222 ################# rewrite 820 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 821 1238 822 1239 branches/message-handling-refactor-branch/src/hefeweizen_library_b2b_system.rb
r229 r232 163 163 end 164 164 165 def get_ebXML_message_parameters_file_content ebXML_message_id 166 file_path = "#{@config['MESSAGE_DIR']}/#{system_name}/#{ebXML_message_id}/ebXML_message_parameters.yml" 167 if FileTest.exists? file_path and FileTest.readable? file_path then 168 return YAML.load((File.open file_path, file_path)) 169 else 170 @logger.warn "There is no ebXML message parameters file for ebXML message with id '#{ebXML_message_id}' in the path of '#{file_path}'." 171 return nil 172 end 173 end 165 174 166 175 # This message processes a directive. This typically invloves to create an ebXML message. … … 206 215 end 207 216 217 comment = HefeWeizen::HefeWeizenLibrary::TempEBMessage2.ebMS_info_includes_ebMS_signal?(ebMS_message_info) ? "is_ebMS_signal" : "is_user_message" 218 @ebMS_message_manager.add_comment_to_ebXML_message system_name, metadata['ebXML_message_id'], comment 219 208 220 success = @ebMS_message_manager.add_ebXML_message_info_file_to_message_store system_name, directory, ebMS_info_file_path 209 221 if success.nil? then … … 211 223 return nil 212 224 end 225 213 226 return ebMS_message_info 214 227 end … … 231 244 232 245 # This method processes an incoming ebXML message 233 def process_incoming_ebXML_message command_hash 246 # This method creates an ebXML message object from an imcoming file. 247 # This method then validates the ebXML message against certain criterias (including CPA). 248 # This method then adds the ebXML message to the message store in case all validations passed 249 # returns 1st ebXML_message_object, 2nd ebMS_info, 3rd validation_errors 250 def create_and_process_incoming_ebXML_message command_hash 234 251 if command_hash.nil? then 235 252 @logger.warn "The command hash is null." 236 253 return nil 237 254 end 255 256 if command_hash['file_header'] then 257 # 1. very basic transport header validation only possible from an transport server 258 transport_header_validation = @ebMS_message_manager.ebXML_message_transport_protocol_header_validation command_hash['file_header'] 259 if transport_header_validation.nil? then 260 @logger.warn "Unable to process ebXML message transport header file." 261 return nil, nil, "System Error" 262 elsif transport_header_validation == false then 263 @logger.warn "The ebXML message transport header does not look qualify for an ebXML message. Rejecting this message." 264 return nil, nil, "Not an ebXML message." 265 end 266 @logger.debug "Incoming message transport header qualifies for an ebXML message." 267 end 268 269 file = command_hash['file_full'].nil? ? command_hash['response_file'] : command_hash['file_full'] 238 270 239 271 # 1. create an ebXML message object 240 ebXML_message_object = @ebMS_message_manager.create_ebXML_message_object_from_file command_hash['file_full']272 ebXML_message_object = @ebMS_message_manager.create_ebXML_message_object_from_file file 241 273 if ebXML_message_object.nil? then 242 274 @logger.warn "Unable to create an ebXML message object from the command_hash" 243 return nil 275 return nil, nil, "Unable to parse ebXML message." 244 276 end 245 277 @logger.debug "Successfully create an ebXML object from the incoming ebXML message. ebXML message is not yet added to the message store." 246 278 247 279 # 1. validate whether it is OK to receive such an ebXML message 248 ok, ebMS_ info, validation_errors = validate_ebXML_message command_hash, ebMS_message_object280 ok, ebMS_message_info, validation_errors = validate_ebXML_message command_hash, ebXML_message_object 249 281 if ok.nil? or ok == false then 250 msg = "Based on ebXML CPA it is not possible to receive this ebXML message(#{eb MS_message.summary})"251 msg += validation_errors.join("\n") 282 msg = "Based on ebXML CPA it is not possible to receive this ebXML message(#{ebXML_message_object.summary})" 283 msg += validation_errors.join("\n") if !validation_errors.nil? 252 284 @logger.warn msg 253 return nil 254 end 255 @logger.debug "The CPA confirms that it is possible to recive such an ebXML message (summary: #{ebMS_message_object.summary})." 256 257 # def add_ebXML_message_and_parameters_file_to_message_store b2b_system_name, metadata_about_ebXML_message, ebXML_message_parameters_file_path 258 259 meatadata = { 260 'temp_ebXML_message_file_path' => ebMS_message_object.raw_message_file_path, 261 'ebXML_message_id' => ebMS_message_object.message_id, 262 'conversation_id' => ebMS_message_object.conversation_id 285 return nil, nil, validation_errors 286 end 287 @logger.debug "The CPA confirms that it is possible to recive such an ebXML message (summary: #{ebXML_message_object.summary})." 288 289 # update metadata about ebXML message 290 # ----------------------------------- 291 292 #add information about actual ebXML message to ebMS info 293 dev = ebMS_message_info['ebXML_message'] = Hash.new 294 dev['ebXML_message_id'] = ebXML_message_object.message_id 295 dev['ebXML_message_conversation_id'] = ebXML_message_object.conversation_id 296 297 # add incoming delivery information to ebMS_info 298 delivery_info = ebMS_message_info['delivery'] = Hash.new 299 delivery_info['transport_protocol'] = command_hash['transport_protocol'] 300 delivery_info['transport_request_or_response'] = command_hash['transport_request_or_response'] rescue nil 301 delivery_info['time'] = command_hash['time'] rescue nil 302 # TODO add metadata about delivery 303 # directive_info.merge! directive.tags 304 305 # create the parameters file for the ebXML message. 306 ebMS_info_file_path = ebMS_info_to_temp_file ebMS_message_info 307 308 @logger.debug "Adding the created ebXML message and parameters file to the message store." 309 310 metadata = { 311 'temp_ebXML_message_file_path' => ebXML_message_object.raw_message_file_path, 312 'ebXML_message_id' => ebXML_message_object.message_id, 313 'ebXML_message_conversation_id' => ebXML_message_object.conversation_id 263 314 } 264 315 265 parameters_file_path = "#{@config['TEMP_FILE_DIR']}/params_file_#{Time.now.to_f.to_s}_#{Time.now.to_f.to_s}" 266 file = File.new parameters_file_path, "w" 267 YAML.dump ebMS_info, file 268 file.close 269 270 complete_ebXML_message_file_path = @ebMS_message_manager.add_ebXML_message_and_parameters_file_to_message_store(system_name, 271 &n
