Skip to content

Commit

Permalink
added soap initial 1.2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Dec 7, 2016
1 parent ee171a9 commit 13f117e
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 82 deletions.
25 changes: 23 additions & 2 deletions src/Soap/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class Operation
{

/**
*
* @var \GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation
Expand All @@ -18,6 +17,12 @@ class Operation
* @var string
*/
protected $action;

/**
* @var boolean
*/
protected $actionRequired = false;

/**
* "rpc|document" - Provides a message style for this operation.
* This is an optional attribute.
Expand Down Expand Up @@ -59,6 +64,22 @@ public function getAction()
return $this->action;
}

/**
* @return boolean
*/
public function isActionRequired()
{
return $this->actionRequired;
}

/**
* @param boolean $actionRequired
*/
public function setActionRequired($actionRequired)
{
$this->actionRequired = (bool)$actionRequired;
}

public function setAction($action)
{
$this->action = $action;
Expand Down Expand Up @@ -116,4 +137,4 @@ public function addFault(Fault $fault)
$this->faults[$fault->getName()] = $fault;
return $this;
}
}
}
24 changes: 23 additions & 1 deletion src/Soap/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

class Service
{

/**
* @var string
*/
protected $version = '1.1';

/**
*
* @var Port
Expand Down Expand Up @@ -101,4 +107,20 @@ public function findByAction($action)
}
}
}
}

/**
* @return string
*/
public function getVersion()
{
return $this->version;
}

/**
* @param string $version
*/
public function setVersion($version)
{
$this->version = $version;
}
}
23 changes: 16 additions & 7 deletions src/SoapReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
class SoapReader implements EventSubscriberInterface
{
const SOAP_NS = 'http://schemas.xmlsoap.org/wsdl/soap/';
const SOAP12_NS = 'http://schemas.xmlsoap.org/wsdl/soap12/';


public static function getSubscribedEvents()
{
Expand Down Expand Up @@ -55,9 +57,12 @@ public function onServicePort(PortEvent $event)
$service = new Service($event->getPort());

foreach ($event->getNode()->childNodes as $node) {
if ($node->namespaceURI == self::SOAP_NS) {
if ($node->namespaceURI == self::SOAP_NS || $node->namespaceURI == self::SOAP12_NS) {
$service->setAddress($node->getAttribute("location"));
}
if ($node->namespaceURI == self::SOAP12_NS) {
$service->setVersion('1.2');
}
}

$this->servicesByBinding [spl_object_hash($event->getPort()->getBinding())] = $service;
Expand All @@ -69,7 +74,7 @@ public function onBinding(BindingEvent $event)
$service = $this->getServiceByBinding($event->getBinding());

foreach ($event->getNode()->childNodes as $node) {
if ($node->namespaceURI == self::SOAP_NS && $node->localName == 'binding') {
if (($node->namespaceURI == self::SOAP12_NS || $node->namespaceURI == self::SOAP_NS) && $node->localName == 'binding') {
$service->setTransport($node->getAttribute("transport"));
if ($node->getAttribute("style")) {
$service->setStyle($node->getAttribute("style"));
Expand Down Expand Up @@ -125,14 +130,18 @@ public function onBindingOperation(BindingOperationEvent $event)
}
$skip = true;
foreach ($event->getNode()->childNodes as $node) {
if ($node->namespaceURI == self::SOAP_NS && $node->localName == 'operation') {
if (($node->namespaceURI == self::SOAP_NS || $node->namespaceURI == self::SOAP12_NS) && $node->localName == 'operation') {
$skip = false;
if ($node->getAttribute("soapAction")) {
$operation->setAction($node->getAttribute("soapAction"));
}
if ($node->namespaceURI == self::SOAP12_NS && $node->getAttribute("soapActionRequired")) {
$operation->setActionRequired($node->getAttribute("soapActionRequired") === 'true' || $node->getAttribute("soapActionRequired") === '1');
}
if ($node->getAttribute("style")) {
$operation->setStyle($node->getAttribute("style"));
}

}
}

Expand Down Expand Up @@ -178,7 +187,7 @@ public function onBindingOperationMessage(BindingOperationMessageEvent $event)
}

foreach ($event->getNode()->childNodes as $node) {
if ($node->namespaceURI !== self::SOAP_NS) {
if ($node->namespaceURI !== self::SOAP_NS && ($node->namespaceURI !== self::SOAP12_NS)) {
continue;
}

Expand Down Expand Up @@ -220,7 +229,7 @@ public function onBindingOperationFault(FaultEvent $event)


foreach ($event->getNode()->childNodes as $node) {
if ($node->namespaceURI !== self::SOAP_NS) {
if ($node->namespaceURI !== self::SOAP_NS && $node->namespaceURI !== self::SOAP12_NS) {
continue;
}
if ($node->localName == 'fault') {
Expand Down Expand Up @@ -270,7 +279,7 @@ private function fillHeader(Header $header, Message $message, \DOMElement $node)
{
$this->fillAbstractHeader($header, $message, $node);
foreach ($node->childNodes as $childNode) {
if ($childNode->namespaceURI == self::SOAP_NS && $childNode->localName == 'headerfault') {
if (($childNode->namespaceURI == self::SOAP_NS || $node->namespaceURI == self::SOAP12_NS) && $childNode->localName == 'headerfault') {

list ($name, $ns) = DefinitionsReader::splitParts($node, $node->getAttribute("message"));
$hMessage = $message->getDefinition()->findMessage($name, $ns);
Expand All @@ -281,4 +290,4 @@ private function fillHeader(Header $header, Message $message, \DOMElement $node)
}
}
}
}
}
65 changes: 65 additions & 0 deletions tests/Reader/SoapReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testSimple()

$soapService = $this->soap->getServiceByPort($port);

$this->assertEquals('1.1', $soapService->getVersion());
$this->assertEquals('http://www.example.org/location', $soapService->getAddress());
$this->assertEquals('document', $soapService->getStyle());
$this->assertEquals('http://schemas.xmlsoap.org/soap/http', $soapService->getTransport());
Expand Down Expand Up @@ -89,6 +90,70 @@ public function testSimple()
$this->assertInstanceOf('GoetasWebservices\XML\SOAPReader\Soap\HeaderFault', $headers[0]->getFaults()[0]);
}

public function testSimple12()
{
$definitions = $this->wsdl->readFile(__DIR__ . '/res/easy.wsdl');

$service = $definitions->getService('easy');
$port = $service->getPort('easySOAP12');

$soapService = $this->soap->getServiceByPort($port);

$this->assertEquals('1.2', $soapService->getVersion());
$this->assertEquals('http://www.example.org/location12', $soapService->getAddress());
$this->assertEquals('document', $soapService->getStyle());
$this->assertEquals('http://schemas.xmlsoap.org/soap/http', $soapService->getTransport());

$this->assertArrayHasKey('run', $soapService->getOperations());

$soapOperation = $soapService->getOperations()['run'];
$this->assertEquals('http://www.example.org/run', $soapOperation->getAction());
$this->assertEquals(true, $soapOperation->isActionRequired());
$this->assertEquals('document', $soapOperation->getStyle());

$this->assertInstanceOf('GoetasWebservices\XML\WSDLReader\Wsdl\Binding\Operation', $soapOperation->getOperation());

$input = $soapOperation->getInput();
$body = $input->getBody();

$this->assertEquals([], $body->getEncoding());
$this->assertEquals('literal', $body->getUse());
$this->assertEquals('', $body->getNamespace());

$bodyParts = $body->getParts();
$this->assertCount(1, $bodyParts);
$this->assertInstanceOf('GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part', $bodyParts['requestParams']);
$this->assertEquals('run', $bodyParts['requestParams']->getElement()->getName());

$output = $soapOperation->getOutput();

$body = $output->getBody();

$this->assertEquals([], $body->getEncoding());
$this->assertEquals('literal', $body->getUse());
$this->assertEquals('', $body->getNamespace());

$bodyParts = $body->getParts();
$this->assertCount(1, $bodyParts);
$this->assertInstanceOf('GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part', $bodyParts['responseParams']);
$this->assertEquals('runResponse', $bodyParts['responseParams']->getElement()->getName());

$faults = $soapOperation->getFaults();

$this->assertCount(2, $faults);
$this->assertArrayHasKey('f1', $faults);
$this->assertArrayHasKey('f2', $faults);

$headers = $soapOperation->getOutput()->getHeaders();

$this->assertCount(1, $headers);
$this->assertInstanceOf('GoetasWebservices\XML\SOAPReader\Soap\Header', $headers[0]);

$this->assertCount(1, $headers[0]->getFaults());

$this->assertInstanceOf('GoetasWebservices\XML\SOAPReader\Soap\HeaderFault', $headers[0]->getFaults()[0]);
}

}


Loading

0 comments on commit 13f117e

Please sign in to comment.