Search in sources :

Example 41 with ConfiguredException

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

the class ServiceListTest method testFail_CheckObjectMetadata.

@Test
public void testFail_CheckObjectMetadata() throws Exception {
    ServiceList services = createServiceList(false);
    ThrowExceptionService errorService = new ThrowExceptionService(new ConfiguredException("Fail"));
    errorService.setUniqueId(getName());
    services.addService(errorService);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    String expectedName = String.format("%s(%s)", ThrowExceptionService.class.getSimpleName(), getName());
    try {
        execute(services, msg);
        fail("Expected Service Exception");
    } catch (ServiceException e) {
        assertEquals("Fail", e.getMessage());
        Exception captured = (Exception) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION);
        String problemComponent = (String) msg.getObjectHeaders().get(CoreConstants.OBJ_METADATA_EXCEPTION_CAUSE);
        assertNotNull(captured);
        assertEquals(captured, e);
        assertNotNull(problemComponent);
        assertEquals(expectedName, problemComponent);
    }
}
Also used : ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Test(org.junit.Test)

Example 42 with ConfiguredException

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

the class MultiProducerWorkflowTest method testHandleServiceException.

@Test
public void testHandleServiceException() throws Exception {
    System.out.println("*** HandleServiceException START");
    MockMessageProducer mock1 = new MockMessageProducer();
    MockMessageProducer mock2 = new MockMessageProducer();
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")) }));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    try {
        MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
        workflow.setUseProcessedMessage(false);
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
        workflow.onAdaptrisMessage(msg);
        assertEquals(0, mock1.getMessages().size());
        assertEquals(0, mock2.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        assertEquals(ORIGINAL_PAYLOAD, meh.getMessages().get(0).getContent());
    } finally {
        channel.requestClose();
    }
    System.out.println("*** HandleServiceException END");
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) ArrayList(java.util.ArrayList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Test(org.junit.Test)

Example 43 with ConfiguredException

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

the class PoolingWorkflowTest method testHandleServiceException.

@Test
public void testHandleServiceException() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer meh = new MockMessageProducer();
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    wf.getServiceCollection().add(new ThrowExceptionService(new ConfiguredException("Fail")));
    try {
        start(channel);
        submitMessages(wf, 1);
        waitForMessages(meh, 1);
        assertEquals(1, meh.messageCount());
        for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
            AdaptrisMessage m = (AdaptrisMessage) i.next();
            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) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Iterator(java.util.Iterator) WaitService(com.adaptris.core.services.WaitService) XmlRoundTripService(com.adaptris.core.stubs.XmlRoundTripService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Test(org.junit.Test)

Example 44 with ConfiguredException

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

the class JettyRoutingServiceTest method retrieveObjectForSampleConfig.

@Override
protected Object retrieveObjectForSampleConfig() {
    BranchingServiceCollection sl = new BranchingServiceCollection();
    JettyRoutingService service = new JettyRoutingService("NotHandled", createRoutes());
    service.setUniqueId("handleRouting");
    sl.addService(service);
    sl.setFirstServiceId(service.getUniqueId());
    sl.addService(new LogMessageService("handleGet"));
    sl.addService(new LogMessageService("handleDelete"));
    sl.addService(new LogMessageService("handleInsert"));
    sl.addService(new ThrowExceptionService("handleUpdate", new ConfiguredException("cannot handle updates")));
    return sl;
}
Also used : BranchingServiceCollection(com.adaptris.core.BranchingServiceCollection) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) LogMessageService(com.adaptris.core.services.LogMessageService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException)

Example 45 with ConfiguredException

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

the class MetadataBranchingServiceTest method create.

protected BranchingServiceCollection create(MetadataValueMatcherCreator m) {
    BranchingServiceCollection sl = new BranchingServiceCollection();
    MetadataValueBranchingService service = new MetadataValueBranchingService();
    service.setValueMatcher(m.create());
    service.setDefaultServiceId("DefaultServiceId");
    service.addMetadataKey("FirstMetadataKeyWhoseValueWeWantToCheck");
    // service.addMetadataKey("Second_Metadata_Key_Whose_Value_Is_Appended_To_FirstMetadataKeyWhoseValueWeWantToCheck");
    service.setMetadataToServiceIdMappings(m.createMappings());
    service.setUniqueId("CheckMetadataValue");
    sl.addService(service);
    sl.setFirstServiceId(service.getUniqueId());
    sl.addService(new LogMessageService("FirstServiceId"));
    sl.addService(new ThrowExceptionService("SecondServiceId", new ConfiguredException("Fail")));
    sl.addService(new LogMessageService("DefaultServiceId"));
    return sl;
}
Also used : BranchingServiceCollection(com.adaptris.core.BranchingServiceCollection) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) 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