i have a problem because of custom ConstraintValidatorContext
initialize()
called first time only when this custom inject called , and after that it run the method isValid only() without construct initialize()
method again every time ! .
example @APIAuth annotation:
@Documented
@Constraint(validatedBy = APIAuthValidator.class)
@Target({ElementType.CONSTRUCTOR,ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface APIAuth {
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
APIAuthValidator.class
public class APIAuthValidator implements ConstraintValidator<APIAuth, String>{
@Override
public void initialize(APIAuth constraintAnnotation) {
System.out.println("echo first time only");
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return true;
}
}
Example for usage inside Restful Stateless Session bean
@Stateless
@Path("Accepted")
public class AcceptedAPI {
@Context
private UriInfo context;
@Context
private HttpServletRequest client;
@PersistenceContext (unitName="APIPU") EntityManager EM;
@GET
@APIAuth
@Produces(MediaType.TEXT_PLAIN)
public String getIps() {
return "Test";
}
}
so when i request the stateless , it echo on console echo first time only
first time , and when i request the stateless again , it don't echo any thing again !
so i think that my custom Validator inject is initialized and cached since first time of it's calling inside the java environment ,
so How i make my custom inject to force initialize
every time i call it ?
Thank you,