Coder Social home page Coder Social logo

Comments (3)

aatarasoff avatar aatarasoff commented on May 20, 2024

Hi, could you provide real stacktraces on client side and server side?

from spring-thrift-starter.

jihor avatar jihor commented on May 20, 2024

Thrift generated sources always declare a org.apache.thrift.TException on methods:

public class TService {
    public interface Iface {
        public Response act() throws MyException, org.apache.thrift.TException;
        ...
    }
}

An implementing class is usually overriding the method with declaring only a custom exception. Since it never throws a org.apache.thrift.TException, why bother declaring it? Example:

public class ThriftEndpoint implements TService.Iface
@Override
public Response act() throws MyException {...}

In runtime, methods of the implementing class are proxied by LoggingThriftMethodInterceptor, and should a subclass of RuntimeException be thrown from the method, the interceptor wil wrap it into a TApplicationException and rethrow it. Since TApplicationException is not declared in method signature of the implementing class, it becomes an UndeclaredThrowableException and then a TTransportException with message HTTP Response code: 406.

Possible workarounds:

  1. always declare org.apache.thrift.TException on methods in implementing classes, even if they are not actually thrown by the method code itself:
@Override
Response act() throws MyException, org.apache.thrift.TException {...}

This will lead to TTransportException with Internal error processing {methodName} message, but message from the original exception will not be delivered to client, so this workaround is obviosly not ideal.

  1. catch any Exceptions in method and wrap them into declared custom exception (it always extends TException and will not be wrapped by interceptor):
@Override
Response act() throws MyException {
    try {
        ...
    } catch (Exception e) {
        throw new MyException(e);
    }
}

I've provided logs here: logs.zip
Also I've written some tests in my fork (https://github.com/jihor/spring-thrift-starter), see TGreetingServiceHandlerTests class, methods are:

  • testMappedClientWithCustomException() - corresponds to workaround (2);
  • testMappedClientWithRuntimeException1() - corresponds to workaround (1);
  • testMappedClientWithRuntimeException2() - this is what you get by default, an HTTP Response code: 406;

It might be useful to merge these tests into master.

from spring-thrift-starter.

jihor avatar jihor commented on May 20, 2024

Hmm, maybe it's worth deleting any exception wrapping from LoggingThriftMethodInterceptor. It's an interceptor for logging an it shouldn't interfere with application flow. Then, should you throw a RuntimeExcepton from your method, you will get a TTransportException on client regardless of the method signature.

EDIT: You will actually still get HTTP Response code: 406, but this time it will not depend on method signature. Well, still better than getting different exception classes based on what did you define on your method.

from spring-thrift-starter.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.