org.apache.thrift.TApplicationException Java Examples

The following examples show how to use org.apache.thrift.TApplicationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractThriftMessageClassFinder.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Nullable
static Class<?> getMatchedClass(@Nullable Class<?> clazz) {
    if (clazz == null) {
        return null;
    }
    // Note, we need to check
    // if the class is abstract, because abstract class does not have metaDataMap
    // if the class has no-arg constructor, because FieldMetaData.getStructMetaDataMap
    //   calls clazz.newInstance
    if (isTBase(clazz) && !isAbstract(clazz) && hasNoArgConstructor(clazz)) {
        return clazz;
    }

    if (isTApplicationException(clazz)) {
        return clazz;
    }

    if (isTApplicationExceptions(clazz)) {
        return TApplicationException.class;
    }

    return null;
}
 
Example #2
Source File: TServiceClientNoPrint.java    From rpc-benchmark with Apache License 2.0 6 votes vote down vote up
@Override
protected void receiveBase(TBase<?, ?> result, String methodName) throws TException {
	TMessage msg = iprot_.readMessageBegin();
	if (msg.type == TMessageType.EXCEPTION) {
		TApplicationException x = new TApplicationException();
		x.read(iprot_);
		iprot_.readMessageEnd();
		throw x;
	}
	// System.out.format("Received %d%n", msg.seqid);
	if (msg.seqid != seqid_) {
		throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, String.format(
				"%s failed: out of sequence response: expected %d but got %d", methodName, seqid_, msg.seqid));
	}
	result.read(iprot_);
	iprot_.readMessageEnd();
}
 
Example #3
Source File: TProtobufProcessor.java    From jigsaw-payment with Apache License 2.0 6 votes vote down vote up
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
	TMessage msg = in.readMessageBegin();
	Controller<?, ?> fn = (Controller<?, ?>) this.beanFactory
			.getBean(msg.name);
	if (fn == null) {
		if (LOGGER.isWarnEnabled()) {
			LOGGER.warn("Invalid request: failed to find interface="
					+ msg.name + ", from: " + getInetAddress(in));
		}

		TProtocolUtil.skip(in, TType.STRUCT);
		in.readMessageEnd();
		TApplicationException x = new TApplicationException(
				TApplicationException.UNKNOWN_METHOD,
				"Invalid method name: '" + msg.name + "'");
		out.writeMessageBegin(new TMessage(msg.name,
				TMessageType.EXCEPTION, msg.seqid));
		x.write(out);
		out.writeMessageEnd();
		out.getTransport().flush();
		return true;
	}
	process(msg.seqid, msg.name, in, out, fn);
	return true;
}
 
Example #4
Source File: HiveMetaStoreClientCompatibility1xx.java    From pxf with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the table given a dbname and table name. This will fallback
 * in Hive 1.x.x servers when a get_table_req API call is made.
 *
 * @param dbname The database the table is located in.
 * @param name   Name of the table to fetch.
 * @return An object representing the table.
 * @throws TException A thrift communication error occurred
 */
@Override
public Table getTable(String dbname, String name) throws TException {
    try {
        return super.getTable(dbname, name);
    } catch (TException e) {
        try {
            LOG.debug("Couldn't invoke method getTable");
            if (e.getClass().isAssignableFrom(TApplicationException.class)) {
                LOG.debug("Attempting to fallback");
                Table table = client.get_table(dbname, name);
                return new GetTableResult(table).getTable();
            }
        } catch (Throwable t) {
            LOG.warn("Unable to run compatibility for metastore client method get_table_req. Will rethrow original exception: ", t);
        }
        throw e;
    }
}
 
Example #5
Source File: TestDriftNettyServerTransport.java    From drift with Apache License 2.0 6 votes vote down vote up
private static ResultCode readLogResponse(int expectedSequenceId, TProtocol protocol)
        throws TException
{
    TMessage message = protocol.readMessageBegin();
    if (message.type == TMessageType.EXCEPTION) {
        throw TApplicationException.readFrom(protocol);
    }
    if (message.type != TMessageType.REPLY) {
        throw new TApplicationException(MISSING_RESULT, "request failed");
    }
    if (message.seqid != expectedSequenceId) {
        throw new TApplicationException(BAD_SEQUENCE_ID, format("expected sequenceId %s, but received %s", expectedSequenceId, message.seqid));
    }

    Log_result result = new Log_result();
    result.read(protocol);
    protocol.readMessageEnd();
    return result.success;
}
 
