Search in sources :

Example 1 with DefaultTxDetailParser

use of org.nhindirect.common.tx.impl.DefaultTxDetailParser in project nhin-d by DirectProject.

the class TxUtil method isReliableAndTimelyRequested.

/**
	 * Determines if the message is requesting timely and reliable delivery.  This is determined by 
     * the existence of the X-DIRECT-FINAL-DESTINATION-DELIVERY message disposition option on the original message.
	 * @param msg The message that is being inspected for timely and reliable messaging.
	 * @return true if the original message indicates that it requires timely and reliable delivery; false otherwise
	 */
public static boolean isReliableAndTimelyRequested(MimeMessage msg) {
    if (msg == null)
        return false;
    final TxDetailParser parser = new DefaultTxDetailParser();
    final Map<String, TxDetail> details = parser.getMessageDetails(msg);
    final Tx tx = new Tx(getMessageType(msg), details);
    return isReliableAndTimelyRequested(tx);
}
Also used : Tx(org.nhindirect.common.tx.model.Tx) TxDetail(org.nhindirect.common.tx.model.TxDetail) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser)

Example 2 with DefaultTxDetailParser

use of org.nhindirect.common.tx.impl.DefaultTxDetailParser in project nhin-d by DirectProject.

the class MockTxsResource method supressNotification.

@Path("suppressNotification")
@TypeHint(Boolean.class)
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response supressNotification(Tx notificationMessage) {
    Boolean retEntity = Boolean.TRUE;
    final String originalMessageId = SuppressNotificationRequest.getOriginalMessageId(notificationMessage, new DefaultTxDetailParser());
    if (originalMessageId.isEmpty() || originalMessageId.equals("NotNotification")) {
        retEntity = Boolean.FALSE;
    }
    return Response.ok(retEntity).build();
}
Also used : DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Path(javax.ws.rs.Path) TypeHint(org.codehaus.enunciate.jaxrs.TypeHint) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 3 with DefaultTxDetailParser

use of org.nhindirect.common.tx.impl.DefaultTxDetailParser in project nhin-d by DirectProject.

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject.

@Test
public void testGenerateDSNFailureMessage_assertMessageCreated_noCopiedSubject() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    String message = TestUtils.readMessageFromFile("MessageWithAttachment.txt");
    DefaultTxDetailParser parser = new DefaultTxDetailParser();
    InputStream str = IOUtils.toInputStream(message);
    try {
        // send original message
        final MimeMessage mimeMessage = new MimeMessage(null, str);
        mimeMessage.setHeader(MailStandard.Headers.Subject, "");
        // change the message id
        mimeMessage.saveChanges();
        Map<String, TxDetail> details = parser.getMessageDetails(mimeMessage);
        Tx originalMessage = new Tx(TxMessageType.IMF, details);
        Collection<Tx> txs = new ArrayList<Tx>();
        txs.add(originalMessage);
        DSNMessageGenerator generator = createGenerator();
        generator.generateDSNFailureMessage(txs, exchange);
        MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
        assertNotNull(dsnMessage);
        // check the subject
        String newSubject = MailStandard.getHeader(dsnMessage, MailStandard.Headers.Subject);
        assertEquals("Not Delivered:", newSubject);
    } finally {
        IOUtils.closeQuietly(str);
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) InputStream(java.io.InputStream) TxDetail(org.nhindirect.common.tx.model.TxDetail) ArrayList(java.util.ArrayList) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Example 4 with DefaultTxDetailParser

use of org.nhindirect.common.tx.impl.DefaultTxDetailParser in project nhin-d by DirectProject.

the class TestNonReliableMessageMonitorRoute method testSingleRecipMDNReceived_readFromMessages_assertConditionComplete.

@Test
public void testSingleRecipMDNReceived_readFromMessages_assertConditionComplete() throws Exception {
    final DefaultTxDetailParser parser = new DefaultTxDetailParser();
    final Map<String, TxDetail> imfDetails = parser.getMessageDetails(TestUtils.readMimeMessageFromFile("MessageFromCernerToAthena.txt"));
    final Map<String, TxDetail> mdnDetails = parser.getMessageDetails(TestUtils.readMimeMessageFromFile("MDNFromAthenaToCerner"));
    MockEndpoint mock = getMockEndpoint("mock:result");
    // send original message
    Tx originalMessage = new Tx(TxMessageType.IMF, imfDetails);
    template.sendBody("direct:start", originalMessage);
    // send MDN to original message
    Tx mdnMessage = new Tx(TxMessageType.MDN, mdnDetails);
    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) TxDetail(org.nhindirect.common.tx.model.TxDetail) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Test(org.junit.Test)

Example 5 with DefaultTxDetailParser

use of org.nhindirect.common.tx.impl.DefaultTxDetailParser in project nhin-d by DirectProject.

the class DSNMessageGenerator_generateDSNFailureMessageTest method testGenerateDSNFailureMessage_assertMessageCreated.

@Test
public void testGenerateDSNFailureMessage_assertMessageCreated() throws Exception {
    Exchange exchange = new DefaultExchange(mock(CamelContext.class));
    String message = TestUtils.readMessageFromFile("MessageWithAttachment.txt");
    DefaultTxDetailParser parser = new DefaultTxDetailParser();
    InputStream str = IOUtils.toInputStream(message);
    try {
        // send original message
        final MimeMessage mimeMessage = new MimeMessage(null, str);
        // change the message id
        mimeMessage.saveChanges();
        Map<String, TxDetail> details = parser.getMessageDetails(mimeMessage);
        Tx originalMessage = new Tx(TxMessageType.IMF, details);
        Collection<Tx> txs = new ArrayList<Tx>();
        txs.add(originalMessage);
        DSNMessageGenerator generator = createGenerator();
        generator.generateDSNFailureMessage(txs, exchange);
        MimeMessage dsnMessage = (MimeMessage) exchange.getIn().getBody();
        assertNotNull(dsnMessage);
        // check the subject
        String newSubject = MailStandard.getHeader(dsnMessage, MailStandard.Headers.Subject);
        assertTrue(newSubject.contains(MailStandard.getHeader(mimeMessage, MailStandard.Headers.Subject)));
        // check for the original message id in the in-reply-to
        String originalMessageId = MailStandard.getHeader(dsnMessage, MailStandard.Headers.InReplyTo);
        assertEquals(MailStandard.getHeader(mimeMessage, MailStandard.Headers.MessageID), originalMessageId);
    } finally {
        IOUtils.closeQuietly(str);
    }
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) CamelContext(org.apache.camel.CamelContext) Tx(org.nhindirect.common.tx.model.Tx) InputStream(java.io.InputStream) TxDetail(org.nhindirect.common.tx.model.TxDetail) ArrayList(java.util.ArrayList) DefaultTxDetailParser(org.nhindirect.common.tx.impl.DefaultTxDetailParser) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Aggregations

DefaultTxDetailParser (org.nhindirect.common.tx.impl.DefaultTxDetailParser)5 Tx (org.nhindirect.common.tx.model.Tx)4 TxDetail (org.nhindirect.common.tx.model.TxDetail)4 Exchange (org.apache.camel.Exchange)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 MimeMessage (javax.mail.internet.MimeMessage)2 CamelContext (org.apache.camel.CamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 TypeHint (org.codehaus.enunciate.jaxrs.TypeHint)1