validationmuleapikit

Mule apiKitGlobalExceptionMapping ValidationException not being thrown


I am using the validation component to validate key pieces of data in my mule messages when processing apiKit routed messages.

I was expecting my exception class to be raised, where I could catch it in the api kit global exception component, but the exceptions always come in as org.mule.api.MessagingException, not my custom class.

what do i need to do to get my exception from the validation component to be separated out in the api kit global exception component? below is my Validation exception component:

package com.comMyAppy.rules;
import com.comMyAppy.rules.MyAppValidationException;
import org.mule.api.MuleEvent;
import org.mule.extension.validation.api.ExceptionFactory;
import org.mule.extension.validation.api.ValidationResult;

public class MyAppValidationExceptionFactory implements ExceptionFactory
{

    @SuppressWarnings("unchecked")
    @Override
    public <T extends Exception> T createException(ValidationResult result,
            Class<T> exceptionClass, MuleEvent event)
    {
        // TODO Auto-generated method stub
        return (T) new MyAppValidationException(result, event);
    }

    @Override
    public Exception createException(ValidationResult result,
            String exceptionClassName, MuleEvent event)
    {
        // TODO Auto-generated method stub
        return new MyAppValidationException(result, event);
    }

}

here is my exception class:

package com.comMyAppy.rules;
import org.mule.api.MuleEvent;
import org.mule.config.i18n.Message;
import org.mule.extension.validation.api.ValidationException;
import org.mule.extension.validation.api.ValidationResult;
@SuppressWarnings("serial")
public class MyAppValidationException extends ValidationException
{

    public MyAppValidationException(ValidationResult validationResult,
            MuleEvent event)
    {
        super(validationResult, event);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected String generateMessage(Message message)
    {
        return "VALIDATION:" + message.getMessage();
    }

}

What am i doing wrong?


Solution

  • I figured out what my problem was: I was using the validation:all component, which just aggregated all of the messages between all of the different validators, and threw a messageException effectively ignoring my validation configuration. my advice: avoid the all validator. it sounds good, but you lose custom exception ability.