TTextProtocol extends TProtocol { @Override public TMessage readMessageBegin() throws TException { root = null; try { readRoot(); } catch (IOException e) { throw new TException("Could not parse input, is it valid json?", e); } if (!root.isObject()) { throw new TException("The top level of the input must be a json object with method and args!"); } if (!root.has("method")) { throw new TException("Object must have field 'method' with the rpc method name!"); } final String methodName = root.get("method").asText(); if (!root.has("type")) { throw new TException( "Object must have field 'type' with the message type (CALL, REPLY, EXCEPTION, ONEWAY)!"); } final Byte messageType = TypedParser.TMESSAGE_TYPE.readFromJsonElement(root.get("type")); if (!root.has("args") || !root.get("args").isObject()) { throw new TException("Object must have field 'args' with the rpc method args!"); } final int sequenceId = root.has("seqid") ? root.get("seqid").asInt() : 0; root = root.get("args"); return new TMessage(methodName, messageType, sequenceId); } TTextProtocol(TTransport trans);   TTextProtocol(TTransport trans, boolean useNamedEnums); @Override @SuppressWarnings("rawtypes") Class<? extends IScheme> getScheme(); @Override void reset(); @Override void writeMessageBegin(TMessage message); @Override void writeMessageEnd(); @Override void writeStructBegin(TStruct struct); @Override void writeStructEnd(); @Override void writeFieldBegin(TField field); @Override void writeFieldEnd(); @Override void writeFieldStop(); @Override void writeMapBegin(TMap map); @Override void writeMapEnd(); @Override void writeListBegin(TList list); @Override void writeListEnd(); @Override void writeSetBegin(TSet set); @Override void writeSetEnd(); @Override void writeBool(boolean b); @Override void writeByte(byte b); @Override void writeI16(short i16); @Override void writeI32(int i32); @Override void writeI64(long i64); @Override void writeDouble(double dub); @Override void writeString(String str); @Override void writeBinary(ByteBuffer buf); @Override TMessage readMessageBegin(); @Override void readMessageEnd(); @Override TStruct readStructBegin(); @Override void readStructEnd(); @Override TField readFieldBegin(); @Override void readFieldEnd(); @Override TMap readMapBegin(); @Override void readMapEnd(); @Override TList readListBegin(); @Override void readListEnd(); @Override TSet readSetBegin(); @Override void readSetEnd(); @Override boolean readBool(); @Override byte readByte(); @Override short readI16(); @Override int readI32(); @Override long readI64(); @Override double readDouble(); @Override String readString(); @Override ByteBuffer readBinary();  }
@Test(expected = TException.class) public void rpcNoMethod() throws Exception { final String request = "{\n" + " \"type\" : \"CALL\",\n" + " \"args\" : {\n" + " \"methodArg1\" : \"foo1\",\n" + " \"methodArg2\" : 200,\n" + " \"details\" : {\n" + " \"detailsArg1\" : \"foo2\",\n" + " \"detailsArg2\" : 100\n" + " }\n" + " }\n" + '}'; final TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); prot.readMessageBegin(); }
@Test(expected = TException.class) public void rpcNoType() throws Exception { final String request = "{\n" + " \"method\" : \"doDebug\",\n" + " \"args\" : {\n" + " \"methodArg1\" : \"foo1\",\n" + " \"methodArg2\" : 200,\n" + " \"details\" : {\n" + " \"detailsArg1\" : \"foo2\",\n" + " \"detailsArg2\" : 100\n" + " }\n" + " }\n" + '}'; final TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); prot.readMessageBegin(); }
@Test(expected = TException.class) public void noRpcArgs() throws Exception { final String request = "{\n" + " \"method\" : \"doDebug\"\n" + " \"type\" : \"CALL\",\n" + '}'; final TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); prot.readMessageBegin(); }
@Test(expected = TException.class) public void rpcArgsNotObject() throws Exception { final String request = "{\n" + " \"method\" : \"doDebug\",\n" + " \"args\" : 100\n" + '}'; final TTextProtocol prot = new TTextProtocol( new TIOStreamTransport(new ByteArrayInputStream(request.getBytes()))); prot.readMessageBegin(); }