18 Commits

Author SHA1 Message Date
e4cb612aed Created a client classmap even when it is empty 2014-04-30 10:54:07 +02:00
59ea6b1ce0 Merge pull request #33 from borissamardzija/master
Update Curl class to support CURLOPT_CAINFO and CURLOPT_CAPATH options
2014-04-25 13:36:04 +02:00
7bb849e394 Update Curl class to support CURLOPT_CAINFO and CURLOPT_CAPATH options 2014-04-25 11:16:34 +02:00
02722eae8f Merge pull request #32 from mremi/filter-request-headers
Added method to tweak HTTP headers of request
2014-04-24 17:22:00 +02:00
b7581f29b0 Removed reference to return an array of HTTP headers 2014-04-24 09:29:58 +02:00
dc6e1e0889 Merge pull request #31 from mremi/http-auth
Added extra option to configure HTTP authentication
2014-04-24 08:38:03 +02:00
f986400dc2 Merge pull request #30 from mremi/method-visibility
Updated visibility from private to protected
2014-04-24 08:36:23 +02:00
67410805ba Added method to tweak HTTP headers of request 2014-04-22 22:29:11 +02:00
2ae7515294 Added extra option to configure HTTP authentication 2014-04-22 22:05:04 +02:00
cdfc3cd5bd Updated visibility from private to protected 2014-04-22 21:53:14 +02:00
9ac755d86e [SoapBundle] Set _format route to xml 2013-12-13 15:25:20 +01:00
321dcf3058 [SoapBundle] Set wsdl request type only if the "wsdl" parameter in present in URL 2013-12-13 11:24:25 +01:00
3a2b8e32ee [SoapBundle] Enhanced SoapFault management 2013-12-13 08:26:18 +01:00
fd5154a469 Fixed typo 2013-12-10 15:25:09 +01:00
188f282a87 [SoapWsdl] Specify an empty message if the input is empty 2013-12-10 15:25:09 +01:00
1b4e262c60 [SoapBundle] Simplified conditional statement 2013-12-08 00:25:20 +01:00
60e3714602 [SoapBundle][SoapCommon] Removed unused TypeRepository in Definition\Method classes 2013-12-08 00:23:30 +01:00
1e82d7fdd7 Fix WSDL schema stylesheet including 2013-12-07 19:55:33 +01:00
16 changed files with 136 additions and 37 deletions

View File

@ -15,6 +15,7 @@ namespace BeSimple\SoapBundle\Controller;
use BeSimple\SoapBundle\Handler\ExceptionHandler; use BeSimple\SoapBundle\Handler\ExceptionHandler;
use BeSimple\SoapBundle\Soap\SoapRequest; use BeSimple\SoapBundle\Soap\SoapRequest;
use BeSimple\SoapBundle\Soap\SoapResponse; use BeSimple\SoapBundle\Soap\SoapResponse;
use BeSimple\SoapServer\SoapServerBuilder;
use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -94,9 +95,10 @@ class SoapWebServiceController extends ContainerAware
) )
)); ));
$query = $this->container->get('request')->query; $request = $this->container->get('request');
if (!$query->has('wsdl') && !$query->has('WSDL')) { $query = $request->query;
$this->container->get('request')->setRequestFormat('xml'); if ($query->has('wsdl') || $query->has('WSDL')) {
$request->setRequestFormat('wsdl');
} }
return $response; return $response;
@ -128,16 +130,30 @@ class SoapWebServiceController extends ContainerAware
'logger' => $logger, 'logger' => $logger,
)); ));
$server = $this $handler = new ExceptionHandler($exception, $details);
->container if ($soapFault = $request->query->get('_besimple_soap_fault')) {
->get(sprintf('besimple.soap.context.%s', $webservice)) $handler->setSoapFault($soapFault);
->getServerBuilder()
->withHandler(new ExceptionHandler($exception, $details)) // 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() ->build()
; ;
ob_start(); 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()); return new Response(ob_get_clean());
} }

View File

