Pages

Monday, July 9, 2012

Thrift exposed via webapp servlet

Thrift services can be exposed via servlets. Now the TServlet class is part of the core thrift package in java. It is relatively easy to use, but there are some nuances.

First - it requires some Processor and Protocol to be used. Example of such usage maybe found here. Though it is about OSGI Servlets, not web applications - this example is easy and small. However it is stated there that due to violation of Servlet specification (no default constructor) it is not possible to use this servlet in web application. Actually it can be used.


  • We can either use it directly with some covering code, like in this stackoverflow answer.
  • We can use any standard way of delegating servlets like Spring, or Guice and maybe some other frameworks that most likely are already used in your application.
I have created some small test project to illustrate these options (hand-written delegating code, Spring and Guice) and placed it on github. Maybe it will be useful to someone except me ;-)

No comments:

Post a Comment