You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jf...@apache.org on 2012/08/22 04:27:07 UTC

svn commit: r1375880 - /thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java

Author: jfarrell
Date: Wed Aug 22 02:27:06 2012
New Revision: 1375880

URL: http://svn.apache.org/viewvc?rev=1375880&view=rev
Log:
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.


Modified:
    thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java

Modified: thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java?rev=1375880&r1=1375879&r2=1375880&view=diff
==============================================================================
--- thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java (original)
+++ thrift/trunk/lib/java/src/org/apache/thrift/ProcessFunction.java Wed Aug 22 02:27:06 2012
@@ -7,10 +7,14 @@ import org.apache.thrift.protocol.TMessa
 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 @@ public abstract class ProcessFunction<I,
       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);