Changeset 244
- Timestamp:
- 12/15/06 18:07:39 (2 years ago)
- Files:
-
- branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb (modified) (6 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_b2b_system.rb (modified) (11 diffs)
- branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message2.rb (modified) (9 diffs)
- branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_dir_observer.rb (modified) (1 diff)
- branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_http_server.rb (modified) (4 diffs)
- branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_send_ebXML_message.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/message-handling-refactor-branch/src/hefeweizen_big_ania.rb
r238 r244 26 26 27 27 --------------------------> set status of ebXML message (specially user message) 28 -----------------------------> if no ack requested set it to delviered. 29 -----------------------------> if ack requested set it to waiting for ack. 30 -----------------------------> if ack receieved set it to delivered_and_acked 31 -----------------------------> if ack requested or not if error message received set it to failed. 28 32 ---------------------------------> link ebXML messages 29 33 … … 1030 1034 1031 1035 # no validation errors 1032 1036 1033 1037 if ebXML_message_object.is_user_message? or ebXML_message_object.is_pig? then 1034 1038 # creating HefeWeizenDirective about new incoming ebXML message. … … 1141 1145 complete_ebXML_message_parameters_file_path = "#{path}/ebXML_message_parameters.yml" 1142 1146 1143 new_transaction.attach_file complete_ebXML_message_file_path, "outgoing ebXML message (response)"1144 new_transaction.attach_file complete_ebXML_message_parameters_file_path, "outgoing ebXML message parameters (response)"1147 new_transaction.attach_file complete_ebXML_message_file_path, "outgoing ebXML message response" 1148 new_transaction.attach_file complete_ebXML_message_parameters_file_path, "outgoing ebXML message parameters response" 1145 1149 1146 1150 # attach the ebXML message to the transaction … … 1232 1236 # end 1233 1237 1238 if instruction_pipe.nil? or instruction_pipe.empty? then 1239 return nil 1240 end 1234 1241 command_to_http_server = { 1235 1242 "from" => "big_ania", … … 1253 1260 create_signed_ack = false 1254 1261 1255 create_ack = ebXML_message_object.has_ack_requested? ? true : false1262 create_ack = ebXML_message_object.has_ack_requested? 1256 1263 1257 1264 if create_ack then 1258 create_signed_ack = ebXML_message_object.has_ack_signature_requested? ? true : false1259 end 1260 1265 create_signed_ack = ebXML_message_object.has_ack_signature_requested? 1266 end 1267 1261 1268 if create_ack == true and create_signed_ack == false then 1262 1269 return true, "Acknowledgment" … … 1264 1271 return true, "SignedAcknowledgment" 1265 1272 end 1266 1273 1274 return false 1275 1267 1276 elsif ebXML_message_object.is_ebMS_signal? then 1268 1277 # an ebMS signal branches/message-handling-refactor-branch/src/hefeweizen_library_b2b_system.rb
r238 r244 166 166 file_path = "#{@config['MESSAGE_DIR']}/#{system_name}/#{ebXML_message_id}/ebXML_message_parameters.yml" 167 167 if FileTest.exists? file_path and FileTest.readable? file_path then 168 return YAML.load((File.open file_path, file_path))168 return YAML.load((File.open file_path, "r")) 169 169 else 170 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 171 return nil 172 end 173 end 174 175 def exists_ebXML_message_by_id? referenced_ebXML_message_id 176 path = "#{@config['MESSAGE_DIR']}/#{system_name}/#{referenced_ebXML_message_id}" 177 if FileTest.exists? path and FileTest.directory? path then 178 ebXML_message = path + "/ebXML_message.ebMS2" 179 if FileTest.exists? ebXML_message then 180 return true 181 else 182 @logger.warn "Message with id #{referenced_ebXML_message_id} does have a directory but does not contain an ebXML_message.ebMS2 message." 183 return false 184 end 185 else 186 @logger.warn "Message with id #{referenced_ebXML_message_id} does not exist in the message store" 187 return false 172 188 end 173 189 end … … 202 218 dev['ebXML_message_conversation_id'] = metadata['ebXML_message_conversation_id'] 203 219 dev['ebXML_message_is_mutliparty'] = metadata['ebXML_message_is_multiparty'] 204 220 dev['ebXML_message_has_ack_requested'] = metadata['ebXML_message_has_ack_requested'] 221 dev['ebXML_message_has_signed_ack_requested'] = metadata['ebXML_message_has_signed_ack_requested'] 222 205 223 # add directive stuff to ebMS_info 206 224 directive_info = ebMS_message_info['directive'] = Hash.new … … 259 277 260 278 if command_hash['file_header'] then 279 261 280 # 1. very basic transport header validation only possible from an transport server 262 281 transport_header_validation = @ebMS_message_manager.ebXML_message_transport_protocol_header_validation command_hash['file_header'] … … 271 290 end 272 291 292 # this is required because an ebXML message can come in async or synchronouse. 273 293 file = command_hash['file_full'].nil? ? command_hash['response_file_path'] : command_hash['file_full'] 274 294 … … 282 302 283 303 # 1. validate whether it is OK to receive such an ebXML message 304 # -> this includes the validation of acknowledgments. whether there are 305 # ebXML messages in the message store that are acknowledged 284 306 ok, ebMS_message_info, validation_errors = validate_ebXML_message command_hash, ebXML_message_object 285 307 if ok.nil? or ok == false then … … 530 552 if ebXML_message_object.is_pig? then 531 553 @logger.warn "An ebMS signal that piggy backs a user message is not yet implemented." 554 532 555 elsif ebXML_message_object.is_user_message? then 556 @logger.debug "We are looking at a user message." 557 558 ####################### 533 559 ####################### 534 560 # CHECK USER MESSAGE 535 561 ####################### 536 @logger.debug "We are looking at a user message."562 ####################### 537 563 538 564 ################################# … … 544 570 # --------------- 545 571 sync_possible = false 572 546 573 if command_hash['transport_protocol'].upcase == 'HTTP' then 547 574 @logger.debug "The ebXML message was received over HTTP." … … 590 617 check_ack_signature_requested = true 591 618 else 619 # per message is always ok. 592 620 check_ack_signature_requested = true 593 # per message is always ok.594 621 end 595 622 … … 615 642 # CHECK DUPLICATE ELIMINATION 616 643 # --------------------------- 617 644 618 645 if info_structure['mc-duplicateElimination'] == 'never' and ebXML_message_object.has_duplicate_elimination? then 619 646 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must be sent never with duplicateElimination set but this message has duplicate elimination set. This is wrong." ) … … 671 698 else 672 699 673 #######################674 # CHECK USER MESSAGE675 #######################676 700 677 701 # 2. ebMS signal 678 702 @logger.debug "We are looking at an ebMS signal." 679 703 680 # TODO add test. 704 ####################### 705 ####################### 706 # CHECK EBMS SIGNAL 707 ####################### 708 ####################### 709 710 if ebXML_message_object.is_ping? or ebXML_message_object.is_pong? or ebXML_message_object.is_status_request? or 711 ebXML_message_object.is_status_response? or ebXML_message_object.is_error_message? then 712 @logger.warn "Ping, Pong, StatusRequest, StatusRequest Response not validated." 713 @logger.warn "Not validating." 714 715 elsif ebXML_message_object.is_acknowledgment? then 716 717 718 # first get the message that gets acknowledged. also get that message parameters file. 719 referenced_ebXML_message_id = ebXML_message_object.ack_ref_to_msg_id 720 if referenced_ebXML_message_id.nil? then 721 @logger.warn "The ebXML Acknowledgement message with id #{ebXML_message_object.message_id} does not contain a ref to mesage id." 722 return nil, nil, nil 723 end 724 725 if !exists_ebXML_message_by_id? referenced_ebXML_message_id then 726 @logger.warn "The ebXML Acknowledgment message with id #{ebXML_message_object.message_id} references an ebXML message with " + 727 "id '#{referenced_ebXML_message_id}' but the message store does not contain this message." 728 return nil, nil, nil 729 end 730 @logger.debug "The referenced ebXML message does exist in the message store." 731 732 referenced_ebXML_message_info = get_ebXML_message_parameters_file_content referenced_ebXML_message_id 733 if referenced_ebXML_message_info.nil? then 734 @logger.warn "Unable to retrieve the ebXML message parameters information for the ebXML message with id '#{referenced_ebXML_message_id}'." 735 return nil, nil, nil 736 end 737 738 @logger.debug "Successfully retrieved ebXML Message info of acknowledged ebXML message." 739 740 puts '---------------------' 741 puts '---------------------' 742 743 puts '---------------------' 744 puts '---------------------' 745 puts '---------------------' 746 puts '---------------------' 747 puts '---------------------' 748 puts '---------------------' 749 puts 'set status of ebXML messages.!' 750 puts '---------------------' 751 puts '---------------------' 752 puts '---------------------' 753 puts '---------------------' 754 puts '---------------------' 755 puts '---------------------' 756 puts '---------------------' 757 puts '---------------------' 758 puts '---------------------' 759 puts '---------------------' 760 761 762 763 764 765 766 767 if referenced_ebXML_message_info['ebXML_message']['ebXML_message_has_ack_requested'] == true then 768 @logger.debug "Original ebXML message had an Acknowledgment Request set. So this ebXML Ack is OK." 769 else 770 @logger.warn "Original ebXML message had no Acknowledgment Request set. So this ebXML Ack is a negative acknowledgment." 771 # NOT OK 772 end 773 puts referenced_ebXML_message_info['ebXML_message']['ebXML_message_has_signed_ack_requested'] 774 775 =begin 776 777 ################################# 778 # CHECK DELIVERY CHANNEL 779 ################################# 780 781 782 783 784 # --------------- 785 # CHECK TRANSPORT 786 # --------------- 787 sync_possible = false 788 789 if command_hash['transport_protocol'].upcase == 'HTTP' then 790 @logger.debug "The ebXML message was received over HTTP." 791 sync_possible = true 792 # HTTP 793 if info_structure['info']['transport-protocol-name'] == "HTTP" then 794 @logger.debug "The message was sent with the correct HTTP transport protocol." 795 796 # ------------------------ 797 # CHECK TRANSPORT SECURITY 798 # ------------------------ 799 800 # TODO 801 # transport client/server security 802 # HTTP OVER SSL? 803 else 804 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must be sent over the #{info_structure['info']['transport-protocol-name']} transport protocol and NOT over HTTP." ) 805 end 806 elsif command_hash['transport_protocol'].upcase == 'SMTP' then 807 @logger.debug "The ebXML message was received over SMTP." 808 sync_possible = false 809 # SMTP 810 if info_structure['info']['transport-protocol-name'] == "SMTP" then 811 @logger.debug "The message was sent with the correct SMTP transport protocol." 812 else 813 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must be sent over the #{info_structure['info']['transport-protocol-name']} transport protocol and NOT over SMTP." ) 814 end 815 else 816 @logger.warn "Unknown transport protocol '#{command_hash['transport_protocol']}'." 817 return nil, nil, nil 818 end 819 820 # ooooooooooooooooooooooooooooooo 821 # CHECK MESSAGING CHARACTERISTICS 822 # ooooooooooooooooooooooooooooooo 823 824 # ------------------- 825 # CHECK ACK REQUESTED --> reliable messaging 826 # ------------------- 827 828 check_ack_signature_requested = false 829 if info_structure['mc-ackRequested'] == 'never' and ebXML_message_object.has_ack_requested? then 830 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must never be sent with an ack requested but this message has an ack requested element. This is wrong." ) 831 elsif info_structure['mc-ackRequested'] == 'always' and !ebXML_message_object.has_ack_requested? then 832 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must always be sent with an ack requested but this message has no ack requested element. This is wrong." ) 833 check_ack_signature_requested = true 834 else 835 # per message is always ok. 836 check_ack_signature_requested = true 837 end 838 839 # ----------------------------- 840 # CHECK ACK SIGNATURE REQUESTED 841 # ----------------------------- 842 if check_ack_signature_requested == true then 843 844 if ebXML_message_object.has_ack_requested? then 845 if info_structure['mc-ackSignatureRequested'] == 'never' and ebXML_message_object.has_signed_ack_requested? then 846 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must never be sent with an ack signature requested but this message has an ack with signature requested element. This is wrong." ) 847 elsif info_structure['mc-ackSignatureRequested'] == 'always' and !ebXML_message_object.has_signed_ack_requested? then 848 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must always be sent with an ack signature requested but this message has no ack with signature requested element. This is wrong." ) 849 else 850 # per message is always ok 851 end 852 else 853 # then it is ok. 854 end 855 end 856 857 # --------------------------- 858 # CHECK DUPLICATE ELIMINATION 859 # --------------------------- 860 861 if info_structure['mc-duplicateElimination'] == 'never' and ebXML_message_object.has_duplicate_elimination? then 862 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must be sent never with duplicateElimination set but this message has duplicate elimination set. This is wrong." ) 863 elsif info_structure['mc-duplicateElimination'] == 'always' and !ebXML_message_object.has_duplicate_elimination? then 864 errors << ( HefeWeizen::HefeWeizenLibrary::EBMSError.new "", "CPA says this message must be sent always with duplicateElimination set but this message has duplicate elimination not set. This is wrong." ) 865 866 else 867 # anythig is ok. 868 end 869 870 # --------------------- 871 # CHECK SYNC REPLY MODE 872 # --------------------- 873 874 # TODO TODO TODO implement 875 # -> hardest part? 876 if sync_possible == true then 877 @logger.debug "The transport protocol allows to be used in a synchronous way so we have to check sync reply mode." 878 if command_hash['transport_request_or_response'].upcase == "REQUEST" then 879 @logger.debug "The ebXML message was received on the request leg of an HTTP post." 880 else 881 @logger.debug "The ebXML message was received on the response leg of an HTTP post. This means this message was received synchronous." 882 end 883 else 884 @logger.debug "The transport protocol does not allow to be used in an synchronous way so we do not have to check " + 885 "the sync reply mode." 886 end 887 888 ########################### 889 # CHECK DOC EXCHANGE 890 ########################### 891 892 # --------------- 893 # NON REPUDIATION 894 # --------------- 895 896 # TODO implement January 2007 897 898 # non repudiation yes/no 899 # non repudiation protocol 900 # non repudiation algorithms 901 # etc. 902 903 =end 904 else 905 @logger.warn "Unknown ebXML message type for validation. Not validating. Message summary :#{ebXML_message_object.summary}." 906 end # if different type of ebMS messages. 907 681 908 682 909 end … … 693 920 694 921 @logger.debug "ebMS message validation checks done." 695 if !errors.empty? then922 if !errors.empty? then 696 923 msg = errors.join("\n") 697 924 @logger.warn msg branches/message-handling-refactor-branch/src/hefeweizen_library_ebMS_message2.rb
r242 r244 71 71 72 72 # creating the ebXML message 73 success, is_multiparty = TempEBMessage2.create_message( party_ids, directive, ebMS_message_info,73 success, is_multiparty, has_ack_requested, has_signed_ack_requested = TempEBMessage2.create_message( party_ids, directive, ebMS_message_info, 74 74 file_path, @config, message_id, conversation_id) 75 75 … … 86 86 'ebXML_message_id' => message_id, 87 87 'ebXML_message_conversation_id' => conversation_id, 88 'ebXML_message_is_multiparty' => is_multiparty 88 'ebXML_message_is_multiparty' => is_multiparty, 89 'ebXML_message_has_ack_requested' => has_ack_requested, 90 'ebXML_message_has_signed_ack_requested' => has_signed_ack_requested 89 91 } 90 92 … … 283 285 attr_reader :errors 284 286 attr_accessor :raw_message_file_path 285 287 attr_reader :ack_ref_to_msg_id 288 286 289 def get_hash_value cpa 287 290 hash = Hash.new … … 324 327 end 325 328 329 def is_user_message? 330 @service != "urn:oasis:names:tc:ebxml-msg:service" 331 end 332 326 333 def is_ebMS_signal? 327 334 (@service == "urn:oasis:names:tc:ebxml-msg:service" and ["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].include? @action ) ? true : false 328 335 end 329 336 330 def is_ user_message?331 @service != "urn:oasis:names:tc:ebxml-msg:service"337 def is_acknowledgment? 338 (@service == "urn:oasis:names:tc:ebxml-msg:service" and @action == "Acknowledgment") ? true : false 332 339 end 333 340 … … 342 349 def is_status_request? 343 350 (@service == "urn:oasis:names:tc:ebxml-msg:service" and @action == "StatusRequest") ? true : false 351 end 352 353 def is_status_response? 354 (@service == "urn:oasis:names:tc:ebxml-msg:service" and @action == "StatusResponse") ? true : false 344 355 end 345 356 … … 395 406 396 407 is_multiparty = false 408 409 has_ack_requested = false 410 has_signed_ack_requested = false 397 411 398 412 # Party Identities … … 430 444 431 445 ebXML_message.close 432 return true, is_multiparty 446 return true, is_multiparty, false, false 433 447 434 448 else … … 448 462 if ebMS_message_info['info']['mc-ackRequested'] == 'always' or 449 463 (ebMS_message_info['info']['mc-ackRequested'] == 'perMessage' and directive.ackRequested == 'yes') then 464 has_ack_requested = true 450 465 if ebMS_message_info['info']['mc-ackSignatureRequested'] == 'always' or 451 466 (ebMS_message_info['info']['mc-ackSignatureRequested'] == 'perMessage' and directive.ackSignatureRequested == 'yes') then 452 467 signed = "yes" 468 has_signed_ack_requested = true 453 469 else 454 470 signed = "false" … … 564 580 end 565 581 566 return true, is_multiparty 582 return true, is_multiparty, has_ack_requested, has_signed_ack_requested 567 583 568 584 end branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_dir_observer.rb
r239 r244 76 76 if !@pipe_to_monitor.nil? then 77 77 f = File.open @pipe_to_monitor, "w" 78 f << string 78 # f.sync = true 79 f.puts string 79 80 f.close 80 81 else branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_http_server.rb
r232 r244 32 32 # the thread can exit. 33 33 class EBMSServlet < WEBrick::HTTPServlet::AbstractServlet 34 35 @@instance_creation_mutex = Mutex.new 36 34 37 35 def do_POST(req, resp) 38 @@instance_creation_mutex.synchronize { 39 40 # 1. 41 # save content (separated header and body) to file. 42 # HTTP header will include the SOAPAction 43 # HTTP body will include rest (SOAP with attachment messes or simply SOAP message) 44 45 now = Time.now 46 file_header_path = "#{@config['TEMP_FILE_DIR']}/file_header_#{now.to_f.to_s}_header" 47 file_header = File.new(file_header_path, "w") 48 file_body_path = "#{@config['TEMP_FILE_DIR']}/file_body_#{now.to_f.to_s}_body" 49 file_body = File.new(file_body_path, "w") 50 file_full_path = "#{@config['TEMP_FILE_DIR']}/file_full_#{now.to_f.to_s}_full" 51 file_full = File.new(file_full_path, "w") 52 file_header.sync = true 53 file_body.sync = true 54 file_full.sync = true 55 file_header << req.raw_header 56 file_body << req.body 57 file_full << req.to_s 58 file_header.close 59 file_body.close 60 file_full.close 61 62 # 2. 63 # create a named pipe so big ania (via ania) can tell us how to proceed. 64 65 my_pipe = "#{@config['PIPE_DIR']}/pipe_to_http_server_#{now.to_f.to_s}" 66 command = "mkfifo #{my_pipe}" 67 system(command) 68 command = "chmod 600 #{my_pipe}" 69 system(command) 70 71 # 3. 72 # send info about new ebXML message to big_ania 36 37 # 1. 38 # save content (separated header and body) to file. 39 # HTTP header will include the SOAPAction 40 # HTTP body will include rest (SOAP with attachment messes or simply SOAP message) 41 42 now = Time.now 43 file_header_path = "#{@config['TEMP_FILE_DIR']}/file_header_#{now.to_f.to_s}_header" 44 file_header = File.new(file_header_path, "w") 45 file_body_path = "#{@config['TEMP_FILE_DIR']}/file_body_#{now.to_f.to_s}_body" 46 file_body = File.new(file_body_path, "w") 47 file_full_path = "#{@config['TEMP_FILE_DIR']}/file_full_#{now.to_f.to_s}_full" 48 file_full = File.new(file_full_path, "w") 49 file_header.sync = true 50 file_body.sync = true 51 file_full.sync = true 52 file_header << req.raw_header 53 file_body << req.body 54 file_full << req.to_s 55 file_header.close 56 file_body.close 57 file_full.close 58 59 # 2. 60 # create a named pipe so big ania (via ania) can tell us how to proceed. 61 62 my_pipe = "#{@config['PIPE_DIR']}/pipe_to_http_server_#{now.to_f.to_s}" 63 command = "mkfifo #{my_pipe}" 64 system(command) 65 command = "chmod 600 #{my_pipe}" 66 system(command) 67 68 # 3. 69 # send info about new ebXML message to big_ania 70 command_hash = { 71 "from" => "hefeweizen_tasker_application_http_server", 72 "to" => "big ania", 73 "b2b_system_name" => @b2b_system_name, 74 "command" => "new ebXML message received", 75 "transport_protocol" => "HTTP", 76 "transport_request_or_response" => "request", 77 "file_header" => file_header.path, 78 "file_body" => file_body.path, 79 "file_full" => file_full.path, 80 "pipe_for_instructions" => my_pipe, 81 "time" => now.to_s, 82 "transaction_id" => "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid}_#{@b2b_system_name}" 83 } 84 85 command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 86 write_to_ania command 87 88 # 4. 89 # lets wait until we get a response (instruction) on the named pipe. 90 # instructions can be: 91 # - close with 200 (OK) 92 # - ebMS signal (eg ack or pong) 93 # - ebMS message (payload with optionally including ack) 94 # - SOAP fault ? or is that part of ebMS signals 95 96 pipe_to_me = File.open(my_pipe, "r+") 97 exit = exit 98 99 # TODO add time constraint here. 100 while !exit do 101 begin 102 command = pipe_to_me.readline 103 exit = true 104 rescue EOFError => error 105 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 106 puts "HTTP SERVER ERROR: #{error.to_s}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 107 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 108 sleep (0.1) 109 end 110 end 111 112 113 # 5. 114 # read response command 115 # send response on HTTP response leg. 116 hash = nil 117 if command.nil? then 118 puts 'HTTP Server. Received empty command. This is bad.' 119 resp['Content-Type'] = "text/html" 120 resp.body = "ERROR here :( sorry dude." 121 else 122 hash = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.command_to_hash command 123 if hash['close_connection'] then 124 resp.body = "" 125 resp.status = 204 126 # HTTPStatus::reason_phrase(204) 127 # resp.status = 204 # do not set resp.body 128 # resp.status = 204 # ok no content 129 else 130 response_file = hash['response_file_name'] 131 resp['Content-Type'] = "text/html" 132 resp.body << File.read(response_file) 133 end 134 135 # 6 136 # send big ania information about sending the response. 73 137 command_hash = { 74 138 "from" => "hefeweizen_tasker_application_http_server", 75 139 "to" => "big ania", 76 140 "b2b_system_name" => @b2b_system_name, 77 "command" => "new ebXML message received", 78 "transport_protocol" => "HTTP", 79 "transport_request_or_response" => "request", 80 "file_header" => file_header.path, 81 "file_body" => file_body.path, 82 "file_full" => file_full.path, 83 "pipe_for_instructions" => my_pipe, 141 "command" => "send ebXML message response done", 142 "state_expectation" => "send ebXML message response done", 84 143 "time" => now.to_s, 85 "transaction_id" => "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid}_#{@b2b_system_name}"144 "transaction_id" => hash['transaction_id'] 86 145 } 146 147 # TODO 148 # how does sending an response fail? 149 # --> maybe calling side closed the connection? 150 151 if true then 152 # send big ania that sending the response was successful. 153 command_hash["status"] = "OK" 154 else 155 # send big ania that sending the response failed. 156 command_hash["status"] = "FAILED" 157 command_hash["reason"] = "????????????????? description" 158 end 87 159 88 160 command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 89 161 write_to_ania command 90 162 91 # 4. 92 # lets wait until we get a response (instruction) on the named pipe. 93 # instructions can be: 94 # - close with 200 (OK) 95 # - ebMS signal (eg ack or pong) 96 # - ebMS message (payload with optionally including ack) 97 # - SOAP fault ? or is that part of ebMS signals 98 99 pipe_to_me = File.open(my_pipe, "r+") 100 exit = exit 101 102 # TODO add time constraint here. 103 while !exit do 104 begin 105 command = pipe_to_me.readline 106 exit = true 107 rescue EOFError => error 108 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 109 puts "HTTP SERVER ERROR: #{error.to_s}XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 110 puts "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 111 sleep (0.1) 112 end 113 end 114 115 116 # 5. 117 # read response command 118 # send response on HTTP response leg. 119 hash = nil 120 if command.nil? then 121 puts 'HTTP Server. Received empty command. This is bad.' 122 resp['Content-Type'] = "text/html" 123 resp.body = "ERROR here :( sorry dude." 124 else 125 hash = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.command_to_hash command 126 if hash['close_connection'] then 127 resp.body = "" 128 resp.status = 204 129 # HTTPStatus::reason_phrase(204) 130 # resp.status = 204 # do not set resp.body 131 # resp.status = 204 # ok no content 132 else 133 response_file = hash['response_file_name'] 134 resp['Content-Type'] = "text/html" 135 resp.body << File.read(response_file) 136 end 137 138 # 6 139 # send big ania information about sending the response. 140 command_hash = { 141 "from" => "hefeweizen_tasker_application_http_server", 142 "to" => "big ania", 143 "b2b_system_name" => @b2b_system_name, 144 "command" => "send ebXML message response done", 145 "state_expectation" => "send ebXML message response done", 146 "time" => now.to_s, 147 "transaction_id" => hash['transaction_id'] 148 } 149 150 # TODO 151 # how does sending an response fail? 152 # --> maybe calling side closed the connection? 153 154 if true then 155 # send big ania that sending the response was successful. 156 command_hash["status"] = "OK" 157 else 158 # send big ania that sending the response failed. 159 command_hash["status"] = "FAILED" 160 command_hash["reason"] = "????????????????? description" 161 end 162 163 command = HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash 164 write_to_ania command 165 166 end 167 168 # X. 169 # clean-up: closing file, remove pipe 170 pipe_to_me.close 171 FileUtils.rm(my_pipe) 172 } 163 end 164 165 # X. 166 # clean-up: closing file, remove pipe 167 pipe_to_me.close 168 FileUtils.rm(my_pipe) 169 173 170 return true 174 171 end … … 181 178 @config = config 182 179 @pipe_to_ania = pipe_to_ania 183 require "#{@config['LIB_DIR']}/hefeweizen_library_utils"184 180 end 185 181 … … 269 265 270 266 def http_server_serve 271 272 267 s = WEBrick::HTTPServer.new( {:Logger => @logger, :Port => @port} ) 273 268 s.mount @path, InitializedEBMSServlet, @b2b_system_name, @config, @pipe_to_ania 274 269 trap("INT"){ s.shutdown } 275 270 s.start 276 277 271 return 0 278 272 … … 291 285 end 292 286 end 293 end # class 287 end # class HTTPServer 294 288 295 289 end # module Tasker branches/message-handling-refactor-branch/src/taskers/hefeweizen_tasker_application_send_ebXML_message.rb
r238 r244 130 130 131 131 # 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}" 132 # 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} "132 # 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} " 133 133 # no retries here! 134 134 135 135 136 # 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} "136 # 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} " 137 137 138 138 # added ignore-length ... had problems with it when using webrick and setting code 204 to it.
