I am looking for a good user input validation scheme for Resteasy services.
Say I have this service:
@Local
@Path("/example")
public interface IExample {
public Response doSomething ( @QueryParam("arg1") String arg1, @QueryParam("arg2") Integer arg2);
}
which I implemented:
@Stateless
public class Example implements IExample {
@Override
public Response doSomething ( String arg1, Integer arg2 ) { ... }
}
What is the best practice for checking arg1 and arg2?
My ideas:
- Confirm inside the doSomething (...) method. Disadvantage: when I add some parameter (e.g. arg3) in the future, I could easily forget to check it.
- In custom javax.servlet.Filter. Disadvantage: I cannot access arg1 and arg2, as they have not yet been analyzed by the Resteasy framework.
I came up with this concept:
public class ExampleValidator implements IExample {
public static class ValidationError extends RuntimeException { ... }
@Override
public Response doSomething ( String arg1, Integer arg2 ) {
return null;
}
}
which can be used as follows:
@Stateless
public class Example implements IExample {
@Override
public Response doSomething ( String arg1, Integer arg2 ) {
try {
(new ExampleValidator()).doSomething(arg1, arg2);
} catch ( ValidationError e ) {
}
}
}
, IExample.doSomething, Validator - . , Resteasy NOT TO Validator , resteasy.jndi.resources resteasy.scan, ( bean ).
- ?
- ?
: , , - - Resteasy? , () , (arg1, arg2)?
, ;)