@ -104,12 +104,8 @@ class BeSimpleSoapExtension extends Extension
$definition->replaceArgument(1, $defOptions); $definition->replaceArgument(1, $defOptions);
if (!empty($options['classmap'])) {
$classmap = $this->createClientClassmap($client, $options['classmap'], $container); $classmap = $this->createClientClassmap($client, $options['classmap'], $container);
$definition->replaceArgument(2, new Reference($classmap)); $definition->replaceArgument(2, new Reference($classmap));
} else {
$definition->replaceArgument(2, null);
}
$this->createClient($client, $container); $this->createClient($client, $container);
} }
@ -120,9 +116,11 @@ class BeSimpleSoapExtension extends Extension
$definition = new DefinitionDecorator('besimple.soap.classmap'); $definition = new DefinitionDecorator('besimple.soap.classmap');
$container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition); $container->setDefinition(sprintf('besimple.soap.classmap.%s', $client), $definition);
if (!empty($classmap)) {
$definition->setMethodCalls(array( $definition->setMethodCalls(array(
array('set', array($classmap)), array('set', array($classmap)),
)); ));
}
return sprintf('besimple.soap.classmap.%s', $client); return sprintf('besimple.soap.classmap.%s', $client);
} }

View File

@ -67,12 +67,18 @@ class SoapExceptionListener extends ExceptionListener
// hack to retrieve the current WebService name in the controller // hack to retrieve the current WebService name in the controller
$request->query->set('_besimple_soap_webservice', $webservice); $request->query->set('_besimple_soap_webservice', $webservice);
$exception = $event->getException();
if ($exception instanceof \SoapFault) {
$request->query->set('_besimple_soap_fault', $exception);
}
parent::onKernelException($event); parent::onKernelException($event);
} }
public static function getSubscribedEvents() public static function getSubscribedEvents()
{ {
return array( return array(
// Must be called before ExceptionListener of HttpKernel component
KernelEvents::EXCEPTION => array('onKernelException', -64), KernelEvents::EXCEPTION => array('onKernelException', -64),
); );
} }

View File

@ -23,6 +23,7 @@ class ExceptionHandler
{ {
protected $exception; protected $exception;
protected $details; protected $details;
protected $soapFault;
public function __construct(FlattenException $exception, $details = null) public function __construct(FlattenException $exception, $details = null)
{ {
@ -30,8 +31,17 @@ class ExceptionHandler
$this->details = $details; $this->details = $details;
} }
public function setSoapFault(\SoapFault $soapFault)
{
$this->soapFault = $soapFault;
}
public function __call($method, $arguments) public function __call($method, $arguments)
{ {
if (isset($this->soapFault)) {
throw $this->soapFault;
}
$code = $this->exception->getStatusCode(); $code = $this->exception->getStatusCode();
throw new ReceiverSoapFault( throw new ReceiverSoapFault(

View 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>

View File

@ -6,13 +6,13 @@
<route id="_webservice_call" pattern="/{webservice}"> <route id="_webservice_call" pattern="/{webservice}">
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Call</default> <default key="_controller">BeSimpleSoapBundle:SoapWebService:Call</default>
<default key="_format">soap</default> <default key="_format">xml</default>
<requirement key="_method">POST</requirement> <requirement key="_method">POST</requirement>
</route> </route>
<route id="_webservice_definition" pattern="/{webservice}"> <route id="_webservice_definition" pattern="/{webservice}">
<default key="_controller">BeSimpleSoapBundle:SoapWebService:Definition</default> <default key="_controller">BeSimpleSoapBundle:SoapWebService:Definition</default>
<default key="_format">wsdl</default> <default key="_format">xml</default>
<requirement key="_method">GET</requirement> <requirement key="_method">GET</requirement>
</route> </route>
</routes> </routes>

View File

@ -44,6 +44,7 @@
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.rpcliteral.class%</argument> <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_request_class">%besimple.soap.binder.request.rpcliteral.class%</argument>
<argument key="binder_response_class">%besimple.soap.binder.response.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>
<argument type="service" id="besimple.soap.cache" /> <argument type="service" id="besimple.soap.cache" />
</service> </service>
@ -58,6 +59,7 @@
<argument key="binder_request_header_class">%besimple.soap.binder.request_header.documentwrapped.class%</argument> <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_request_class">%besimple.soap.binder.request.documentwrapped.class%</argument>
<argument key="binder_response_class">%besimple.soap.binder.response.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>
<argument type="service" id="besimple.soap.cache" /> <argument type="service" id="besimple.soap.cache" />
</service> </service>

View File

@ -112,9 +112,8 @@ class RpcLiteralRequestMessageBinder implements MessageBinderInterface
$value = $this->processType($type->getType(), $value); $value = $this->processType($type->getType(), $value);
$messageBinder->writeProperty($property, $value); $messageBinder->writeProperty($property, $value);
} } elseif (!$type->isNillable()) {
// @TODO use xmlType instead of phpType
if (!$type->isNillable() && null === $value) {
throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName())); throw new \SoapFault('SOAP_ERROR_COMPLEX_TYPE', sprintf('"%s:%s" cannot be null.', ucfirst($phpType), $type->getName()));
} }
} }

