Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a2b8e32ee | |||
fd5154a469 | |||
188f282a87 | |||
1b4e262c60 | |||
60e3714602 | |||
1e82d7fdd7 |
@ -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(
|
||||
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://besim.pl/soap/exception/1.0/">'.
|
||||
'<soapenv:Header/>'.
|
||||
'<soapenv:Body>'.
|
||||
'<ns:exception />'.
|
||||
'</soapenv:Body>'.
|
||||
'</soapenv:Envelope>'
|
||||
);
|
||||
|
||||
return new Response(ob_get_clean());
|
||||
}
|
||||
|
@ -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),
|
||||
);
|
||||
}
|
||||
|
@ -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(
|
||||
|
31
src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl
Normal file
31
src/BeSimple/SoapBundle/Handler/wsdl/exception.wsdl
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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/">
|
||||
|
||||
<portType name="ExceptionPortType">
|
||||
<operation name="exception">
|
||||
<input message="tns:empty"/>
|
||||
<output message="tns:empty"/>
|
||||
</operation>
|
||||
</portType>
|
||||
|
||||
<message name="empty" />
|
||||
|
||||
<binding name="ExceptionBinding" type="tns:ExceptionPortType">
|
||||
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
|
||||
<operation name="exception">
|
||||
<soap:operation soapAction="http://besim.pl/soap/exception/1.0/exception"/>
|
||||
<input>
|
||||
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</input>
|
||||
<output>
|
||||
<soap:body use="literal" namespace="http://besim.pl/soap/exception/1.0/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
|
||||
<service name="ExceptionService">
|
||||
<port name="ExceptionPort" binding="tns:ExceptionBinding">
|
||||
<soap:address location="http://localhost/soap/Exception"/>
|
||||
</port>
|
||||
</service>
|
||||
</definitions>
|
@ -44,6 +44,7 @@
|
||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.rpcliteral.class%</argument>
|
||||
<argument key="binder_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
|
||||
<argument key="binder_response_class">%besimple.soap.binder.response.rpcliteral.class%</argument>
|
||||
<argument key="wsdl_stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
|
||||
</argument>
|
||||
<argument type="service" id="besimple.soap.cache" />
|
||||
</service>
|
||||
@ -58,6 +59,7 @@
|
||||
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.documentwrapped.class%</argument>
|
||||
<argument key="binder_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
|
||||
<argument key="binder_response_class">%besimple.soap.binder.response.documentwrapped.class%</argument>
|
||||
<argument key="wsdl_stylesheet">%besimple.soap.definition.dumper.options.stylesheet%</argument>
|
||||
</argument>
|
||||
<argument type="service" id="besimple.soap.cache" />
|
||||
</service>
|
||||
|
@ -112,9 +112,8 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
|
||||
$value = $this->processType($type->getType(), $value);
|
||||
|
||||
$messageBinder->writeProperty($property, $value);
|
||||
}
|
||||
|
||||
if (!$type->isNillable() && null === $value) {
|
||||
} elseif (!$type->isNillable()) {
|
||||
// @TODO use xmlType instead of phpType
|
||||
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface
|
||||
$this->messageRefs[$hash] = $message;
|
||||
|
||||
if (!$message instanceof $phpType) {
|
||||
throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', get_class($message), $phpType));
|
||||
throw new \InvalidArgumentException(sprintf('The instance class must be "%s", "%s" given.', $phpType, get_class($message)));
|
||||
}
|
||||
|
||||
$messageBinder = new MessageBinder($message);
|
||||
|
@ -88,7 +88,6 @@ class AnnotationClassLoader extends Loader
|
||||
|
||||
$serviceMethod = new Definition\Method(
|
||||
$annotation->getValue(),
|
||||
$this->typeRepository,
|
||||
$this->getController($class, $method, $annotation)
|
||||
);
|
||||
} elseif ($annotation instanceof Annotation\Result) {
|
||||
|
@ -23,9 +23,9 @@ class Method extends BaseMethod
|
||||
{
|
||||
private $controller;
|
||||
|
||||
public function __construct($name, TypeRepository $typeRepository, $controller)
|
||||
public function __construct($name, $controller)
|
||||
{
|
||||
parent::__construct($name, $typeRepository);
|
||||
parent::__construct($name);
|
||||
|
||||
$this->controller = $controller;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class WebServiceContext
|
||||
$definition->setOption('location', $endpoint);
|
||||
}
|
||||
|
||||
$dumper = new Dumper($definition);
|
||||
$dumper = new Dumper($definition, array('stylesheet' => $this->options['wsdl_stylesheet']));
|
||||
$cache->write($dumper->dump());
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,14 @@ class Method
|
||||
private $output;
|
||||
private $fault;
|
||||
|
||||
public function __construct($name, TypeRepository $typeRepository)
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
$this->headers = new Message($name.'Header', $typeRepository);
|
||||
$this->input = new Message($name.'Request', $typeRepository);
|
||||
$this->output = new Message($name.'Response', $typeRepository);
|
||||
$this->fault = new Message($name.'Fault', $typeRepository);
|
||||
$this->headers = new Message($name.'Header');
|
||||
$this->input = new Message($name.'Request');
|
||||
$this->output = new Message($name.'Response');
|
||||
$this->fault = new Message($name.'Fault');
|
||||
}
|
||||
|
||||
public function getName()
|
||||
|
@ -69,6 +69,7 @@ class Dumper
|
||||
'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12',
|
||||
'version11_name' => $this->definition->getName(),
|
||||
'version12_name' => $this->definition->getName().'12',
|
||||
'stylesheet' => null,
|
||||
);
|
||||
|
||||
$invalid = array();
|
||||
@ -123,6 +124,8 @@ class Dumper
|
||||
|
||||
$this->document->formatOutput = true;
|
||||
|
||||
$this->addStylesheet();
|
||||
|
||||
return $this->document->saveXML();
|
||||
}
|
||||
|
||||
@ -186,7 +189,7 @@ class Dumper
|
||||
protected function addMessages(array $messages)
|
||||
{
|
||||
foreach ($messages as $message) {
|
||||
if ($message->isEmpty()) {
|
||||
if (preg_match('#Header$#', $message->getName()) && $message->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -282,7 +285,7 @@ class Dumper
|
||||
$operation->setAttribute('name', $method->getName());
|
||||
|
||||
foreach (array('input' => $method->getInput(), 'output' => $method->getOutput(), 'fault' => $method->getFault()) as $type => $message) {
|
||||
if ($message->isEmpty()) {
|
||||
if ('fault' === $type && $message->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -297,6 +300,15 @@ class Dumper
|
||||
return $operation;
|
||||
}
|
||||
|
||||
protected function addStylesheet()
|
||||
{
|
||||
if ($this->options['stylesheet']) {
|
||||
$stylesheet = $this->document->createProcessingInstruction('xml-stylesheet', sprintf('type="text/xsl" href="%s"', $this->options['stylesheet']));
|
||||
|
||||
$this->document->insertBefore($stylesheet, $this->document->documentElement);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVersion($version)
|
||||
{
|
||||
if (\SOAP_1_2 === $version) {
|
||||
|
Reference in New Issue
Block a user