Просмотр исходного кода

ZF-6689 - Functions and Methods with @return void are now interpreted as One-Way messages in WSDL AutoDiscover

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15830 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 лет назад
Родитель
Сommit
bc56d0d3e0

+ 27 - 10
library/Zend/Soap/AutoDiscover.php

@@ -260,15 +260,6 @@ class Zend_Soap_AutoDiscover implements Zend_Server_Interface {
         $wsdl->addSoapBinding($binding, $this->_bindingStyle['style'], $this->_bindingStyle['transport']);
         $wsdl->addService($class . 'Service', $class . 'Port', 'tns:' . $class . 'Binding', $uri);
         foreach ($this->_reflection->reflectClass($class)->getMethods() as $method) {
-            /* <wsdl:portType>'s */
-            $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' .$method->getName(). 'Request', 'tns:' .$method->getName(). 'Response');
-            $desc = $method->getDescription();
-            if (strlen($desc) > 0) {
-                /** @todo check, what should be done for portoperation documentation */
-                //$wsdl->addDocumentation($portOperation, $desc);
-            }
-            /* </wsdl:portType>'s */
-
             $this->_functions[] = $method->getName();
 
             $selectedPrototype = null;
@@ -283,6 +274,27 @@ class Zend_Soap_AutoDiscover implements Zend_Server_Interface {
 
             if($selectedPrototype != null) {
                 $prototype = $selectedPrototype;
+
+                $isOneWayCall = false;
+                if ($prototype->getReturnType() == "void") {
+                    $isOneWayCall = true;
+                }
+
+                if($isOneWayCall == true) {
+                    $responseMessage = false;
+                } else {
+                    $responseMessage = 'tns:' .$method->getName(). 'Response';
+                }
+
+                /* <wsdl:portType>'s */
+                $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' .$method->getName(). 'Request', $responseMessage);
+                $desc = $method->getDescription();
+                if (strlen($desc) > 0) {
+                    /** @todo check, what should be done for portoperation documentation */
+                    //$wsdl->addDocumentation($portOperation, $desc);
+                }
+                /* </wsdl:portType>'s */
+
                 $args = array();
                 foreach($prototype->getParameters() as $param) {
                     $args[$param->getName()] = $wsdl->getType($param->getType());
@@ -349,12 +361,17 @@ class Zend_Soap_AutoDiscover implements Zend_Server_Interface {
                 if (strlen($desc) > 0) {
                     //$wsdl->addDocumentation($message, $desc);
                 }
+                
                 if($prototype->getReturnType() != "void") {
+                    $responseMessage = 'tns:' .$method->getName(). 'Response';
                     $returnName = "return";
                     $message = $wsdl->addMessage($method->getName() . 'Response', array($returnName => $wsdl->getType($prototype->getReturnType())));
+                } else {
+                    $responseMessage = false;
                 }
+                
                  /* <wsdl:portType>'s */
-                   $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' .$method->getName(). 'Request', 'tns:' .$method->getName(). 'Response');
+                   $portOperation = $wsdl->addPortOperation($port, $method->getName(), 'tns:' .$method->getName(). 'Request', $responseMessage);
                 if (strlen($desc) > 0) {
                     //$wsdl->addDocumentation($portOperation, $desc);
                 }

+ 32 - 2
tests/Zend/Soap/AutoDiscoverTest.php

@@ -383,7 +383,7 @@ class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
                 '<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="' . $scriptUri . '" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 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="' .$name. '" targetNamespace="' . $scriptUri . '">'.
                 '<portType name="' .$name. 'Port">'.
                 '<operation name="Zend_Soap_AutoDiscover_TestFunc"><input message="tns:Zend_Soap_AutoDiscover_TestFuncRequest"/><output message="tns:Zend_Soap_AutoDiscover_TestFuncResponse"/></operation>'.
-                '<operation name="Zend_Soap_AutoDiscover_TestFunc2"><input message="tns:Zend_Soap_AutoDiscover_TestFunc2Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc2Response"/></operation>'.
+                '<operation name="Zend_Soap_AutoDiscover_TestFunc2"><input message="tns:Zend_Soap_AutoDiscover_TestFunc2Request"/></operation>'.
                 '<operation name="Zend_Soap_AutoDiscover_TestFunc3"><input message="tns:Zend_Soap_AutoDiscover_TestFunc3Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc3Response"/></operation>'.
                 '<operation name="Zend_Soap_AutoDiscover_TestFunc4"><input message="tns:Zend_Soap_AutoDiscover_TestFunc4Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc4Response"/></operation>'.
                 '<operation name="Zend_Soap_AutoDiscover_TestFunc5"><input message="tns:Zend_Soap_AutoDiscover_TestFunc5Request"/><output message="tns:Zend_Soap_AutoDiscover_TestFunc5Response"/></operation>'.
@@ -455,7 +455,7 @@ class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
                 '<message name="Zend_Soap_AutoDiscover_TestFunc9Request"><part name="foo" type="xsd:string"/><part name="bar" type="xsd:string"/></message>'.
                 '<message name="Zend_Soap_AutoDiscover_TestFunc9Response"><part name="return" type="xsd:string"/></message>'.
                 '</definitions>';
-        $this->assertEquals($wsdl, $this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Bad WSDL generated");
+        $this->assertEquals($wsdl, $this->sanatizeWsdlXmlOutputForOsCompability($dom->saveXML()), "Generated WSDL did not match expected XML");
         $this->assertTrue($dom->schemaValidate(dirname(__FILE__) .'/schemas/wsdl.xsd'), "WSDL Did not validate");
 
         unlink(dirname(__FILE__).'/_files/addfunction2.wsdl');
@@ -778,4 +778,34 @@ class Zend_Soap_AutoDiscoverTest extends PHPUnit_Framework_TestCase
 
         $this->assertContains("http://example.com/?a=b&amp;b=c", $wsdl);
     }
+
+    /**
+     * @group ZF-6689
+     */
+    public function testNoReturnIsOneWayCallInSetClass()
+    {
+        $autodiscover = new Zend_Soap_AutoDiscover();
+        $autodiscover->setClass('Zend_Soap_AutoDiscover_NoReturnType');
+        $wsdl = $autodiscover->toXml();
+
+        $this->assertContains(
+            '<operation name="pushOneWay"><input message="tns:pushOneWayRequest"/></operation>',
+            $wsdl
+        );
+    }
+
+    /**
+     * @group ZF-6689
+     */
+    public function testNoReturnIsOneWayCallInAddFunction()
+    {
+        $autodiscover = new Zend_Soap_AutoDiscover();
+        $autodiscover->addFunction('Zend_Soap_AutoDiscover_OneWay');
+        $wsdl = $autodiscover->toXml();
+
+        $this->assertContains(
+            '<operation name="Zend_Soap_AutoDiscover_OneWay"><input message="tns:Zend_Soap_AutoDiscover_OneWayRequest"/></operation>',
+            $wsdl
+        );
+    }
 }

+ 20 - 0
tests/Zend/Soap/_files/commontypes.php

@@ -335,4 +335,24 @@ class Zend_Soap_AutoDiscover_Recursion
      * @var Zend_Soap_AutoDiscover_Recursion
      */
     public $recursion;
+}
+
+/**
+ * @param string $message
+ */
+function Zend_Soap_AutoDiscover_OneWay($message)
+{
+    
+}
+
+class Zend_Soap_AutoDiscover_NoReturnType
+{
+    /**
+     *
+     * @param string $message
+     */
+    public function pushOneWay($message)
+    {
+
+    }
 }