Search in sources :

Example 91 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TxsResource_addTxTest method testAddTx_nullTemplate_assertExcecption.

@Test
public void testAddTx_nullTemplate_assertExcecption() {
    Tx tx = mock(Tx.class);
    TxsResource resource = new TxsResource(null, null);
    boolean exceptionOccured = false;
    try {
        resource.addTx(tx);
    } catch (IllegalStateException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) Test(org.junit.Test)

Example 92 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TestFilterNonCompletedExchangesMonitorRoute method testTimeoutReliableMessage_conditionComplete_assertMessageMovedForware.

@Test
public void testTimeoutReliableMessage_conditionComplete_assertMessageMovedForware() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // send MDN processed to original message
    Tx mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Processed);
    template.sendBody("direct:start", mdnMessage);
    // send MDN dispatched to original message
    mdnMessage = TestUtils.makeReliableMessage(TxMessageType.MDN, UUID.randomUUID().toString(), originalMessageId, "gm2552@direct.securehealthemail.com", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", MDNStandard.Disposition_Dispatched);
    template.sendBody("direct:start", mdnMessage);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    assertEquals(1, exchanges.size());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 93 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TestFilterNonCompletedExchangesMonitorRoute method testTimeoutReliableMessage_conditionNotComplete_assertFilteredOut.

@Test
public void testTimeoutReliableMessage_conditionNotComplete_assertFilteredOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    final String originalMessageId = UUID.randomUUID().toString();
    Tx originalMessage = TestUtils.makeReliableMessage(TxMessageType.IMF, originalMessageId, "", "gm2552@cerner.com", "gm2552@direct.securehealthemail.com", "", "", "");
    template.sendBody("direct:start", originalMessage);
    // no MDN sent... messages should timeout after 2 seconds
    // sleep 3 seconds to make sure it completes
    Thread.sleep(3000);
    List<Exchange> exchanges = mock.getReceivedExchanges();
    // this message should be removed out by the completion filter
    assertEquals(0, exchanges.size());
}
Also used : Exchange(org.apache.camel.Exchange) Tx(org.nhindirect.common.tx.model.Tx) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 94 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet method service.

/**
	 * {@inheritDoc}
	 */
@SuppressWarnings("unchecked")
@Override
public void service(Mail mail) throws MessagingException {
    GatewayState.getInstance().lockForProcessing();
    try {
        Tx txToMonitor = null;
        LOGGER.trace("Entering service(Mail mail)");
        onPreprocessMessage(mail);
        final MimeMessage msg = mail.getMessage();
        final NHINDAddressCollection recipients = getMailRecipients(mail);
        // get the sender
        final NHINDAddress sender = getMailSender(mail);
        LOGGER.info("Proccessing incoming message from sender " + sender.toString());
        MessageProcessResult result = null;
        final boolean isOutgoing = this.isOutgoing(msg, sender);
        // gathered now before the message is transformed
        if (isOutgoing)
            txToMonitor = getTxToTrack(msg, sender, recipients);
        // recipients can get modified by the security and trust agent, so make a local copy
        // before processing
        final NHINDAddressCollection originalRecipList = NHINDAddressCollection.create(recipients);
        try {
            // process the message with the agent stack
            LOGGER.trace("Calling agent.processMessage");
            result = agent.processMessage(msg, recipients, sender);
            LOGGER.trace("Finished calling agent.processMessage");
            if (result == null) {
                LOGGER.error("Failed to process message.  processMessage returned null.");
                onMessageRejected(mail, originalRecipList, sender, isOutgoing, txToMonitor, null);
                mail.setState(Mail.GHOST);
                LOGGER.trace("Exiting service(Mail mail)");
                return;
            }
        } catch (Exception e) {
            // catch all
            LOGGER.error("Failed to process message: " + e.getMessage(), e);
            onMessageRejected(mail, originalRecipList, sender, isOutgoing, txToMonitor, e);
            mail.setState(Mail.GHOST);
            LOGGER.trace("Exiting service(Mail mail)");
            return;
        }
        if (result.getProcessedMessage() != null) {
            mail.setMessage(result.getProcessedMessage().getMessage());
        } else {
            /*
				 * TODO: Handle exception... GHOST the message for now and eat it
				 */
            LOGGER.debug("Processed message is null.  GHOST and eat the message.");
            onMessageRejected(mail, recipients, sender, null);
            mail.setState(Mail.GHOST);
            return;
        }
        // remove reject recipients from the RCTP headers
        if (result.getProcessedMessage().getRejectedRecipients() != null && result.getProcessedMessage().getRejectedRecipients().size() > 0 && mail.getRecipients() != null && mail.getRecipients().size() > 0) {
            final Collection<MailAddress> newRCPTList = new ArrayList<MailAddress>();
            for (MailAddress rctpAdd : (Collection<MailAddress>) mail.getRecipients()) {
                if (!isRcptRejected(rctpAdd, result.getProcessedMessage().getRejectedRecipients())) {
                    newRCPTList.add(rctpAdd);
                }
            }
            mail.setRecipients(newRCPTList);
        }
        /*
			 * Handle sending MDN messages
			 */
        final Collection<NotificationMessage> notifications = result.getNotificationMessages();
        if (notifications != null && notifications.size() > 0) {
            LOGGER.info("MDN messages requested.  Sending MDN \"processed\" messages");
            // create a message for each notification and put it on James "stack"
            for (NotificationMessage message : notifications) {
                try {
                    this.getMailetContext().sendMail(message);
                } catch (Throwable t) {
                    // don't kill the process if this fails
                    LOGGER.error("Error sending MDN message.", t);
                }
            }
        }
        // track message
        trackMessage(txToMonitor, isOutgoing);
        onPostprocessMessage(mail, result, isOutgoing, txToMonitor);
        LOGGER.trace("Exiting service(Mail mail)");
    } finally {
        GatewayState.getInstance().unlockFromProcessing();
    }
}
Also used : MailAddress(org.apache.mailet.MailAddress) Tx(org.nhindirect.common.tx.model.Tx) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) ArrayList(java.util.ArrayList) MessageProcessResult(org.nhindirect.gateway.smtp.MessageProcessResult) MessagingException(javax.mail.MessagingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) NHINDAddress(org.nhindirect.stagent.NHINDAddress) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) Collection(java.util.Collection) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection)

