How to change protocol to TJSONProtocol. in apache thrift java

Discussion in 'Java' started by ankit patel, Nov 17, 2012.

  1. ankit patel

    ankit patel Guest

    Please help me i want to change my java api transport protocol from binary to json.
    so that it can be tested by cUrl.
     
    ankit patel, Nov 17, 2012
    #1
    1. Advertising

  2. ankit patel

    Guest

    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<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
     
    , Feb 28, 2014
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    955
  2. Replies:
    2
    Views:
    13,834
  3. D Godwin
    Replies:
    2
    Views:
    606
    D Godwin
    Apr 21, 2006
  4. Replies:
    4
    Views:
    614
    Joseph Kesselman
    Aug 10, 2006
  5. Vincent
    Replies:
    0
    Views:
    186
    Vincent
    Jan 6, 2013
Loading...

Share This Page