use of com.adaptris.core.StandardProcessingExceptionHandler in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.
// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
MockMessageProducer meh = new MockMessageProducer();
Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setStrict(Boolean.FALSE);
workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
waitForMessages(meh, msgCount);
assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.StandardProcessingExceptionHandler 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);
}
}
use of com.adaptris.core.StandardProcessingExceptionHandler in project interlok by adaptris.
the class LargeMessageWorkflowTest method testProduceException.
@Override
@Test
public void testProduceException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new ProduceException();
}
};
;
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);
}
}
use of com.adaptris.core.StandardProcessingExceptionHandler in project interlok by adaptris.
the class AdapterManagerTest method testMBean_NotificationOnSetMessageErrorHandler.
@Test
public void testMBean_NotificationOnSetMessageErrorHandler() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName, 1, 1);
String newCompXml = DefaultMarshaller.getDefaultMarshaller().marshal(new StandardProcessingExceptionHandler());
AdapterManager adapterManager = new AdapterManager(adapter);
ObjectName adapterObj = adapterManager.createObjectName();
SimpleNotificationListener listener = new SimpleNotificationListener();
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(NOTIF_TYPE_ADAPTER_CONFIG);
try {
adapterManager.registerMBean();
mBeanServer.addNotificationListener(adapterObj, listener, filter, null);
AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
adapterManagerProxy.setMessageErrorHandler(newCompXml);
listener.waitForMessages(1);
assertEquals(1, listener.getNotifications().size());
Notification n = listener.getNotifications().get(0);
assertEquals(NOTIF_TYPE_ADAPTER_CONFIG, n.getType());
assertEquals(NOTIF_MSG_CONFIG_UPDATED, n.getMessage());
assertEquals(adapterManagerProxy.getConfiguration(), n.getUserData());
} finally {
}
}
use of com.adaptris.core.StandardProcessingExceptionHandler in project interlok by adaptris.
the class AdapterManagerTest method testMBean_SetMessageErrorHandler.
@Test
public void testMBean_SetMessageErrorHandler() throws Exception {
String adapterName = this.getClass().getSimpleName() + "." + getName();
Adapter adapter = createAdapter(adapterName);
AdapterManager adapterManager = new AdapterManager(adapter);
StandardProcessingExceptionHandler meh = new StandardProcessingExceptionHandler();
meh.setUniqueId(getName());
ObjectName adapterObj = adapterManager.createObjectName();
List<BaseComponentMBean> mBeans = new ArrayList<BaseComponentMBean>();
mBeans.add(adapterManager);
mBeans.addAll(adapterManager.getAllDescendants());
try {
register(mBeans);
AdapterManagerMBean adapterManagerProxy = JMX.newMBeanProxy(mBeanServer, adapterObj, AdapterManagerMBean.class);
adapterManagerProxy.setMessageErrorHandler(DefaultMarshaller.getDefaultMarshaller().marshal(meh));
Adapter marshalledAdapter = (Adapter) DefaultMarshaller.getDefaultMarshaller().unmarshal(adapterManagerProxy.getConfiguration());
assertEquals(StandardProcessingExceptionHandler.class, marshalledAdapter.getMessageErrorHandler().getClass());
assertEquals(meh.getUniqueId(), ((StandardProcessingExceptionHandler) marshalledAdapter.getMessageErrorHandler()).getUniqueId());
} finally {
}
}
Aggregations