thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hasini Gunasinghe <hasi7...@gmail.com>
Subject Re: Intercepting thrift messages before they reach the service methods
Date Thu, 16 Jul 2015 17:54:09 GMT
Hi Jools,

How did you get it to properly propagate the exceptions thrown in the
"invoke" method of the MethodInterceptor to the client side?
Although I throw a custom exception with a proper error message in the
"invoke" method of the the MethodInterceptor (for unauthorized calls), what
thrift propagates to the client side is a general exception:
org.apache.thrift.TApplicationException: Internal error processing <method
name>

Appreciate any insights on resolving this.

Thanks & Best Regards,
Hasini.



On Thu, Jul 16, 2015 at 7:37 AM, Jools <joolski@gmail.com> wrote:

> My pleasure
>
> --Jools
>
> On 16 July 2015 at 11:07, Hasini Gunasinghe <hasi7786@gmail.com> wrote:
>
> > Hi Jools,
> >
> > Thank you very much. It worked.
> >
> > Best Regards,
> > Hasini.
> >
> > On Wed, Jul 15, 2015 at 6:06 AM, Jools <joolski@gmail.com> 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 <hasi7786@gmail.com>
> 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.
> > > >
> > >
> >
>

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