use of javax.validation.ValidationException in project jersey by jersey.
the class ValidateOnExecutionHandler method processAnnotation.
/**
* Process {@link ValidateOnExecution} annotation for given method on a class hierarchy.
*
* @param method method to be examined.
* @param hierarchy class hierarchy to be examined.
* @param checkOverrides flag whether a overriding/implementing methods should also be checked.
* @return {@code true} if the method should be validated, {@code false} if not, {@code null} if the flag cannot be
* determined (no annotation present).
*/
private Boolean processAnnotation(final Method method, final Deque<Class<?>> hierarchy, final boolean checkOverrides) {
// Overridden methods.
while (!hierarchy.isEmpty()) {
final Class<?> overriddenClass = hierarchy.removeFirst();
final Method overriddenMethod = AccessController.doPrivileged(ReflectionHelper.findMethodOnClassPA(overriddenClass, method));
if (overriddenMethod != null) {
// Method.
Set<ExecutableType> executableTypes = getExecutableTypes(overriddenMethod);
if (!executableTypes.isEmpty()) {
// If an overriding/implementing method is annotated with @ValidateOnExecution, throw an exception.
if (checkOverrides && processAnnotation(method, hierarchy, false) != null) {
final String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
throw new ValidationException(LocalizationMessages.OVERRIDE_CHECK_ERROR(methodName));
}
return validateMethod(overriddenMethod, true, executableTypes);
}
// Class.
executableTypes = getExecutableTypes(overriddenClass);
if (!executableTypes.isEmpty() && // ExecutableType#IMPLICIT on class itself does nothing.
!(executableTypes.size() == 1 && executableTypes.contains(ExecutableType.IMPLICIT))) {
return validateMethod(overriddenMethod, false, executableTypes);
}
}
}
return null;
}
use of javax.validation.ValidationException in project apex-core by apache.
the class OiOStreamTest method validateNegativeOiOiOExtendeddiamond.
@Test
public void validateNegativeOiOiOExtendeddiamond() {
logger.info("Checking the logic for sanity checking of OiO");
LogicalPlan plan = new LogicalPlan();
ThreadIdValidatingInputOperator inputOperator = plan.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = plan.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = plan.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator3 = plan.addOperator("intermediateOperator3", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator4 = plan.addOperator("intermediateOperator4", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = plan.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
plan.addStream("OiOin", inputOperator.output, intermediateOperator1.input, intermediateOperator3.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOIntermediate1", intermediateOperator1.output, intermediateOperator2.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("nonOiOIntermediate2", intermediateOperator3.output, intermediateOperator4.input).setLocality(null);
plan.addStream("OiOout1", intermediateOperator2.output, outputOperator.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOout2", intermediateOperator4.output, outputOperator.input2).setLocality(Locality.THREAD_LOCAL);
try {
plan.validate();
Assert.fail("OiOiO extended diamond validation");
} catch (ConstraintViolationException ex) {
Assert.assertTrue("OiOiO extended diamond validation", true);
} catch (ValidationException ex) {
Assert.assertTrue("OiOiO extended diamond validation", true);
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class OiOStreamTest method validateNegativeOiO.
@Test
public void validateNegativeOiO() {
LogicalPlan plan = new LogicalPlan();
RecoverableInputOperator inputOp1 = plan.addOperator("InputOperator1", new RecoverableInputOperator());
RecoverableInputOperator inputOp2 = plan.addOperator("InputOperator2", new RecoverableInputOperator());
GenericOperator genOp = plan.addOperator("GenericOperator", new GenericOperator());
StreamMeta oio1 = plan.addStream("OiO1", inputOp1.output, genOp.ip1).setLocality(Locality.THREAD_LOCAL);
StreamMeta oio2 = plan.addStream("OiO2", inputOp2.output, genOp.ip2).setLocality(Locality.THREAD_LOCAL);
try {
plan.validate();
Assert.fail("OIO Both InputPorts");
} catch (ConstraintViolationException ex) {
Assert.assertTrue("OiO validation passed", true);
} catch (ValidationException ex) {
Assert.assertTrue("OiO validation passed", true);
}
oio1.setLocality(null);
try {
plan.validate();
Assert.fail("OIO First InputPort");
} catch (ConstraintViolationException ex) {
Assert.assertTrue("OiO validation passed", true);
} catch (ValidationException ex) {
Assert.assertTrue("OiO validation passed", true);
}
oio1.setLocality(Locality.THREAD_LOCAL);
oio2.setLocality(null);
try {
plan.validate();
Assert.fail("OIO Second InputPort");
} catch (ConstraintViolationException ex) {
Assert.assertTrue("OiO validation passed", true);
} catch (ValidationException ex) {
Assert.assertTrue("OiO validation passed", true);
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class OiOStreamTest method validateNegativeOiOiOdiamond.
@Test
public void validateNegativeOiOiOdiamond() {
logger.info("Checking the logic for sanity checking of OiO");
LogicalPlan plan = new LogicalPlan();
ThreadIdValidatingInputOperator inputOperator = plan.addOperator("inputOperator", new ThreadIdValidatingInputOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator1 = plan.addOperator("intermediateOperator1", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericIntermediateOperator intermediateOperator2 = plan.addOperator("intermediateOperator2", new ThreadIdValidatingGenericIntermediateOperator());
ThreadIdValidatingGenericOperatorWithTwoInputPorts outputOperator = plan.addOperator("outputOperator", new ThreadIdValidatingGenericOperatorWithTwoInputPorts());
plan.addStream("OiOin", inputOperator.output, intermediateOperator1.input, intermediateOperator2.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("OiOout1", intermediateOperator1.output, outputOperator.input).setLocality(Locality.THREAD_LOCAL);
plan.addStream("nonOiOout2", intermediateOperator2.output, outputOperator.input2).setLocality(null);
try {
plan.validate();
Assert.fail("OIOIO negative diamond");
} catch (ConstraintViolationException ex) {
Assert.assertTrue("OIOIO negative diamond", true);
} catch (ValidationException ex) {
Assert.assertTrue("OIOIO negative diamond", true);
}
}
use of javax.validation.ValidationException in project apex-core by apache.
the class LogicalPlan method checkAttributeValueSerializable.
private void checkAttributeValueSerializable(AttributeMap attributes, String context) {
StringBuilder sb = new StringBuilder();
String delim = "";
// Check all attributes got operator are serializable
for (Entry<Attribute<?>, Object> entry : attributes.entrySet()) {
if (entry.getValue() != null && !(entry.getValue() instanceof Serializable)) {
sb.append(delim).append(entry.getKey().getSimpleName());
delim = ", ";
}
}
if (sb.length() > 0) {
throw new ValidationException("Attribute value(s) for " + sb.toString() + " in " + context + " are not serializable");
}
}
Aggregations