thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jools <>
Subject Re: Intercepting thrift messages before they reach the service methods
Date Wed, 15 Jul 2015 10:06:57 GMT
We use Google Guice to accomplish this, I'm sure you can use any of the AOP

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;*





*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.


* @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

* requestInjection(interceptor);*

* bindInterceptor(Matchers.any(), *

*     Matchers.annotatedWith(ServiceCall.class), *

*     interceptor);*

You will now need to create an AbstractModule for each of your service


On 15 July 2015 at 09:44, Hasini Gunasinghe <> 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 :
> 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.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message