Search in sources :

Example 16 with ThrowExceptionService

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

the class StandardWorkflowTest method testOnMessage_ServiceFailsWithRetryHandlerFailureCallback.

@Test
public void testOnMessage_ServiceFailsWithRetryHandlerFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
    channel.setMessageErrorHandler(new RetryMessageErrorHandler(3, new TimeInterval(100l, TimeUnit.MILLISECONDS), new NullService()));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg, (m) -> {
            onSuccess.set(true);
        }, (m) -> {
            onSuccess.set(false);
        });
        assertFalse(onSuccess.get());
    } finally {
        stop(channel);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 17 with ThrowExceptionService

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

the class StandardWorkflowTest method testOnMessage_ServiceFailsFailureCallback.

@Test
public void testOnMessage_ServiceFailsFailureCallback() throws Exception {
    AtomicBoolean onSuccess = new AtomicBoolean(false);
    MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg, (m) -> {
            onSuccess.set(true);
        }, (m) -> {
            onSuccess.set(false);
        });
        assertFalse(onSuccess.get());
    } finally {
        stop(channel);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 18 with ThrowExceptionService

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

the class StandardProcessingExceptionHandlerTest method testServiceListWithErrorWithBlankServiceId.

@Test
public void testServiceListWithErrorWithBlankServiceId() throws Exception {
    StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
    MockMessageProducer producer = new MockMessageProducer();
    try {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("XXXX");
        ServiceList services = new ServiceList(Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Always Fail")), new StandaloneProducer(producer) }));
        services.setUniqueId("");
        meh.setProcessingExceptionService(services);
        start(meh);
        meh.handleProcessingException(msg);
        assertTrue("Make sure none produced", producer.getMessages().size() == 0);
    } finally {
        stop(meh);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 19 with ThrowExceptionService

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

the class StandardProcessingExceptionHandlerTest method testMultipleErrorHandlers_AlwaysHandle_False.

@Test
public void testMultipleErrorHandlers_AlwaysHandle_False() throws Exception {
    MockMessageProducer aep = new MockMessageProducer();
    MockMessageProducer wep = new MockMessageProducer();
    MockMessageProducer cep = new MockMessageProducer();
    StandardProcessingExceptionHandler aeh = new StandardProcessingExceptionHandler(new StandaloneProducer(aep));
    aeh.setAlwaysHandleException(false);
    StandardProcessingExceptionHandler weh = new StandardProcessingExceptionHandler(new StandaloneProducer(wep));
    StandardProcessingExceptionHandler ceh = new StandardProcessingExceptionHandler(new StandaloneProducer(cep));
    Adapter adapter = AdapterTest.createAdapter(getName());
    adapter.setMessageErrorHandler(aeh);
    MockMessageConsumer consumer = new MockMessageConsumer();
    adapter.getChannelList().clear();
    adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
    try {
        start(adapter);
        consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertEquals(0, aep.messageCount());
        assertEquals(0, cep.messageCount());
        assertEquals(1, wep.messageCount());
    } finally {
        stop(adapter);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 20 with ThrowExceptionService

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

the class BranchingHttpRequestServiceTest method retrieveObjectForSampleConfig.

@Override
protected BranchingServiceCollection retrieveObjectForSampleConfig() {
    BranchingHttpRequestService service = createForExamples();
    BranchingServiceCollection sl = new BranchingServiceCollection();
    sl.addService(service);
    sl.setFirstServiceId(service.getUniqueId());
    sl.addService(new ThrowExceptionService("5XX Server Error", new ConfiguredException("Got 5XX error from server")));
    sl.addService(new ThrowExceptionService("4XX Client Error", new ConfiguredException("Got 4XX error from server")));
    sl.addService(new NullService("Not Found"));
    sl.addService(new LogMessageService("2XX OK"));
    sl.addService(new ThrowExceptionService("DefaultServiceId", new ConfiguredException("Unmatched Response")));
    return sl;
}
Also used : BranchingServiceCollection(com.adaptris.core.BranchingServiceCollection) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) NullService(com.adaptris.core.NullService) LogMessageService(com.adaptris.core.services.LogMessageService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException)

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