eliocs
eliocs

Reputation: 18827

Using EJB interceptors for parameter validity

I am developing application which receives parameters from URLs and therefore I am limited to the String type. At the start of every bean method I check the parameter format, I thought I could reduce my code If I used interceptors to check parameter format depending on annotations set to each parameter. I have little experience on using annotations and interceptors and only find really easy examples on Google. Is there any library or framework which handles this functionality? Or example?

Thanks in advance.

Upvotes: 1

Views: 1502

Answers (2)

Nayan Wadekar
Nayan Wadekar

Reputation: 11622

Interceptors can be used to the execute custom code before the bean method gets invoked. You can either define an interceptor method in the bean class itself, or in separate classes.

@AroundInvoke
public Object defaultInterceptor(InvocationContext ctx) throws Exception
{
   Object[] parameters = ctx.getParameters();

   /* parameters will have values that will be 
      passed to the method of the target class */

   return ctx.proceed();
}

Creating entry of interceptor in ejb-jar.xml by specifying fully qualified path. This would be applied to each method of all beans.

<interceptor-binding>
      <ejb-name>*</ejb-name>
      <interceptor-class>com.interceptor.DefaultInterceptor</interceptor-class>
   </interceptor-binding>

Upvotes: 3

Omnaest
Omnaest

Reputation: 3096

Do you have the opportunity to use special frameworks for that like Hibernate Validator? This would be less work to implement...

Upvotes: 0

Related Questions