List of usage examples for org.apache.thrift.protocol TJSONProtocol TJSONProtocol
public TJSONProtocol(TTransport trans)
From source file:MapDExample.java
License:Apache License
public static MapD.Client get_client(String host_or_uri, int port, boolean http) { THttpClient httpTransport;//from w w w . j a v a 2s . co m TTransport transport; TBinaryProtocol protocol; TJSONProtocol jsonProtocol; TSocket socket; MapD.Client client; try { if (http) { httpTransport = new THttpClient(host_or_uri); jsonProtocol = new TJSONProtocol(httpTransport); client = new MapD.Client(jsonProtocol); httpTransport.open(); return client; } else { transport = new TSocket(host_or_uri, port); protocol = new TBinaryProtocol(transport); client = new MapD.Client(protocol); transport.open(); return client; } } catch (TException x) { x.printStackTrace(); } return null; }
From source file:com.facebook.buck.distributed.ThriftOverHttp.java
License:Apache License
public ThriftOverHttp(String uri, Encoding type) throws TTransportException { transport = new THttpClient(uri); transport.setReadTimeout(READ_TIMEOUT_MS); transport.setCustomHeader("X-Thrift-Protocol", type.toString()); transport.open();/*w w w .j a v a 2 s.c om*/ switch (type) { case json: proto = new TJSONProtocol(transport); break; case compact: proto = new TCompactProtocol(transport); break; case binary: default: proto = new TBinaryProtocol(transport); break; } }
From source file:com.kromatik.dasshy.server.thrift.TUtils.java
License:Open Source License
/** * Serialize the thrift entity using Json protocol * * @param tEntity thrift entity// w w w .j a va 2 s .c o m * @return byte[] * @throws TException */ public static byte[] serializeJson(final TBase tEntity) throws TException { final TMemoryBuffer memoryBuffer = new TMemoryBuffer(1); tEntity.write(new TJSONProtocol(memoryBuffer)); memoryBuffer.flush(); try { return memoryBuffer.toString("UTF-8").getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new TException(e); } finally { memoryBuffer.close(); } }
From source file:com.kromatik.dasshy.server.thrift.TUtils.java
License:Open Source License
/** * Deserialize into thrift entity using JSON protocol * * @param bytesEntity byte[] to deserialize * @param tBase thrift entity//from w ww .j av a 2 s . c o m * @throws TException */ public static void deserializeJson(byte[] bytesEntity, final TBase tBase) throws TException { final TMemoryBuffer memoryBuffer = new TMemoryBuffer(bytesEntity.length); memoryBuffer.write(bytesEntity); tBase.read(new TJSONProtocol(memoryBuffer)); memoryBuffer.close(); }
From source file:com.mapd.jdbc.MapDConnection.java
License:Apache License
public MapDConnection(String url, Properties info) throws SQLException { //logger.debug("Entered"); this.url = url; this.properties = info; this.user = info.getProperty("user"); boolean http_session = false; //logger.debug("We got to here " + url + " info: " + info.toString()); String[] temp = url.split(":"); //for (int i = 0; i < temp.length; i++) { // logger.debug("temp " + i + " " + temp[i].toString()); //}/*from w w w . j a v a 2 s.c o m*/ String machine = temp[2]; // deal with requirement that there may be double // before the machine if (machine.startsWith("//")) { machine = machine.substring(2); } //logger.debug("machine : " + machine); int port = Integer.valueOf(temp[3]); this.catalog = temp[4]; //test for http protocol request (we could consider using properties) if (temp.length == 6) { if (temp[5].equals("http")) { http_session = true; } else { throw new SQLException("Connection failed invalid protocol option- " + temp[5]); } } try { TProtocol protocol = null; if (http_session) { transport = new THttpClient("http://" + machine + ":" + port); transport.open(); protocol = new TJSONProtocol(transport); } else { transport = new TSocket(machine, port); transport.open(); protocol = new TBinaryProtocol(transport); } client = new MapD.Client(protocol); session = client.connect(info.getProperty("user"), info.getProperty("password"), this.catalog); logger.debug("Connected session is " + session); } catch (TTransportException ex) { throw new SQLException("Connection failed - " + ex.toString()); } catch (TMapDException ex) { throw new SQLException("Connection failed - " + ex.toString()); } catch (TException ex) { throw new SQLException("Connection failed - " + ex.toString()); } }
From source file:com.mapd.logrunner.LogRunner.java
License:Apache License
private MapD.Client getClient(String hostname, int port) throws TTransportException { TTransport transport = null;/*from w w w . j a va2 s .c o m*/ //transport = new TSocket("localhost", 9091); transport = new THttpClient("http://" + hostname + ":" + port); transport.open(); //TProtocol protocol = new TBinaryProtocol(transport); TProtocol protocol = new TJSONProtocol(transport); //TProtocol protocol = new TProtocol(transport); return new MapD.Client(protocol); }
From source file:com.nearinfinity.blur.analysis.BlurAnalyzer.java
License:Apache License
public String toJSON() { TMemoryBuffer trans = new TMemoryBuffer(1024); TJSONProtocol protocol = new TJSONProtocol(trans); try {/*from w w w. j ava 2s . c o m*/ _analyzerDefinition.write(protocol); } catch (TException e) { throw new RuntimeException(e); } trans.close(); byte[] array = trans.getArray(); return new String(array, 0, trans.length()); }
From source file:com.nearinfinity.blur.analysis.BlurAnalyzer.java
License:Apache License
public static BlurAnalyzer create(InputStream inputStream) throws IOException { TMemoryInputTransport trans = new TMemoryInputTransport(getBytes(inputStream)); TJSONProtocol protocol = new TJSONProtocol(trans); AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); try {// w ww . j a va 2 s.co m analyzerDefinition.read(protocol); } catch (TException e) { throw new RuntimeException(e); } trans.close(); return new BlurAnalyzer(analyzerDefinition); }
From source file:com.nearinfinity.blur.manager.clusterstatus.ZookeeperClusterStatus.java
License:Apache License
@SuppressWarnings("unchecked") private <T extends TBase<?, ?>> T fromBytes(byte[] data, Class<T> clazz) { try {/*from ww w . j av a 2 s . co m*/ if (data == null) { return null; } TBase<?, ?> base = clazz.newInstance(); TMemoryInputTransport trans = new TMemoryInputTransport(data); TJSONProtocol protocol = new TJSONProtocol(trans); base.read(protocol); trans.close(); return (T) base; } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (TException e) { throw new RuntimeException(e); } }
From source file:com.nearinfinity.blur.utils.BlurUtil.java
License:Apache License
public static byte[] read(TBase<?, ?> base) { if (base == null) { return null; }// w w w . j a v a 2 s.c o m TMemoryBuffer trans = new TMemoryBuffer(1024); TJSONProtocol protocol = new TJSONProtocol(trans); try { base.write(protocol); } catch (TException e) { throw new RuntimeException(e); } trans.close(); byte[] buf = new byte[trans.length()]; System.arraycopy(trans.getArray(), 0, buf, 0, trans.length()); return buf; }