View File

@ -85,7 +85,7 @@ class RpcLiteralResponseMessageBinder implements MessageBinderInterface
$this->messageRefs[$hash] = $message; $this->messageRefs[$hash] = $message;
if (!$message instanceof $phpType) { 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); $messageBinder = new MessageBinder($message);

View File

@ -88,7 +88,6 @@ class AnnotationClassLoader extends Loader
$serviceMethod = new Definition\Method( $serviceMethod = new Definition\Method(
$annotation->getValue(), $annotation->getValue(),
$this->typeRepository,
$this->getController($class, $method, $annotation) $this->getController($class, $method, $annotation)
); );
} elseif ($annotation instanceof Annotation\Result) { } elseif ($annotation instanceof Annotation\Result) {

View File

@ -23,9 +23,9 @@ class Method extends BaseMethod
{ {
private $controller; private $controller;
public function __construct($name, TypeRepository $typeRepository, $controller) public function __construct($name, $controller)
{ {
parent::__construct($name, $typeRepository); parent::__construct($name);
$this->controller = $controller; $this->controller = $controller;
} }

View File

@ -78,7 +78,7 @@ class WebServiceContext
$definition->setOption('location', $endpoint); $definition->setOption('location', $endpoint);
} }
$dumper = new Dumper($definition); $dumper = new Dumper($definition, array('stylesheet' => $this->options['wsdl_stylesheet']));
$cache->write($dumper->dump()); $cache->write($dumper->dump());
} }

View File