Example #6
Source File: ThriftIDLSerializer.java    From octo-rpc with Apache License 2.0 6 votes vote down vote up
protected RpcResult doDeserializeResponse(DefaultResponse response, TMessage message,
                                          TProtocol protocol) throws Exception {
    RpcResult rpcResult = new RpcResult();
    if (message.type == TMessageType.REPLY) {
        Object realResult = deserializeResult(protocol, response.getServiceInterface().getName(), message.name);
        if (realResult instanceof Exception) {
            // 服务端自定义异常
            response.setException((Exception) realResult);
        }
        rpcResult.setReturnVal(realResult);
    } else if (message.type == TMessageType.EXCEPTION) {
        TApplicationException exception = TApplicationException.read(protocol);
        MetaUtil.wrapException(exception, response);
    }
    if (!response.isOctoProtocol() && hasOldRequestHeader(protocol)) {
        // 解析老协议的Header
        RequestHeader requestHeader = new RequestHeader();
        protocol.readFieldBegin();
        requestHeader.read(protocol);
        protocol.readFieldEnd();
    }
    return rpcResult;
}
 
Example #7
Source File: LocatorServiceImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
      .get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    return fn.getClass() != LocatorService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
 
Example #8
Source File: ThriftJacksonTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void serializeThriftReplyWithException() throws IOException {
    final ThriftReply reply = new ThriftReply(
            new TMessage(THRIFT_METHOD_NAME, TMessageType.EXCEPTION, 0),
            new TApplicationException(1, "don't wanna say hello"));
    final String actualJson = defaultMapper.writeValueAsString(reply);
    final String actualJson2 = customMapper.writeValueAsString(reply);

    assertThatJson(actualJson).isEqualTo(
            '{' +
            "    \"header\": {" +
            "        \"name\": \"hello\"," +
            "        \"type\": 3," +
            "        \"seqid\": 0" +
            "    }," +
            "    \"result\": null," +
            "    \"exception\": {" +
            "        \"type\": 1," +
            "        \"message\": \"don't wanna say hello\"" +
            "    }" +
            '}');
    assertThatJson(actualJson2).isEqualTo(actualJson);
}
 
Example #9
Source File: DistributedLogClientImpl.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #10
Source File: NettyDispatcher.java    From ikasoa with MIT License 6 votes vote down vote up
private void sendTApplicationException(TApplicationException e, ChannelHandlerContext ctx, TNettyMessage request,
		int responseSequenceId, TNettyTransport requestTransport, TProtocol inProtocol, TProtocol outProtocol) {
	if (ctx.getChannel().isConnected()) {
		try {
			TMessage message = inProtocol.readMessageBegin();
			outProtocol.writeMessageBegin(new TMessage(message.name, TMessageType.EXCEPTION, message.seqid));
			e.write(outProtocol);
			outProtocol.writeMessageEnd();
			requestTransport.setTApplicationException(e);
			outProtocol.getTransport().flush();
			writeResponse(ctx, request.getMessageFactory().create(requestTransport.getOutputBuffer()),
					responseSequenceId, DispatcherContext.isResponseOrderingRequired(ctx));
		} catch (TException ex) {
			onDispatchException(ctx, ex);
		}
	}
}
 
Example #11
Source File: AbstractThriftBase.java    From ikasoa with MIT License 6 votes vote down vote up
/**
 * 读取操作
 */
@Override
public void read(TProtocol iprot) throws TException {
	if (!StringUtil.equals("org.apache.thrift.scheme.StandardScheme", iprot.getScheme().getName()))
		throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
	TField schemeField;
	iprot.readStructBegin();
	while (true) {
		schemeField = iprot.readFieldBegin();
		if (ObjectUtil.same(schemeField.type, TType.STOP))
			break;
		if (ObjectUtil.same(schemeField.type, TType.STRING))
			str = iprot.readString();
		else
			throw new TApplicationException("field type must be 'String' !");
		iprot.readFieldEnd();
	}
	iprot.readStructEnd();
}
 
Example #12
Source File: DistributedLogClientImpl.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #13
Source File: LocatorServiceImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
      .get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    return fn.getClass() != LocatorService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
 
