THRIFT-1222 Unhandled exception for TEvhttpServer request
Patch: Alexandre Parenteau

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1147542 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/Makefile.am b/lib/cpp/Makefile.am
index 253b68e..35bc8a8 100644
--- a/lib/cpp/Makefile.am
+++ b/lib/cpp/Makefile.am
@@ -70,11 +70,13 @@
                        src/server/TSimpleServer.cpp \
                        src/server/TThreadPoolServer.cpp \
                        src/server/TThreadedServer.cpp \
-											 src/async/TAsyncChannel.cpp \
+                       src/async/TAsyncChannel.cpp \
                        src/processor/PeekProcessor.cpp
 
 libthriftnb_la_SOURCES = src/server/TNonblockingServer.cpp \
-                         src/async/TAsyncProtocolProcessor.cpp
+                         src/async/TAsyncProtocolProcessor.cpp \
+                         src/async/TEvhttpServer.cpp \
+                         src/async/TEvhttpClientChannel.cpp 
 
 libthriftz_la_SOURCES = src/transport/TZlibTransport.cpp
 
diff --git a/lib/cpp/src/async/TEvhttpClientChannel.cpp b/lib/cpp/src/async/TEvhttpClientChannel.cpp
index 54676a1..8b47173 100644
--- a/lib/cpp/src/async/TEvhttpClientChannel.cpp
+++ b/lib/cpp/src/async/TEvhttpClientChannel.cpp
@@ -19,6 +19,7 @@
 
 #include "TEvhttpClientChannel.h"
 #include <evhttp.h>
+#include "transport/TBufferTransports.h"
 
 namespace apache { namespace thrift { namespace async {
 
diff --git a/lib/cpp/src/async/TEvhttpServer.cpp b/lib/cpp/src/async/TEvhttpServer.cpp
index 2997597..30e33e5 100644
--- a/lib/cpp/src/async/TEvhttpServer.cpp
+++ b/lib/cpp/src/async/TEvhttpServer.cpp
@@ -22,6 +22,10 @@
 #include "transport/TBufferTransports.h"
 #include <evhttp.h>
 
+#ifndef HTTP_INTERNAL // libevent < 2
+#define HTTP_INTERNAL 500
+#endif
+
 using apache::thrift::transport::TMemoryBuffer;
 
 namespace apache { namespace thrift { namespace async {
@@ -98,7 +102,11 @@
 
 
 void TEvhttpServer::request(struct evhttp_request* req, void* self) {
-  static_cast<TEvhttpServer*>(self)->process(req);
+  try {
+    static_cast<TEvhttpServer*>(self)->process(req);
+  } catch(std::exception& e) {
+    evhttp_send_reply(req, HTTP_INTERNAL, e.what(), 0);
+  }
 }