use of org.apache.camel.spi.Validator in project camel by apache.
the class DefaultValidatorRegistry method put.
@Override
public Validator put(ValidatorKey key, Validator validator) {
// at first we must see if the key already exists and then replace it back, so it stays the same spot
Validator answer = staticMap.remove(key);
if (answer != null) {
// replace existing
staticMap.put(key, validator);
return answer;
}
answer = super.remove(key);
if (answer != null) {
// replace existing
super.put(key, validator);
return answer;
}
// we want validators to be static if they are part of setting up or starting routes
if (context.isSetupRoutes() || context.isStartingRoutes()) {
answer = staticMap.put(key, validator);
} else {
answer = super.put(key, validator);
}
return answer;
}
use of org.apache.camel.spi.Validator in project camel by apache.
the class ManagedValidatorRegistry method listValidators.
@SuppressWarnings("unchecked")
public TabularData listValidators() {
try {
TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listValidatorsTabularType());
Collection<Validator> validators = validatorRegistry.values();
for (Validator validator : validators) {
CompositeType ct = CamelOpenMBeanTypes.listValidatorsCompositeType();
DataType type = validator.getType();
String desc = validator.toString();
boolean isStatic = validatorRegistry.isStatic(type);
boolean isDynamic = validatorRegistry.isDynamic(type);
CompositeData data = new CompositeDataSupport(ct, new String[] { "type", "static", "dynamic", "description" }, new Object[] { type.toString(), isStatic, isDynamic, desc });
answer.put(data);
}
return answer;
} catch (Exception e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
use of org.apache.camel.spi.Validator in project camel by apache.
the class AbstractLocalCamelController method getValidators.
@Override
public List<Map<String, String>> getValidators(String camelContextName) throws Exception {
List<Map<String, String>> answer = new ArrayList<Map<String, String>>();
if (camelContextName != null) {
CamelContext context = this.getLocalCamelContext(camelContextName);
if (context != null) {
List<Validator> validators = new ArrayList<Validator>(context.getValidatorRegistry().values());
for (Validator validator : validators) {
Map<String, String> row = new LinkedHashMap<String, String>();
row.put("camelContextName", context.getName());
row.put("type", validator.getType().toString());
row.put("state", validator.getStatus().toString());
row.put("description", validator.toString());
answer.add(row);
}
}
}
return answer;
}
use of org.apache.camel.spi.Validator in project camel by apache.
the class CustomValidatorDefinition method doCreateValidator.
@Override
protected Validator doCreateValidator(CamelContext context) throws Exception {
if (ref == null && className == null) {
throw new IllegalArgumentException("'ref' or 'type' must be specified for customValidator");
}
Validator validator;
if (ref != null) {
validator = context.getRegistry().lookupByNameAndType(ref, Validator.class);
if (validator == null) {
throw new IllegalArgumentException("Cannot find validator with ref:" + ref);
}
if (validator.getType() != null) {
throw new IllegalArgumentException(String.format("Validator '%s' is already in use. Please check if duplicate validator exists.", ref));
}
} else {
Class<Validator> validatorClass = context.getClassResolver().resolveMandatoryClass(className, Validator.class);
if (validatorClass == null) {
throw new IllegalArgumentException("Cannot find validator class: " + className);
}
validator = context.getInjector().newInstance(validatorClass);
}
validator.setCamelContext(context);
return validator.setType(getType());
}
use of org.apache.camel.spi.Validator 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));
}
}
Aggregations