Example #14
Source File: GreetingMessageService.java    From spring-thrift-starter with MIT License 6 votes vote down vote up
public String constructGreeting(TName name) throws TApplicationException {
    if (name.getFirstName().equals("John") && name.getSecondName().equals("Doe"))
        throw new TApplicationException("No John Doe allowed");

    StringBuilder result = new StringBuilder();

    result.append("Hello ");

    if(name.isSetStatus()) {
        result.append(org.springframework.util.StringUtils.capitalize(name.getStatus().name().toLowerCase()));
        result.append(" ");
    }

    result.append(name.getFirstName());
    result.append(" ");
    result.append(name.getSecondName());

    return result.toString();
}
 
Example #15
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(SerializationFormatProvider.class)
void testAsync_FileService_create_exception(SerializationFormat defaultSerializationFormat)
        throws Exception {
    final FileService.Client client = new FileService.Client.Factory().getClient(
            inProto(defaultSerializationFormat), outProto(defaultSerializationFormat));
    client.send_create(BAZ);
    assertThat(out.length()).isGreaterThan(0);

    final RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    final THttpService service = THttpService.of(
            (FileService.AsyncIface) (path, resultHandler) ->
                    resultHandler.onError(exception), defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType()).isEqualTo(TApplicationException.INTERNAL_ERROR);
        assertThat(e.getMessage()).contains(exception.toString());
    }
}
 
Example #16
Source File: RetryingRpcClientTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void propagateLastResponseWhenNextRetryIsAfterTimeout() throws Exception {
    final BlockingQueue<RequestLog> logQueue = new LinkedTransferQueue<>();
    final RetryRuleWithContent<RpcResponse> rule =
            (ctx, response, cause) -> CompletableFuture.completedFuture(
                    RetryDecision.retry(Backoff.fixed(10000000)));
    final HelloService.Iface client = helloClient(rule, 100, logQueue);
    when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException());
    final Throwable thrown = catchThrowable(() -> client.hello("hello"));
    assertThat(thrown).isInstanceOf(TApplicationException.class);
    assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR);
    verify(serviceHandler, only()).hello("hello");

    // Make sure the last HTTP request is set to the parent's HTTP request.
    final RequestLog log = logQueue.poll(10, TimeUnit.SECONDS);
    assertThat(log).isNotNull();
    assertThat(log.children()).isNotEmpty();
    final HttpRequest lastHttpReq = log.children().get(log.children().size() - 1).context().request();
    assertThat(lastHttpReq).isSameAs(log.context().request());
}
 
Example #17
Source File: ClusterManager.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Override
public void releaseResource(String handle, List<Integer> idList)
  throws TException, InvalidSessionHandle, SafeModeException {
  checkSafeMode("releaseResource");
  try {
    LOG.info("Release " + idList.size() + " resources from session: " +
             handle);
    sessionManager.heartbeat(handle);
    Collection<ResourceGrant> canceledGrants =
      sessionManager.releaseResource(handle, idList);

    if (canceledGrants == null) {
      // LOG.info("No canceled grants for session " + handle);
      return;
    }

    for (ResourceGrant grant: canceledGrants) {
      nodeManager.cancelGrant(grant.nodeName, handle, grant.id);
      metrics.releaseResource(grant.type);
    }

    scheduler.notifyScheduler();
  } catch (RuntimeException e) {
    throw new TApplicationException(e.getMessage());
  }
}
 
Example #18
Source File: ThriftServiceTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@ArgumentsSource(SerializationFormatProvider.class)
void testSync_FileService_create_exception(SerializationFormat defaultSerializationFormat)
        throws Exception {
    final FileService.Client client = new FileService.Client.Factory().getClient(
            inProto(defaultSerializationFormat), outProto(defaultSerializationFormat));
    client.send_create(BAZ);
    assertThat(out.length()).isGreaterThan(0);

    final RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    final THttpService service = THttpService.of((FileService.Iface) path -> {
        throw exception;
    }, defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType()).isEqualTo(TApplicationException.INTERNAL_ERROR);
        assertThat(e.getMessage()).contains(exception.toString());
    }
}
 
