Author: bryanduxbury
Date: Wed Jun 17 16:43:25 2009
New Revision: 785713

URL: http://svn.apache.org/viewvc?rev=785713&view=rev
Log:
THRIFT-378. java: Java servers do not turn internal errors into thrift 
exceptions

This patch causes Java servers to log internal server errors and return an 
INTERNAL_ERROR exception instead of just closing the connection.

Author: Jonathan Ellis


Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
    
incubator/thrift/trunk/lib/java/src/org/apache/thrift/TApplicationException.java

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc?rev=785713&r1=785712&r2=785713&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc 
(original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc Wed 
Jun 17 16:43:25 2009
@@ -279,7 +279,8 @@
     "import java.util.HashMap;\n" +
     "import java.util.Set;\n" +
     "import java.util.HashSet;\n" +
-    "import java.util.Collections;\n\n";
+    "import java.util.Collections;\n" +
+    "import org.apache.log4j.Logger;\n\n";
 }
 
 /**
@@ -1940,6 +1941,8 @@
     "public static class Processor" << extends_processor << " implements 
TProcessor {" << endl;
   indent_up();
 
+  indent(f_service_) << "private static final Logger LOGGER = 
Logger.getLogger(Processor.class.getName());" << endl;
+
   indent(f_service_) <<
     "public Processor(Iface iface)" << endl;
   scope_up(f_service_);
@@ -2128,7 +2131,18 @@
         f_service_ << "}";
       }
     }
-    f_service_ << endl;
+    f_service_ << " catch (Throwable th) {" << endl;
+    indent_up();
+    f_service_ <<
+      indent() << "LOGGER.error(\"Internal error processing " << 
tfunction->get_name() << "\", th);" << endl <<
+      indent() << "TApplicationException x = new 
TApplicationException(TApplicationException.INTERNAL_ERROR, \"Internal error 
processing " << tfunction->get_name() << "\");" << endl <<
+      indent() << "oprot.writeMessageBegin(new TMessage(\"" << 
tfunction->get_name() << "\", TMessageType.EXCEPTION, seqid));" << endl <<
+      indent() << "x.write(oprot);" << endl <<
+      indent() << "oprot.writeMessageEnd();" << endl <<
+      indent() << "oprot.getTransport().flush();" << endl <<
+      indent() << "return;" << endl;
+    indent_down();
+    f_service_ << indent() << "}" << endl;
   }
 
   // Shortcut out here for oneway functions

Modified: 
incubator/thrift/trunk/lib/java/src/org/apache/thrift/TApplicationException.java
URL: 
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/java/src/org/apache/thrift/TApplicationException.java?rev=785713&r1=785712&r2=785713&view=diff
==============================================================================
--- 
incubator/thrift/trunk/lib/java/src/org/apache/thrift/TApplicationException.java
 (original)
+++ 
incubator/thrift/trunk/lib/java/src/org/apache/thrift/TApplicationException.java
 Wed Jun 17 16:43:25 2009
@@ -43,6 +43,7 @@
   public static final int WRONG_METHOD_NAME = 3;
   public static final int BAD_SEQUENCE_ID = 4;
   public static final int MISSING_RESULT = 5;
+  public static final int INTERNAL_ERROR = 6;
 
   protected int type_ = UNKNOWN;
 


Reply via email to