| 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 | | |
|---|