Example #19
Source File: ThriftJacksonSerializers.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type,
                                        BeanDescription beanDesc) {

    final Class<?> rawType = type.getRawClass();
    if (TMessage.class.isAssignableFrom(rawType)) {
        return new TMessageJsonSerializer();
    }
    if (TBase.class.isAssignableFrom(rawType)) {
        return new TBaseJsonSerializer(useNamedEnums);
    }
    if (TApplicationException.class.isAssignableFrom(rawType)) {
        return new TApplicationExceptionJsonSerializer(useNamedEnums);
    }
    if (ThriftCall.class.isAssignableFrom(rawType)) {
        return new ThriftCallJsonSerializer(useNamedEnums);
    }
    if (ThriftReply.class.isAssignableFrom(rawType)) {
        return new ThriftReplyJsonSerializer(useNamedEnums);
    }
    return super.findSerializer(config, type, beanDesc);
}
 
Example #20
Source File: THttpClientDelegate.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Nullable
private static TApplicationException readApplicationException(int seqId, ThriftFunction func,
                                                              TProtocol inputProtocol,
                                                              TMessage msg) throws TException {
    if (msg.seqid != seqId) {
        throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID);
    }

    if (!func.name().equals(msg.name)) {
        return new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    }

    if (msg.type == TMessageType.EXCEPTION) {
        final TApplicationException appEx = TApplicationExceptions.read(inputProtocol);
        inputProtocol.readMessageEnd();
        return appEx;
    }

    return null;
}
 
Example #21
Source File: ThriftFunction.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the specified {@code result} into a Java object.
 */
@Nullable
public Object getResult(TBase<?, ?> result) throws TException {
    for (TFieldIdEnum fieldIdEnum : exceptionFields()) {
        if (ThriftFieldAccess.isSet(result, fieldIdEnum)) {
            throw (TException) ThriftFieldAccess.get(result, fieldIdEnum);
        }
    }

    final TFieldIdEnum successField = successField();
    if (successField == null) { //void method
        return null;
    } else if (ThriftFieldAccess.isSet(result, successField)) {
        return ThriftFieldAccess.get(result, successField);
    } else {
        throw new TApplicationException(
                TApplicationException.MISSING_RESULT,
                result.getClass().getName() + '.' + successField.getFieldName());
    }
}
 
Example #22
Source File: ClusterManager.java    From RDFS with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionHeartbeat(String handle) throws TException,
    InvalidSessionHandle, SafeModeException {
  checkSafeMode("sessionHeartbeat");
  try {
    sessionManager.heartbeat(handle);
  } catch (RuntimeException e) {
    throw new TApplicationException(e.getMessage());
  }
}
 
Example #23
Source File: ThriftReply.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance that contains a Thrift {@link TMessageType#EXCEPTION} message.
 */
public ThriftReply(TMessage header, TApplicationException exception) {
    super(header);
    if (header.type != TMessageType.EXCEPTION) {
        throw new IllegalArgumentException(
                "header.type: " + typeStr(header.type) + " (expected: EXCEPTION)");
    }

    result = null;
    this.exception = requireNonNull(exception, "exception");
}
 
Example #24
Source File: AbstractThriftOverHttpTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 10000)
public void testMessageLogsForException() throws Exception {
    try (TTransport transport = newTransport("http", "/exception")) {
        final HelloService.Client client =
                new HelloService.Client.Factory().getClient(
                        ThriftProtocolFactories.BINARY.getProtocol(transport));
        recordMessageLogs = true;
        assertThatThrownBy(() -> client.hello("Trustin")).isInstanceOf(TApplicationException.class);
    }

    final RequestLog log = takeLog();

    assertThat(log.requestHeaders()).isInstanceOf(HttpHeaders.class);
    assertThat(log.requestContent()).isInstanceOf(RpcRequest.class);
    assertThat(log.rawRequestContent()).isInstanceOf(ThriftCall.class);

    final RpcRequest request = (RpcRequest) log.requestContent();
    assertThat(request.serviceType()).isEqualTo(HelloService.AsyncIface.class);
    assertThat(request.method()).isEqualTo("hello");
    assertThat(request.params()).containsExactly("Trustin");

    final ThriftCall rawRequest = (ThriftCall) log.rawRequestContent();
    assertThat(rawRequest.header().type).isEqualTo(TMessageType.CALL);
    assertThat(rawRequest.header().name).isEqualTo("hello");
    assertThat(rawRequest.args()).isInstanceOf(HelloService.hello_args.class);
    assertThat(((HelloService.hello_args) rawRequest.args()).getName()).isEqualTo("Trustin");

    assertThat(log.responseHeaders()).isInstanceOf(HttpHeaders.class);
    assertThat(log.responseContent()).isInstanceOf(RpcResponse.class);
    assertThat(log.rawResponseContent()).isInstanceOf(ThriftReply.class);

    final RpcResponse response = (RpcResponse) log.responseContent();
    assertThat(response.cause()).isNotNull();

    final ThriftReply rawResponse = (ThriftReply) log.rawResponseContent();
    assertThat(rawResponse.header().type).isEqualTo(TMessageType.EXCEPTION);
    assertThat(rawResponse.header().name).isEqualTo("hello");
    assertThat(rawResponse.exception()).isNotNull();
}
 
