diff --git a/library/Zend/Soap/Server.php b/library/Zend/Soap/Server.php index 21584927eb6..7abd177ec5d 100644 --- a/library/Zend/Soap/Server.php +++ b/library/Zend/Soap/Server.php @@ -57,6 +57,11 @@ class Server implements ZendServerServer */ protected $faultExceptions = array(); + /** + * Container for caught exception during business code execution + * @var \Exception + */ + protected $caughtException = null; /** * SOAP Server Features * @var int @@ -993,6 +998,15 @@ public function getFaultExceptions() return $this->faultExceptions; } + /** + * Return caught exception during business code execution + * @return null|\Exception caught exception + */ + public function getException() + { + return $this->caughtException; + } + /** * Generate a server fault * @@ -1009,6 +1023,8 @@ public function getFaultExceptions() */ public function fault($fault = null, $code = 'Receiver') { + $this->caughtException = (is_string($fault)) ? new \Exception($fault) : $fault; + if ($fault instanceof \Exception) { if ($this->isRegisteredAsFaultException($fault)) { $message = $fault->getMessage(); diff --git a/tests/ZendTest/Soap/ServerTest.php b/tests/ZendTest/Soap/ServerTest.php index df4dce4ae1f..37676161c63 100644 --- a/tests/ZendTest/Soap/ServerTest.php +++ b/tests/ZendTest/Soap/ServerTest.php @@ -937,4 +937,15 @@ public function testShouldThrowExceptionIfHandledRequestContainsDoctype() $this->assertContains('Invalid XML', $response->getMessage()); } + public function testGetOriginalCaughtException() + { + $server = new Server(); + $fault = $server->fault(new \Exception('test')); + + $exception = $server->getException(); + $this->assertInstanceOf('\Exception', $exception); + $this->assertEquals('test', $exception->getMessage()); + $this->assertInstanceOf('\SoapFault', $fault); + $this->assertEquals('Unknown error', $fault->getMessage()); + } }