mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
Thrift application exceptions in Java
Reviewed By: thrift git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665008 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4c948d4b5c
commit
3d42440e42
107
lib/java/src/TApplicationException.java
Normal file
107
lib/java/src/TApplicationException.java
Normal file
@ -0,0 +1,107 @@
|
||||
package com.facebook.thrift;
|
||||
|
||||
import com.facebook.thrift.protocol.TField;
|
||||
import com.facebook.thrift.protocol.TProtocol;
|
||||
import com.facebook.thrift.protocol.TProtocolUtil;
|
||||
import com.facebook.thrift.protocol.TStruct;
|
||||
import com.facebook.thrift.protocol.TType;
|
||||
|
||||
/**
|
||||
* Application level exception
|
||||
*
|
||||
* @author Mark Slee <mcslee@facebook.com>
|
||||
*/
|
||||
public class TApplicationException extends TException {
|
||||
|
||||
public static final int UNKNOWN = 0;
|
||||
public static final int UNKNOWN_METHOD = 1;
|
||||
public static final int INVALID_MESSAGE_TYPE = 2;
|
||||
public static final int WRONG_METHOD_NAME = 3;
|
||||
public static final int BAD_SEQUENCE_ID = 4;
|
||||
public static final int MISSING_RESULT = 5;
|
||||
|
||||
protected int type_ = 0;
|
||||
|
||||
public TApplicationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TApplicationException(int type) {
|
||||
super();
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
public TApplicationException(int type, String message) {
|
||||
super(message);
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
public TApplicationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type_;
|
||||
}
|
||||
|
||||
public static TApplicationException read(TProtocol iprot) throws TException {
|
||||
TField field;
|
||||
TStruct struct = iprot.readStructBegin();
|
||||
|
||||
String message = null;
|
||||
int type = UNKNOWN;
|
||||
|
||||
while (true) {
|
||||
field = iprot.readFieldBegin();
|
||||
if (field.type == TType.STOP) {
|
||||
break;
|
||||
}
|
||||
switch (field.id) {
|
||||
case 1:
|
||||
if (field.type == TType.STRING) {
|
||||
message = iprot.readString();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (field.type == TType.I32) {
|
||||
type = iprot.readI32();
|
||||
} else {
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
TProtocolUtil.skip(iprot, field.type);
|
||||
break;
|
||||
}
|
||||
iprot.readFieldEnd();
|
||||
}
|
||||
iprot.readStructEnd();
|
||||
|
||||
return new TApplicationException(type, message);
|
||||
}
|
||||
|
||||
public void write(TProtocol oprot) throws TException {
|
||||
TStruct struct = new TStruct("TApplicationException");
|
||||
TField field = new TField();
|
||||
oprot.writeStructBegin(struct);
|
||||
if (getMessage() != null) {
|
||||
field.name = "message";
|
||||
field.type = TType.STRING;
|
||||
field.id = 1;
|
||||
oprot.writeFieldBegin(field);
|
||||
oprot.writeString(getMessage());
|
||||
oprot.writeFieldEnd();
|
||||
}
|
||||
field.name = "type";
|
||||
field.type = TType.I32;
|
||||
field.id = 2;
|
||||
oprot.writeFieldBegin(field);
|
||||
oprot.writeI32(type_);
|
||||
oprot.writeFieldEnd();
|
||||
oprot.writeFieldStop();
|
||||
oprot.writeStructEnd();
|
||||
|
||||
}
|
||||
}
|
@ -8,4 +8,5 @@ package com.facebook.thrift.protocol;
|
||||
public final class TMessageType {
|
||||
public static final byte CALL = 1;
|
||||
public static final byte REPLY = 2;
|
||||
public static final byte EXCEPTION = 3;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user