Thrift-1658:Java thrift server is not throwing TApplicationException

Client: java
Patch: Keith Turner

Exceptions not being handled correctly within newly modified ProcessFunctions. Added back code previously removed from auto generated class.



git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1375880 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jake Farrell 2012-08-22 02:27:06 +00:00
parent c02efe21c1
commit 2853cc0adf

View File

@ -7,10 +7,14 @@ import org.apache.thrift.protocol.TMessage;
import org.apache.thrift.protocol.TMessageType; import org.apache.thrift.protocol.TMessageType;
import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.protocol.TProtocolException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class ProcessFunction<I, T extends TBase> { public abstract class ProcessFunction<I, T extends TBase> {
private final String methodName; private final String methodName;
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessFunction.class.getName());
public ProcessFunction(String methodName) { public ProcessFunction(String methodName) {
this.methodName = methodName; this.methodName = methodName;
} }
@ -29,7 +33,21 @@ public abstract class ProcessFunction<I, T extends TBase> {
return; return;
} }
iprot.readMessageEnd(); iprot.readMessageEnd();
TBase result = getResult(iface, args); TBase result = null;
try {
result = getResult(iface, args);
} catch(Throwable th) {
LOGGER.error("Internal error processing " + getMethodName(), th);
TApplicationException x = new TApplicationException(TApplicationException.INTERNAL_ERROR,
"Internal error processing " + getMethodName());
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.EXCEPTION, seqid));
x.write(oprot);
oprot.writeMessageEnd();
oprot.getTransport().flush();
return;
}
if(!isOneway()) { if(!isOneway()) {
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.REPLY, seqid)); oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.REPLY, seqid));
result.write(oprot); result.write(oprot);