Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to change protocol to TJSONProtocol. in apache thrift java (http://www.velocityreviews.com/forums/t954584-how-to-change-protocol-to-tjsonprotocol-in-apache-thrift-java.html)

ankit patel 11-17-2012 07:34 PM

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

mrantonindanek@gmail.com 02-28-2014 10:31 PM

Re: How to change protocol to TJSONProtocol. in apache thrift java
 
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


All times are GMT. The time now is 10:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.