Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27621 > unrolled thread

Re: How to change protocol to TJSONProtocol. in apache thrift java

Started bymrantonindanek@gmail.com
First post2014-02-28 14:31 -0800
Last post2014-02-28 14:31 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to change protocol to TJSONProtocol. in apache thrift java mrantonindanek@gmail.com - 2014-02-28 14:31 -0800

#27621 — Re: How to change protocol to TJSONProtocol. in apache thrift java

Frommrantonindanek@gmail.com
Date2014-02-28 14:31 -0800
SubjectRe: How to change protocol to TJSONProtocol. in apache thrift java
Message-ID<3fe2852c-2da5-48e1-ba59-66a58652e63d@googlegroups.com>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web