Example 95 with Tx

use of org.nhindirect.common.tx.model.Tx in project nhin-d by DirectProject.

the class TimelyAndReliableLocalDelivery method service.

/**
	 * {@inheritDoc}
	 */
@Override
public void service(Mail mail) throws MessagingException {
    LOGGER.debug("Calling timely and reliable service method.");
    boolean deliverySuccessful = false;
    final MimeMessage msg = mail.getMessage();
    final boolean isReliableAndTimely = TxUtil.isReliableAndTimelyRequested(msg);
    final NHINDAddressCollection recipients = getMailRecipients(mail);
    final NHINDAddress sender = getMailSender(mail);
    try {
        serviceMethod.invoke(localDeliveryMailet, mail);
        deliverySuccessful = true;
    } catch (Exception e) {
        LOGGER.error("Failed to invoke service method.", e);
    }
    final Tx txToTrack = this.getTxToTrack(msg, sender, recipients);
    if (deliverySuccessful) {
        if (isReliableAndTimely && txToTrack.getMsgType() == TxMessageType.IMF) {
            // send back an MDN dispatched message
            final Collection<NotificationMessage> notifications = notificationProducer.produce(new Message(msg), recipients.toInternetAddressCollection());
            if (notifications != null && notifications.size() > 0) {
                LOGGER.debug("Sending MDN \"dispatched\" messages");
                // create a message for each notification and put it on James "stack"
                for (NotificationMessage message : notifications) {
                    try {
                        message.saveChanges();
                        if (dispatchedMDNDelay > 0)
                            Thread.sleep(dispatchedMDNDelay);
                        getMailetContext().sendMail(message);
                    }///CLOVER:OFF
                     catch (Throwable t) {
                        // don't kill the process if this fails
                        LOGGER.error("Error sending MDN dispatched message.", t);
                    }
                ///CLOVER:ON
                }
            }
        }
    } else {
        // create a DSN message regarless if timely and reliable was requested
        if (txToTrack != null && txToTrack.getMsgType() == TxMessageType.IMF)
            this.sendDSN(txToTrack, recipients, false);
    }
    LOGGER.debug("Exiting timely and reliable service method.");
}
Also used : NHINDAddress(org.nhindirect.stagent.NHINDAddress) Tx(org.nhindirect.common.tx.model.Tx) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) Message(org.nhindirect.stagent.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) NotificationMessage(org.nhindirect.stagent.mail.notifications.NotificationMessage) MimeMessage(javax.mail.internet.MimeMessage) NHINDAddressCollection(org.nhindirect.stagent.NHINDAddressCollection) MessagingException(javax.mail.MessagingException)

Aggregations

Tx (org.nhindirect.common.tx.model.Tx)174 Test (org.junit.Test)156 Exchange (org.apache.camel.Exchange)83 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)49 TxDetail (org.nhindirect.common.tx.model.TxDetail)35 DefaultExchange (org.apache.camel.impl.DefaultExchange)32 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)19 MimeMessage (javax.mail.internet.MimeMessage)17 CamelContext (org.apache.camel.CamelContext)17 ConcurrentJPAAggregationRepository (org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository)15 TxCompletionCondition (org.nhindirect.monitor.condition.TxCompletionCondition)14 TxTimeoutCondition (org.nhindirect.monitor.condition.TxTimeoutCondition)8 Collection (java.util.Collection)7 NotificationDuplicationDAO (org.nhindirect.monitor.dao.NotificationDuplicationDAO)7 NHINDAddress (org.nhindirect.stagent.NHINDAddress)6 NHINDAddressCollection (org.nhindirect.stagent.NHINDAddressCollection)6 Response (javax.ws.rs.core.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 MessagingException (javax.mail.MessagingException)4