use of org.apache.thrift.TApplicationException in project hive by apache.
the class TUGIBasedProcessor method handleSetUGI.
private void handleSetUGI(TUGIContainingTransport ugiTrans, ThriftHiveMetastore.Processor.set_ugi<Iface> fn, TMessage msg, TProtocol iprot, TProtocol oprot) throws TException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
UserGroupInformation clientUgi = ugiTrans.getClientUGI();
if (null != clientUgi) {
throw new TException(new IllegalStateException("UGI is already set. Resetting is not " + "allowed. Current ugi is: " + clientUgi.getUserName()));
}
set_ugi_args args = fn.getEmptyArgsInstance();
try {
args.read(iprot);
} catch (TProtocolException e) {
iprot.readMessageEnd();
TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage());
oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
x.write(oprot);
oprot.writeMessageEnd();
oprot.getTransport().flush();
return;
}
iprot.readMessageEnd();
set_ugi_result result = fn.getResult(iface, args);
List<String> principals = result.getSuccess();
// Store the ugi in transport and then continue as usual.
ugiTrans.setClientUGI(UserGroupInformation.createRemoteUser(principals.remove(principals.size() - 1)));
oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
result.write(oprot);
oprot.writeMessageEnd();
oprot.getTransport().flush();
}
use of org.apache.thrift.TApplicationException in project dubbo by alibaba.
the class ThriftCodecTest method testEncodeExceptionResponse.
@Test
public void testEncodeExceptionResponse() throws Exception {
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:" + port + "/" + Demo.Iface.class.getName());
Channel channel = new MockedChannel(url);
Request request = createRequest();
AppResponse appResponse = new AppResponse();
String exceptionMessage = "failed";
appResponse.setException(new RuntimeException(exceptionMessage));
Response response = new Response();
response.setResult(appResponse);
response.setId(request.getId());
ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);
ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString");
ThriftCodec.CACHED_REQUEST.put(request.getId(), rd);
codec.encode(channel, bos, response);
byte[] buf = new byte[bos.writerIndex() - 4];
System.arraycopy(bos.array(), 4, buf, 0, bos.writerIndex() - 4);
ByteArrayInputStream bis = new ByteArrayInputStream(buf);
if (bis.markSupported()) {
bis.mark(0);
}
TIOStreamTransport transport = new TIOStreamTransport(bis);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
Assertions.assertEquals(ThriftCodec.MAGIC, protocol.readI16());
Assertions.assertEquals(protocol.readI32() + 4, bos.writerIndex());
int headerLength = protocol.readI16();
Assertions.assertEquals(ThriftCodec.VERSION, protocol.readByte());
Assertions.assertEquals(Demo.Iface.class.getName(), protocol.readString());
Assertions.assertEquals(request.getId(), protocol.readI64());
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
Assertions.assertEquals("echoString", message.name);
Assertions.assertEquals(TMessageType.EXCEPTION, message.type);
Assertions.assertEquals(ThriftCodec.getSeqId(), message.seqid);
TApplicationException exception = TApplicationException.readFrom(protocol);
protocol.readMessageEnd();
Assertions.assertEquals(exceptionMessage, exception.getMessage());
}
use of org.apache.thrift.TApplicationException in project distributedlog by twitter.
the class DistributedLogClientImpl method handleTApplicationException.
void handleTApplicationException(Throwable cause, Optional<StreamOp> op, SocketAddress addr, ProxyClient sc) {
TApplicationException ex = (TApplicationException) cause;
if (ex.getType() == TApplicationException.UNKNOWN_METHOD) {
// if we encountered unknown method exception on thrift server, it means this proxy
// has problem. we should remove it from routing service, clean up ownerships
routingService.removeHost(addr, cause);
onServerLeft(addr, sc);
if (op.isPresent()) {
ownershipCache.removeOwnerFromStream(op.get().stream, addr, cause.getMessage());
doSend(op.get(), addr);
}
} else {
handleException(cause, op, addr);
}
}
Aggregations