Search in sources :

Example 6 with StandardProcessingExceptionHandler

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

the class ExceptionReportServiceTest method testBug2356.

@Test
public void testBug2356() throws Exception {
    ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
    MockMessageProducer mockProducer = new MockMessageProducer();
    StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
    MockChannel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    StandardWorkflow wf = new StandardWorkflow();
    wf.getServiceCollection().add(failingService);
    wf.setConsumer(consumer);
    channel.setMessageErrorHandler(speh);
    channel.getWorkflowList().add(wf);
    try {
        channel.prepare();
        channel.requestStart();
        consumer.submitMessage(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
        assertNotSame(XML_PAYLOAD, failedMessage.getContent());
        XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
        assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
        assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
        String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
        assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) ServiceImp(com.adaptris.core.ServiceImp) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) InsertNode(com.adaptris.util.text.xml.InsertNode) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 7 with StandardProcessingExceptionHandler

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

the class BaseCase method createandStartDummyMessageErrorHandler.

public static ProcessingExceptionHandler createandStartDummyMessageErrorHandler() throws CoreException {
    StandardProcessingExceptionHandler eh = new StandardProcessingExceptionHandler();
    LifecycleHelper.init(eh);
    LifecycleHelper.start(eh);
    return eh;
}
Also used : StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler)

Example 8 with StandardProcessingExceptionHandler

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

the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionStrictWithErrorHandler.

// In Strict Mode, Then even if you have configured an error handler, then
// the transaction is unsucessful if we have an exception, leading to msgs on
// the queue.
@Test
public void testServiceExceptionStrictWithErrorHandler() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    MockMessageProducer meh = new MockMessageProducer();
    Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionStrictWithErrorHandler", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setStrict(Boolean.TRUE);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
    } finally {
        channel.requestClose();
    }
    assertEquals(msgCount, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 9 with StandardProcessingExceptionHandler

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

the class LargeMessageWorkflowTest method testRuntimeException.

@Override
@Test
public void testRuntimeException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer() {

        @Override
        protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
            throw new RuntimeException();
        }
    };
    ;
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    try {
        LargeMessageWorkflow workflow = (LargeMessageWorkflow) channel.getWorkflowList().get(0);
        channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
        channel.prepare();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
        start(channel);
        workflow.onAdaptrisMessage(msg);
        assertEquals("Make none produced", 0, producer.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        for (AdaptrisMessage m : meh.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Service(com.adaptris.core.Service) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) MetadataElement(com.adaptris.core.MetadataElement) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test) StandardWorkflowTest(com.adaptris.core.StandardWorkflowTest)

Aggregations

StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)9 Test (org.junit.Test)8 Service (com.adaptris.core.Service)6 ServiceList (com.adaptris.core.ServiceList)6 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 MockChannel (com.adaptris.core.stubs.MockChannel)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)5 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)4 MetadataElement (com.adaptris.core.MetadataElement)3 StandardWorkflowTest (com.adaptris.core.StandardWorkflowTest)3 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)3 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)3 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)3 Adapter (com.adaptris.core.Adapter)2 Channel (com.adaptris.core.Channel)2 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)2 PtpProducer (com.adaptris.core.jms.PtpProducer)2 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)2 ObjectName (javax.management.ObjectName)2