I have been unit testing using annotations with Hibernate Validator [hibernate-validator-4.1.0.Final.jar] and have everything working well. Now, I want to execute the exact same validations using the "Programmatic" API (see below).
Unfortunately... import org.hibernate.validator.cfg.defs.*;
Caused by: javax.xml.ws.soap.SOAPFaultException: Unable to instantiateorg.hibernate.validator.cfg.defs.NotNullDef at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.createSystemException(MethodMarshallerUtils.java:1153) at org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils.demarshalFaultResponse(MethodMarshallerUtils.java:916) at org.apache.axis2.jaxws.marshaller.impl.alt.DocLitBareMethodMarshaller.demarshalFaultResponse(DocLitBareMethodMarshaller.java:366) at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.getFaultResponse(JAXWSProxyHandler.java:451) at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.createResponse(JAXWSProxyHandler.java:424) at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:336) at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:148) at $Proxy56.bookAdventure(Unknown Source) at sun.reflect.GeneratedMethodAccessor647.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:618) at com.ford.it.wscore.consumer.as.WscBaseGenericConsumerAS.executeBusinessProcess(WscBaseGenericConsumerAS.java:447) at com.ford.it.wscore.consumer.as.WscBaseGenericConsumerAS.processConsumer(WscBaseGenericConsumerAS.java:301) ... 41 more
/** * This instance contains the "declarative" validation rules. */ private ConstraintMapping constraintMapping = new ConstraintMapping();
/** * Construct a BookAdventureProviderController instance * * @param webServiceContext The web service context * @param jaxbRequest The JAXB request */ public BookAdventure2ProviderController( final WebServiceContext webServiceContext, final Object jaxbRequest) { super(webServiceContext, jaxbRequest);
this.constraintMapping.type(BookingType.class)
.property("startDate", ElementType.FIELD) .constraint(NotNullDef.class)
.property("endDate", ElementType.FIELD) .constraint(NotNullDef.class)
.property("customer", ElementType.FIELD) .constraint(NotNullDef.class)
.property("adventure", ElementType.FIELD) .constraint(NotNullDef.class) .valid("adventure", ElementType.FIELD)
.type(AdventureType.class)
.property("departingFlight", ElementType.FIELD) .constraint(NotNullDef.class) .valid("departingFlight", ElementType.FIELD)
.property("returningFlight", ElementType.FIELD) .constraint(NotNullDef.class) .valid("returningFlight", ElementType.FIELD)
.type(FlightType.class)
.property("flightNumber", ElementType.FIELD) .constraint(NotBlankDef.class)
.type(AdventureType.class)
.property("name", ElementType.FIELD) .constraint(NotBlankDef.class)
.type(CustomerType.class)
.property("customerEmailId", ElementType.FIELD) .constraint(NotBlankDef.class) .constraint(EmailDef.class)
.property("firstName", ElementType.FIELD) .constraint(NotBlankDef.class)
.property("lastName", ElementType.FIELD) .constraint(NotBlankDef.class)
.property("phone", ElementType.FIELD) .constraint(NotBlankDef.class) .constraint(DecimalMaxDef.class) .value("9999999999") .constraint(DecimalMinDef.class) .value("1000000000")
.type(AddressType.class)
.property("streetAddress1", ElementType.FIELD) .constraint(NotBlankDef.class)
.property("city", ElementType.FIELD) .constraint(NotBlankDef.class)
.property("state", ElementType.FIELD) .constraint(NotBlankDef.class)
.property("country", ElementType.FIELD) .constraint(NotBlankDef.class); }
// #1 of 1: The parent domain instance is validated.
validateDeclarativeFirstErrorOnlyUsingProgrammaticAPI( bookAdventureRequestType.getBooking(), this.constraintMapping);
/** * This convenience method is used to invoke declarative validation. * * @param <T> Instance to be validated. * @param instanceToBeValidated Instance to be validated. * @param constraintMapping The validation rules for the instance being * validated. */ protected <T> void validateDeclarativeFirstErrorOnlyUsingProgrammaticAPI( final T instanceToBeValidated, final ConstraintMapping constraintMapping) {
final String METHOD_NAME = "validateDeclarativeFirstErrorOnlyUsingProgrammaticAPI"; log.entering(CLASS_NAME, METHOD_NAME);
// Declare/Initialize final HibernateValidatorConfiguration hibernateValidatorConfiguration = Validation.byProvider(HibernateValidator.class).configure();
hibernateValidatorConfiguration.addMapping(constraintMapping);
final ValidatorFactory validatorFactory = hibernateValidatorConfiguration.buildValidatorFactory();
final Validator validator = validatorFactory.getValidator();
// Declarative validation NOW! final Set<ConstraintViolation<T>> constraintViolationSet = validator.validate(instanceToBeValidated);
final StringBuffer message = new StringBuffer(); if (!constraintViolationSet.isEmpty()) {
for (final ConstraintViolation<T> constraintViolation : constraintViolationSet) {
message.append(constraintViolation.getMessage()); message.append(" ["); message.append(constraintViolation.getLeafBean() .getClass() .getSimpleName()); message.append("."); message.append(constraintViolation.getPropertyPath().toString());
}
throw new WscValidationClientFaultException( new FordExceptionAttributes.Builder(CLASS_NAME, METHOD_NAME).build(), message.toString()); }
log.exiting(CLASS_NAME, METHOD_NAME); return;
}
|