Skip to content
Mihail Kuznetsov edited this page Mar 16, 2015 · 2 revisions

method invocation

Method Invocation

Since version 1.0.1 EverRest make possible to customize process of method invocation.

  1. Create subclass of org.everrest.core.impl.method.MethodInvokerDecorator
public class MyMethodInvokerDecorator extends MethodInvokerDecorator
{
   public MyMethodInvokerDecorator(MethodInvoker invoker)
   {
      super(invoker);
   }

   @Override
   public Object invokeMethod(Object resource, GenericMethodResource genericMethodResource, ApplicationContext context)
   {
      // Do something before
      Object result = super.invokeMethod(resource, genericMethodResource, context);
      // Do something after
      return result;
   }
}
  1. Implement org.everrest.core.impl.method.MethodInvokerDecoratorFactory.
public class MyMethodInvokerDecoratorFactory implements MethodInvokerDecoratorFactory
{
   @Override
   public MethodInvokerDecorator makeDecorator(MethodInvoker invoker)
   {
      return new MyMethodInvokerDecorator(invoker);
   }
}
  1. Create file META-INF/services/org.everrest.core.impl.method.MethodInvokerDecoratorFactory with content:
org.everrest.test.MyMethodInvokerDecoratorFactory

See details about ServiceLoader

  1. NOTE: If you create war file then be sure file org.everrest.core.impl.method.MethodInvokerDecoratorFactory is in ${my_application}/WEB-INF/classes/META-INF/services folder (not in folder ${my_application}/META-INF/services). Otherwise file is not available for web application class loaded.