Hi Jools, Thank you very much. It worked.
Best Regards, Hasini. On Wed, Jul 15, 2015 at 6:06 AM, Jools <[email protected]> wrote: > We use Google Guice to accomplish this, I'm sure you can use any of the AOP > frameworks, > > So, first thing you'll need to do is create an annotation. > > > *import java.lang.annotation.ElementType;* > > *import java.lang.annotation.Retention;* > > *import java.lang.annotation.RetentionPolicy;* > > *import java.lang.annotation.Target;* > > > *import com.google.inject.BindingAnnotation;* > > > *@Retention(RetentionPolicy.RUNTIME)* > > *@Target({ElementType.METHOD})* > > *@BindingAnnotation* > > *public @interface ServiceCall {* > > *// Add additional annotations here for meta data etc.* > > > *}* > > Add this annotation to all the service methods which require a callback to > be attached. > > All out service methods are defined with an authentication token on the > first argument, the service methods themselves don't use the token, but an > interceptor will interrogate the token to ensure it's valid before the > service method is invoked. > > > *@Override* > > * @ServiceCall* > > * public List<DataRecord> findDataRecords(final AuthToken authToken, final > ByteBuffer startKey, final int limit, final boolean includeContent) {* > > * return dataRecordHelper.findAll(startKey, limit, includeContent);* > > * }* > > > Now for the interceptor. > > > *public class ThriftServiceCallMethodInterceptor implements > MethodInterceptor {* > > * @Override* > > * public Object invoke(final MethodInvocation invocation) throws Throwable > {* > > *// do your thing here* > > *return invocation.proceed();* > > *}* > > *}* > > > Now we need to tell Guice about the interceptor, this code lives in the > configure() method of an AbstractModule. > > > *final ThriftServiceCallMethodInterceptor interceptor = new > ThriftServiceCallMethodInterceptor();* > > * requestInjection(interceptor);* > > * bindInterceptor(Matchers.any(), * > > * Matchers.annotatedWith(ServiceCall.class), * > > * interceptor);* > > > You will now need to create an AbstractModule for each of your service > implementations. > > > --Jools > > > > > > > On 15 July 2015 at 09:44, Hasini Gunasinghe <[email protected]> wrote: > > > Hi, > > > > I want to apply some security checks on the thrift method calls, before > the > > message hits the thrift service method. (similar to an interceptor, > handler > > or filter) > > > > Is it possible to do this on the server side of thrift (java)? > > > > From searching, the closest that I found was the filter implemented by > > Finagle : > > http://stevenskelton.ca/developer-friendly-thrift-request-logging/ > > > > But I could not figure out if it is possible to do similar thing in java. > > > > I would appreciate any insights on this. > > > > Thanks & Best Regards, > > Hasini. > > >
