From 3a2b8e32eec56f19c494bc416b715676be890e3f Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Fri, 13 Dec 2013 08:26:18 +0100 Subject: [PATCH] [SoapBundle] Enhanced SoapFault management --- .../Controller/SoapWebServiceController.php | 27 ++++++++++++---- .../EventListener/SoapExceptionListener.php | 6 ++++ .../SoapBundle/Handler/ExceptionHandler.php | 10 ++++++ .../SoapBundle/Handler/wsdl/exception.wsdl | 31 +++++++++++++++++++ 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl diff --git a/src/BeSimple/SoapBundle/Controller/SoapWebServiceController.php b/src/BeSimple/SoapBundle/Controller/SoapWebServiceController.php index fd52d33..0a2b4d7 100644 --- a/src/BeSimple/SoapBundle/Controller/SoapWebServiceController.php +++ b/src/BeSimple/SoapBundle/Controller/SoapWebServiceController.php @@ -15,6 +15,7 @@ namespace BeSimple\SoapBundle\Controller; use BeSimple\SoapBundle\Handler\ExceptionHandler; use BeSimple\SoapBundle\Soap\SoapRequest; use BeSimple\SoapBundle\Soap\SoapResponse; +use BeSimple\SoapServer\SoapServerBuilder; use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -128,16 +129,30 @@ class SoapWebServiceController extends ContainerAware 'logger' => $logger, )); - $server = $this - ->container - ->get(sprintf('besimple.soap.context.%s', $webservice)) - ->getServerBuilder() - ->withHandler(new ExceptionHandler($exception, $details)) + $handler = new ExceptionHandler($exception, $details); + if ($soapFault = $request->query->get('_besimple_soap_fault')) { + $handler->setSoapFault($soapFault); + + // Remove parameter from query because cannot be Serialized in Logger + $request->query->remove('_besimple_soap_fault'); + } + + $server = SoapServerBuilder::createWithDefaults() + ->withWsdl(__DIR__.'/../Handler/wsdl/exception.wsdl') + ->withWsdlCacheNone() + ->withHandler($handler) ->build() ; ob_start(); - $server->handle($request->getContent()); + $server->handle( + ''. + ''. + ''. + ''. + ''. + '' + ); return new Response(ob_get_clean()); } diff --git a/src/BeSimple/SoapBundle/EventListener/SoapExceptionListener.php b/src/BeSimple/SoapBundle/EventListener/SoapExceptionListener.php index 5448ac7..89508b7 100644 --- a/src/BeSimple/SoapBundle/EventListener/SoapExceptionListener.php +++ b/src/BeSimple/SoapBundle/EventListener/SoapExceptionListener.php @@ -67,12 +67,18 @@ class SoapExceptionListener extends ExceptionListener // hack to retrieve the current WebService name in the controller $request->query->set('_besimple_soap_webservice', $webservice); + $exception = $event->getException(); + if ($exception instanceof \SoapFault) { + $request->query->set('_besimple_soap_fault', $exception); + } + parent::onKernelException($event); } public static function getSubscribedEvents() { return array( + // Must be called before ExceptionListener of HttpKernel component KernelEvents::EXCEPTION => array('onKernelException', -64), ); } diff --git a/src/BeSimple/SoapBundle/Handler/ExceptionHandler.php b/src/BeSimple/SoapBundle/Handler/ExceptionHandler.php index 56d2f18..54c12b4 100644 --- a/src/BeSimple/SoapBundle/Handler/ExceptionHandler.php +++ b/src/BeSimple/SoapBundle/Handler/ExceptionHandler.php @@ -23,6 +23,7 @@ class ExceptionHandler { protected $exception; protected $details; + protected $soapFault; public function __construct(FlattenException $exception, $details = null) { @@ -30,8 +31,17 @@ class ExceptionHandler $this->details = $details; } + public function setSoapFault(\SoapFault $soapFault) + { + $this->soapFault = $soapFault; + } + public function __call($method, $arguments) { + if (isset($this->soapFault)) { + throw $this->soapFault; + } + $code = $this->exception->getStatusCode(); throw new ReceiverSoapFault( diff --git a/src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl b/src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl new file mode 100644 index 0000000..26f0452 --- /dev/null +++ b/src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +