You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Denuwanthi Hasanthika <de...@gmail.com> on 2013/04/09 11:51:12 UTC

Running a Thrift server inside Tomcat.

Hi,

I want to run a Thrift server inside Apache Tomcat server.
As for now, I  implemented a Thrift Server and tested it with clients
.*But, I want to know wether there is a way to deploy a Thrift Server
inside
Tomcat? .*
*If not, is there a way to run a Thrift server inside a servlet deployed in
Tomcat?.*
 I tried doing that by calling the Thrift Server inside the init() method
of the servlet. But, didn't work. I use Eclipse IDE in my development work
and configured Tomcat to run from Eclipse.


Thanks,
Denuwanthi

Re: Running a Thrift server inside Tomcat.

Posted by Denuwanthi Hasanthika <de...@gmail.com>.
Thanks for the details.
I already tried using a ThriftServlet as the server side implementation.It
works fine. I am keeping it as an option too. Meanwhile I am getting
familiar with Spring framework to create a Thrift Server inside the
container (Tomcat), as you have pointed out.

Thanks,
Denuwanthi


On Thu, Apr 11, 2013 at 9:19 AM, Matthew Chambers <mc...@wetafx.co.nz>wrote:

> Oh yeah, there is another trick you can do if you want to serve out Thrift
> JSON from Tomcat, or any other container.I expose the Binary/Framed thrift
> connection for C++ clients, but for javascript clients you can wrap your
> thrift server side implementation in a servet.
>
> https://github.com/sqlboy/**plow/blob/master/server/src/**
> main/java/com/breakersoft/**plow/thrift/ThriftServlet.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServlet.java>
>
> Then you get free Json over HTTP with about 10 lines of extra code. That
> example uses spring (sorry) but there is a wiki page with an example of
> exactly your stack here.
>
> http://wiki.apache.org/thrift/**Thrift%20%26%20Eclipse%20%26%**
> 20JUnit%20with%20TServlet<http://wiki.apache.org/thrift/Thrift%20%26%20Eclipse%20%26%20JUnit%20with%20TServlet>
>
>
>
> On 10/04/13 19:57, Denuwanthi Hasanthika wrote:
>
>> Thanks for the information.
>>
>> As I understood, your ServerConfiguration.java class is where the
>> ThriftServer gets invoked.
>> Can you please tell me how/where is the
>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>> main/java/com/breakersoft/**plow/thrift/**ServerConfiguration.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java>
>>
>> class is invoked?
>>
>> -Denuwanthi
>>
>>
>> On Wed, Apr 10, 2013 at 2:53 AM, Matthew Chambers <mchambers@wetafx.co.nz
>> >wrote:
>>
>>  Doesn't really matter what servlet container you are using, you do it
>>> pretty much the same way.  Since starting the server blocks you have to
>>> start it in a thread.
>>>
>>> Here is an example using Spring I did a long time ago, I'd probably do an
>>> anonymous runnable if I did it again.
>>> https://github.com/sqlboy/****plow/blob/master/server/src/**<https://github.com/sqlboy/**plow/blob/master/server/src/**>
>>> main/java/com/breakersoft/****plow/thrift/ThriftServer.java<**
>>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>>> main/java/com/breakersoft/**plow/thrift/ThriftServer.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java>
>>> >
>>> https://github.com/sqlboy/****plow/blob/master/server/src/**<https://github.com/sqlboy/**plow/blob/master/server/src/**>
>>> main/java/com/breakersoft/****plow/thrift/****ServerConfiguration.java<
>>> https**://github.com/sqlboy/plow/**blob/master/server/src/main/**
>>> java/com/breakersoft/plow/**thrift/ServerConfiguration.**java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java>
>>> >
>>>
>>>
>>> A non spring example would just initialize and wrap the serve() function
>>> in a thread.
>>>
>>> -Matt
>>>
>>>
>>>
>>> On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
>>>
>>>  Hi,
>>>>
>>>> I want to run a Thrift server inside Apache Tomcat server.
>>>> As for now, I  implemented a Thrift Server and tested it with clients
>>>> .*But, I want to know wether there is a way to deploy a Thrift Server
>>>> inside
>>>> Tomcat? .*
>>>> *If not, is there a way to run a Thrift server inside a servlet deployed
>>>> in
>>>> Tomcat?.*
>>>>
>>>>    I tried doing that by calling the Thrift Server inside the init()
>>>> method
>>>> of the servlet. But, didn't work. I use Eclipse IDE in my development
>>>> work
>>>> and configured Tomcat to run from Eclipse.
>>>>
>>>>
>>>> Thanks,
>>>> Denuwanthi
>>>>
>>>>
>>>>
>

Re: Running a Thrift server inside Tomcat.

Posted by Matthew Chambers <mc...@wetafx.co.nz>.
Oh yeah, there is another trick you can do if you want to serve out 
Thrift JSON from Tomcat, or any other container.I expose the 
Binary/Framed thrift connection for C++ clients, but for javascript 
clients you can wrap your thrift server side implementation in a servet.

https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServlet.java

Then you get free Json over HTTP with about 10 lines of extra code. That 
example uses spring (sorry) but there is a wiki page with an example of 
exactly your stack here.

http://wiki.apache.org/thrift/Thrift%20%26%20Eclipse%20%26%20JUnit%20with%20TServlet


On 10/04/13 19:57, Denuwanthi Hasanthika wrote:
> Thanks for the information.
>
> As I understood, your ServerConfiguration.java class is where the
> ThriftServer gets invoked.
> Can you please tell me how/where is the
> https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java
>
> class is invoked?
>
> -Denuwanthi
>
>
> On Wed, Apr 10, 2013 at 2:53 AM, Matthew Chambers <mc...@wetafx.co.nz>wrote:
>
>> Doesn't really matter what servlet container you are using, you do it
>> pretty much the same way.  Since starting the server blocks you have to
>> start it in a thread.
>>
>> Here is an example using Spring I did a long time ago, I'd probably do an
>> anonymous runnable if I did it again.
>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>> main/java/com/breakersoft/**plow/thrift/ThriftServer.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java>
>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>> main/java/com/breakersoft/**plow/thrift/**ServerConfiguration.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java>
>>
>> A non spring example would just initialize and wrap the serve() function
>> in a thread.
>>
>> -Matt
>>
>>
>>
>> On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
>>
>>> Hi,
>>>
>>> I want to run a Thrift server inside Apache Tomcat server.
>>> As for now, I  implemented a Thrift Server and tested it with clients
>>> .*But, I want to know wether there is a way to deploy a Thrift Server
>>> inside
>>> Tomcat? .*
>>> *If not, is there a way to run a Thrift server inside a servlet deployed
>>> in
>>> Tomcat?.*
>>>
>>>    I tried doing that by calling the Thrift Server inside the init() method
>>> of the servlet. But, didn't work. I use Eclipse IDE in my development work
>>> and configured Tomcat to run from Eclipse.
>>>
>>>
>>> Thanks,
>>> Denuwanthi
>>>
>>>


Re: Running a Thrift server inside Tomcat.

Posted by Matthew Chambers <mc...@wetafx.co.nz>.
The fact it has a @Configuration annotation means that the Spring 
framework automatically creates an instance of it. Since your not using 
spring, you have to wire all that stuff up on your own.

Here are the basics of how the IoC stuff works in spring though.
http://static.springsource.org/spring/docs/2.5.3/reference/beans.html

On 10/04/13 19:57, Denuwanthi Hasanthika wrote:
> Thanks for the information.
>
> As I understood, your ServerConfiguration.java class is where the
> ThriftServer gets invoked.
> Can you please tell me how/where is the
> https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java
>
> class is invoked?
>
> -Denuwanthi
>
>
> On Wed, Apr 10, 2013 at 2:53 AM, Matthew Chambers <mc...@wetafx.co.nz>wrote:
>
>> Doesn't really matter what servlet container you are using, you do it
>> pretty much the same way.  Since starting the server blocks you have to
>> start it in a thread.
>>
>> Here is an example using Spring I did a long time ago, I'd probably do an
>> anonymous runnable if I did it again.
>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>> main/java/com/breakersoft/**plow/thrift/ThriftServer.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java>
>> https://github.com/sqlboy/**plow/blob/master/server/src/**
>> main/java/com/breakersoft/**plow/thrift/**ServerConfiguration.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java>
>>
>> A non spring example would just initialize and wrap the serve() function
>> in a thread.
>>
>> -Matt
>>
>>
>>
>> On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
>>
>>> Hi,
>>>
>>> I want to run a Thrift server inside Apache Tomcat server.
>>> As for now, I  implemented a Thrift Server and tested it with clients
>>> .*But, I want to know wether there is a way to deploy a Thrift Server
>>> inside
>>> Tomcat? .*
>>> *If not, is there a way to run a Thrift server inside a servlet deployed
>>> in
>>> Tomcat?.*
>>>
>>>    I tried doing that by calling the Thrift Server inside the init() method
>>> of the servlet. But, didn't work. I use Eclipse IDE in my development work
>>> and configured Tomcat to run from Eclipse.
>>>
>>>
>>> Thanks,
>>> Denuwanthi
>>>
>>>


Re: Running a Thrift server inside Tomcat.

Posted by Yuhan Zhang <yu...@gmail.com>.
my way is to define and start a thrift server inside a spring bean. So the
thrift server is initialized during tomcat startup.but as the thrift server
is on another port, it is kind unnecessary to put it onto tomcat. (Plus the
embedded thrift server won't be restarted when you are deploying a new war
file, which is annoying. ) It is better to keep it away from tomcat.
On Apr 10, 2013 12:57 AM, "Denuwanthi Hasanthika" <
denuwanthi.hasanthika@gmail.com> wrote:

> Thanks for the information.
>
> As I understood, your ServerConfiguration.java class is where the
> ThriftServer gets invoked.
> Can you please tell me how/where is the
>
> https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java
>
> class is invoked?
>
> -Denuwanthi
>
>
> On Wed, Apr 10, 2013 at 2:53 AM, Matthew Chambers <mchambers@wetafx.co.nz
> >wrote:
>
> > Doesn't really matter what servlet container you are using, you do it
> > pretty much the same way.  Since starting the server blocks you have to
> > start it in a thread.
> >
> > Here is an example using Spring I did a long time ago, I'd probably do an
> > anonymous runnable if I did it again.
> > https://github.com/sqlboy/**plow/blob/master/server/src/**
> > main/java/com/breakersoft/**plow/thrift/ThriftServer.java<
> https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java
> >
> > https://github.com/sqlboy/**plow/blob/master/server/src/**
> > main/java/com/breakersoft/**plow/thrift/**ServerConfiguration.java<
> https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java
> >
> >
> > A non spring example would just initialize and wrap the serve() function
> > in a thread.
> >
> > -Matt
> >
> >
> >
> > On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
> >
> >> Hi,
> >>
> >> I want to run a Thrift server inside Apache Tomcat server.
> >> As for now, I  implemented a Thrift Server and tested it with clients
> >> .*But, I want to know wether there is a way to deploy a Thrift Server
> >> inside
> >> Tomcat? .*
> >> *If not, is there a way to run a Thrift server inside a servlet deployed
> >> in
> >> Tomcat?.*
> >>
> >>   I tried doing that by calling the Thrift Server inside the init()
> method
> >> of the servlet. But, didn't work. I use Eclipse IDE in my development
> work
> >> and configured Tomcat to run from Eclipse.
> >>
> >>
> >> Thanks,
> >> Denuwanthi
> >>
> >>
> >
>

Re: Running a Thrift server inside Tomcat.

Posted by Denuwanthi Hasanthika <de...@gmail.com>.
Thanks for the information.

As I understood, your ServerConfiguration.java class is where the
ThriftServer gets invoked.
Can you please tell me how/where is the
https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java

class is invoked?

-Denuwanthi


On Wed, Apr 10, 2013 at 2:53 AM, Matthew Chambers <mc...@wetafx.co.nz>wrote:

> Doesn't really matter what servlet container you are using, you do it
> pretty much the same way.  Since starting the server blocks you have to
> start it in a thread.
>
> Here is an example using Spring I did a long time ago, I'd probably do an
> anonymous runnable if I did it again.
> https://github.com/sqlboy/**plow/blob/master/server/src/**
> main/java/com/breakersoft/**plow/thrift/ThriftServer.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java>
> https://github.com/sqlboy/**plow/blob/master/server/src/**
> main/java/com/breakersoft/**plow/thrift/**ServerConfiguration.java<https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java>
>
> A non spring example would just initialize and wrap the serve() function
> in a thread.
>
> -Matt
>
>
>
> On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
>
>> Hi,
>>
>> I want to run a Thrift server inside Apache Tomcat server.
>> As for now, I  implemented a Thrift Server and tested it with clients
>> .*But, I want to know wether there is a way to deploy a Thrift Server
>> inside
>> Tomcat? .*
>> *If not, is there a way to run a Thrift server inside a servlet deployed
>> in
>> Tomcat?.*
>>
>>   I tried doing that by calling the Thrift Server inside the init() method
>> of the servlet. But, didn't work. I use Eclipse IDE in my development work
>> and configured Tomcat to run from Eclipse.
>>
>>
>> Thanks,
>> Denuwanthi
>>
>>
>

Re: Running a Thrift server inside Tomcat.

Posted by Matthew Chambers <mc...@wetafx.co.nz>.
Doesn't really matter what servlet container you are using, you do it 
pretty much the same way.  Since starting the server blocks you have to 
start it in a thread.

Here is an example using Spring I did a long time ago, I'd probably do 
an anonymous runnable if I did it again.
https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ThriftServer.java
https://github.com/sqlboy/plow/blob/master/server/src/main/java/com/breakersoft/plow/thrift/ServerConfiguration.java

A non spring example would just initialize and wrap the serve() function 
in a thread.

-Matt


On 09/04/13 21:51, Denuwanthi Hasanthika wrote:
> Hi,
>
> I want to run a Thrift server inside Apache Tomcat server.
> As for now, I  implemented a Thrift Server and tested it with clients
> .*But, I want to know wether there is a way to deploy a Thrift Server
> inside
> Tomcat? .*
> *If not, is there a way to run a Thrift server inside a servlet deployed in
> Tomcat?.*
>   I tried doing that by calling the Thrift Server inside the init() method
> of the servlet. But, didn't work. I use Eclipse IDE in my development work
> and configured Tomcat to run from Eclipse.
>
>
> Thanks,
> Denuwanthi
>