users@jersey.java.net

[Jersey] Re: Entity Validation

From: Miles, Eric (CONT) <"Miles,>
Date: Thu, 24 Oct 2013 15:04:37 -0400

Silly question, but did you setup the ValidationConfig at all through a Provider or some other mechanism?


From: Bob Krier <rkrier_at_axway.com<mailto:rkrier_at_axway.com>>
Reply-To: Jersey Users <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Thursday, October 24, 2013 3:01 PM
To: Jersey Users <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Entity Validation

Hi Everyone,

I'm unclear about setting up entity validation. To give you some foreground, our app runs embedded Jetty with Jersey as a REST provider (2.3.1). I have a Annotation defined as follows.

@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = BeanValidation.Validator.class)
public @interface BeanValidation
{
String message() default "{com.axway.constraint.Some.message}";
Class[] groups() default {};
Class[] payload() default {};

public class Validator implements ConstraintValidator<BeanValidation, Object>
{
@Override
public void initialize(final BeanValidation bean)
{
}

@Override
public boolean isValid(final Object bean, final ConstraintValidatorContext constraintValidatorContext)
{
AnnotationValidator validator = new AnnotationValidator();
List<ResponseMessage> messages = validator.doValidate(bean); // Todo – return true or false depending on the outcome.
return true;
}
}
}

I have my resource defined like this:

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public OrganizationBean addOrganization(@BeanValidation OrganizationBean bean)
{
return ….;
}


Here is my web.xml:

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.axway.rest.api.v1.resources;com.axway.rest.api.v1.mappers.exceptions;com.axway.rest.tools.resolvers;com.axway.rest.api</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>0.1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
.
.
.



When I execute the POST, the BeanValidation.Validator is not executed (have a break point on the "isValidMethod"). Is there a step I'm missing?

Regards,

Bob


________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.