Hi,
I'm setting up a web service using grpc-java and hibernate. I want to start a transaction whenever I receive a new call from a client and commit/abort it after it.
As far as I understand I should do something like this:
public class DatabaseTransactionInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
MethodDescriptor<ReqT, RespT> methodDescriptor,
ServerCall<RespT> serverCall,
Metadata metadata,
ServerCallHandler<ReqT, RespT> serverCallHandler) {
// Initiate transaction and add it to grpc context
return new SimpleForwardingServerCallListener<ReqT>(serverCallHandler.startCall(
methodDescriptor, serverCall, metadata)) {
@Override
public void onCancel() {
super.onCancel();
// Abort transaction and remove it from grpc context
}
@Override
public void onComplete() {
super.onComplete();
// Commit transaction and remove it from grpc context
}
};
}
}
And then get it from the context on the implementation of the services and use it.
My problem is that it one of the implementations throws onComplete() is called instead of onCancel(), so I guess I'm getting something wrong.
Can you give me any hint about who to do this?
Thanks,
Pato