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
diff --git a/lib/java/src/org/apache/thrift/ProcessFunction.java b/lib/java/src/org/apache/thrift/ProcessFunction.java
index 3afd38c..2ba3527 100644
--- a/lib/java/src/org/apache/thrift/ProcessFunction.java
+++ b/lib/java/src/org/apache/thrift/ProcessFunction.java
@@ -7,10 +7,14 @@
import org.apache.thrift.protocol.TMessageType;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public abstract class ProcessFunction<I, T extends TBase> {
private final String methodName;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProcessFunction.class.getName());
+
public ProcessFunction(String methodName) {
this.methodName = methodName;
}
@@ -29,7 +33,21 @@
return;
}
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()) {
oprot.writeMessageBegin(new TMessage(getMethodName(), TMessageType.REPLY, seqid));
result.write(oprot);