Daniel Feist
2012-01-31 22:58:59 UTC
Couple of comment:
- The name "ChoiceMessagingExceptionHandler" could be improved, it's very easily confused with ChoiceMessagingExceptionStrategy. In fact this interface isn't specifically related to ChoiceES either It could apply to any exception handler or any MP at all for that matter. Can't it be pulled out and implemented by TemplateES for example?
- Is the ChoiceDelegateMessagingExceptionStrategy/addDefaultExceptionStrategyIfRequired really needed? Can't you just get/use default ES after the for loop in handleException and it would be less complex?
- Best to put this "validateConfiguredExceptionStrategies" in the initialise phase, generally all this kind of validation is done at initialisation. One advantage is that once we decouple lifecycle from Mule this error won't be wrapped inside a spring error.
Dan
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
- The name "ChoiceMessagingExceptionHandler" could be improved, it's very easily confused with ChoiceMessagingExceptionStrategy. In fact this interface isn't specifically related to ChoiceES either It could apply to any exception handler or any MP at all for that matter. Can't it be pulled out and implemented by TemplateES for example?
- Is the ChoiceDelegateMessagingExceptionStrategy/addDefaultExceptionStrategyIfRequired really needed? Can't you just get/use default ES after the for loop in handleException and it would be less complex?
- Best to put this "validateConfiguredExceptionStrategies" in the initialise phase, generally all this kind of validation is done at initialisation. One advantage is that once we decouple lifecycle from Mule this error won't be wrapped inside a spring error.
Dan
Revision
23768
Author
pablo.lagreca
Date
2012-01-31 10:08:45 -0600 (Tue, 31 Jan 2012)
Log Message
MULE-5894 - Adding choice-exception-strategy - Creating exception-type expression evalutor and extending functionality for match exact type and regex
Modified Paths
• branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java
• branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java
• branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java
• branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java
• branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd
• branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java
• branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java
Added Paths
• branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java
• branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java
• branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java
• branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java
• branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java
• branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml
Diff
Added: branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.api.exception;
+
+import org.mule.api.MuleEvent;
+
+/**
+ * Provides capability to only accept handling certain MuleEvents.
+ */
+public interface ChoiceMessagingExceptionHandler extends MessagingExceptionHandler
+{
+ /**
+ * false otherwise
+ */
+ boolean accept(MuleEvent event);
+
+ /**
+ */
+ boolean acceptsAll();
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,15 +10,6 @@
package org.mule.config;
-import org.mule.api.MuleException;
-import org.mule.api.MuleRuntimeException;
-import org.mule.api.config.ExceptionReader;
-import org.mule.api.registry.ServiceType;
-import org.mule.config.i18n.CoreMessages;
-import org.mule.util.ClassUtils;
-import org.mule.util.MapUtils;
-import org.mule.util.SpiUtils;
-
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
@@ -31,6 +22,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.mule.api.MuleException;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.config.ExceptionReader;
+import org.mule.api.registry.ServiceType;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.util.ClassUtils;
+import org.mule.util.MapUtils;
+import org.mule.util.SpiUtils;
/**
* <code>ExceptionHelper</code> provides a number of helper functions that can be
@@ -343,6 +342,25 @@
return DefaultMuleConfiguration.fullStackTraces ? root : sanitize(root);
}
+ public static Throwable getNonMuleException(Throwable t)
+ {
+ if (!(t instanceof MuleException))
+ {
+ return t;
+ }
+ Throwable cause = t;
+ while (cause != null)
+ {
+ cause = getExceptionReader(cause).getCause(cause);
+ // address some misbehaving exceptions, avoid endless loop
+ if (t == cause || !(cause instanceof MuleException))
+ {
+ break;
+ }
+ }
+ return cause instanceof MuleException ? null : cause;
+ }
+
public static Throwable sanitizeIfNeeded(Throwable t)
{
return DefaultMuleConfiguration.fullStackTraces ? t : sanitize(t);
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -40,7 +40,7 @@
public AbstractMessagingExceptionStrategy(MuleContext muleContext)
{
- this.muleContext = muleContext;
+ setMuleContext(muleContext);
}
public MuleEvent handleException(Exception ex, MuleEvent event)
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,7 +9,6 @@
*/
package org.mule.exception;
-import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;
public class CatchMessagingExceptionStrategy extends TemplateMessagingExceptionStrategy
@@ -32,4 +31,5 @@
{
return event;
}
+
}
Added: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,59 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.mule.api.MuleEvent;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.api.exception.MessagingExceptionHandler;
+import org.mule.processor.AbstractMuleObjectOwner;
+
+public class ChoiceDelegateMessagingExceptionStrategy extends AbstractMuleObjectOwner<MessagingExceptionHandler> implements ChoiceMessagingExceptionHandler
+{
+ private MessagingExceptionHandler delegate;
+
+ public ChoiceDelegateMessagingExceptionStrategy(MessagingExceptionHandler messagingExceptionHandler)
+ {
+ this.delegate = messagingExceptionHandler;
+ }
+
+ public boolean accept(MuleEvent event)
+ {
+ if (delegate instanceof ChoiceMessagingExceptionHandler)
+ {
+ return ((ChoiceMessagingExceptionHandler)delegate).accept(event);
+ }
+ return true;
+ }
+
+ public boolean acceptsAll()
+ {
+ if (delegate instanceof ChoiceMessagingExceptionHandler)
+ {
+ return ((ChoiceMessagingExceptionHandler)delegate).acceptsAll();
+ }
+ return true;
+ }
+
+ public MuleEvent handleException(Exception exception, MuleEvent event)
+ {
+ return delegate.handleException(exception,event);
+ }
+
+ protected List<MessagingExceptionHandler> getOwnedObjects() {
+ return Arrays.asList(delegate);
+ }
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,82 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.mule.api.MuleEvent;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.api.exception.MessagingExceptionHandler;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.message.DefaultExceptionPayload;
+import org.mule.processor.AbstractMuleObjectOwner;
+
+/**
+ * Selects which exception strategy to execute based on filtering.
+ *
+ */
+public class ChoiceMessagingExceptionStrategy extends AbstractMuleObjectOwner<ChoiceMessagingExceptionHandler> implements MessagingExceptionHandler, MuleContextAware, Lifecycle
+{
+ private List<ChoiceMessagingExceptionHandler> exceptionListeners;
+
+ public MuleEvent handleException(Exception exception, MuleEvent event)
+ {
+ event.getMessage().setExceptionPayload(new DefaultExceptionPayload(exception));
+ for (ChoiceMessagingExceptionHandler exceptionListener : exceptionListeners)
+ {
+ if (exceptionListener.accept(event))
+ {
+ event.getMessage().setExceptionPayload(null);
+ return exceptionListener.handleException(exception,event);
+ }
+ }
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Default exception strategy must accept any event."));
+ }
+
+ public void setExceptionListeners(List<ChoiceMessagingExceptionHandler> exceptionListeners)
+ {
+ this.exceptionListeners = exceptionListeners;
+ validateConfiguredExceptionStrategies();
+ addDefaultExceptionStrategyIfRequired();
+ }
+
+ protected List<ChoiceMessagingExceptionHandler> getOwnedObjects() {
+ return Collections.unmodifiableList(exceptionListeners);
+ }
+
+ private void addDefaultExceptionStrategyIfRequired()
+ {
+ if (!exceptionListeners.get(exceptionListeners.size()-1).acceptsAll())
+ {
+ this.exceptionListeners.add(new ChoiceDelegateMessagingExceptionStrategy(getMuleContext().getDefaultExceptionStrategy()));
+ }
+ }
+
+ private void validateConfiguredExceptionStrategies()
+ {
+ for (int i = 0; i < exceptionListeners.size()-1; i++)
+ {
+ ChoiceMessagingExceptionHandler choiceMessagingExceptionHandler = exceptionListeners.get(i);
+ if (choiceMessagingExceptionHandler.acceptsAll())
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Only last exception strategy inside <choice-exception-strategy> can accept any message. Maybe expression attribute is empty."));
+ }
+ }
+ }
+
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,8 +12,7 @@
import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
-import org.mule.api.exception.MessagingExceptionHandler;
-import org.mule.api.exception.RollbackSourceCallback;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
import org.mule.api.lifecycle.InitialisationException;
import org.mule.api.processor.MessageProcessor;
import org.mule.api.processor.MessageProcessorChain;
@@ -22,15 +21,20 @@
import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
import org.mule.routing.requestreply.ReplyToPropertyRequestReplyReplier;
-import java.net.URI;
-
-public abstract class TemplateMessagingExceptionStrategy extends AbstractExceptionListener implements MessagingExceptionHandler
+public abstract class TemplateMessagingExceptionStrategy extends AbstractExceptionListener implements ChoiceMessagingExceptionHandler
{
private MessageProcessorChain configuredMessageProcessors;
private MessageProcessor replyToMessageProcessor = new ReplyToPropertyRequestReplyReplier();
+ private String expression;
@Override
+ public boolean accept(MuleEvent event)
+ {
+ return acceptsAll() || muleContext.getExpressionManager().evaluateBoolean(expression,event.getMessage());
+ }
+
final public MuleEvent handleException(Exception exception, MuleEvent event)
{
fireNotification(exception);
@@ -104,6 +108,17 @@
}
}
+ public void setExpression(String expression)
+ {
+ this.expression = expression;
+ }
+
+ public boolean acceptsAll()
+ {
+ return expression == null;
+ }
+
protected abstract MuleEvent afterRouting(Exception exception, MuleEvent event);
protected abstract MuleEvent beforeRouting(Exception exception, MuleEvent event);
Added: branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.expression;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mule.api.MuleMessage;
+import org.mule.api.expression.ExpressionEvaluator;
+import org.mule.routing.filters.ExceptionTypeFilter;
+
+public class ExceptionTypeExpressionEvaluator implements ExpressionEvaluator
+{
+ protected transient Log logger = LogFactory.getLog(ExceptionTypeExpressionEvaluator.class);
+
+ public Object evaluate(String expression, MuleMessage message)
+ {
+ return new ExceptionTypeFilter(expression).accept(message);
+ }
+
+ public void setName(String name)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getName()
+ {
+ return "exception-type";
+ }
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,104 +9,25 @@
*/
package org.mule.processor;
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.mule.api.AnnotatedObject;
-import org.mule.api.MuleContext;
-import org.mule.api.MuleException;
-import org.mule.api.construct.FlowConstruct;
import org.mule.api.construct.FlowConstructAware;
import org.mule.api.context.MuleContextAware;
-import org.mule.api.lifecycle.Disposable;
-import org.mule.api.lifecycle.Initialisable;
-import org.mule.api.lifecycle.InitialisationException;
import org.mule.api.lifecycle.Lifecycle;
-import org.mule.api.lifecycle.Startable;
-import org.mule.api.lifecycle.Stoppable;
import org.mule.api.processor.MessageProcessor;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.xml.namespace.QName;
-
/**
* An object that owns message processors and delegates startup/shutdown events to them.
*/
-public abstract class AbstractMessageProcessorOwner implements Lifecycle, MuleContextAware, FlowConstructAware, AnnotatedObject
+public abstract class AbstractMessageProcessorOwner extends AbstractMuleObjectOwner<MessageProcessor> implements Lifecycle, MuleContextAware, FlowConstructAware, AnnotatedObject
{
- protected MuleContext muleContext;
- protected FlowConstruct flowConstruct;
private final Map<QName, Object> annotations = new ConcurrentHashMap<QName, Object>();
- public void setMuleContext(MuleContext context)
- {
- this.muleContext = context;
- }
-
- public void setFlowConstruct(FlowConstruct flowConstruct)
- {
- this.flowConstruct = flowConstruct;
- }
-
- public void initialise() throws InitialisationException
- {
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof MuleContextAware)
- {
- ((MuleContextAware) processor).setMuleContext(muleContext);
- }
- if (processor instanceof FlowConstructAware)
- {
- ((FlowConstructAware) processor).setFlowConstruct(flowConstruct);
- }
- if (processor instanceof Initialisable)
- {
- ((Initialisable) processor).initialise();
- }
- }
- }
-
- public void dispose()
- {
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
-
- if (processor instanceof Disposable)
- {
- ((Disposable) processor).dispose();
- }
- }
- }
-
-
- public void start() throws MuleException
- {
-
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof Startable)
- {
- ((Startable) processor).start();
- }
- }
- }
-
-
- public void stop() throws MuleException
- {
-
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof Stoppable)
- {
- ((Stoppable) processor).stop();
- }
-
- }
- }
-
public final Object getAnnotation(QName name)
{
return annotations.get(name);
@@ -123,6 +44,11 @@
annotations.putAll(newAnnotations);
}
+ protected List<MessageProcessor> getOwnedObjects()
+ {
+ return getOwnedMessageProcessors();
+ }
+
protected abstract List<MessageProcessor> getOwnedMessageProcessors();
}
Added: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.processor;
+
+import java.util.List;
+
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.construct.FlowConstruct;
+import org.mule.api.construct.FlowConstructAware;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.lifecycle.Disposable;
+import org.mule.api.lifecycle.Initialisable;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.api.lifecycle.Startable;
+import org.mule.api.lifecycle.Stoppable;
+
+/**
+ * An object that owns Mule objects and delegates startup/shutdown events to them.
+ */
+public abstract class AbstractMuleObjectOwner<T> implements Lifecycle, MuleContextAware, FlowConstructAware {
+
+ protected MuleContext muleContext;
+ protected FlowConstruct flowConstruct;
+
+ public void setMuleContext(MuleContext context) {
+ this.muleContext = context;
+ }
+
+ public void setFlowConstruct(FlowConstruct flowConstruct) {
+ this.flowConstruct = flowConstruct;
+ }
+
+ public MuleContext getMuleContext() {
+ return muleContext;
+ }
+
+ public FlowConstruct getFlowConstruct() {
+ return flowConstruct;
+ }
+
+ public void initialise() throws InitialisationException {
+ for (T object : getOwnedObjects()) {
+ if (object instanceof MuleContextAware) {
+ ((MuleContextAware) object).setMuleContext(muleContext);
+ }
+ if (object instanceof FlowConstructAware) {
+ ((FlowConstructAware) object).setFlowConstruct(flowConstruct);
+ }
+ if (object instanceof Initialisable) {
+ ((Initialisable) object).initialise();
+ }
+ }
+ }
+
+ public void dispose() {
+ for (T processor : getOwnedObjects()) {
+
+ if (processor instanceof Disposable) {
+ ((Disposable) processor).dispose();
+ }
+ }
+ }
+
+
+ public void start() throws MuleException {
+
+ for (T processor : getOwnedObjects()) {
+ if (processor instanceof Startable) {
+ ((Startable) processor).start();
+ }
+ }
+ }
+
+
+ public void stop() throws MuleException {
+
+ for (T processor : getOwnedObjects()) {
+ if (processor instanceof Stoppable) {
+ ((Stoppable) processor).stop();
+ }
+
+ }
+ }
+
+ protected abstract List<T> getOwnedObjects();
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,6 +12,7 @@
import org.mule.api.ExceptionPayload;
import org.mule.api.MuleMessage;
+import org.mule.config.ExceptionHelper;
import org.mule.util.ClassUtils;
/**
@@ -22,15 +23,25 @@
public class ExceptionTypeFilter extends PayloadTypeFilter
{
+ private String expression;
+
public ExceptionTypeFilter()
{
super();
}
- public ExceptionTypeFilter(String expectedType) throws ClassNotFoundException
+ public ExceptionTypeFilter(String expectedType)
{
- this(ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class));
+ try
+ {
+ Class exceptionType = ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class);
+ setExpectedType(exceptionType);
+ }
+ catch (ClassNotFoundException e)
+ {
+ this.expression = expectedType;
+ }
}
public ExceptionTypeFilter(Class expectedType)
@@ -48,13 +59,32 @@
{
ExceptionPayload epl = message.getExceptionPayload();
- if (getExpectedType() == null)
+ if (getExpectedType() == null && this.expression == null)
{
return epl != null;
}
else if (epl != null)
{
- return getExpectedType().isAssignableFrom(epl.getException().getClass());
+ Throwable wrappedException = ExceptionHelper.getNonMuleException(epl.getException());
+ if (getExpectedType() != null)
+ {
+ //Exception type configured
+ return getExpectedType().isAssignableFrom(epl.getException().getClass()) || (wrappedException != null && getExpectedType().isAssignableFrom(wrappedException.getClass()));
+ }
+ else
+ {
+ //Expression configured
+ if (expression.startsWith("="))
+ {
+ String expectedType = expression.substring(1, expression.length());
+ return epl.getException().getClass().getName().equals(expectedType) || (wrappedException != null && wrappedException.getClass().getName().equals(expectedType));
+ }
+ else
+ {
+ RegExFilter regExFilter = new RegExFilter(expression);
+ return regExFilter.accept(epl.getException().getClass().getName()) || (wrappedException != null && regExFilter.accept(wrappedException.getClass().getName()));
+ }
+ }
}
else
{
Modified: branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,6 +12,10 @@
import static org.mule.util.ClassUtils.equal;
import static org.mule.util.ClassUtils.hash;
+import java.text.MessageFormat;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.api.context.MuleContextAware;
@@ -20,11 +24,6 @@
import org.mule.expression.ExpressionConfig;
import org.mule.util.StringUtils;
-import java.text.MessageFormat;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Allows boolean expressions to be executed on a message. Note that when using this filter you must be able to either specify
* a boolean expression when using an expression filter or use one of the standard Mule filters. These can be defined as follows -
@@ -169,22 +168,13 @@
}
else if(config.getEvaluator().equals("exception-type"))
{
- try
+ if (StringUtils.isEmpty(config.getExpression()))
{
- if (StringUtils.isEmpty(config.getExpression()))
- {
- delegateFilter = new ExceptionTypeFilter();
- }
- else
- {
- delegateFilter = new ExceptionTypeFilter(config.getExpression());
- }
+ delegateFilter = new ExceptionTypeFilter();
}
- catch (ClassNotFoundException e)
+ else
{
- IllegalArgumentException iae = new IllegalArgumentException();
- iae.initCause(e);
- throw iae;
+ delegateFilter = new ExceptionTypeFilter(config.getExpression());
}
}
else
Modified: branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties (23767 => 23768)
--- branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties 2012-01-31 16:08:45 UTC (rev 23768)
@@ -22,6 +22,7 @@
core.object.22=org.mule.expression.MessageHeaderExpressionEnricher
core.object.23=org.mule.expression.VariableExpressionEnricher
core.object.24=org.mule.expression.RegexExpressionEvaluator
+core.object.25=org.mule.expression.ExceptionTypeExpressionEvaluator
core.transformer.1=org.mule.transformer.simple.ObjectToByteArray
core.transformer.2=org.mule.transformer.simple.ObjectToOutputHandler
Added: branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.internal.verification.VerificationModeFactory;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleContext;
+import org.mule.api.MuleEvent;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
+
+public class ChoiceMessagingExceptionStrategyTestCase extends AbstractMuleTestCase
+{
+
+ private ChoiceMessagingExceptionHandler mockTestExceptionStrategy1;
+ private ChoiceMessagingExceptionHandler mockTestExceptionStrategy2;
+ private ChoiceMessagingExceptionHandler mockDefaultTestExceptionStrategy2;
+ private MuleEvent mockMuleEvent;
+ private MuleContext mockMuleContext;
+ private Exception mockException = new Exception();
+
+ public void testNonMatchThenCallDefault() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ choiceMessagingExceptionStrategy.handleException(mockException,mockMuleEvent);
+ verify(mockTestExceptionStrategy1, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockTestExceptionStrategy2, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockDefaultTestExceptionStrategy2, VerificationModeFactory.times(1)).handleException(mockException, mockMuleEvent);
+ }
+
+ public void testNoneMatchEvenDefault() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ choiceMessagingExceptionStrategy.handleException(mockException, mockMuleEvent);
+ }
+
+ public void testSecondMatches() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ choiceMessagingExceptionStrategy.handleException(mockException,mockMuleEvent);
+ verify(mockTestExceptionStrategy1, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockDefaultTestExceptionStrategy2, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockTestExceptionStrategy2, VerificationModeFactory.times(1)).handleException(mockException, mockMuleEvent);
+ }
+
+ public void testFirstAcceptsAllMatches() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ when(mockTestExceptionStrategy1.acceptsAll()).thenReturn(true);
+ when(mockTestExceptionStrategy2.acceptsAll()).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.acceptsAll()).thenReturn(true);
+ choiceMessagingExceptionStrategy.initialise();
+ }
+
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.expression;
+
+import org.hamcrest.core.Is;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleMessage;
+import org.mule.api.MuleRuntimeException;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
+
+public class ExceptionTypeExpressionEvaluatorTestCase extends AbstractMuleTestCase
+{
+
+ private ExceptionTypeExpressionEvaluator exceptionTypeExpressionEvaluator = new ExceptionTypeExpressionEvaluator();
+ private MuleMessage mockMuleMessage;
+
+ public void testEvaluateNotMatchingExpression() throws Exception
+ {
+ exceptionTypeExpressionEvaluator.evaluate("asdf", mockMuleMessage);
+ }
+
+ public void testEvaluateMatchingExceptionType() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean) exceptionTypeExpressionEvaluator.evaluate(NullPointerException.class.getName(), mockMuleMessage), Is.is(true));
+ }
+
+ public void testEvaluateMatchingSubtype() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate(RuntimeException.class.getName(), mockMuleMessage),Is.is(true));
+ }
+
+ public void testEvaluateExactMatchingType() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("=" + NullPointerException.class.getName(), mockMuleMessage),Is.is(true));
+ }
+
+ public void testEvaluateExactSubtype() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("=" + RuntimeException.class.getName(), mockMuleMessage),Is.is(false));
+ }
+
+ public void testEvaluateMatchingUsingRegex() throws Exception
+ {
+ configureExceptionPayload(new MuleRuntimeException(new Exception()));
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("(.*).mule.(.*)Exception", mockMuleMessage),Is.is(true));
+ }
+ public void testEvaluateNotMatchingUsingRegex() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("(.*).mule.not.matching.(.*)Exception", mockMuleMessage),Is.is(false));
+ }
+
+ private void configureExceptionPayload(Exception e)
+ {
+ Mockito.when(mockMuleMessage.getExceptionPayload().getException()).thenReturn(e);
+ }
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,117 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.processor;
+
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.construct.FlowConstruct;
+import org.mule.api.construct.FlowConstructAware;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.tck.size.SmallTest;
+
+public class AbstractMuleObjectOwnerTest {
+
+ private TestClass mockObject1;
+ private TestClass mockObject2;
+ private MuleContext mockMuleContext;
+ private FlowConstruct mockFlowConstruct;
+ private AbstractMuleObjectOwner<TestClass> abstractMuleObjectOwner;
+
+ public void before()
+ {
+ abstractMuleObjectOwner = new AbstractMuleObjectOwner<TestClass>()
+ {
+ protected List<TestClass> getOwnedObjects() {
+ return Arrays.asList(mockObject1,mockObject2);
+ }
+ };
+ abstractMuleObjectOwner.setFlowConstruct(mockFlowConstruct);
+ abstractMuleObjectOwner.setMuleContext(mockMuleContext);
+ }
+
+ public void testInitialise() throws Exception {
+ abstractMuleObjectOwner.initialise();
+ verify(mockObject1).initialise();
+ verify(mockObject2).initialise();
+ verify(mockObject1).setMuleContext(mockMuleContext);
+ verify(mockObject2).setMuleContext(mockMuleContext);
+ verify(mockObject1).setFlowConstruct(mockFlowConstruct);
+ verify(mockObject2).setFlowConstruct(mockFlowConstruct);
+ }
+
+ public void testDispose() throws Exception {
+ abstractMuleObjectOwner.dispose();
+ verify(mockObject1).dispose();
+ verify(mockObject2).dispose();
+ }
+
+ public void testStart() throws Exception {
+ abstractMuleObjectOwner.start();
+ verify(mockObject1).start();
+ verify(mockObject2).start();
+ }
+
+ public void testStop() throws Exception {
+ abstractMuleObjectOwner.stop();
+ verify(mockObject1).stop();
+ verify(mockObject2).stop();
+ }
+
+ public class TestClass implements Lifecycle, MuleContextAware, FlowConstructAware
+ {
+ public void dispose() {
+ }
+
+ public void setFlowConstruct(FlowConstruct flowConstruct) {
+ }
+
+ public void initialise() throws InitialisationException {
+ }
+
+ public void setMuleContext(MuleContext context) {
+ }
+
+ public void start() throws MuleException {
+ }
+
+ public void stop() throws MuleException {
+ }
+ }
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -111,8 +111,9 @@
import org.mule.endpoint.EndpointURIEndpointBuilder;
import org.mule.enricher.MessageEnricher;
import org.mule.enricher.MessageEnricher.EnrichExpressionPair;
+import org.mule.exception.CatchMessagingExceptionStrategy;
+import org.mule.exception.ChoiceMessagingExceptionStrategy;
import org.mule.exception.DefaultMessagingExceptionStrategy;
-import org.mule.exception.CatchMessagingExceptionStrategy;
import org.mule.expression.ExpressionConfig;
import org.mule.expression.transformers.BeanBuilderTransformer;
import org.mule.expression.transformers.ExpressionArgument;
@@ -245,6 +246,7 @@
// Exception Strategies
registerBeanDefinitionParser("default-exception-strategy", new ExceptionStrategyDefinitionParser(DefaultMessagingExceptionStrategy.class));
registerBeanDefinitionParser("catch-exception-strategy", new ExceptionStrategyDefinitionParser(CatchMessagingExceptionStrategy.class));
+ registerBeanDefinitionParser("choice-exception-strategy", new ExceptionStrategyDefinitionParser(ChoiceMessagingExceptionStrategy.class));
registerMuleBeanDefinitionParser("exception-strategy", new ReferenceExceptionStrategyDefinitionParser());
registerDeprecatedBeanDefinitionParser("default-service-exception-strategy", new ChildDefinitionParser("exceptionListener", DefaultMessagingExceptionStrategy.class), "Use default-exception-strategy instead.");
registerBeanDefinitionParser("custom-exception-strategy", new ExceptionStrategyDefinitionParser(null));
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,11 +9,15 @@
*/
package org.mule.config.spring.parsers.specific;
+import org.mule.api.MuleRuntimeException;
import org.mule.api.config.MuleConfiguration;
import org.mule.api.config.MuleProperties;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.config.spring.parsers.PostProcessor;
+import org.mule.config.spring.parsers.assembly.BeanAssembler;
import org.mule.config.spring.parsers.generic.NamedDefinitionParser;
-
import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -34,6 +38,27 @@
{
super(MuleProperties.OBJECT_MULE_CONFIGURATION);
addIgnored(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE);
+ registerPostProcessor(new PostProcessor()
+ {
+ public void postProcess(ParserContext context, BeanAssembler assembler, Element element)
+ {
+ AbstractBeanDefinition beanDefinition = assembler.getBean().getBeanDefinition();
+ if (beanDefinition.hasAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE))
+ {
+ Object defaultExceptionStrategyBeanName = beanDefinition.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE);
+ if (!context.getRegistry().containsBeanDefinition((String) defaultExceptionStrategyBeanName))
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage(String.format("No global exception strategy defined with name %s.",defaultExceptionStrategyBeanName)));
+ }
+ BeanDefinition defaultExceptionStrategyBeanDefinition = context.getRegistry().getBeanDefinition(element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
+ if (defaultExceptionStrategyBeanDefinition.hasAttribute("expression"))
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Default exception strategy must not have expression attribute. It must accept any message."));
+ }
+ }
+ }
+ });
singleton=true;
}
@@ -48,7 +73,7 @@
{
if (element.hasAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE))
{
- builder.addPropertyValue("defaultExceptionStrategyName",element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
+ builder.addPropertyValue("defaultExceptionStrategyName", element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
}
super.doParse(element,context,builder);
}
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,44 +10,16 @@
package org.mule.config.spring.parsers.specific;
import static org.mule.config.spring.parsers.specific.ExceptionStrategyDefinitionParser.createNoNameAttributePreProcessor;
-import org.mule.api.config.MuleProperties;
+
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
-import org.mule.config.spring.parsers.delegate.ParentContextDefinitionParser;
-import org.mule.config.spring.parsers.generic.OrphanDefinitionParser;
import org.mule.config.spring.parsers.generic.ParentDefinitionParser;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-public class ReferenceExceptionStrategyDefinitionParser extends ParentContextDefinitionParser
+public class ReferenceExceptionStrategyDefinitionParser extends ParentDefinitionParser
{
public ReferenceExceptionStrategyDefinitionParser()
{
- super("configuration", createConfigurationDefinitionParser());
- otherwise(createInFlowServiceDefinitionParser());
+ addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "exceptionListener");
+ registerPreProcessor(createNoNameAttributePreProcessor());
}
- private ParentDefinitionParser createInFlowServiceDefinitionParser()
- {
- ParentDefinitionParser inFlowServiceDefinitionParser = new ParentDefinitionParser();
- inFlowServiceDefinitionParser.addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "exceptionListener");
- inFlowServiceDefinitionParser.registerPreProcessor(createNoNameAttributePreProcessor());
- return inFlowServiceDefinitionParser;
- }
-
- private static OrphanDefinitionParser createConfigurationDefinitionParser()
- {
- OrphanDefinitionParser orphanDefinitionParser = new OrphanDefinitionParser(false){
- protected AbstractBeanDefinition parseInternal(Element element, ParserContext context)
- {
- String ref = element.getAttribute("ref");
- context.getRegistry().registerAlias(ref,MuleProperties.OBJECT_DEFAULT_GLOBAL_EXCEPTION_STRATEGY);
- return null;
- }
- };
- orphanDefinitionParser.registerPreProcessor(createNoNameAttributePreProcessor());
- return orphanDefinitionParser;
- }
-
}
Modified: branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd 2012-01-31 16:08:45 UTC (rev 23768)
@@ -1718,7 +1718,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
- <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0" />
+ <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0"/>
<xsd:element ref="abstract-message-info-mapping" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
@@ -1813,6 +1813,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
+ <xsd:attribute name="expression" type="xsd:string" use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ The expression that will be evaluated to determine if this expcetion strategy should be executed. This should always be a boolean expression.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -2189,7 +2196,7 @@
</xsd:complexType>
</xsd:element>
</xsd:choice>
- <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0"/>
+ <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="abstract-message-info-mapping" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
@@ -4374,6 +4381,7 @@
<xsd:enumeration value="attachments-list"/>
<xsd:enumeration value="bean"/>
<xsd:enumeration value="endpoint"/>
+ <xsd:enumeration value="exception-type"/>
<xsd:enumeration value="function"/>
<xsd:enumeration value="groovy"/>
<xsd:enumeration value="header"/>
@@ -4801,6 +4809,15 @@
</xsd:annotation>
</xsd:element>
+ <xsd:element name="choice-exception-strategy" type="choiceExceptionStrategyType"
+ substitutionGroup="abstract-exception-strategy">
+ <xsd:annotation>
+ <xsd:documentation>
+ Exception strategy used to route to different exception strategies. It will execute the exception strategy which expression attribute matches against MuleMessage. In case there's no match, then default exception strategy will be exeucted.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
<xsd:element name="exception-strategy" type="referenceExceptionStrategyType"
substitutionGroup="abstract-exception-strategy">
<xsd:annotation>
@@ -4825,6 +4842,24 @@
</xsd:complexContent>
</xsd:complexType>
+
+ <xsd:complexType name="choiceExceptionStrategyType">
+ <xsd:complexContent>
+ <xsd:extension base="exceptionStrategyType">
+ <xsd:sequence>
+ <xsd:element ref="abstract-exception-strategy" minOccurs="1" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="name" type="substitutableName" use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ Name of the exception strategy that will be used in ref attribute of 'exception-strategy' element
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
<xsd:complexType name="serviceExceptionStrategyType">
<xsd:complexContent>
<xsd:extension base="abstractExceptionStrategyType">
Modified: branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java (23767 => 23768)
--- branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,20 +10,27 @@
package org.mule.test.config;
-import org.mule.api.DefaultMuleException;
-import org.mule.config.ExceptionHelper;
-import org.mule.config.i18n.MessageFactory;
-import org.mule.tck.junit4.AbstractMuleTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import java.util.List;
import java.util.Map;
+import org.hamcrest.core.IsInstanceOf;
+import org.hamcrest.core.IsNull;
import org.junit.Test;
+import org.mule.api.DefaultMuleException;
+import org.mule.api.config.ConfigurationException;
+import org.mule.api.registry.ResolverException;
+import org.mule.config.ExceptionHelper;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.config.i18n.MessageFactory;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
public class ExceptionHelperTestCase extends AbstractMuleTestCase
{
@@ -61,6 +68,21 @@
assertNotNull(summary);
}
+ public void testGetNonMuleExceptionCause()
+ {
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(), null)), IsNull.<Object>nullValue());
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(), null))), IsNull.<Object>nullValue());
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(),
+ new IllegalArgumentException()))), IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(),
+ new IllegalArgumentException(new NullPointerException())))), IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ assertThat(ExceptionHelper.getNonMuleException(new IllegalArgumentException()),IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ }
+
private Exception getException()
{
return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
Added: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,131 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.test.integration.exceptions;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.sql.SQLDataException;
+
+import org.junit.Test;
+import org.mule.api.MuleEventContext;
+import org.mule.api.MuleMessage;
+import org.mule.api.client.MuleClient;
+import org.mule.api.registry.ResolverException;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.tck.functional.EventCallback;
+import org.mule.tck.functional.FunctionalTestComponent;
+import org.mule.tck.junit4.FunctionalTestCase;
+
+public class ChoiceExceptionStrategyTestCase extends FunctionalTestCase
+{
+ protected String getConfigResources()
+ {
+ return "org/mule/test/integration/exceptions/choice-exception-strategy.xml";
+ }
+
+ public void testMatchesCorrectExceptionStrategy() throws Exception
+ {
+ callVmAndThrowException(new IllegalStateException(),"0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingWrapper() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new IllegalStateException()), "0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingWrapperAndCause() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new IllegalStateException(new NullPointerException())), "0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingBaseClass() throws Exception
+ {
+ callVmAndThrowException(new BaseException(), "0 catch-3");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingSubtypeClass() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new SubtypeException()), "0 catch-4");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingSubtypeSubtypeClass() throws Exception
+ {
+ callVmAndThrowException(new SubtypeSubtypeException(), "0 catch-4");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingRegex() throws Exception
+ {
+ callVmAndThrowException(new AnotherTypeMyException(), "0 catch-5");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingGroovyExpressionEvaluator() throws Exception
+ {
+ callVmAndThrowException("groovy", new SQLDataException(), "groovy catch-6");
+ }
+
+ public void testMatchesCorrectExceptionUsingNoCause() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage("")), "{NullPayload}");
+ }
+
+ public void testNoMatchThenCallDefaultExceptionStrategy() throws Exception
+ {
+ callVmAndThrowException(new ArithmeticException(),"0 global catch es");
+ }
+
+ private void callVmAndThrowException(final Exception exceptionToThrow, final String expectedMessage) throws Exception
+ {
+ callVmAndThrowException("0", exceptionToThrow, expectedMessage);
+ }
+
+ private void callVmAndThrowException(Object payload, final Exception exceptionToThrow, final String expectedMessage) throws Exception
+ {
+ MuleClient client = muleContext.getClient();
+ FunctionalTestComponent ftc = getFunctionalTestComponent("matchesCorrectExceptionStrategyUsingExceptionType");
+ ftc.setEventCallback(new EventCallback()
+ {
+ public void eventReceived(MuleEventContext context, Object component) throws Exception
+ {
+ throw exceptionToThrow;
+ }
+ });
+ MuleMessage response = client.send("vm://in", payload, null);
+ assertThat(response.getPayloadAsString(), is(expectedMessage));
+ }
+
+ public static class BaseException extends Exception
+ {
+ }
+
+ public static class SubtypeException extends BaseException
+ {
+ }
+
+ public static class SubtypeSubtypeException extends SubtypeException
+ {
+ }
+
+ public static class AnotherTypeMyException extends Exception
+ {
+ }
+}
Property changes on: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java (23767 => 23768)
--- branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,6 +9,11 @@
*/
package org.mule.test.integration.exceptions;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.junit.Test;
import org.mule.api.MuleContext;
import org.mule.api.MuleException;
@@ -24,11 +29,6 @@
import org.mule.tck.junit4.AbstractMuleTestCase;
import org.mule.util.concurrent.Latch;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
public class ExceptionStrategyConfigurationFailuresTestCase extends AbstractMuleTestCase
{
@@ -51,6 +51,18 @@
}
@Test(expected = ConfigurationException.class)
+ public void testChoiceExceptionStrategyCantHaveMiddleExceptionStrategyWithoutExpression() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml");
+ }
+
+ public void testChoiceExceptionStrategyCantHaveDefaultExceptionStrategy() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml");
+ }
+
public void testDefaultEsFailsAsReferencedExceptionStrategy() throws Exception
{
loadConfiguration("org/mule/test/integration/exceptions/default-es-as-referenced-exception-strategy.xml");
@@ -62,6 +74,12 @@
loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-reference-non-existent-es.xml");
}
+ public void testDefaultExceptionStrategyReferencesExceptionStrategyWithExpression() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml");
+ }
+
private void loadConfiguration(String configuration) throws MuleException, InterruptedException
{
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+ xmlns:http="http://www.mulesoft.org/schema/mule/http"
+ xmlns:test="http://www.mulesoft.org/schema/mule/test"
+ xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
+ http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/3.2/mule-test.xsd
+
+ http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd
+ http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.2/mule-http.xsd">
+
+ <catch-exception-strategy name="global-catch" expression="#[exception-type:java.lang.ArithmeticException]">
+ <append-string-transformer message=" global catch es"/>
+ </catch-exception-strategy>
+
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalArgumentException]">
+ <append-string-transformer message=" catch-1"/>
+ </catch-exception-strategy>
+
+ <flow name="matchesCorrectExceptionStrategyUsingExceptionType">
+ <vm:inbound-endpoint path="in" exchange-pattern="request-response"/>
+ <test:component/>
+ <choice-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalArgumentException]">
+ <append-string-transformer message=" catch-1"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalStateException]">
+ <append-string-transformer message=" catch-2"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:=org.mule.test.integration.exceptions.ChoiceExceptionStrategyTestCase$BaseException]">
+ <append-string-transformer message=" catch-3"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:org.mule.test.integration.exceptions.ChoiceExceptionStrategyTestCase$SubtypeException]">
+ <append-string-transformer message=" catch-4"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:(.*)mule.test.integration.(.*).ChoiceExceptionStrategyTestCase(.*)MyException]">
+ <append-string-transformer message=" catch-5"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[groovy:payload.equals('groovy')]">
+ <append-string-transformer message=" catch-6"/>
+ </catch-exception-strategy>
+ <exception-strategy ref="global-catch"/>
+ </choice-exception-strategy>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <flow name="flowA">
+ <logger/>
+ <choice-exception-strategy name="choice">
+ <catch-exception-strategy expression="#[exception-type:java.lang.NullPointerException]"/>
+ <defaul-exception-strategy/>
+ </choice-exception-strategy>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <configuration defaultExceptionStrategy-ref="exception-strategy-with-expression"/>
+
+ <catch-exception-strategy expression="#[exception-type:something]" name="exception-strategy-with-expression"/>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <choice-exception-strategy name="choice">
+ <catch-exception-strategy/>
+ <catch-exception-strategy/>
+ </choice-exception-strategy>
+
+ <flow name="flowA">
+ <logger/>
+ <exception-strategy ref="choice"/>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------23768
Author
pablo.lagreca
Date
2012-01-31 10:08:45 -0600 (Tue, 31 Jan 2012)
Log Message
MULE-5894 - Adding choice-exception-strategy - Creating exception-type expression evalutor and extending functionality for match exact type and regex
Modified Paths
• branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java
• branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java
• branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java
• branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java
• branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java
• branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd
• branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java
• branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java
Added Paths
• branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java
• branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java
• branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java
• branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java
• branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java
• branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java
• branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml
• branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml
Diff
Added: branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,30 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.api.exception;
+
+import org.mule.api.MuleEvent;
+
+/**
+ * Provides capability to only accept handling certain MuleEvents.
+ */
+public interface ChoiceMessagingExceptionHandler extends MessagingExceptionHandler
+{
+ /**
+ * false otherwise
+ */
+ boolean accept(MuleEvent event);
+
+ /**
+ */
+ boolean acceptsAll();
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/api/exception/ChoiceMessagingExceptionHandler.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/config/ExceptionHelper.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,15 +10,6 @@
package org.mule.config;
-import org.mule.api.MuleException;
-import org.mule.api.MuleRuntimeException;
-import org.mule.api.config.ExceptionReader;
-import org.mule.api.registry.ServiceType;
-import org.mule.config.i18n.CoreMessages;
-import org.mule.util.ClassUtils;
-import org.mule.util.MapUtils;
-import org.mule.util.SpiUtils;
-
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
@@ -31,6 +22,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.mule.api.MuleException;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.config.ExceptionReader;
+import org.mule.api.registry.ServiceType;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.util.ClassUtils;
+import org.mule.util.MapUtils;
+import org.mule.util.SpiUtils;
/**
* <code>ExceptionHelper</code> provides a number of helper functions that can be
@@ -343,6 +342,25 @@
return DefaultMuleConfiguration.fullStackTraces ? root : sanitize(root);
}
+ public static Throwable getNonMuleException(Throwable t)
+ {
+ if (!(t instanceof MuleException))
+ {
+ return t;
+ }
+ Throwable cause = t;
+ while (cause != null)
+ {
+ cause = getExceptionReader(cause).getCause(cause);
+ // address some misbehaving exceptions, avoid endless loop
+ if (t == cause || !(cause instanceof MuleException))
+ {
+ break;
+ }
+ }
+ return cause instanceof MuleException ? null : cause;
+ }
+
public static Throwable sanitizeIfNeeded(Throwable t)
{
return DefaultMuleConfiguration.fullStackTraces ? t : sanitize(t);
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/AbstractMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -40,7 +40,7 @@
public AbstractMessagingExceptionStrategy(MuleContext muleContext)
{
- this.muleContext = muleContext;
+ setMuleContext(muleContext);
}
public MuleEvent handleException(Exception ex, MuleEvent event)
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/CatchMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,7 +9,6 @@
*/
package org.mule.exception;
-import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;
public class CatchMessagingExceptionStrategy extends TemplateMessagingExceptionStrategy
@@ -32,4 +31,5 @@
{
return event;
}
+
}
Added: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,59 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.mule.api.MuleEvent;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.api.exception.MessagingExceptionHandler;
+import org.mule.processor.AbstractMuleObjectOwner;
+
+public class ChoiceDelegateMessagingExceptionStrategy extends AbstractMuleObjectOwner<MessagingExceptionHandler> implements ChoiceMessagingExceptionHandler
+{
+ private MessagingExceptionHandler delegate;
+
+ public ChoiceDelegateMessagingExceptionStrategy(MessagingExceptionHandler messagingExceptionHandler)
+ {
+ this.delegate = messagingExceptionHandler;
+ }
+
+ public boolean accept(MuleEvent event)
+ {
+ if (delegate instanceof ChoiceMessagingExceptionHandler)
+ {
+ return ((ChoiceMessagingExceptionHandler)delegate).accept(event);
+ }
+ return true;
+ }
+
+ public boolean acceptsAll()
+ {
+ if (delegate instanceof ChoiceMessagingExceptionHandler)
+ {
+ return ((ChoiceMessagingExceptionHandler)delegate).acceptsAll();
+ }
+ return true;
+ }
+
+ public MuleEvent handleException(Exception exception, MuleEvent event)
+ {
+ return delegate.handleException(exception,event);
+ }
+
+ protected List<MessagingExceptionHandler> getOwnedObjects() {
+ return Arrays.asList(delegate);
+ }
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceDelegateMessagingExceptionStrategy.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,82 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.mule.api.MuleEvent;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.api.exception.MessagingExceptionHandler;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.message.DefaultExceptionPayload;
+import org.mule.processor.AbstractMuleObjectOwner;
+
+/**
+ * Selects which exception strategy to execute based on filtering.
+ *
+ */
+public class ChoiceMessagingExceptionStrategy extends AbstractMuleObjectOwner<ChoiceMessagingExceptionHandler> implements MessagingExceptionHandler, MuleContextAware, Lifecycle
+{
+ private List<ChoiceMessagingExceptionHandler> exceptionListeners;
+
+ public MuleEvent handleException(Exception exception, MuleEvent event)
+ {
+ event.getMessage().setExceptionPayload(new DefaultExceptionPayload(exception));
+ for (ChoiceMessagingExceptionHandler exceptionListener : exceptionListeners)
+ {
+ if (exceptionListener.accept(event))
+ {
+ event.getMessage().setExceptionPayload(null);
+ return exceptionListener.handleException(exception,event);
+ }
+ }
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Default exception strategy must accept any event."));
+ }
+
+ public void setExceptionListeners(List<ChoiceMessagingExceptionHandler> exceptionListeners)
+ {
+ this.exceptionListeners = exceptionListeners;
+ validateConfiguredExceptionStrategies();
+ addDefaultExceptionStrategyIfRequired();
+ }
+
+ protected List<ChoiceMessagingExceptionHandler> getOwnedObjects() {
+ return Collections.unmodifiableList(exceptionListeners);
+ }
+
+ private void addDefaultExceptionStrategyIfRequired()
+ {
+ if (!exceptionListeners.get(exceptionListeners.size()-1).acceptsAll())
+ {
+ this.exceptionListeners.add(new ChoiceDelegateMessagingExceptionStrategy(getMuleContext().getDefaultExceptionStrategy()));
+ }
+ }
+
+ private void validateConfiguredExceptionStrategies()
+ {
+ for (int i = 0; i < exceptionListeners.size()-1; i++)
+ {
+ ChoiceMessagingExceptionHandler choiceMessagingExceptionHandler = exceptionListeners.get(i);
+ if (choiceMessagingExceptionHandler.acceptsAll())
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Only last exception strategy inside <choice-exception-strategy> can accept any message. Maybe expression attribute is empty."));
+ }
+ }
+ }
+
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/exception/ChoiceMessagingExceptionStrategy.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/exception/TemplateMessagingExceptionStrategy.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,8 +12,7 @@
import org.mule.api.MuleContext;
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
-import org.mule.api.exception.MessagingExceptionHandler;
-import org.mule.api.exception.RollbackSourceCallback;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
import org.mule.api.lifecycle.InitialisationException;
import org.mule.api.processor.MessageProcessor;
import org.mule.api.processor.MessageProcessorChain;
@@ -22,15 +21,20 @@
import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
import org.mule.routing.requestreply.ReplyToPropertyRequestReplyReplier;
-import java.net.URI;
-
-public abstract class TemplateMessagingExceptionStrategy extends AbstractExceptionListener implements MessagingExceptionHandler
+public abstract class TemplateMessagingExceptionStrategy extends AbstractExceptionListener implements ChoiceMessagingExceptionHandler
{
private MessageProcessorChain configuredMessageProcessors;
private MessageProcessor replyToMessageProcessor = new ReplyToPropertyRequestReplyReplier();
+ private String expression;
@Override
+ public boolean accept(MuleEvent event)
+ {
+ return acceptsAll() || muleContext.getExpressionManager().evaluateBoolean(expression,event.getMessage());
+ }
+
final public MuleEvent handleException(Exception exception, MuleEvent event)
{
fireNotification(exception);
@@ -104,6 +108,17 @@
}
}
+ public void setExpression(String expression)
+ {
+ this.expression = expression;
+ }
+
+ public boolean acceptsAll()
+ {
+ return expression == null;
+ }
+
protected abstract MuleEvent afterRouting(Exception exception, MuleEvent event);
protected abstract MuleEvent beforeRouting(Exception exception, MuleEvent event);
Added: branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.expression;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mule.api.MuleMessage;
+import org.mule.api.expression.ExpressionEvaluator;
+import org.mule.routing.filters.ExceptionTypeFilter;
+
+public class ExceptionTypeExpressionEvaluator implements ExpressionEvaluator
+{
+ protected transient Log logger = LogFactory.getLog(ExceptionTypeExpressionEvaluator.class);
+
+ public Object evaluate(String expression, MuleMessage message)
+ {
+ return new ExceptionTypeFilter(expression).accept(message);
+ }
+
+ public void setName(String name)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getName()
+ {
+ return "exception-type";
+ }
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/expression/ExceptionTypeExpressionEvaluator.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMessageProcessorOwner.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,104 +9,25 @@
*/
package org.mule.processor;
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
import org.mule.api.AnnotatedObject;
-import org.mule.api.MuleContext;
-import org.mule.api.MuleException;
-import org.mule.api.construct.FlowConstruct;
import org.mule.api.construct.FlowConstructAware;
import org.mule.api.context.MuleContextAware;
-import org.mule.api.lifecycle.Disposable;
-import org.mule.api.lifecycle.Initialisable;
-import org.mule.api.lifecycle.InitialisationException;
import org.mule.api.lifecycle.Lifecycle;
-import org.mule.api.lifecycle.Startable;
-import org.mule.api.lifecycle.Stoppable;
import org.mule.api.processor.MessageProcessor;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.xml.namespace.QName;
-
/**
* An object that owns message processors and delegates startup/shutdown events to them.
*/
-public abstract class AbstractMessageProcessorOwner implements Lifecycle, MuleContextAware, FlowConstructAware, AnnotatedObject
+public abstract class AbstractMessageProcessorOwner extends AbstractMuleObjectOwner<MessageProcessor> implements Lifecycle, MuleContextAware, FlowConstructAware, AnnotatedObject
{
- protected MuleContext muleContext;
- protected FlowConstruct flowConstruct;
private final Map<QName, Object> annotations = new ConcurrentHashMap<QName, Object>();
- public void setMuleContext(MuleContext context)
- {
- this.muleContext = context;
- }
-
- public void setFlowConstruct(FlowConstruct flowConstruct)
- {
- this.flowConstruct = flowConstruct;
- }
-
- public void initialise() throws InitialisationException
- {
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof MuleContextAware)
- {
- ((MuleContextAware) processor).setMuleContext(muleContext);
- }
- if (processor instanceof FlowConstructAware)
- {
- ((FlowConstructAware) processor).setFlowConstruct(flowConstruct);
- }
- if (processor instanceof Initialisable)
- {
- ((Initialisable) processor).initialise();
- }
- }
- }
-
- public void dispose()
- {
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
-
- if (processor instanceof Disposable)
- {
- ((Disposable) processor).dispose();
- }
- }
- }
-
-
- public void start() throws MuleException
- {
-
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof Startable)
- {
- ((Startable) processor).start();
- }
- }
- }
-
-
- public void stop() throws MuleException
- {
-
- for (MessageProcessor processor : getOwnedMessageProcessors())
- {
- if (processor instanceof Stoppable)
- {
- ((Stoppable) processor).stop();
- }
-
- }
- }
-
public final Object getAnnotation(QName name)
{
return annotations.get(name);
@@ -123,6 +44,11 @@
annotations.putAll(newAnnotations);
}
+ protected List<MessageProcessor> getOwnedObjects()
+ {
+ return getOwnedMessageProcessors();
+ }
+
protected abstract List<MessageProcessor> getOwnedMessageProcessors();
}
Added: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java (0 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java (rev 0)
+++ branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.processor;
+
+import java.util.List;
+
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.construct.FlowConstruct;
+import org.mule.api.construct.FlowConstructAware;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.lifecycle.Disposable;
+import org.mule.api.lifecycle.Initialisable;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.api.lifecycle.Startable;
+import org.mule.api.lifecycle.Stoppable;
+
+/**
+ * An object that owns Mule objects and delegates startup/shutdown events to them.
+ */
+public abstract class AbstractMuleObjectOwner<T> implements Lifecycle, MuleContextAware, FlowConstructAware {
+
+ protected MuleContext muleContext;
+ protected FlowConstruct flowConstruct;
+
+ public void setMuleContext(MuleContext context) {
+ this.muleContext = context;
+ }
+
+ public void setFlowConstruct(FlowConstruct flowConstruct) {
+ this.flowConstruct = flowConstruct;
+ }
+
+ public MuleContext getMuleContext() {
+ return muleContext;
+ }
+
+ public FlowConstruct getFlowConstruct() {
+ return flowConstruct;
+ }
+
+ public void initialise() throws InitialisationException {
+ for (T object : getOwnedObjects()) {
+ if (object instanceof MuleContextAware) {
+ ((MuleContextAware) object).setMuleContext(muleContext);
+ }
+ if (object instanceof FlowConstructAware) {
+ ((FlowConstructAware) object).setFlowConstruct(flowConstruct);
+ }
+ if (object instanceof Initialisable) {
+ ((Initialisable) object).initialise();
+ }
+ }
+ }
+
+ public void dispose() {
+ for (T processor : getOwnedObjects()) {
+
+ if (processor instanceof Disposable) {
+ ((Disposable) processor).dispose();
+ }
+ }
+ }
+
+
+ public void start() throws MuleException {
+
+ for (T processor : getOwnedObjects()) {
+ if (processor instanceof Startable) {
+ ((Startable) processor).start();
+ }
+ }
+ }
+
+
+ public void stop() throws MuleException {
+
+ for (T processor : getOwnedObjects()) {
+ if (processor instanceof Stoppable) {
+ ((Stoppable) processor).stop();
+ }
+
+ }
+ }
+
+ protected abstract List<T> getOwnedObjects();
+}
Property changes on: branches/mule-3.x/core/src/main/java/org/mule/processor/AbstractMuleObjectOwner.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExceptionTypeFilter.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,6 +12,7 @@
import org.mule.api.ExceptionPayload;
import org.mule.api.MuleMessage;
+import org.mule.config.ExceptionHelper;
import org.mule.util.ClassUtils;
/**
@@ -22,15 +23,25 @@
public class ExceptionTypeFilter extends PayloadTypeFilter
{
+ private String expression;
+
public ExceptionTypeFilter()
{
super();
}
- public ExceptionTypeFilter(String expectedType) throws ClassNotFoundException
+ public ExceptionTypeFilter(String expectedType)
{
- this(ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class));
+ try
+ {
+ Class exceptionType = ClassUtils.loadClass(expectedType, ExceptionTypeFilter.class);
+ setExpectedType(exceptionType);
+ }
+ catch (ClassNotFoundException e)
+ {
+ this.expression = expectedType;
+ }
}
public ExceptionTypeFilter(Class expectedType)
@@ -48,13 +59,32 @@
{
ExceptionPayload epl = message.getExceptionPayload();
- if (getExpectedType() == null)
+ if (getExpectedType() == null && this.expression == null)
{
return epl != null;
}
else if (epl != null)
{
- return getExpectedType().isAssignableFrom(epl.getException().getClass());
+ Throwable wrappedException = ExceptionHelper.getNonMuleException(epl.getException());
+ if (getExpectedType() != null)
+ {
+ //Exception type configured
+ return getExpectedType().isAssignableFrom(epl.getException().getClass()) || (wrappedException != null && getExpectedType().isAssignableFrom(wrappedException.getClass()));
+ }
+ else
+ {
+ //Expression configured
+ if (expression.startsWith("="))
+ {
+ String expectedType = expression.substring(1, expression.length());
+ return epl.getException().getClass().getName().equals(expectedType) || (wrappedException != null && wrappedException.getClass().getName().equals(expectedType));
+ }
+ else
+ {
+ RegExFilter regExFilter = new RegExFilter(expression);
+ return regExFilter.accept(epl.getException().getClass().getName()) || (wrappedException != null && regExFilter.accept(wrappedException.getClass().getName()));
+ }
+ }
}
else
{
Modified: branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java (23767 => 23768)
--- branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/java/org/mule/routing/filters/ExpressionFilter.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -12,6 +12,10 @@
import static org.mule.util.ClassUtils.equal;
import static org.mule.util.ClassUtils.hash;
+import java.text.MessageFormat;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.api.context.MuleContextAware;
@@ -20,11 +24,6 @@
import org.mule.expression.ExpressionConfig;
import org.mule.util.StringUtils;
-import java.text.MessageFormat;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
/**
* Allows boolean expressions to be executed on a message. Note that when using this filter you must be able to either specify
* a boolean expression when using an expression filter or use one of the standard Mule filters. These can be defined as follows -
@@ -169,22 +168,13 @@
}
else if(config.getEvaluator().equals("exception-type"))
{
- try
+ if (StringUtils.isEmpty(config.getExpression()))
{
- if (StringUtils.isEmpty(config.getExpression()))
- {
- delegateFilter = new ExceptionTypeFilter();
- }
- else
- {
- delegateFilter = new ExceptionTypeFilter(config.getExpression());
- }
+ delegateFilter = new ExceptionTypeFilter();
}
- catch (ClassNotFoundException e)
+ else
{
- IllegalArgumentException iae = new IllegalArgumentException();
- iae.initCause(e);
- throw iae;
+ delegateFilter = new ExceptionTypeFilter(config.getExpression());
}
}
else
Modified: branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties (23767 => 23768)
--- branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/core/src/main/resources/META-INF/services/org/mule/config/registry-bootstrap.properties 2012-01-31 16:08:45 UTC (rev 23768)
@@ -22,6 +22,7 @@
core.object.22=org.mule.expression.MessageHeaderExpressionEnricher
core.object.23=org.mule.expression.VariableExpressionEnricher
core.object.24=org.mule.expression.RegexExpressionEvaluator
+core.object.25=org.mule.expression.ExceptionTypeExpressionEvaluator
core.transformer.1=org.mule.transformer.simple.ObjectToByteArray
core.transformer.2=org.mule.transformer.simple.ObjectToOutputHandler
Added: branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,110 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.exception;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.internal.verification.VerificationModeFactory;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleContext;
+import org.mule.api.MuleEvent;
+import org.mule.api.MuleRuntimeException;
+import org.mule.api.exception.ChoiceMessagingExceptionHandler;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
+
+public class ChoiceMessagingExceptionStrategyTestCase extends AbstractMuleTestCase
+{
+
+ private ChoiceMessagingExceptionHandler mockTestExceptionStrategy1;
+ private ChoiceMessagingExceptionHandler mockTestExceptionStrategy2;
+ private ChoiceMessagingExceptionHandler mockDefaultTestExceptionStrategy2;
+ private MuleEvent mockMuleEvent;
+ private MuleContext mockMuleContext;
+ private Exception mockException = new Exception();
+
+ public void testNonMatchThenCallDefault() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ choiceMessagingExceptionStrategy.handleException(mockException,mockMuleEvent);
+ verify(mockTestExceptionStrategy1, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockTestExceptionStrategy2, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockDefaultTestExceptionStrategy2, VerificationModeFactory.times(1)).handleException(mockException, mockMuleEvent);
+ }
+
+ public void testNoneMatchEvenDefault() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(false);
+ choiceMessagingExceptionStrategy.handleException(mockException, mockMuleEvent);
+ }
+
+ public void testSecondMatches() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ choiceMessagingExceptionStrategy.initialise();
+ when(mockTestExceptionStrategy1.accept(mockMuleEvent)).thenReturn(false);
+ when(mockTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ when(mockDefaultTestExceptionStrategy2.accept(mockMuleEvent)).thenReturn(true);
+ choiceMessagingExceptionStrategy.handleException(mockException,mockMuleEvent);
+ verify(mockTestExceptionStrategy1, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockDefaultTestExceptionStrategy2, VerificationModeFactory.times(0)).handleException(any(Exception.class),any(MuleEvent.class));
+ verify(mockTestExceptionStrategy2, VerificationModeFactory.times(1)).handleException(mockException, mockMuleEvent);
+ }
+
+ public void testFirstAcceptsAllMatches() throws Exception
+ {
+ ChoiceMessagingExceptionStrategy choiceMessagingExceptionStrategy = new ChoiceMessagingExceptionStrategy();
+ choiceMessagingExceptionStrategy.setExceptionListeners(new ArrayList<ChoiceMessagingExceptionHandler>(Arrays.<ChoiceMessagingExceptionHandler>asList(mockTestExceptionStrategy1, mockTestExceptionStrategy2)));
+ when(mockMuleContext.getDefaultExceptionStrategy()).thenReturn(mockDefaultTestExceptionStrategy2);
+ choiceMessagingExceptionStrategy.setMuleContext(mockMuleContext);
+ when(mockTestExceptionStrategy1.acceptsAll()).thenReturn(true);
+ when(mockTestExceptionStrategy2.acceptsAll()).thenReturn(false);
+ when(mockDefaultTestExceptionStrategy2.acceptsAll()).thenReturn(true);
+ choiceMessagingExceptionStrategy.initialise();
+ }
+
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/exception/ChoiceMessagingExceptionStrategyTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.expression;
+
+import org.hamcrest.core.Is;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleMessage;
+import org.mule.api.MuleRuntimeException;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
+
+public class ExceptionTypeExpressionEvaluatorTestCase extends AbstractMuleTestCase
+{
+
+ private ExceptionTypeExpressionEvaluator exceptionTypeExpressionEvaluator = new ExceptionTypeExpressionEvaluator();
+ private MuleMessage mockMuleMessage;
+
+ public void testEvaluateNotMatchingExpression() throws Exception
+ {
+ exceptionTypeExpressionEvaluator.evaluate("asdf", mockMuleMessage);
+ }
+
+ public void testEvaluateMatchingExceptionType() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean) exceptionTypeExpressionEvaluator.evaluate(NullPointerException.class.getName(), mockMuleMessage), Is.is(true));
+ }
+
+ public void testEvaluateMatchingSubtype() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate(RuntimeException.class.getName(), mockMuleMessage),Is.is(true));
+ }
+
+ public void testEvaluateExactMatchingType() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("=" + NullPointerException.class.getName(), mockMuleMessage),Is.is(true));
+ }
+
+ public void testEvaluateExactSubtype() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("=" + RuntimeException.class.getName(), mockMuleMessage),Is.is(false));
+ }
+
+ public void testEvaluateMatchingUsingRegex() throws Exception
+ {
+ configureExceptionPayload(new MuleRuntimeException(new Exception()));
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("(.*).mule.(.*)Exception", mockMuleMessage),Is.is(true));
+ }
+ public void testEvaluateNotMatchingUsingRegex() throws Exception
+ {
+ configureExceptionPayload(new NullPointerException());
+ Assert.assertThat((Boolean)exceptionTypeExpressionEvaluator.evaluate("(.*).mule.not.matching.(.*)Exception", mockMuleMessage),Is.is(false));
+ }
+
+ private void configureExceptionPayload(Exception e)
+ {
+ Mockito.when(mockMuleMessage.getExceptionPayload().getException()).thenReturn(e);
+ }
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/expression/ExceptionTypeExpressionEvaluatorTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java (0 => 23768)
--- branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java (rev 0)
+++ branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,117 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.processor;
+
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mule.api.MuleContext;
+import org.mule.api.MuleException;
+import org.mule.api.construct.FlowConstruct;
+import org.mule.api.construct.FlowConstructAware;
+import org.mule.api.context.MuleContextAware;
+import org.mule.api.lifecycle.InitialisationException;
+import org.mule.api.lifecycle.Lifecycle;
+import org.mule.tck.size.SmallTest;
+
+public class AbstractMuleObjectOwnerTest {
+
+ private TestClass mockObject1;
+ private TestClass mockObject2;
+ private MuleContext mockMuleContext;
+ private FlowConstruct mockFlowConstruct;
+ private AbstractMuleObjectOwner<TestClass> abstractMuleObjectOwner;
+
+ public void before()
+ {
+ abstractMuleObjectOwner = new AbstractMuleObjectOwner<TestClass>()
+ {
+ protected List<TestClass> getOwnedObjects() {
+ return Arrays.asList(mockObject1,mockObject2);
+ }
+ };
+ abstractMuleObjectOwner.setFlowConstruct(mockFlowConstruct);
+ abstractMuleObjectOwner.setMuleContext(mockMuleContext);
+ }
+
+ public void testInitialise() throws Exception {
+ abstractMuleObjectOwner.initialise();
+ verify(mockObject1).initialise();
+ verify(mockObject2).initialise();
+ verify(mockObject1).setMuleContext(mockMuleContext);
+ verify(mockObject2).setMuleContext(mockMuleContext);
+ verify(mockObject1).setFlowConstruct(mockFlowConstruct);
+ verify(mockObject2).setFlowConstruct(mockFlowConstruct);
+ }
+
+ public void testDispose() throws Exception {
+ abstractMuleObjectOwner.dispose();
+ verify(mockObject1).dispose();
+ verify(mockObject2).dispose();
+ }
+
+ public void testStart() throws Exception {
+ abstractMuleObjectOwner.start();
+ verify(mockObject1).start();
+ verify(mockObject2).start();
+ }
+
+ public void testStop() throws Exception {
+ abstractMuleObjectOwner.stop();
+ verify(mockObject1).stop();
+ verify(mockObject2).stop();
+ }
+
+ public class TestClass implements Lifecycle, MuleContextAware, FlowConstructAware
+ {
+ public void dispose() {
+ }
+
+ public void setFlowConstruct(FlowConstruct flowConstruct) {
+ }
+
+ public void initialise() throws InitialisationException {
+ }
+
+ public void setMuleContext(MuleContext context) {
+ }
+
+ public void start() throws MuleException {
+ }
+
+ public void stop() throws MuleException {
+ }
+ }
+}
Property changes on: branches/mule-3.x/core/src/test/java/org/mule/processor/AbstractMuleObjectOwnerTest.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/handlers/MuleNamespaceHandler.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -111,8 +111,9 @@
import org.mule.endpoint.EndpointURIEndpointBuilder;
import org.mule.enricher.MessageEnricher;
import org.mule.enricher.MessageEnricher.EnrichExpressionPair;
+import org.mule.exception.CatchMessagingExceptionStrategy;
+import org.mule.exception.ChoiceMessagingExceptionStrategy;
import org.mule.exception.DefaultMessagingExceptionStrategy;
-import org.mule.exception.CatchMessagingExceptionStrategy;
import org.mule.expression.ExpressionConfig;
import org.mule.expression.transformers.BeanBuilderTransformer;
import org.mule.expression.transformers.ExpressionArgument;
@@ -245,6 +246,7 @@
// Exception Strategies
registerBeanDefinitionParser("default-exception-strategy", new ExceptionStrategyDefinitionParser(DefaultMessagingExceptionStrategy.class));
registerBeanDefinitionParser("catch-exception-strategy", new ExceptionStrategyDefinitionParser(CatchMessagingExceptionStrategy.class));
+ registerBeanDefinitionParser("choice-exception-strategy", new ExceptionStrategyDefinitionParser(ChoiceMessagingExceptionStrategy.class));
registerMuleBeanDefinitionParser("exception-strategy", new ReferenceExceptionStrategyDefinitionParser());
registerDeprecatedBeanDefinitionParser("default-service-exception-strategy", new ChildDefinitionParser("exceptionListener", DefaultMessagingExceptionStrategy.class), "Use default-exception-strategy instead.");
registerBeanDefinitionParser("custom-exception-strategy", new ExceptionStrategyDefinitionParser(null));
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ConfigurationDefinitionParser.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,11 +9,15 @@
*/
package org.mule.config.spring.parsers.specific;
+import org.mule.api.MuleRuntimeException;
import org.mule.api.config.MuleConfiguration;
import org.mule.api.config.MuleProperties;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.config.spring.parsers.PostProcessor;
+import org.mule.config.spring.parsers.assembly.BeanAssembler;
import org.mule.config.spring.parsers.generic.NamedDefinitionParser;
-
import org.springframework.beans.factory.BeanDefinitionStoreException;
+import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
@@ -34,6 +38,27 @@
{
super(MuleProperties.OBJECT_MULE_CONFIGURATION);
addIgnored(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE);
+ registerPostProcessor(new PostProcessor()
+ {
+ public void postProcess(ParserContext context, BeanAssembler assembler, Element element)
+ {
+ AbstractBeanDefinition beanDefinition = assembler.getBean().getBeanDefinition();
+ if (beanDefinition.hasAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE))
+ {
+ Object defaultExceptionStrategyBeanName = beanDefinition.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE);
+ if (!context.getRegistry().containsBeanDefinition((String) defaultExceptionStrategyBeanName))
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage(String.format("No global exception strategy defined with name %s.",defaultExceptionStrategyBeanName)));
+ }
+ BeanDefinition defaultExceptionStrategyBeanDefinition = context.getRegistry().getBeanDefinition(element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
+ if (defaultExceptionStrategyBeanDefinition.hasAttribute("expression"))
+ {
+ throw new MuleRuntimeException(CoreMessages.createStaticMessage("Default exception strategy must not have expression attribute. It must accept any message."));
+ }
+ }
+ }
+ });
singleton=true;
}
@@ -48,7 +73,7 @@
{
if (element.hasAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE))
{
- builder.addPropertyValue("defaultExceptionStrategyName",element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
+ builder.addPropertyValue("defaultExceptionStrategyName", element.getAttribute(DEFAULT_EXCEPTION_STRATEGY_ATTRIBUTE));
}
super.doParse(element,context,builder);
}
Modified: branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/java/org/mule/config/spring/parsers/specific/ReferenceExceptionStrategyDefinitionParser.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,44 +10,16 @@
package org.mule.config.spring.parsers.specific;
import static org.mule.config.spring.parsers.specific.ExceptionStrategyDefinitionParser.createNoNameAttributePreProcessor;
-import org.mule.api.config.MuleProperties;
+
import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
-import org.mule.config.spring.parsers.delegate.ParentContextDefinitionParser;
-import org.mule.config.spring.parsers.generic.OrphanDefinitionParser;
import org.mule.config.spring.parsers.generic.ParentDefinitionParser;
-import org.springframework.beans.factory.support.AbstractBeanDefinition;
-import org.springframework.beans.factory.xml.ParserContext;
-import org.w3c.dom.Element;
-public class ReferenceExceptionStrategyDefinitionParser extends ParentContextDefinitionParser
+public class ReferenceExceptionStrategyDefinitionParser extends ParentDefinitionParser
{
public ReferenceExceptionStrategyDefinitionParser()
{
- super("configuration", createConfigurationDefinitionParser());
- otherwise(createInFlowServiceDefinitionParser());
+ addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "exceptionListener");
+ registerPreProcessor(createNoNameAttributePreProcessor());
}
- private ParentDefinitionParser createInFlowServiceDefinitionParser()
- {
- ParentDefinitionParser inFlowServiceDefinitionParser = new ParentDefinitionParser();
- inFlowServiceDefinitionParser.addAlias(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF, "exceptionListener");
- inFlowServiceDefinitionParser.registerPreProcessor(createNoNameAttributePreProcessor());
- return inFlowServiceDefinitionParser;
- }
-
- private static OrphanDefinitionParser createConfigurationDefinitionParser()
- {
- OrphanDefinitionParser orphanDefinitionParser = new OrphanDefinitionParser(false){
- protected AbstractBeanDefinition parseInternal(Element element, ParserContext context)
- {
- String ref = element.getAttribute("ref");
- context.getRegistry().registerAlias(ref,MuleProperties.OBJECT_DEFAULT_GLOBAL_EXCEPTION_STRATEGY);
- return null;
- }
- };
- orphanDefinitionParser.registerPreProcessor(createNoNameAttributePreProcessor());
- return orphanDefinitionParser;
- }
-
}
Modified: branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd (23767 => 23768)
--- branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/modules/spring-config/src/main/resources/META-INF/mule.xsd 2012-01-31 16:08:45 UTC (rev 23768)
@@ -1718,7 +1718,7 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
- <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0" />
+ <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0"/>
<xsd:element ref="abstract-message-info-mapping" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
@@ -1813,6 +1813,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
+ <xsd:attribute name="expression" type="xsd:string" use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ The expression that will be evaluated to determine if this expcetion strategy should be executed. This should always be a boolean expression.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
@@ -2189,7 +2196,7 @@
</xsd:complexType>
</xsd:element>
</xsd:choice>
- <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0"/>
+ <xsd:element ref="legacy-abstract-exception-strategy" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="abstract-message-info-mapping" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
@@ -4374,6 +4381,7 @@
<xsd:enumeration value="attachments-list"/>
<xsd:enumeration value="bean"/>
<xsd:enumeration value="endpoint"/>
+ <xsd:enumeration value="exception-type"/>
<xsd:enumeration value="function"/>
<xsd:enumeration value="groovy"/>
<xsd:enumeration value="header"/>
@@ -4801,6 +4809,15 @@
</xsd:annotation>
</xsd:element>
+ <xsd:element name="choice-exception-strategy" type="choiceExceptionStrategyType"
+ substitutionGroup="abstract-exception-strategy">
+ <xsd:annotation>
+ <xsd:documentation>
+ Exception strategy used to route to different exception strategies. It will execute the exception strategy which expression attribute matches against MuleMessage. In case there's no match, then default exception strategy will be exeucted.
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:element>
+
<xsd:element name="exception-strategy" type="referenceExceptionStrategyType"
substitutionGroup="abstract-exception-strategy">
<xsd:annotation>
@@ -4825,6 +4842,24 @@
</xsd:complexContent>
</xsd:complexType>
+
+ <xsd:complexType name="choiceExceptionStrategyType">
+ <xsd:complexContent>
+ <xsd:extension base="exceptionStrategyType">
+ <xsd:sequence>
+ <xsd:element ref="abstract-exception-strategy" minOccurs="1" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ <xsd:attribute name="name" type="substitutableName" use="optional">
+ <xsd:annotation>
+ <xsd:documentation>
+ Name of the exception strategy that will be used in ref attribute of 'exception-strategy' element
+ </xsd:documentation>
+ </xsd:annotation>
+ </xsd:attribute>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
<xsd:complexType name="serviceExceptionStrategyType">
<xsd:complexContent>
<xsd:extension base="abstractExceptionStrategyType">
Modified: branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java (23767 => 23768)
--- branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/tests/functional/src/test/java/org/mule/test/config/ExceptionHelperTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -10,20 +10,27 @@
package org.mule.test.config;
-import org.mule.api.DefaultMuleException;
-import org.mule.config.ExceptionHelper;
-import org.mule.config.i18n.MessageFactory;
-import org.mule.tck.junit4.AbstractMuleTestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
import java.util.List;
import java.util.Map;
+import org.hamcrest.core.IsInstanceOf;
+import org.hamcrest.core.IsNull;
import org.junit.Test;
+import org.mule.api.DefaultMuleException;
+import org.mule.api.config.ConfigurationException;
+import org.mule.api.registry.ResolverException;
+import org.mule.config.ExceptionHelper;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.config.i18n.MessageFactory;
+import org.mule.tck.junit4.AbstractMuleTestCase;
+import org.mule.tck.size.SmallTest;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
public class ExceptionHelperTestCase extends AbstractMuleTestCase
{
@@ -61,6 +68,21 @@
assertNotNull(summary);
}
+ public void testGetNonMuleExceptionCause()
+ {
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(), null)), IsNull.<Object>nullValue());
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(), null))), IsNull.<Object>nullValue());
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(),
+ new IllegalArgumentException()))), IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ assertThat(ExceptionHelper.getNonMuleException(new ResolverException(CoreMessages.failedToBuildMessage(),
+ new ConfigurationException(CoreMessages.failedToBuildMessage(),
+ new IllegalArgumentException(new NullPointerException())))), IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ assertThat(ExceptionHelper.getNonMuleException(new IllegalArgumentException()),IsInstanceOf.instanceOf(IllegalArgumentException.class));
+ }
+
private Exception getException()
{
return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
Added: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,131 @@
+/*
+ * $Id$
+ * --------------------------------------------------------------------------------------
+ * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
+ *
+ * The software in this package is published under the terms of the CPAL v1.0
+ * license, a copy of which has been included with this distribution in the
+ * LICENSE.txt file.
+ */
+package org.mule.test.integration.exceptions;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.sql.SQLDataException;
+
+import org.junit.Test;
+import org.mule.api.MuleEventContext;
+import org.mule.api.MuleMessage;
+import org.mule.api.client.MuleClient;
+import org.mule.api.registry.ResolverException;
+import org.mule.config.i18n.CoreMessages;
+import org.mule.tck.functional.EventCallback;
+import org.mule.tck.functional.FunctionalTestComponent;
+import org.mule.tck.junit4.FunctionalTestCase;
+
+public class ChoiceExceptionStrategyTestCase extends FunctionalTestCase
+{
+ protected String getConfigResources()
+ {
+ return "org/mule/test/integration/exceptions/choice-exception-strategy.xml";
+ }
+
+ public void testMatchesCorrectExceptionStrategy() throws Exception
+ {
+ callVmAndThrowException(new IllegalStateException(),"0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingWrapper() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new IllegalStateException()), "0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingWrapperAndCause() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new IllegalStateException(new NullPointerException())), "0 catch-2");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingBaseClass() throws Exception
+ {
+ callVmAndThrowException(new BaseException(), "0 catch-3");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingSubtypeClass() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage(""), new SubtypeException()), "0 catch-4");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingSubtypeSubtypeClass() throws Exception
+ {
+ callVmAndThrowException(new SubtypeSubtypeException(), "0 catch-4");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingRegex() throws Exception
+ {
+ callVmAndThrowException(new AnotherTypeMyException(), "0 catch-5");
+ }
+
+ public void testMatchesCorrectExceptionStrategyUsingGroovyExpressionEvaluator() throws Exception
+ {
+ callVmAndThrowException("groovy", new SQLDataException(), "groovy catch-6");
+ }
+
+ public void testMatchesCorrectExceptionUsingNoCause() throws Exception
+ {
+ callVmAndThrowException(new ResolverException(CoreMessages.createStaticMessage("")), "{NullPayload}");
+ }
+
+ public void testNoMatchThenCallDefaultExceptionStrategy() throws Exception
+ {
+ callVmAndThrowException(new ArithmeticException(),"0 global catch es");
+ }
+
+ private void callVmAndThrowException(final Exception exceptionToThrow, final String expectedMessage) throws Exception
+ {
+ callVmAndThrowException("0", exceptionToThrow, expectedMessage);
+ }
+
+ private void callVmAndThrowException(Object payload, final Exception exceptionToThrow, final String expectedMessage) throws Exception
+ {
+ MuleClient client = muleContext.getClient();
+ FunctionalTestComponent ftc = getFunctionalTestComponent("matchesCorrectExceptionStrategyUsingExceptionType");
+ ftc.setEventCallback(new EventCallback()
+ {
+ public void eventReceived(MuleEventContext context, Object component) throws Exception
+ {
+ throw exceptionToThrow;
+ }
+ });
+ MuleMessage response = client.send("vm://in", payload, null);
+ assertThat(response.getPayloadAsString(), is(expectedMessage));
+ }
+
+ public static class BaseException extends Exception
+ {
+ }
+
+ public static class SubtypeException extends BaseException
+ {
+ }
+
+ public static class SubtypeSubtypeException extends SubtypeException
+ {
+ }
+
+ public static class AnotherTypeMyException extends Exception
+ {
+ }
+}
Property changes on: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ChoiceExceptionStrategyTestCase.java
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Modified: branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java (23767 => 23768)
--- branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java 2012-01-31 13:24:51 UTC (rev 23767)
+++ branches/mule-3.x/tests/integration/src/test/java/org/mule/test/integration/exceptions/ExceptionStrategyConfigurationFailuresTestCase.java 2012-01-31 16:08:45 UTC (rev 23768)
@@ -9,6 +9,11 @@
*/
package org.mule.test.integration.exceptions;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.junit.Test;
import org.mule.api.MuleContext;
import org.mule.api.MuleException;
@@ -24,11 +29,6 @@
import org.mule.tck.junit4.AbstractMuleTestCase;
import org.mule.util.concurrent.Latch;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-
public class ExceptionStrategyConfigurationFailuresTestCase extends AbstractMuleTestCase
{
@@ -51,6 +51,18 @@
}
@Test(expected = ConfigurationException.class)
+ public void testChoiceExceptionStrategyCantHaveMiddleExceptionStrategyWithoutExpression() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml");
+ }
+
+ public void testChoiceExceptionStrategyCantHaveDefaultExceptionStrategy() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml");
+ }
+
public void testDefaultEsFailsAsReferencedExceptionStrategy() throws Exception
{
loadConfiguration("org/mule/test/integration/exceptions/default-es-as-referenced-exception-strategy.xml");
@@ -62,6 +74,12 @@
loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-reference-non-existent-es.xml");
}
+ public void testDefaultExceptionStrategyReferencesExceptionStrategyWithExpression() throws Exception
+ {
+ loadConfiguration("org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml");
+ }
+
private void loadConfiguration(String configuration) throws MuleException, InterruptedException
{
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+ xmlns:http="http://www.mulesoft.org/schema/mule/http"
+ xmlns:test="http://www.mulesoft.org/schema/mule/test"
+ xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd
+ http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/3.2/mule-test.xsd
+
+ http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.2/mule-vm.xsd
+ http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/3.2/mule-http.xsd">
+
+ <catch-exception-strategy name="global-catch" expression="#[exception-type:java.lang.ArithmeticException]">
+ <append-string-transformer message=" global catch es"/>
+ </catch-exception-strategy>
+
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalArgumentException]">
+ <append-string-transformer message=" catch-1"/>
+ </catch-exception-strategy>
+
+ <flow name="matchesCorrectExceptionStrategyUsingExceptionType">
+ <vm:inbound-endpoint path="in" exchange-pattern="request-response"/>
+ <test:component/>
+ <choice-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalArgumentException]">
+ <append-string-transformer message=" catch-1"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:java.lang.IllegalStateException]">
+ <append-string-transformer message=" catch-2"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:=org.mule.test.integration.exceptions.ChoiceExceptionStrategyTestCase$BaseException]">
+ <append-string-transformer message=" catch-3"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:org.mule.test.integration.exceptions.ChoiceExceptionStrategyTestCase$SubtypeException]">
+ <append-string-transformer message=" catch-4"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[exception-type:(.*)mule.test.integration.(.*).ChoiceExceptionStrategyTestCase(.*)MyException]">
+ <append-string-transformer message=" catch-5"/>
+ </catch-exception-strategy>
+ <catch-exception-strategy expression="#[groovy:payload.equals('groovy')]">
+ <append-string-transformer message=" catch-6"/>
+ </catch-exception-strategy>
+ <exception-strategy ref="global-catch"/>
+ </choice-exception-strategy>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/choice-exception-strategy.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <flow name="flowA">
+ <logger/>
+ <choice-exception-strategy name="choice">
+ <catch-exception-strategy expression="#[exception-type:java.lang.NullPointerException]"/>
+ <defaul-exception-strategy/>
+ </choice-exception-strategy>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-in-choice.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <configuration defaultExceptionStrategy-ref="exception-strategy-with-expression"/>
+
+ <catch-exception-strategy expression="#[exception-type:something]" name="exception-strategy-with-expression"/>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/default-exception-strategy-reference-has-expression.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
Added: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml (0 => 23768)
--- branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml (rev 0)
+++ branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml 2012-01-31 16:08:45 UTC (rev 23768)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.2/mule.xsd">
+
+ <choice-exception-strategy name="choice">
+ <catch-exception-strategy/>
+ <catch-exception-strategy/>
+ </choice-exception-strategy>
+
+ <flow name="flowA">
+ <logger/>
+ <exception-strategy ref="choice"/>
+ </flow>
+
+</mule>
Property changes on: branches/mule-3.x/tests/integration/src/test/resources/org/mule/test/integration/exceptions/exception-strategy-in-choice-without-expression.xml
___________________________________________________________________
Added: svn:keywords
Added: svn:eol-style
http://xircles.codehaus.org/manage_email
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email