@ -88,13 +88,19 @@ class Curl
curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']); curl_setopt($this->ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_password']);
} }
if (isset($options['login'])) { if (isset($options['login'])) {
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($this->ch, CURLOPT_HTTPAUTH, isset($options['extra_options']['http_auth']) ? $options['extra_options']['http_auth'] : CURLAUTH_ANY);
curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']); curl_setopt($this->ch, CURLOPT_USERPWD, $options['login'].':'.$options['password']);
} }
if (isset($options['local_cert'])) { if (isset($options['local_cert'])) {
curl_setopt($this->ch, CURLOPT_SSLCERT, $options['local_cert']); curl_setopt($this->ch, CURLOPT_SSLCERT, $options['local_cert']);
curl_setopt($this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase']); curl_setopt($this->ch, CURLOPT_SSLCERTPASSWD, $options['passphrase']);
} }
if (isset($options['ca_info'])) {
curl_setopt($this->ch, CURLOPT_CAINFO, $options['ca_info']);
}
if (isset($options['ca_path'])) {
curl_setopt($this->ch, CURLOPT_CAPATH, $options['ca_path']);
}
} }
/** /**

View File

@ -113,6 +113,11 @@ class SoapClient extends \SoapClient
$this->cliWebserverWorkaround = $options['cli_webserver_workaround']; $this->cliWebserverWorkaround = $options['cli_webserver_workaround'];
} }
$this->curl = new Curl($options); $this->curl = new Curl($options);
if (isset($options['extra_options'])) {
unset($options['extra_options']);
}
$wsdlFile = $this->loadWsdl($wsdl, $options); $wsdlFile = $this->loadWsdl($wsdl, $options);
// TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion); // TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion);
$this->soapKernel = new SoapKernel(); $this->soapKernel = new SoapKernel();
@ -173,6 +178,8 @@ class SoapClient extends \SoapClient
$headers = array(); $headers = array();
} }
$headers = $this->filterRequestHeaders($soapRequest, $headers);
// execute HTTP request with cURL // execute HTTP request with cURL
$responseSuccessfull = $this->curl->exec( $responseSuccessfull = $this->curl->exec(
$location, $location,
@ -253,6 +260,19 @@ class SoapClient extends \SoapClient
return $soapResponse; return $soapResponse;
} }
/**
* Filters HTTP headers which will be sent
*
* @param SoapRequest $soapRequest SOAP request object
* @param array $headers An array of HTTP headers
*
* @return array
*/
protected function filterRequestHeaders(SoapRequest $soapRequest, array $headers)
{
return $headers;
}
/** /**
* Get last request HTTP headers. * Get last request HTTP headers.
* *
@ -354,7 +374,7 @@ class SoapClient extends \SoapClient
* *
* @return string * @return string
*/ */
private function loadWsdl($wsdl, array $options) protected function loadWsdl($wsdl, array $options)
{ {
// option to resolve wsdl/xsd includes // option to resolve wsdl/xsd includes
$resolveRemoteIncludes = true; $resolveRemoteIncludes = true;

View File

@ -26,14 +26,14 @@ class Method
private $output; private $output;
private $fault; private $fault;
public function __construct($name, TypeRepository $typeRepository) public function __construct($name)
{ {
$this->name = $name; $this->name = $name;
$this->headers = new Message($name.'Header', $typeRepository); $this->headers = new Message($name.'Header');
$this->input = new Message($name.'Request', $typeRepository); $this->input = new Message($name.'Request');
$this->output = new Message($name.'Response', $typeRepository); $this->output = new Message($name.'Response');
$this->fault = new Message($name.'Fault', $typeRepository); $this->fault = new Message($name.'Fault');
} }
public function getName() public function getName()

View File

@ -69,6 +69,7 @@ class Dumper
'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12', 'version12_class' => 'BeSimple\\SoapWsdl\\Dumper\\Version12',
'version11_name' => $this->definition->getName(), 'version11_name' => $this->definition->getName(),
'version12_name' => $this->definition->getName().'12', 'version12_name' => $this->definition->getName().'12',
'stylesheet' => null,
); );
$invalid = array(); $invalid = array();
@ -123,6 +124,8 @@ class Dumper
$this->document->formatOutput = true; $this->document->formatOutput = true;
$this->addStylesheet();
return $this->document->saveXML(); return $this->document->saveXML();
} }
@ -186,7 +189,7 @@ class Dumper
protected function addMessages(array $messages) protected function addMessages(array $messages)
{ {
foreach ($messages as $message) { foreach ($messages as $message) {
if ($message->isEmpty()) { if (preg_match('#Header$#', $message->getName()) && $message->isEmpty()) {
continue; continue;
} }
@ -282,7 +285,7 @@ class Dumper
$operation->setAttribute('name', $method->getName()); $operation->setAttribute('name', $method->getName());
foreach (array('input' => $method->getInput(), 'output' => $method->getOutput(), 'fault' => $method->getFault()) as $type => $message) { foreach (array('input' => $method->getInput(), 'output' => $method->getOutput(), 'fault' => $method->getFault()) as $type => $message) {
if ($message->isEmpty()) { if ('fault' === $type && $message->isEmpty()) {
continue; continue;
} }
@ -297,6 +300,15 @@ class Dumper
return $operation; 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) protected function getVersion($version)
{ {
if (\SOAP_1_2 === $version) { if (\SOAP_1_2 === $version) {