Example #25
Source File: GFXDServiceImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public final boolean process(final TProtocol in, final TProtocol out)
    throws TException {
  final TMessage msg = in.readMessageBegin();
  final ProcessFunction<GFXDServiceImpl, ?> fn = this.fnMap.get(msg.name);
  if (fn != null) {
    fn.process(msg.seqid, in, out, this.inst);
    // terminate connection on receiving closeConnection
    // direct class comparison should be the fastest way
    // TODO: SW: also need to clean up connection artifacts in the case of
    // client connection failure (ConnectionListener does get a notification
    // but how to tie the socket/connectionNumber to the connectionID?)
    return fn.getClass() != GFXDService.Processor.closeConnection.class;
  }
  else {
    TProtocolUtil.skip(in, TType.STRUCT);
    in.readMessageEnd();
    TApplicationException x = new TApplicationException(
        TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
            + msg.name + "'");
    out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
        msg.seqid));
    x.write(out);
    out.writeMessageEnd();
    out.getTransport().flush();
    return true;
  }
}
 
Example #26
Source File: ClusterManager.java    From RDFS with Apache License 2.0 5 votes vote down vote up
@Override
public void sessionUpdateInfo(String handle, SessionInfo info)
    throws TException, InvalidSessionHandle, SafeModeException {
  checkSafeMode("sessionUpdateInfo");
  try {
    LOG.info("sessionUpdateInfo called for session: " + handle +
             " with info: " + info);
    sessionManager.heartbeat(handle);
    sessionManager.updateInfo(handle, info);
  } catch (RuntimeException e) {
    throw new TApplicationException(e.getMessage());
  }
}
 
Example #27
Source File: ThriftHiveMetastore.java    From presto with Apache License 2.0 5 votes vote down vote up
private static boolean isUnknownMethodExceptionalResponse(Exception exception)
{
    if (!(exception instanceof TApplicationException)) {
        return false;
    }

    TApplicationException applicationException = (TApplicationException) exception;
    return applicationException.getType() == UNKNOWN_METHOD;
}
 
Example #28
Source File: InternalScribeCodec.java    From zipkin-reporter-java with Apache License 2.0 5 votes vote down vote up
static boolean parseResponse(TBinaryProtocol iprot) throws TException {
  Boolean result = null;
  iprot.readStructBegin();
  TField schemeField;
  while ((schemeField = iprot.readFieldBegin()).type != TType.STOP) {
    if (schemeField.id == 0 /* SUCCESS */ && schemeField.type == TType.I32) {
      result = iprot.readI32() == 0;
    } else {
      TProtocolUtil.skip(iprot, schemeField.type);
    }
  }
  iprot.readStructEnd();
  if (result != null) return result;
  throw new TApplicationException(MISSING_RESULT, "Log failed: unknown result");
}
 
Example #29
Source File: HiveCompatibleThriftHiveMetastoreIfaceFactoryTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void underlyingExceptionIsThrownWhenCompatibilityFails() throws Exception {
  CloseableThriftHiveMetastoreIface thriftHiveMetastoreIface = factory.newInstance(delegate);
  TApplicationException cause = new TApplicationException("CAUSE");
  when(delegate.get_all_databases()).thenThrow(cause);
  try {
    thriftHiveMetastoreIface.get_all_databases();
    fail("exception should have been thrown");
  } catch (TApplicationException e) {
    assertThat(e, is(cause));
  }
}
 
Example #30
Source File: LoggingThriftMethodInterceptor.java    From spring-thrift-starter with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
public void afterThrowing(Method method, Object[] args, Object target, Exception e) throws Throwable {
    if (!(e instanceof TException)) {
        log.warn("Unexpected exception in " + target.getClass().getCanonicalName() + "." + method.getName(), e);
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.toString());
    }
    log.warn("Exception in Thrift method {}.{}() when called with args: {}", target.getClass().getSimpleName(), method.getName(), args, e);
}