From 2853cc0adffae223e0861524eb8e23af03b7a19b Mon Sep 17 00:00:00 2001 From: Jake Farrell Date: Wed, 22 Aug 2012 02:27:06 +0000 Subject: [PATCH] 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 --- .../org/apache/thrift/ProcessFunction.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/java/src/org/apache/thrift/ProcessFunction.java b/lib/java/src/org/apache/thrift/ProcessFunction.java index 3afd38cc..2ba35279 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.TMessage; 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 { 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 @@ public abstract class ProcessFunction { 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); -- 2.17.1