Skip to content

Commit 3a2b8e3

Browse files
committed
[SoapBundle] Enhanced SoapFault management
1 parent fd5154a commit 3a2b8e3

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

src/BeSimple/SoapBundle/Controller/SoapWebServiceController.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BeSimple\SoapBundle\Handler\ExceptionHandler;
1616
use BeSimple\SoapBundle\Soap\SoapRequest;
1717
use BeSimple\SoapBundle\Soap\SoapResponse;
18+
use BeSimple\SoapServer\SoapServerBuilder;
1819
use Symfony\Component\DependencyInjection\ContainerAware;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpFoundation\Response;
@@ -128,16 +129,30 @@ public function exceptionAction(Request $request, FlattenException $exception, D
128129
'logger' => $logger,
129130
));
130131

131-
$server = $this
132-
->container
133-
->get(sprintf('besimple.soap.context.%s', $webservice))
134-
->getServerBuilder()
135-
->withHandler(new ExceptionHandler($exception, $details))
132+
$handler = new ExceptionHandler($exception, $details);
133+
if ($soapFault = $request->query->get('_besimple_soap_fault')) {
134+
$handler->setSoapFault($soapFault);
135+
136+
// Remove parameter from query because cannot be Serialized in Logger
137+
$request->query->remove('_besimple_soap_fault');
138+
}
139+
140+
$server = SoapServerBuilder::createWithDefaults()
141+
->withWsdl(__DIR__.'/../Handler/wsdl/exception.wsdl')
142+
->withWsdlCacheNone()
143+
->withHandler($handler)
136144
->build()
137145
;
138146

139147
ob_start();
140-
$server->handle($request->getContent());
148+
$server->handle(
149+
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://besim.pl/soap/exception/1.0/">'.
150+
'<soapenv:Header/>'.
151+
'<soapenv:Body>'.
152+
'<ns:exception />'.
153+
'</soapenv:Body>'.
154+
'</soapenv:Envelope>'
155+
);
141156

142157
return new Response(ob_get_clean());
143158
}

src/BeSimple/SoapBundle/EventListener/SoapExceptionListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ public function onKernelException(GetResponseForExceptionEvent $event)
6767
// hack to retrieve the current WebService name in the controller
6868
$request->query->set('_besimple_soap_webservice', $webservice);
6969

70+
$exception = $event->getException();
71+
if ($exception instanceof \SoapFault) {
72+
$request->query->set('_besimple_soap_fault', $exception);
73+
}
74+
7075
parent::onKernelException($event);
7176
}
7277

7378
public static function getSubscribedEvents()
7479
{
7580
return array(
81+
// Must be called before ExceptionListener of HttpKernel component
7682
KernelEvents::EXCEPTION => array('onKernelException', -64),
7783
);
7884
}

src/BeSimple/SoapBundle/Handler/ExceptionHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,25 @@ class ExceptionHandler
2323
{
2424
protected $exception;
2525
protected $details;
26+
protected $soapFault;
2627

2728
public function __construct(FlattenException $exception, $details = null)
2829
{
2930
$this->exception = $exception;
3031
$this->details = $details;
3132
}
3233

34+
public function setSoapFault(\SoapFault $soapFault)
35+
{
36+
$this->soapFault = $soapFault;
37+
}
38+
3339
public function __call($method, $arguments)
3440
{
41+
if (isset($this->soapFault)) {
42+
throw $this->soapFault;
43+
}
44+
3545
$code = $this->exception->getStatusCode();
3646

3747
throw new ReceiverSoapFault(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://besim.pl/soap/exception/1.0/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Exception" targetNamespace="http://besim.pl/soap/exception/1.0/">
3+
4+
<portType name="ExceptionPortType">
5+
<operation name="exception">
6+
<input message="tns:empty"/>
7+
<output message="tns:empty"/>
8+
</operation>
9+
</portType>
10+
11+
<message name="empty" />
12+
13+
<binding name="ExceptionBinding" type="tns:ExceptionPortType">
14+
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
15+
<operation name="exception">
16+
<soap:operation soapAction="http://besim.pl/soap/exception/1.0/exception"/>
17+
<input>
18+
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
19+
</input>
20+
<output>
21+
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
22+
</output>
23+
</operation>
24+
</binding>
25+
26+
<service name="ExceptionService">
27+
<port name="ExceptionPort" binding="tns:ExceptionBinding">
28+
<soap:address location="http://localhost/soap/Exception"/>
29+
</port>
30+
</service>
31+
</definitions>

0 commit comments

Comments
 (0)