Changeset 255

Show
Ignore:
Timestamp:
12/19/06 14:50:32 (2 years ago)
Author:
sacha
Message:

added start of message states support. probably needs a rewrite already.

Files:

Legend:

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

    r244 r255  
    2323o create response (ebxml ack, http ok, nothing, error message) 
    2424  o no user message response, yet 
    25 o produce directive of incoming ebxml message 
    2625 
    2726--------------------------> set status of ebXML message (specially user message) 
     
    426425    ############################################################ 
    427426 
    428     ################# rewrite 
    429     ################# rewrite 
    430     ################# rewrite 
    431     ################# rewrite 
    432  
    433  
    434  
    435427    # This method executes on the commands 
    436428    # Must return a true in case some code did deal with the command. 
     
    444436          return false 
    445437        else 
    446           result = process_new_directive2 command, command_hash, transaction 
     438          result = process_new_directive command, command_hash, transaction 
    447439          @logger.debug "Processed directive." 
    448440 
     
    549541 
    550542      elsif command == 'send ebXML message done' 
     543        # called from the HTTP client 
    551544        @logger.debug "Send ebXML message done." 
    552         # this does not yet mean that the message is delivered. This means that the ebXML message made it 
    553         # to the other side. Things that can happen are  
     545        # this does not yet mean that the message is delivered. This means that the ebXML message was sent off. 
     546        # Things that can happen now are  
     547        # o nothing 
    554548        # o synchronous or asynchronous ebXML error message for this ebXML message is received. 
    555549        # o an acknowledgment may be required for the ebXML message. 
    556         success, comment = process_send_ebXML_message_response transaction, command, command_hash 
     550        success, comment = process_send_ebXML_message_response transaction, command, command_hash, "client" 
    557551        if command == false then 
    558552          msg = "It is not possible to process response of sending an ebXML message." 
     
    567561 
    568562      elsif command == 'send ebXML message response done' then 
     563        # called from the HTTP server 
    569564        @logger.debug "sending response (could be empty) done." 
    570         transaction.succeed "job done" 
     565        success, comment = process_send_ebXML_message_response transaction, command, command_hash, "server" 
     566        if command == false then 
     567          msg = "It is not possible to process response of sending an ebXML message." 
     568          @logger.warn msg + comment 
     569          transaction.fail msg + comment 
     570          return false 
     571        else 
     572          @logger.debug "Successfully processed response of sending an ebXML message response." 
     573          transaction.succeed "job done" 
     574          return true 
     575        end 
     576 
    571577         
    572578      elsif command == 'new ebXML message received' then 
     
    576582          return false 
    577583        else 
    578           result = process_new_ebXML_message2 command, command_hash, transaction 
     584          result = process_new_ebXML_message command, command_hash, transaction 
    579585          if result == false then 
    580586            @logger.error "Error processing incoming ebXML Message" 
     
    589595      end 
    590596       
    591  
    592  
    593597      # if transaction still open and noone processed it ....... I may have to close it. 
    594598       
     
    701705    # o when the message was sent via HTTP and there was no sync response then there is no info here. 
    702706    # 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." 
     707    def process_send_ebXML_message_response transaction, command, command_hash, server_or_client 
     708      @logger.debug "sending of ebXML message done. confirmation of '#{command_hash['transport_protocol']}' client." if server_or_client == "client" 
     709      @logger.debug "sending of ebXML message done. confirmation of '#{command_hash['transport_protocol']}' server." if server_or_client == "server" 
     710 
     711      transaction.transition_to_new_state "ebXML message sent and processing response if any." if server_or_client == "client" 
     712      transaction.transition_to_new_state "response message sent." if server_or_client == "server" 
     713       
    706714      transaction.attach_file command_hash['transfer_info_path'], "transfer information" if command_hash['transfer_info_path'] 
    707715      transaction.remember_file_to_remove command_hash['transfer_info_path'] if command_hash['transfer_info_path'] 
     
    709717      transaction.remember_file_to_remove command_hash['response_file_path'] if command_hash['response_file_path'] 
    710718 
     719      b2b_system = @b2b_systems[command_hash['b2b_system_name']] 
     720      if b2b_system.nil? then 
     721        @logger.warn "There is no B2B system with the name #{command_hash['b2b_system_name']}." 
     722        return false 
     723      end 
     724 
    711725      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." 
     726        @logger.debug "Received Success OK from the ebXML message sending client tasker." if server_or_client == "client" 
     727        @logger.debug "Received Success OK from the sending response (ebXML message or simply closing) server tasker." if server_or_client == "server" 
     728 
     729        # --------------------------- 
     730        # set new ebXML message state 
     731        # --------------------------- 
     732        b2b_system.set_ebXML_message_state command_hash['ebXML_message_id'], "sent" if server_or_client == "client" 
     733 
     734      else 
     735        msg = "Received a FAILURE as status from the ebXML message sending tasker." if server_or_client == 'client' 
     736        msg = "Received a FAILURE as status from the ebXML message server tasker." if server_or_client == 'server' 
    715737        @logger.warn msg  
     738 
     739        # --------------------------- 
     740        # set new ebXML message state 
     741        # --------------------------- 
     742        b2b_system.set_ebXML_message_state command_hash['ebXML_message_id'], "failed_to_send" 
     743 
     744        # ----------------------------- 
     745        # set final ebXML message state 
     746        # ----------------------------- 
     747        # TODO 
     748        # -> reliable messaging retries! will set the final state of original messages. 
     749 
    716750        return false, msg 
     751      end 
     752 
     753      ######################################### 
     754      ## TODO  
     755      ## UGLY UGLY 
     756      ######################################### 
     757 
     758      # ----------------------------- 
     759      # set final ebXML message state 
     760      # ----------------------------- 
     761      do_check = true 
     762      if server_or_client == "server" then 
     763        if command_hash['ebXML_message_id'].nil? then 
     764          do_check = false 
     765        end 
     766      end 
     767 
     768      if command_hash['ebXML_message_id'].nil? then 
     769        do_check = false 
     770      end 
     771 
     772      if do_check == true then 
     773        @logger.debug "Searching for the ebXML info content for ebXML message with id '#{command_hash['ebXML_message_id']}'." 
     774        info = get_ebMS_info command_hash['ebXML_message_id'], command_hash['b2b_system_name'] 
     775        # check if user message: 
     776        if !info.nil? and !info['ebXML_message'].nil? and !info['ebXML_message']['ebXML_message_has_ack_requested'].nil? and 
     777            info['ebXML_message']['ebXML_message_has_ack_requested'] == false then 
     778          # we can set the message status to delivered. any error message will later fail it. 
     779          b2b_system.set_ebXML_message_state command_hash['ebXML_message_id'], "delivered" 
     780        end 
     781 
     782#        b2b_system.set_ebXML_message_state command_hash['ref_ebXML_message_id'], "delivered" unless command_hash['ebXML_message_is_ack_for_message_id'].nil? 
     783#        b2b_system.set_ebXML_message_state command_hash['ref_ebXML_message_id'], "failed" unless command_hash['ebXML_message_is_error_for_message_id'].nil? 
     784#        b2b_system.set_ebXML_message_state command_hash['ref_ebXML_message_id'], "delivered" unless command_hash['ebXML_message_is_pong_for_message_id'].nil? 
     785 
    717786      end 
    718787 
     
    720789        @logger.debug "The SMTP transport protocol was used so no direct response (ebXML MS signal) possible." 
    721790 
    722         # TODO set ebXML message to delivered! 
    723791        return true, "Successfully completed transaction." 
    724       else 
     792 
     793      else 
     794 
     795        # The server does not have a ebXML response possible. 
     796        if server_or_client == 'server' then 
     797          return true, "Success" 
     798        end 
     799 
    725800        transfer_info_file = command_hash['transfer_info_path'] 
    726801        response_file = command_hash['response_file_path'] 
     
    740815              @logger.warn "HTTP response indicates that there is no content (response code 204) but the response file exists and is not empty." 
    741816              @logger.debug "Continuing with processing response file." 
    742               result = process_new_ebXML_message2 command, command_hash, transaction               
     817              result = process_new_ebXML_message command, command_hash, transaction               
    743818              if result == false then 
    744819                msg = "Error processing response from sending an ebXML Message." 
     
    750825              @logger.debug 'There was no response from sending ebXML message.' 
    751826              # TODO validate if that is OK. 
    752               return true, "I ASSUME THIS FUCKER IS OKEY." 
     827              return true, "I ASSUME THIS EBXML MESSAGE IS OK." 
    753828            end 
    754829 
    755830          elsif has_content == true then 
    756831            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." 
     832              msg = "HTTP response indicates that there is content but the response file is empty." 
    758833              @logger.warn msg 
    759               @logger.debug "Failing transction" 
     834              @logger.debug "Failing transaction" 
    760835              return false, msg 
    761836            else 
    762837              @logger.debug "Processing response from sending ebXML message." 
    763               result = process_new_ebXML_message2 command, command_hash, transaction               
     838              result = process_new_ebXML_message command, command_hash, transaction               
    764839              if result == false then 
    765840                msg = "Error processing response from sending an ebXML Message." 
     
    788863    # then this method updates the transaction to know about the new ebXML message 
    789864    # and ebXML message info. 
    790     def process_new_directive2 command, command_hash, transaction 
     865    def process_new_directive command, command_hash, transaction 
    791866       
    792867      b2b_system = @b2b_systems[command_hash['b2b_system_name']] 
     
    868943      return true 
    869944    end 
     945 
     946 
    870947 
    871948    # Add the information of an ebXML message to a transaction. 
     
    921998 
    922999    # This method receives an ebXML message and starts to process it. 
    923     def process_new_ebXML_message2 command, command_hash, transaction 
     1000    def process_new_ebXML_message command, command_hash, transaction 
    9241001      @logger.debug "Reading received ebXML message." 
    9251002       
     
    10021079        if new_ebXML_message_object.nil? then 
    10031080          @logger.warn "Error creating an ebXML Error message for the ebXML message: #{ebXML_message_object.summary}. The erros are: #{validation_errors.to_s}" 
     1081          # --------------------------- 
     1082          # Set new ebXML Message state 
     1083          # --------------------------- 
     1084          b2b_system.set_ebXML_message_state ebXML_message_object.message_id, "failed" 
    10041085            # TODO delete stuff?? 
    10051086          return false 
     
    10211102        # attach the ebXML message to the transaction 
    10221103        transaction.add_ebXML_message_id_reference new_ebXML_message_object.message_id, "ErrorMessage" 
     1104 
     1105        # some more metadata 
     1106        new_ebXML_message_info['ebXML_message']['ebXML_message_is_error_for_message_id'] = true 
     1107        new_ebXML_message_info['ebXML_message']['ref_ebXML_message_id'] = ebXML_message_object.message_id 
     1108        store_ebMS_info new_ebMS_info, b2b_system_name 
    10231109 
    10241110        new_delivery = true 
     
    10431129          transaction.transition_to_new_state "Receiving ebXML user message information sent to integration point." 
    10441130          @logger.debug "Created incoming directive at : #{path}" 
     1131 
    10451132        end 
    10461133 
     
    10531140        if action_required == true then 
    10541141          @logger.debug "Requires further action: #{action}" 
     1142          # includes to set the state of the ebXML messages. 
    10551143          new_ebXML_message_object, new_ebXML_message_info = b2b_system.create_and_process_new_ebXML_signal_message ebXML_message_object, action 
    10561144          if new_ebXML_message_object.nil? then 
     
    10761164          transaction.add_ebXML_message_id_reference new_ebXML_message_object.message_id, "Acknowledgment" 
    10771165           
     1166          # some more metadata 
     1167          if action == "Acknowledgment" then 
     1168            new_ebXML_message_info['ebXML_message']['ebXML_message_is_ack_for_message_id'] = true 
     1169            new_ebXML_message_info['ebXML_message']['ref_ebXML_message_id'] = ebXML_message_object.message_id 
     1170          elsif action == "Pong" then 
     1171            new_ebXML_message_info['ebXML_message']['ebXML_message_is_pong_for_message_id'] = true 
     1172            new_ebXML_message_info['ebXML_message']['ref_ebXML_message_id'] = ebXML_message_object.message_id 
     1173            # elsif action == "StatusResponse" then 
     1174          end 
     1175          store_ebMS_info new_ebXML_message_info, b2b_system.system_name 
     1176 
    10781177          new_delivery = true 
    10791178 
     
    11661265            elsif ebMS_info['info']['mc-syncReplyMode'] == 'mshSignalsOnly' 
    11671266              @logger.debug "Sending msh signal synchronously back over HTTP transport protocol." 
    1168               send_sync_response new_ebXML_message_object.raw_message_file_path, transaction, instruction_pipe 
     1267              send_sync_response new_ebXML_message_object.raw_message_file_path, transaction, instruction_pipe, new_ebXML_message_object.message_id 
    11691268               
    11701269            elsif ebMS_info['info']['mc-syncReplyMode'] == 'signalsOnly' 
     
    11941293 
    11951294          else 
    1196             @logger.error "Responding an ebXML user message as a response to an ebXML message is not yet implemented." 
     1295            @logger.warn "Responding an ebXML user message as a response to an ebXML message is not yet implemented." 
    11971296            return false 
    11981297          end 
     
    12001299        end 
    12011300         
    1202         # some more validations! 
    1203         # o if sync protocol and no sync response expected. 
    1204          
    12051301      else           
    12061302        @logger.debug "There are no responses to be delivered. Closing any open connection" 
     
    12131309    end 
    12141310     
    1215     def send_sync_response ebXML_message_file_path, transaction, instruction_pipe 
     1311    def send_sync_response ebXML_message_file_path, transaction, instruction_pipe, ebXML_message_id 
    12161312      @logger.debug "Sending command to send the ebXML response message." 
    12171313      command_to_http_server = { 
     
    12201316        "response_file_name" => ebXML_message_file_path, 
    12211317        "transaction_id" => transaction.transaction_id, 
     1318        "ebXML_message_id" => ebXML_message_id, 
    12221319        "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    12231320      } 
     
    12921389    end 
    12931390 
    1294  
    1295  
    1296  
    1297  
    1298  
    1299  
    1300     ################# rewrite 
    1301     ################# rewrite 
    1302     ################# rewrite 
    1303     ################# rewrite 
    1304      
    1305  
    1306  
    1307  
    1308  
    1309  
    1310  
    1311  
    1312  
    1313  
    1314  
    1315  
    1316  
    1317  
    1318  
    1319  
    1320  
    1321  
    1322     
    1323  
    1324  
    1325  
    1326  
    1327     def old_____process_command_with_transaction transaction, command, command_hash 
    1328       ######################################### 
    1329       # the commands below are related to: 
    1330       # RECEIVING ebXML MESSAGES 
    1331       # --> includes creation of directives 
    1332       # --> includes creation of responses 
    1333       ######################################### 
    1334       if command == 'new ebXML message received' then 
    1335        @logger.debug "Received new ebXML message!" 
    1336         result = process_new_ebXML_message command, command_hash, transaction 
    1337         if result == false then 
    1338           @logger.error "Error processing ebXML Message" 
    1339           transaction.close_transaction('failed', "Failed to process ebXML message.") if transaction.is_open? 
    1340           return false 
    1341         else 
    1342           return true 
    1343         end 
    1344          
    1345       elsif command.strip == 'send ebXML message response done' then 
    1346         # TODO  
    1347         # - add place for a failed response. 
    1348         @logger.debug "Sending ebXML message response done." 
    1349         if command_hash['state_expectation'] == transaction.get_next_expectation then 
    1350           @logger.debug "YES. Expected transition to #{transaction.get_next_expectation}" 
    1351            
    1352           if command_hash["status"] == "OK" then 
    1353             @logger.debug "Successfully responded with ebXML message." 
    1354             @logger.debug "Transitioning to succeeded state." 
    1355             transaction.close_transaction('succeeded', "All done.") 
    1356           else 
    1357             @logger.warn "Error respnding with ebXML message. Failed to respond. Reason #{command_hash['reason']}" 
    1358             @logger.debug "Transitionin to failed state." 
    1359             # ????? 
    1360             # TODO 
    1361             # ARE WE TALKING ABOUT THE SAME TRANSACTION HERE???? 
    1362             # A) TRANSACTION TO SEND MESSAGE 
    1363             # B) PERSISTENCE TRANSACTION 
    1364             transaction.close_transaction('failed', "Failed to close transaction. #{command_hash['reason']}.") 
    1365           end 
    1366           return true 
    1367         else 
    1368           @logger.error "Unexpected transition to '#{command_hash['state_expectation']}' instead of '#{transaction.get_next_expectation}' for ongoing transaction." 
    1369           # TODO 
    1370           # clean up???? 
    1371           return false 
    1372         end 
    1373  
    1374         ########################################### 
    1375         # the commands below are related to: 
    1376         # SENDING ebXML MESSAGES 
    1377         # --> includes receiving a directive first 
    1378         ########################################### 
    1379       elsif command == 'new directive' then 
    1380         @logger.debug "Received new directive!" 
    1381         # process this new directive command. this includes to send an ebXML message 
    1382         result = process_new_directive command, command_hash, transaction 
    1383         if result == false then 
    1384           @logger.error "Error processing directive." 
    1385           transaction.close_transaction('failed', "Failed to process Directive.") 
    1386           return false 
    1387         else 
    1388           return true 
    1389         end 
    1390  
    1391       elsif command.strip == 'send ebXML message done' then 
    1392         @logger.debug "Sending ebXML message done." 
    1393         @logger.debug "Response file: #{command_hash['response_file_path']}" 
    1394         if command_hash['state_expectation'] == transaction.get_next_expectation then 
    1395           @logger.debug "YES. Expected transition to #{transaction.get_next_expectation}" 
    1396           if command_hash['status'] == "FAILED" then 
    1397             @logger.warn "Error sending the ebXML message. Message sending failed. Reason: #{command_hash['reason']}" 
    1398             transaction.transition_to_new_state "ebXML message failed to send" 
    1399             transaction.attach_file command_hash['transfer_info_path'], "transfer information" if command_hash['transfer_info_path'] 
    1400             transaction.remember_file_to_remove command_hash['transfer_info_path'] if command_hash['transfer_info_path'] 
    1401             transaction.close_transaction('failed', command_hash['reason']) 
    1402             return true 
    1403           end 
    1404  
    1405           @logger.debug "Transitioning to new state" 
    1406           transaction.transition_to_new_state "ebXML message sent" 
    1407           transaction.attach_file command_hash['response_file_path'], "outgoing ebXML message response" 
    1408           transaction.remember_file_to_remove command_hash['response_file_path'] 
    1409           transaction.attach_file command_hash['transfer_info_path'], "transfer information" if command_hash['transfer_info_path'] 
    1410           transaction.remember_file_to_remove command_hash['transfer_info_path'] if command_hash['transfer_info_path'] 
    1411            
    1412           ######################### 
    1413           ## process reponse 
    1414           ## will be factored out! 
    1415           ######################### 
    1416  
    1417           begin 
    1418             @logger.debug "Creating an ebXML message object from the received ebXML message" 
    1419             ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.new @config, command_hash['response_file_path'] 
    1420           rescue Exception => e 
    1421             message = "It is not possible to create an ebXML Message object from the ebXML message response to a outgoing ebXML message: #{e.to_s}" 
    1422             @logger.warn message 
    1423             # HACK ALERT! 
    1424             if File.read(command_hash['response_file_path']).to_s.strip.to_s == '200' then 
    1425               @logger.debug "Received HTTP 200 OK" 
    1426               transaction.close_transaction('succeeded', message) 
    1427               return true 
    1428             else 
    1429               @logger.warn File.read(command_hash['response_file_path']).to_s 
    1430               transaction.close_transaction('failed', message) 
    1431               # HACK is this right? 
    1432               return false 
    1433             end 
    1434           end   
    1435            
    1436           # VALIDATION 
    1437           # TODO more to validation. 
    1438  
    1439           ok, ebMS_info, reason = validate_ebXML_message command_hash, ebMS_message 
    1440           if ok.nil? or ok == false then 
    1441             message = "Based on the ebXML CPA it is not possible to receive such an ebXML message (#{ebMS_message.summary})." 
    1442             @logger.warn message 
    1443             transaction.close_transaction('failed', message) 
    1444             return true 
    1445           end 
    1446           @logger.debug "The CPA confirms that it is possible to recive such an ebXML message." 
    1447           @logger.debug "Short ebXML message summary: #{ebMS_message.summary}" 
    1448            
    1449           b2b_system = @b2b_systems[command_hash['b2b_system_name']] 
    1450           if ebMS_message.is_pong? then 
    1451             HefeWeizen::HefeWeizenLibrary::HefeWeizenDirective.create_ping_pong_directive_and_save b2b_system.get_incoming_directive_directory, ebMS_message.cpa_id 
    1452             transaction.transition_to_new_state "Pong information sent to integration point." 
    1453             @logger.debug "Successfully processed ebXML message response" 
    1454           elsif ebMS_message.is_ack? then 
    1455              
    1456             # CONTINUE HERE 
    1457             # CONTINUE HERE 
    1458             # CONTINUE HERE 
    1459             # CONTINUE HERE 
    1460              
    1461           else 
    1462             message = "Unknonw ebMS_message response: #{ebMS_message.summary}" 
    1463             @logger.warn message. 
    1464             transaction.close_transaction('failed', message) 
    1465             return true 
    1466           end 
    1467  
    1468           # check it is NOT empty for example ... if empty. fail the transaction. 
    1469           transaction.close_transaction('succeeded', "All done. Life is good.") 
    1470  
    1471           return true 
    1472         else 
    1473           @logger.error "Unexpected transition to '#{command_hash['state_expectation']}' instead of '#{transaction.get_next_expectation}' for ongoing transaction." 
    1474           # TODO 
    1475           # clean up???? 
    1476           return false 
    1477         end 
    1478       else 
    1479         @logger.warn "Unknown Command. Pass command on to next command processing." 
    1480         return false 
    1481       end 
    1482  
    1483       return false 
    1484     end 
    1485  
    1486      
    1487     # This method handles a new directive. 
    1488     # --> includes the creation of a new HefeWeizenDirective object.  
    1489     def process_new_directive command, command_hash, transaction 
    1490       if transaction.is_open? and transaction.get_current_state_name == "new" then 
    1491         @logger.debug "This is a new and open transaction." 
    1492         begin 
    1493           directive = HefeWeizen::HefeWeizenLibrary::HefeWeizenDirective.new(@config, command_hash['file']) 
    1494         rescue Exception => e 
    1495           error = "Unable to process Directive: #{e.to_s}" 
    1496           @logger.warn error 
    1497           # do compensation/rollback 
    1498           transaction.remember_file_to_remove command_hash['file'] 
    1499           transaction.close_transaction("failed", "Unable to process Directive") 
    1500           return true 
    1501         end 
    1502  
    1503         # @logger.debug "Directive successfully read" 
    1504         # directive.print_directive_tags 
    1505         # @logger.debug "The directive is a ebMS signal: #{directive.is_a_ebMS_signal?.to_s}" 
    1506          
    1507         # This is a new transaction so we have to set the root cause of this new transaction. 
    1508         if !transaction.set_root_cause directive then 
    1509           @logger.error "Unable to store the directive as root cause to the new transaction" 
    1510           return false 
    1511         else 
    1512           @logger.debug "Succesfully stored the directive as root cause" 
    1513         end 
    1514          
    1515         b2b_system = @b2b_systems[command_hash['b2b_system_name']] 
    1516         if b2b_system.nil? then 
    1517           @logger.warn "There is no B2B system with the name #{command_hash['b2b_system_name']}." 
    1518           return false 
    1519         end 
    1520          
    1521         if !b2b_system.supports_directive? directive then 
    1522           @logger.warn "B2BSystem #{b2b_system.system_name} does not support the directive." 
    1523           return false 
    1524         end 
    1525          
    1526         # get the ebXML Message information 
    1527         # this will hold all the required information about what has to be 
    1528         # in the ebXML message plus how it has to be sent. 
    1529         ebMS_message_info = b2b_system.get_ebMS_message_info directive 
    1530         if ebMS_message_info.nil? then 
    1531           @logger.error "CPA Manager could not provide a valid ebXML Message information." 
    1532           return false 
    1533         end 
    1534          
    1535         # CREATE ebXML MESSAGE 
    1536         # -------------------- 
    1537         # potential for a tasker 
    1538         @logger.debug "Creating ebXML message" 
    1539         ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.create_message @config, directive, ebMS_message_info 
    1540         if ebMS_message.nil? then 
    1541           @logger.error "Error creating ebXML message" 
    1542           return false 
    1543         end 
    1544         @logger.debug "Successfully created ebXML message object: #{ebMS_message.summary}" 
    1545          
    1546         # ENCRYPT ebXML MESSAGE IF REQUIRED 
    1547         # --------------------------------- 
    1548         # --> not implemented yet 
    1549         # will be a tasker 
    1550          
    1551         # SIGN ebXML MESSAGE IF REQUIRED 
    1552         # ------------------------------ 
    1553         # --> not implemented yet 
    1554         # will be a tasker 
    1555  
    1556         # create an ebXML message file 
    1557         ebXML_message_file_path = ebMS_message.create_ebXML_message_file 
    1558         if ebXML_message_file_path.nil? then 
    1559           @logger.error "Unable to create ebXML message file." 
    1560           return false 
    1561         end 
    1562          
    1563         transaction.attach_file ebXML_message_file_path, "outgoing ebXML message" 
    1564         transaction.remember_file_to_remove ebXML_message_file_path 
    1565          
    1566         # create an ebXML message parameters file 
    1567         ebXML_message_parameters_file_path = ebMS_message.create_ebXML_message_parameters_file ebMS_message_info, ebMS_message.is_multipart? 
    1568         if ebXML_message_parameters_file_path.nil? then 
    1569           @logger.error "Unable to create ebXML message parameters file." 
    1570           return false 
    1571         end 
    1572          
    1573         transaction.attach_file ebXML_message_parameters_file_path, "outgoing ebXML message parameters" 
    1574         transaction.remember_file_to_remove ebXML_message_parameters_file_path 
    1575          
    1576         # SEND ebXML MESSAGE 
    1577         # ------------------ 
    1578         if ebMS_message_info['info']['transport-protocol-name'].upcase == "HTTP" then 
    1579           expectation = "send_ebXML_message_done" 
    1580           command_hash = { 
    1581             "from" => "big_ania",  
    1582             "to" => "ania",  
    1583             "command" => "start_tasker", 
    1584             "tasker" => "#{@config['BIN_DIR']}/hefeweizen_tasker_application_send_ebXML_message_http.rb", 
    1585             "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}", 
    1586             "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    1587           } 
    1588         elsif ebMS_message_info['info']['transport-protocol-name'].upcase == "SMTP" then 
    1589           @logger.error "Message expected to be sent via SMTP but SMTP is not yet implemented." 
    1590           return false 
    1591         else 
    1592           @logger.error "Message expected to be sent via #{ebMS_message_info['info']['transport-protocol-name']} which is unknwn and not supported." 
    1593           return false 
    1594         end 
    1595  
    1596         @logger.debug "Call tasker to send ebXML message." 
    1597         say_to_ania "#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command command_hash}" 
    1598          
    1599         # SET EXPECTED NEW STATE 
    1600         transaction.set_next_expectation(expectation) 
    1601          
    1602         return true 
    1603       else 
    1604         @logger.error "Error unexpected transaction for new directive." 
    1605         return false 
    1606       end 
    1607     end 
    1608      
    1609     # This method processes a new incoming ebXML message. 
    1610     # todo 
    1611     # we have to determine wether it is  
    1612     # o a request ebXML message or 
    1613     # o a response ebXML message to a request message 
    1614     def process_new_ebXML_message command, command_hash, transaction 
    1615       @logger.debug "Reading received ebXML message." 
    1616       ebMS_message_header = File.read(command_hash['file_header'])  
    1617        
    1618       # setting root cause of this new transaction. 
    1619       transaction.set_root_cause command_hash['file_full'] 
    1620        
    1621       # maybe stuff this into ebMS class 
    1622       if !(ebMS_message_header =~ /^.*SOAPAction: ebXML.*$/ or ebMS_message_header =~ /.*SOAPAction: \"ebXML\".*/) then 
    1623         msg = "Received a message but the received message does not have a \"SOAPAction: ebXML\" HTTP header, so it is not an ebXML message." 
    1624         @logger.info msg 
    1625         transaction.remember_file_to_remove [command_hash['file_full'], command_hash['file_body'], command_hash['file_header']] 
    1626         send_error "Bad Request", transaction, command_hash 
    1627         transaction.close_transaction('failed',  msg) 
    1628         return true 
    1629       else 
    1630         @logger.debug "HTTP header indicates that it is an ebXML message." 
    1631       end 
    1632        
    1633       # DUPLICATE! ok for now. -> add link_to in transaction class 
    1634       transaction.attach_file command_hash['file_full'], "incoming ebXML message" 
    1635  
    1636       transaction.remember_file_to_remove command_hash['file_full'] 
    1637       transaction.remember_file_to_remove command_hash['file_body'] 
    1638       transaction.remember_file_to_remove command_hash['file_header'] 
    1639        
    1640       begin 
    1641         @logger.debug "Creating an ebXML message object from the received ebXML message. Provides basic ebXML message parsing." 
    1642         ebMS_message = HefeWeizen::HefeWeizenLibrary::EBMSMessage.new @config, command_hash['file_full'], true 
    1643         @logger.debug "Successfully created ebXML message object: #{ebMS_message.summary}" 
    1644       rescue Exception => e 
    1645         msg = "It is not possible to create an ebXML Message object from the incoming ebXML message: #{e.to_s}" 
    1646         @logger.warn msg 
    1647         send_error "Bad Request", transaction, command_hash 
    1648         transaction.close_transaction('failed',  msg) 
    1649         return true 
    1650       end   
    1651        
    1652       # from here on we have to send back ebXML error messages. 
    1653  
    1654       # in order to capture all errors we keep continuing here but keep there 
    1655       # errors. Than at the end if there have been any errors we simply send 
    1656       # the errors back but not the created response message (if there is any). 
    1657  
    1658       # check if it is OK to receive such a message 
    1659       ok, ebMS_info, validation_errors = validate_ebXML_message command_hash, ebMS_message 
    1660       if ok.nil? or ok == false then 
    1661         msg = "Based on ebXML CPA it is not possible to receive this ebXML message(#{ebMS_message.summary})" 
    1662         msg += validation_errors.join("\n") 
    1663         @logger.warn msg 
    1664       else 
    1665         @logger.debug "The CPA confirms that it is possible to recive such an ebXML message." 
    1666         @logger.debug "Short ebXML message summary: #{ebMS_message.summary}" 
    1667       end 
    1668        
    1669       # CONTINUE HERE 
    1670       # if combining receiving and sending ebXML message then add here: 
    1671       # if response required then  
    1672       #    ..... 
    1673       # else 
    1674       #    ok we are done. 
    1675       # end 
    1676  
    1677       ############################################### 
    1678       ## creating an ebXML response message 
    1679       ## -> this can be an ERROR message 
    1680       ## -> this can be a HTTP 204 OK 
    1681       ## -> this can be a ebMS signal 
    1682       ## ---> this can be a ebMS signal (ACK) including 
    1683       ##      a response payload (not implemented) 
    1684       ############################################### 
    1685        
    1686       if validation_errors and !validation_errors.empty? then 
    1687         @logger.warn "There are validation errors. We are creating an ebXML error message." 
    1688         error_message = ebMS_message.create_error_message validation_errors 
    1689         send_error_response error_message, transaction, command_hash 
    1690  
    1691         # must have a new expected state to have error message sent! 
    1692         # ???? transaction.close_transaction('failed',  msg) 
    1693         return true 
    1694       end 
    1695  
    1696       response_file_name = create_ebXML_response ebMS_info, ebMS_message, command_hash, transaction 
    1697        
    1698       if response_file_name == false or response_file_name == true then 
    1699         return response_file_name 
    1700       end 
    1701        
    1702       # check syncmode here! 
    1703       # do we need to close a previous connection or can we use it for the response? 
    1704  
    1705       # CONTINUE HERE 
    1706       # CONTINUE HERE 
    1707       # CONTINUE HERE 
    1708       # CONTINUE HERE 
    1709       # CONTINUE HERE 
    1710       # CONTINUE HERE 
    1711       # CONTINUE HERE 
    1712  
    1713       instruction_pipe = command_hash['pipe_for_instructions'] 
    1714       transaction.attach_file response_file_name, "incoming ebXML message response" 
    1715       transaction.remember_file_to_remove response_file_name 
    1716        
    1717       # SET EXPECTED NEW STATE 
    1718       expectation = "send ebXML message response done" 
    1719       transaction.set_next_expectation(expectation) 
    1720        
    1721       @logger.debug "Sending command to send the ebXML response message." 
    1722       command_to_http_server = { 
    1723         "from" => "big_ania",  
    1724         "to" => "http server",  
    1725         "response_file_name" => response_file_name, 
    1726         "transaction_id" => transaction.transaction_id, 
    1727         "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    1728       } 
    1729        
    1730       command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 
    1731       system command 
    1732        
    1733       return true 
    1734  
    1735     end 
    1736  
    1737     # This method creates an appropriate response ebXML message 
    1738     def create_ebXML_response ebMS_info, ebMS_message, command_hash, transaction 
    1739        
    1740       if ebMS_message.is_ebMS_signal? then 
    1741          
    1742         if ebMS_message.is_ping? then 
    1743           @logger.debug "Received an ebXML ping message. Creating an ebXML pong message." 
    1744           # here are two ways possible 
    1745           # a) create a brand new pong from the CPA 
    1746           # b) create a ping cloned pong 
    1747            
    1748           # using b) variant first 
    1749           response = ebMS_message.create_pong 
    1750           response_file_name = response.create_ebXML_message_file 
    1751         elsif ebMS_message.is_status_request? then 
    1752             @logger.warn "Received an ebXML Status Request message. An ebXML Status Request Response is not yet implemented." 
    1753           response_file_name = create_error_response 
    1754            
    1755           # TODO implement error message 
    1756           # elsif ebMS_message.is_error_message? then 
    1757         else 
    1758           msg = "Unknow ebXML Message Signal: #{ebMS_message.summary}" 
    1759           @logger.warn msg 
    1760           send_error "Bad Request", transaction, command_hash 
    1761           transaction.close_transaction('failed',  msg) 
    1762           return true 
    1763         end 
    1764          
    1765       else 
    1766          
    1767         # it is a user message so we have to produce the directive. 
    1768         b2b_system = @b2b_systems[command_hash['b2b_system_name']] 
    1769         path = HefeWeizen::HefeWeizenLibrary::HefeWeizenDirective.create_user_message_directive_and_save( b2b_system.get_incoming_directive_directory,  
    1770                                                                                                           b2b_system.get_incoming_payloads_directory,  
    1771                                                                                                           ebMS_message) 
    1772         transaction.transition_to_new_state "Receiving ebXML message information sent to integration point." 
    1773         @logger.debug "Created incoming directive at : #{path}" 
    1774          
    1775         # AckRequested is a Reliale Messaging Feature 
    1776         if ebMS_message.ack_requested? and (ebMS_info['info']['mc-ackRequested'] == 'always' or ebMS_info['info']['mc-ackRequested'] == 'perMessage' ) then 
    1777           @logger.debug "Received ebXML message requires to send an Acknowledgment" 
    1778           response = ebMS_message.create_ack 
    1779           if response.nil? then 
    1780             msg = "Error creating response acknowledgment." 
    1781             @logger.warn msg 
    1782             send_error "Bad Request", transaction, command_hash 
    1783             transaction.close_transaction('failed',  msg) 
    1784             return true 
    1785           end 
    1786           @logger.debug "Successfully created response message." 
    1787           response_file_name = response.create_ebXML_message_file 
    1788         elsif ebMS_message.ack_requested? and ebMS_info['info']['mc-ackRequested'] == 'never' then 
    1789           msg = "ebMS message requires ack but CPA says no." 
    1790           @logger.warn msg 
    1791           send_error "Bad Request", transaction, command_hash 
    1792           transaction.close_transaction('failed',  msg) 
    1793           return true 
    1794         else 
    1795           @logger.debug "Received ebXML message does not require to send an Acknowledgment" 
    1796           response_file_name = create_204_ok_response 
    1797         end 
    1798       end 
    1799     end 
    1800        
    1801     def send_error reason, transaction, command_hash 
    1802       if command_hash['transport_protocol'] == "HTTP" then 
    1803         error_code = nil 
    1804         if reason == "Bad Request" then 
    1805           error_code = 400 
    1806         else 
    1807           error_code = 400 
    1808         end 
    1809         command_to_http_server = { 
    1810           "from" => "big_ania",  
    1811           "to" => "http server",  
    1812           "close_connection_with_code" => error_code, 
    1813           "transaction_id" => transaction.transaction_id, 
    1814           "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    1815         } 
    1816         command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{command_hash['pipe_for_instructions']}" 
    1817         system command 
    1818       else 
    1819         # SMTP transport protocol has already a closed connection. Nothing to do. 
    1820       end 
    1821     end 
    1822  
    1823     def send_error_response response_file_name, transaction, instruction_pipe 
    1824       command_to_http_server = { 
    1825         "from" => "big_ania",  
    1826         "to" => "http server",  
    1827         "response_file_name" => response_file_name, 
    1828         "transaction_id" => transaction.transaction_id, 
    1829         "uuid" => HefeWeizen::HefeWeizenLibrary::HefeWeizenUUID.uuid 
    1830       } 
    1831       command = "echo \"#{HefeWeizen::HefeWeizenLibrary::HefeWeizenCommand.hash_to_command(command_to_http_server)}\" > #{instruction_pipe}" 
    1832       system command 
    1833  
    1834     end 
    1835  
    1836     def create_204_ok_response 
    1837       response = %{ 
    1838 200 
    1839 } 
    1840       time = Time.now.to_f.to_s 
    1841       response_file_name = "#{@config['TEMP_FILE_DIR']}/incoming_ebXML_message_response_#{time}" 
    1842       file = File.new(response_file_name, "w") 
    1843       file.sync = true 
    1844       file << response 
    1845       file.close 
    1846       return response_file_name 
    1847     end 
    1848  
    1849  
    1850     def create_error_response 
    1851       response = %{ 
    1852 <html> 
    1853 <body> 
    1854 <h1>HefeWeizen HTTP Server</h1> 
    1855 <p>Time: #{Time.now}</p 
    1856 <p>This is a respose created by big_ania</p> 
    1857 <p>This is a respose created by big_ania</p> 
    1858