1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.thrift; 21 22 import org.apache.thrift.protocol.TField; 23 import org.apache.thrift.protocol.TProtocol; 24 import org.apache.thrift.protocol.TProtocolUtil; 25 import org.apache.thrift.protocol.TStruct; 26 import org.apache.thrift.protocol.TType; 27 28 /** 29 * Application level exception 30 * 31 */ 32 public class TApplicationException extends TException { 33 34 private static final long serialVersionUID = 1L; 35 36 public static final int UNKNOWN = 0; 37 public static final int UNKNOWN_METHOD = 1; 38 public static final int INVALID_MESSAGE_TYPE = 2; 39 public static final int WRONG_METHOD_NAME = 3; 40 public static final int BAD_SEQUENCE_ID = 4; 41 public static final int MISSING_RESULT = 5; 42 public static final int INTERNAL_ERROR = 6; 43 public static final int PROTOCOL_ERROR = 7; 44 public static final int INVALID_TRANSFORM = 8; 45 public static final int INVALID_PROTOCOL = 9; 46 public static final int UNSUPPORTED_CLIENT_TYPE = 10; 47 48 protected int type_ = UNKNOWN; 49 TApplicationException()50 public TApplicationException() { 51 super(); 52 } 53 TApplicationException(int type)54 public TApplicationException(int type) { 55 super(); 56 type_ = type; 57 } 58 TApplicationException(int type, String message)59 public TApplicationException(int type, String message) { 60 super(message); 61 type_ = type; 62 } 63 TApplicationException(String message)64 public TApplicationException(String message) { 65 super(message); 66 } 67 getType()68 public int getType() { 69 return type_; 70 } 71 read(TProtocol iprot)72 public static TApplicationException read(TProtocol iprot) throws TException { 73 TField field; 74 iprot.readStructBegin(); 75 76 String message = null; 77 int type = UNKNOWN; 78 79 while (true) { 80 field = iprot.readFieldBegin(); 81 if (field.type == TType.STOP) { 82 break; 83 } 84 switch (field.id) { 85 case 1: 86 if (field.type == TType.STRING) { 87 message = iprot.readString(); 88 } else { 89 TProtocolUtil.skip(iprot, field.type); 90 } 91 break; 92 case 2: 93 if (field.type == TType.I32) { 94 type = iprot.readI32(); 95 } else { 96 TProtocolUtil.skip(iprot, field.type); 97 } 98 break; 99 default: 100 TProtocolUtil.skip(iprot, field.type); 101 break; 102 } 103 iprot.readFieldEnd(); 104 } 105 iprot.readStructEnd(); 106 107 return new TApplicationException(type, message); 108 } 109 write(TProtocol oprot)110 public void write(TProtocol oprot) throws TException { 111 TStruct struct = new TStruct("TApplicationException"); 112 TField field = new TField(); 113 oprot.writeStructBegin(struct); 114 if (getMessage() != null) { 115 field.name = "message"; 116 field.type = TType.STRING; 117 field.id = 1; 118 oprot.writeFieldBegin(field); 119 oprot.writeString(getMessage()); 120 oprot.writeFieldEnd(); 121 } 122 field.name = "type"; 123 field.type = TType.I32; 124 field.id = 2; 125 oprot.writeFieldBegin(field); 126 oprot.writeI32(type_); 127 oprot.writeFieldEnd(); 128 oprot.writeFieldStop(); 129 oprot.writeStructEnd(); 130 131 } 132 } 133