Various Thrift fixes, including Application Exception support in Ruby, better errror messages across languages, etc.

Reviewed By: thrift


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665058 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tutorial/php/PhpClient.php b/tutorial/php/PhpClient.php
index ca4f50d..fdd12ac 100755
--- a/tutorial/php/PhpClient.php
+++ b/tutorial/php/PhpClient.php
@@ -24,41 +24,46 @@
 require_once $GEN_DIR.'/tutorial_types.php';
 error_reporting(E_ALL);
 
-$socket = new TSocket('localhost', 9090);
-$transport = new TBufferedTransport($socket, 1024, 1024);
-$protocol = new TBinaryProtocol($transport);
-$client = new CalculatorClient($protocol);
-
-$transport->open();
-
-$client->ping();
-print "ping()\n";
-
-$sum = $client->add(1,1);
-print "1+1=$sum\n";
-
-$work = new tutorial_Work();
-
-$work->op = tutorial_Operation::DIVIDE;
-$work->num1 = 1;
-$work->num2 = 0;
-
 try {
-  $client->calculate(1, $work);
-  print "Whoa! We can divide by zero?\n";
-} catch (tutorial_InvalidOperation $io) {
-  print "InvalidOperation: $io->why\n";
+  $socket = new TSocket('localhost', 9090);
+  $transport = new TBufferedTransport($socket, 1024, 1024);
+  $protocol = new TBinaryProtocol($transport);
+  $client = new CalculatorClient($protocol);
+  
+  $transport->open();
+  
+  $client->ping();
+  print "ping()\n";
+ 
+  $sum = $client->add(1,1);
+  print "1+1=$sum\n";
+  
+  $work = new tutorial_Work();
+  
+  $work->op = tutorial_Operation::DIVIDE;
+  $work->num1 = 1;
+  $work->num2 = 0;
+
+  try {
+    $client->calculate(1, $work);
+    print "Whoa! We can divide by zero?\n";
+  } catch (tutorial_InvalidOperation $io) {
+    print "InvalidOperation: $io->why\n";
+  }
+  
+  $work->op = tutorial_Operation::SUBTRACT;
+  $work->num1 = 15;
+  $work->num2 = 10;
+  $diff = $client->calculate(1, $work);
+  print "15-10=$diff\n";
+  
+  $log = $client->getStruct(1);
+  print "Log: $log->value\n";
+  
+  $transport->close();
+  
+} catch (TException $tx) {
+  print 'TException: '.$tx->getMessage()."\n";
 }
 
-$work->op = tutorial_Operation::SUBTRACT;
-$work->num1 = 15;
-$work->num2 = 10;
-$diff = $client->calculate(1, $work);
-print "15-10=$diff\n";
-
-$log = $client->getStruct(1);
-print "Log: $log->value\n";
-
-$transport->close();
-
 ?>
diff --git a/tutorial/py/PythonClient.py b/tutorial/py/PythonClient.py
index 96ca03a..9dcecd9 100755
--- a/tutorial/py/PythonClient.py
+++ b/tutorial/py/PythonClient.py
@@ -6,53 +6,58 @@
 from tutorial import Calculator
 from tutorial.ttypes import *
 
+from thrift import Thrift
 from thrift.transport import TSocket
 from thrift.transport import TTransport
 from thrift.protocol import TBinaryProtocol
 
-# Make socket
-transport = TSocket.TSocket('localhost', 9090)
-
-# Buffering is critical. Raw sockets are very slow
-transport = TTransport.TBufferedTransport(transport)
-
-# Wrap in a protocol
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
-
-# Create a client to use the protocol encoder
-client = Calculator.Client(protocol)
-
-# Connect!
-transport.open()
-
-client.ping()
-print 'ping()'
-
-sum = client.add(1,1)
-print '1+1=%d' % (sum)
-
-work = Work()
-
-work.op = Operation.DIVIDE
-work.num1 = 1
-work.num2 = 0
-
 try:
-  quotient = client.calculate(1, work)
-  print 'Whoa? You know how to divide by zero?'
-except InvalidOperation, io:
-  print 'InvalidOperation: %s' % (io.__str__())
 
-work.op = Operation.SUBTRACT
-work.num1 = 15
-work.num2 = 10
+  # Make socket
+  transport = TSocket.TSocket('localhost', 9090)
 
