How to change protocol to TJSONProtocol. in apache thrift java

A

ankit patel

Please help me i want to change my java api transport protocol from binary to json.
so that it can be tested by cUrl.
 
M

mrantonindanek

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<ThriftDataBenchmarkHandler> 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<ThriftDataBenchmarkHandler>(
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top