Search in sources :

Example 6 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class LargeMessageWorkflowTest method testServiceException.

@Override
@Test
public void testServiceException() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    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), new ThrowExceptionService(new ConfiguredException("Fail")) }));
    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));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION));
            assertNotNull(m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
            assertEquals(ThrowExceptionService.class.getSimpleName(), m.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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)

Example 7 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class StandardMessageErrorDigestTest method testMBean_GetMessageDigestMultipleWorkflow.

@Test
public void testMBean_GetMessageDigestMultipleWorkflow() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    adapter.setMessageErrorDigester(new StandardMessageErrorDigester(getName()));
    Channel channel1 = createChannel("channel1");
    StandardWorkflow workflow1 = createWorkflow("workflow1");
    StandardWorkflow workflow2 = createWorkflow("workflow2");
    workflow1.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail1")));
    workflow2.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("fail2")));
    channel1.getWorkflowList().add(workflow1);
    channel1.getWorkflowList().add(workflow2);
    adapter.getChannelList().add(channel1);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        ObjectName digesterObj = createMessageErrorDigestObjectName(adapterName, getName());
        StandardMessageErrorDigesterJmxMBean errDigester = JMX.newMBeanProxy(mBeanServer, digesterObj, StandardMessageErrorDigesterJmxMBean.class);
        workflow1.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow1"));
        workflow2.onAdaptrisMessage(new DefaultMessageFactory().newMessage("Hello Workflow2"));
        // They should have failed.
        assertNotNull(errDigester.getDigest());
        assertEquals(2, errDigester.getDigest().size());
        assertEquals(2, errDigester.getTotalErrorCount());
        MessageDigestErrorEntry entry1 = errDigester.getDigest().get(0);
        MessageDigestErrorEntry entry2 = errDigester.getDigest().get(1);
        assertEquals("workflow1@channel1", entry1.getWorkflowId());
        assertEquals("workflow2@channel1", entry2.getWorkflowId());
    } finally {
        stop(adapter);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) StandardWorkflow(com.adaptris.core.StandardWorkflow) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Channel(com.adaptris.core.Channel) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 8 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailuresIgnored.

@Test
public void testDoServiceWithFailuresIgnored() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    service.setIgnoreSplitMessageFailures(true);
    execute(service, msg);
    assertEquals("Number of messages", 0, producer.getMessages().size());
    // We should still get 4 messages as the splitCount. They may not have been successfully
    // processed, but they were still results from the split!
    assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
    int count = 0;
    for (AdaptrisMessage m : producer.getMessages()) {
        count++;
        assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 9 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_NullEventHandler_SendEvents.

@Test
public void testDoServiceWithFailures_NullEventHandler_SendEvents() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    service.registerEventHandler(null);
    service.setSendEvents(true);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 10 with ThrowExceptionService

use of com.adaptris.core.services.exception.ThrowExceptionService in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsTrue.

@Test
public void testDoServiceWithFailures_SendEventsTrue() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    DefaultEventHandler eh = new DefaultEventHandler();
    MockMessageProducer ehp = new MockMessageProducer();
    eh.setProducer(ehp);
    LifecycleHelper.initAndStart(eh);
    service.registerEventHandler(eh);
    service.setSendEvents(true);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
    LifecycleHelper.stopAndClose(eh);
    assertEvents(ehp, 1, MessageLifecycleEvent.class);
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)45 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)45 Test (org.junit.Test)41 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)26 MockChannel (com.adaptris.core.stubs.MockChannel)18 StandaloneProducer (com.adaptris.core.StandaloneProducer)13 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)13 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)12 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)10 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)10 Channel (com.adaptris.core.Channel)8 ServiceException (com.adaptris.core.ServiceException)7 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)6 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)6 PtpProducer (com.adaptris.core.jms.PtpProducer)5 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)5 TimeInterval (com.adaptris.util.TimeInterval)5 Iterator (java.util.Iterator)5 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)4