-diff = client.calculate(1, work)
-print '15-10=%d' % (diff)
+  # Buffering is critical. Raw sockets are very slow
+  transport = TTransport.TBufferedTransport(transport)
 
-log = client.getStruct(1)
-print 'Check log: %s' % (log.value)
+  # Wrap in a protocol
+  protocol = TBinaryProtocol.TBinaryProtocol(transport)
 
-# Close!
-transport.close()
+  # Create a client to use the protocol encoder
+  client = Calculator.Client(protocol)
 
+  # Connect!
+  transport.open()
+
+  client.ping()
+  print 'ping()'
+
+  sum = client.add(1,1)
+  print '1+1=%d' % (sum)
+
+  work = Work()
+  
+  work.op = Operation.DIVIDE
+  work.num1 = 1
+  work.num2 = 0
+
+  try:
+    quotient = client.calculate(1, work)
+    print 'Whoa? You know how to divide by zero?'
+  except InvalidOperation, io:
+    print 'InvalidOperation: %s' % (io.__str__())
+    
+  work.op = Operation.SUBTRACT
+  work.num1 = 15
+  work.num2 = 10
+    
+  diff = client.calculate(1, work)
+  print '15-10=%d' % (diff)
+
+  log = client.getStruct(1)
+  print 'Check log: %s' % (log.value)
+
+  # Close!
+  transport.close()
+
+except Thrift.TException, tx:
+  print '%s' % (tx.message)
diff --git a/tutorial/rb/RubyClient.rb b/tutorial/rb/RubyClient.rb
index e0b47b6..bcf1300 100755
--- a/tutorial/rb/RubyClient.rb
+++ b/tutorial/rb/RubyClient.rb
@@ -7,37 +7,43 @@
 
 require 'Calculator'
 
-transport = TSocket.new('localhost', 9090)
-protocol = TBinaryProtocol.new(transport)
-client = Calculator::Client.new(protocol)
-
-transport.open()
-
-client.ping()
-print "ping()\n"
-
-sum = client.add(1,1)
-print "1+1=", sum, "\n"
-
-work = Work.new()
-
 begin
-  work.op = Operation::DIVIDE
-  work.num1 = 1
-  work.num2 = 0
-  quot = client.calculate(1, work)
-  puts "Whoa, we can divide by 0 now?"
-rescue InvalidOperation => io
-  print "InvalidOperation: ", io.why, "\n"
+  
+  transport = TBufferedTransport.new(TSocket.new('localhost', 9090))
+  protocol = TBinaryProtocol.new(transport)
+  client = Calculator::Client.new(protocol)
+  
+  transport.open()
+  
+  client.ping()
+  print "ping()\n"
+  
+  sum = client.add(1,1)
+  print "1+1=", sum, "\n"
+  
+  work = Work.new()
+  
+  begin
+    work.op = Operation::DIVIDE
+    work.num1 = 1
+    work.num2 = 0
+    quot = client.calculate(1, work)
+    puts "Whoa, we can divide by 0 now?"
+  rescue InvalidOperation => io
+    print "InvalidOperation: ", io.why, "\n"
+  end
+  
+  work.op = Operation::SUBTRACT
+  work.num1 = 15
+  work.num2 = 10
+  diff = client.calculate(1, work)
+  print "15-10=", diff, "\n"
+  
+  log = client.getStruct(1)
+  print "Log: ", log.value, "\n"
+  
+  transport.close()
+
+rescue TException => tx
+  print 'TException: ', tx.message, "\n"
 end
-
-work.op = Operation::SUBTRACT
-work.num1 = 15
-work.num2 = 10
-diff = client.calculate(1, work)
-print "15-10=", diff, "\n"
-
-log = client.getStruct(1)
-print "Log: ", log.value, "\n"
-
-transport.close()
diff --git a/tutorial/rb/RubyServer.rb b/tutorial/rb/RubyServer.rb
index 2e9145d..ea39e15 100755
--- a/tutorial/rb/RubyServer.rb
+++ b/tutorial/rb/RubyServer.rb
@@ -71,7 +71,8 @@
 handler = CalculatorHandler.new()
 processor = Calculator::Processor.new(handler)
 transport = TServerSocket.new(9090)
-server = TSimpleServer.new(processor, transport)
+transportFactory = TBufferedTransportFactory.new()
+server = TSimpleServer.new(processor, transport, transportFactory)
 
 puts "Starting the server..."
 server.serve()