use of org.apache.camel.ValidationException in project camel by apache.
the class BeanWithExceptionTest method testInvalidMessage.
public void testInvalidMessage() throws Exception {
validEndpoint.expectedMessageCount(0);
invalidEndpoint.expectedMessageCount(1);
Exchange exchange = template.send("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("<invalid/>");
exchange.getIn().setHeader("foo", "notMatchedHeaderValue");
exchange.setProperty("cheese", "old");
}
});
assertNotNull(exchange.getException());
ValidationException exception = assertIsInstanceOf(ValidationException.class, exchange.getException());
assertEquals("Invalid header foo: notMatchedHeaderValue", exception.getMessage());
assertMockEndpointsSatisfied();
}
use of org.apache.camel.ValidationException in project camel by apache.
the class DefaultExceptionPolicyStrategyTest method testClosetMatch1.
public void testClosetMatch1() {
setupPolicies();
OnExceptionDefinition result = strategy.getExceptionPolicy(policies, null, new ValidationException(null, ""));
assertEquals(type1, result);
result = strategy.getExceptionPolicy(policies, null, new ExchangeTimedOutException(null, 0));
assertEquals(type1, result);
}
use of org.apache.camel.ValidationException in project camel by apache.
the class ContractAdvice method doValidate.
private void doValidate(Message message, DataType type) throws ValidationException {
Validator validator = message.getExchange().getContext().resolveValidator(type);
if (validator != null) {
LOG.debug("Applying validator: type='{}', validator='{}'", type, validator);
validator.validate(message, type);
} else {
throw new ValidationException(message.getExchange(), String.format("No Validator found for '%s'", type));
}
}
use of org.apache.camel.ValidationException in project camel by apache.
the class ProcessorValidator method validate.
/**
* Perform content validation with specified type using Processor.
*
* @param message message to apply validation
* @param type 'from' data type
*/
@Override
public void validate(Message message, DataType type) throws ValidationException {
Exchange exchange = message.getExchange();
LOG.debug("Sending to validate processor '{}'", processor);
DefaultExchange validateExchange = new DefaultExchange(exchange);
validateExchange.setIn(message);
validateExchange.setProperties(exchange.getProperties());
try {
processor.process(validateExchange);
} catch (Exception e) {
if (e instanceof ValidationException) {
throw (ValidationException) e;
} else {
throw new ValidationException(String.format("Validation failed for '%s'", type), validateExchange, e);
}
}
}
Aggregations