Search in sources :

Example 26 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class AggregatingJmsConsumeServiceTest method testService_MultipleMessages.

@Test
public void testService_MultipleMessages() throws Exception {
    AggregatingQueueConsumer consumer = new AggregatingQueueConsumer();
    consumer.setMessageAggregator(new IgnoreOriginalMimeAggregator());
    AggregatingJmsConsumeService service = createService(activeMqBroker, consumer, getName());
    try {
        sendDataMessage(activeMqBroker, getName());
        sendDataMessage(activeMqBroker, getName());
        start(service);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(PAYLOAD);
        msg.addMetadata(DEFAULT_FILTER_KEY, "JMSCorrelationID = '0001'");
        service.doService(msg);
        BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
        assertEquals(2, input.size());
    } finally {
        stop(service);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) IgnoreOriginalMimeAggregator(com.adaptris.core.services.aggregator.IgnoreOriginalMimeAggregator) Test(org.junit.Test)

Example 27 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class AggregatingJmsConsumeServiceTest method sendDataMessage.

private void sendDataMessage(EmbeddedActiveMq broker, String queue) throws Exception {
    PtpProducer producer = new PtpProducer().withQueue(queue);
    MetadataCorrelationIdSource corr = new MetadataCorrelationIdSource();
    corr.setMetadataKey(CORRELATION_ID_KEY);
    producer.setCorrelationIdSource(corr);
    StandaloneProducer sp = new StandaloneProducer(broker.getJmsConnection(new BasicActiveMqImplementation(), true), producer);
    try {
        start(sp);
        AdaptrisMessage msg = new DefaultMessageFactory().newMessage(DATA_PAYLOAD);
        msg.addMetadata(CORRELATION_ID_KEY, "0001");
        sp.doService(msg);
    } finally {
        stop(sp);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) BasicActiveMqImplementation(com.adaptris.core.jms.activemq.BasicActiveMqImplementation) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer)

Example 28 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveMetadataAdaptrisMessageToJmsMessage.

@Test
public void testMoveMetadataAdaptrisMessageToJmsMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        start(trans);
        Message jmsMsg = trans.translate(msg);
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 29 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveJmsHeadersJmsMessageToAdaptrisMessage.

@Test
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 30 with DefaultMessageFactory

use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.

the class XmlNotificationSerializerTest method testSerialize_WithContentEncoding_FromMessage.

@Test
public void testSerialize_WithContentEncoding_FromMessage() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    n.setUserData(new Object());
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    AdaptrisMessageFactory factory = new DefaultMessageFactory();
    factory.setDefaultCharEncoding("ISO-8859-1");
    AdaptrisMessage msg = serializer.serialize(n, factory.newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNotNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("ISO-8859-1", msg.getContentEncoding());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Aggregations

DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)170 Test (org.junit.Test)163 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)158 Channel (com.adaptris.core.Channel)37 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)30 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)30 StandaloneProducer (com.adaptris.core.StandaloneProducer)27 ServiceException (com.adaptris.core.ServiceException)26 File (java.io.File)26 ServiceList (com.adaptris.core.ServiceList)18 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)18 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)18 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)18 GuidGenerator (com.adaptris.util.GuidGenerator)18 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)15 ValidationStage (com.adaptris.transform.validate.ValidationStage)15 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)12 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10