users@jersey.java.net

[Jersey] Re: Entity Validation

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

In the Jersey examples bundle, take a look at the bean validation app. Specifically, the org.glassfish.jersey.examples.beanvalidation.webapp.MyApplication class. They are registering a ContextResolver that returns an instance of ValidationConfig. I THINK this is necessary to get bean validation going on your project (that's what we did in ours and it seems to be working ok).

Good luck.

Eric
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:10 PM
To: Jersey Users <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Re: Entity Validation

Thanks Eric,

Not a silly question at all. No I am not doing that. I think that is my question. I'm not clear from the docs how to do that for my case. I am not using the Hibernate-Validators. Basically I have a bunch of beans that can be POSTed or PUTted through different resources. I would like to automatically call my generic validator on each bean for an add or update. I guess annotating them alone is not enough, huh?

Bob

From: <Miles>, "Eric (CONT)" <Eric.Miles_at_capitalone.com<mailto:Eric.Miles_at_capitalone.com>>
Reply-To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Thursday, October 24, 2013 12:04 PM
To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Re: Entity Validation

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/j2eehttp://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.
________________________________________________________

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.