Object recv(TProtocol protocol, int seqid) throws Exception { TMessage msg = protocol.readMessageBegin(); if (msg.type == TMessageType.EXCEPTION) { TApplicationException applicationException = TApplicationException.read(protocol); protocol.readMessageEnd(); throw applicationException; } if (msg.seqid != seqid) { throw new TApplicationException( TApplicationException.BAD_SEQUENCE_ID, methodName + " failed: out of sequence response"); } protocol.readStructBegin(); Object success = null; Exception exception = null; while (true) { TField tField = protocol.readFieldBegin(); if (tField.type == TType.STOP) { break; } FieldSpec fieldSpec = null; if (tField.id == 0) { fieldSpec = responseSuccessType; } else { fieldSpec = responseExceptionTypeMap.get(tField.id); } if (fieldSpec == null || fieldSpec.typeAdapter.getTType() != tField.type) { TProtocolUtil.skip(protocol, tField.type); } else { Object value = fieldSpec.typeAdapter.read(protocol); if (tField.id == 0) { success = value; } else { exception = (Exception) value; } } protocol.readFieldEnd(); } protocol.readStructEnd(); protocol.readMessageEnd(); if (exception != null) { throw exception; } if (success != null) { return success; } if (isVoid) { return null; } throw new TApplicationException( org.apache.thrift.TApplicationException.MISSING_RESULT, methodName + " failed: unknown result"); }
protected void receiveBase(TBase result, String methodName) throws TException { TMessage msg = iprot_.readMessageBegin(); if (msg.type == TMessageType.EXCEPTION) { TApplicationException x = TApplicationException.read(iprot_); iprot_.readMessageEnd(); throw x; } if (msg.seqid != seqid_) { throw new TApplicationException( TApplicationException.BAD_SEQUENCE_ID, methodName + " failed: out of sequence response"); } result.read(iprot_); iprot_.readMessageEnd(); }
@Override public boolean process(TProtocol in, TProtocol out) throws TException { TMessage msg = in.readMessageBegin(); String name = msg.name; int idx = name.indexOf('.'); if (idx != -1) { name = name.substring(idx + 1); } TDynamicFunction f = descManager.getFunction(name); if (f == null) throw new TException("unknow function '" + name + "'"); Reader reader = new Reader(f.getManager()); Xdom param = reader.readStruct(f.getParamStruct(), in); in.readMessageEnd(); if (!f.isOneway()) { XdomMap rep; TDynamicField retf = f.getReturnStruct().getField("success"); if (retf.getTypeValue() != TType.VOID) { Xdom ret = handle(name, param); rep = new XdomMap(); rep.put("success", ret); } else { rep = new XdomMap(); } TMessage repmsg = new TMessage(name, TMessageType.REPLY, msg.seqid); out.writeMessageBegin(repmsg); Writer writer = new Writer(f.getManager()); writer.writeStruct(f.getReturnStruct(), rep, out); out.writeMessageEnd(); out.getTransport().flush(); } return true; }
public boolean process(TProtocol iprot, TProtocol oprot) throws TException { String ip = getClientIp(iprot); if (!whiteListHelper.check(ip)) { System.out.println( "------------ customized secure check, client ip (" + ip + ") not allowed"); TMessage msg = iprot.readMessageBegin(); TProtocolUtil.skip(iprot, TType.STRUCT); iprot.readMessageEnd(); TApplicationException appException = new TApplicationException(TApplicationException.UNKNOWN, "Invalid ip: " + ip); oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid)); appException.write(oprot); oprot.writeMessageEnd(); oprot.getTransport().flush(); return false; } System.out.println("------------ customized secure check, client ip (" + ip + ") allowed"); boolean result = super.process(iprot, oprot); return result; }
public void readMessageEnd() throws TException { delegate.readMessageEnd(); }