Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to change protocol to TJSONProtocol. in apache thrift java

Reply
Thread Tools

How to change protocol to TJSONProtocol. in apache thrift java

 
 
ankit patel
Guest
Posts: n/a
 
      11-17-2012
Please help me i want to change my java api transport protocol from binary to json.
so that it can be tested by cUrl.
 
Reply With Quote
 
 
 
 
mrantonindanek@gmail.com
Guest
Posts: n/a
 
      02-28-2014
On Saturday, November 17, 2012 8:34:30 PM UTC+1, ankit patel wrote:
> Please help me i want to change my java api transport protocol from binary to json.
>
> so that it can be tested by cUrl.


Hi,
you can do it like this:

Server side:

public class JSONThriftServer {

final static int PORT = 9090;

public static void startThriftServer(
ThriftDataBenchmark.Processor<ThriftDataBenchmarkH andler> processor) {
try {

TServerTransport serverTransport = new TServerSocket(PORT);

TServer server = new TSimpleServer(new Args(serverTransport)
.processor(processor)
.inputProtocolFactory(new TJSONProtocol.Factory())
.outputProtocolFactory(new TJSONProtocol.Factory()));

System.out.println("JSON Thrift server started on port " + PORT
+ "...");
server.serve();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
startThriftServer(new ThriftDataBenchmark.Processor<ThriftDataBenchmarkH andler>(
new ThriftDataBenchmarkHandler()));
}

}


Client side:

TTransport transport;

transport = new TSocket(endPoint, serverPort);
transport.open();

TProtocol protocol = new TJSONProtocol(transport);

ThriftDataBenchmark.Client client = new ThriftDataBenchmark.Client(
protocol);


Hope this helps,
Antony
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
A question about thrift performance. Vincent Python 0 01-06-2013 02:16 AM
gem install thrift fails on windows Saravanan Krishnan Ruby 2 03-24-2011 12:53 PM
Protocol Chart - Learn how to use a Protocol Analyzer news.comcast.giganews.com Wireless Networking 0 08-21-2004 04:35 PM
When i try to implement a server program giving UDP as protocol , it works fine , but if the same code is executed with TCP as protocol option, it gives an error. Tompyna Perl Misc 4 02-17-2004 06:51 PM



Advertisments