From 7f96a20f6671d282a40d9b0683775d8804b2df14 Mon Sep 17 00:00:00 2001 From: Andreas Schamberger Date: Sun, 15 Jan 2012 11:42:21 +0100 Subject: [PATCH 1/5] Several WS and CS fixes --- src/BeSimple/SoapClient/Curl.php | 4 +-- src/BeSimple/SoapClient/SoapClient.php | 2 +- src/BeSimple/SoapClient/SoapClientBuilder.php | 1 + tests/AxisInterop/MTOM.php | 16 +++++++++- tests/AxisInterop/SwA.php | 2 -- tests/AxisInterop/WsAddressing.php | 2 -- tests/AxisInterop/WsSecurityUserPass.php | 2 -- tests/BeSimple/Tests/SoapClient/CurlTest.php | 7 +++-- .../Tests/SoapClient/WsdlDownloaderTest.php | 29 ++++++++++--------- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/BeSimple/SoapClient/Curl.php b/src/BeSimple/SoapClient/Curl.php index ae57933..54e40cf 100644 --- a/src/BeSimple/SoapClient/Curl.php +++ b/src/BeSimple/SoapClient/Curl.php @@ -72,7 +72,7 @@ class Curl CURLOPT_HEADER => true, CURLOPT_USERAGENT => $options['user_agent'], CURLINFO_HEADER_OUT => true, - ); + ); curl_setopt_array($this->ch, $curlOptions); if (isset($options['compression']) && !($options['compression'] & SOAP_COMPRESSION_ACCEPT)) { curl_setopt($this->ch, CURLOPT_ENCODING, 'identity'); @@ -215,7 +215,7 @@ class Curl 67 => 'Could not connect to host', //CURLE_LOGIN_DENIED 77 => 'Could not connect to host', //CURLE_SSL_CACERT_BADFILE 80 => 'Error Fetching http body, No Content-Length, connection closed or chunked data', //CURLE_SSL_SHUTDOWN_FAILED - ); + ); } /** diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php index 90d8f1d..c5b9117 100644 --- a/src/BeSimple/SoapClient/SoapClient.php +++ b/src/BeSimple/SoapClient/SoapClient.php @@ -77,7 +77,7 @@ class SoapClient extends \SoapClient private $lastResponse = ''; /** - * Last response. + * Soap kernel. * * @var \BeSimple\SoapCommon\SoapKernel */ diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php index 3759f13..b2ceb61 100644 --- a/src/BeSimple/SoapClient/SoapClientBuilder.php +++ b/src/BeSimple/SoapClient/SoapClientBuilder.php @@ -13,6 +13,7 @@ namespace BeSimple\SoapClient; use BeSimple\SoapCommon\AbstractSoapBuilder; +use BeSimple\SoapCommon\Helper; /** * Fluent interface builder for SoapClient instance. diff --git a/tests/AxisInterop/MTOM.php b/tests/AxisInterop/MTOM.php index cbfe886..8f091bc 100644 --- a/tests/AxisInterop/MTOM.php +++ b/tests/AxisInterop/MTOM.php @@ -5,7 +5,21 @@ use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient; require '../bootstrap.php'; -echo '
';
+class base64Binary
+{
+    public $_;
+    public $contentType;
+}
+
+class AttachmentType
+{
+    public $fileName;
+    public $binaryData;
+}
+
+class AttachmentRequest extends AttachmentType
+{
+}
 
 $options = array(
     'soap_version'    => SOAP_1_1,
diff --git a/tests/AxisInterop/SwA.php b/tests/AxisInterop/SwA.php
index 0cf5b77..eaf1bc6 100644
--- a/tests/AxisInterop/SwA.php
+++ b/tests/AxisInterop/SwA.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version'    => SOAP_1_1,
     'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/AxisInterop/WsAddressing.php b/tests/AxisInterop/WsAddressing.php
index 9ec1bcc..dacabcb 100644
--- a/tests/AxisInterop/WsAddressing.php
+++ b/tests/AxisInterop/WsAddressing.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\WsAddressingFilter as BeSimpleWsAddressingFilter;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version' => SOAP_1_2,
     'features'     => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/AxisInterop/WsSecurityUserPass.php b/tests/AxisInterop/WsSecurityUserPass.php
index 595d9ba..231f1e5 100644
--- a/tests/AxisInterop/WsSecurityUserPass.php
+++ b/tests/AxisInterop/WsSecurityUserPass.php
@@ -5,8 +5,6 @@ use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter;
 
 require '../bootstrap.php';
 
-echo '
';
-
 $options = array(
     'soap_version' => SOAP_1_2,
     'features'     => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
diff --git a/tests/BeSimple/Tests/SoapClient/CurlTest.php b/tests/BeSimple/Tests/SoapClient/CurlTest.php
index b940b2a..d669f4c 100644
--- a/tests/BeSimple/Tests/SoapClient/CurlTest.php
+++ b/tests/BeSimple/Tests/SoapClient/CurlTest.php
@@ -23,11 +23,12 @@ class CurlTest extends \PHPUnit_Framework_TestCase
 
     protected function startPhpWebserver()
     {
-        if ('Windows' == substr(php_uname('s'), 0, 7 )) {
-            $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
+            $dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
+        if ('Windows' == substr(php_uname('s'), 0, 7)) {
+            $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
             $shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
         } else {
-            $shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &";
+            $shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
         }
         $output = array();
         exec($shellCommand, $output);
diff --git a/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php b/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php
index 14ac58a..198341d 100644
--- a/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php
+++ b/tests/BeSimple/Tests/SoapClient/WsdlDownloaderTest.php
@@ -24,11 +24,12 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
 
     protected function startPhpWebserver()
     {
-        if ('Windows' == substr(php_uname('s'), 0, 7 )) {
-            $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
+        $dir = __DIR__.DIRECTORY_SEPARATOR.'Fixtures';
+        if ('Windows' == substr(php_uname('s'), 0, 7)) {
+            $powershellCommand = "\$app = start-process php.exe -ArgumentList '-S localhost:8000 -t ".$dir."' -WindowStyle 'Hidden' -passthru; Echo \$app.Id;";
             $shellCommand = 'powershell -command "& {'.$powershellCommand.'}"';
         } else {
-            $shellCommand = "nohup php -S localhost:8000 -t ".__DIR__.DIRECTORY_SEPARATOR."Fixtures &";
+            $shellCommand = "nohup php -S localhost:8000 -t ".$dir." &";
         }
         $output = array();
         exec($shellCommand, $output);
@@ -38,7 +39,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
     protected function stopPhpWebserver()
     {
         if (!is_null($this->webserverProcessId)) {
-            if ('Windows' == substr(php_uname('s'), 0, 7 )) {
+            if ('Windows' == substr(php_uname('s'), 0, 7)) {
                 exec('TASKKILL /F /PID ' . $this->webserverProcessId);
             } else {
                 exec('kill ' . $this->webserverProcessId);
@@ -57,7 +58,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         $cacheDir = ini_get('soap.wsdl_cache_dir');
         if (!is_dir($cacheDir)) {
             $cacheDir = sys_get_temp_dir();
-            $cacheDirForRegExp = preg_quote( $cacheDir );
+            $cacheDirForRegExp = preg_quote($cacheDir);
         }
 
         $tests = array(
@@ -82,7 +83,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         foreach ($tests as $name => $values) {
             $cacheFileName = $wd->download($values['source']);
             $result = file_get_contents($cacheFileName);
-            $this->assertRegExp($values['assertRegExp'],$result,$name);
+            $this->assertRegExp($values['assertRegExp'], $result, $name);
             unlink($cacheFileName);
         }
 
@@ -129,7 +130,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         $cacheDir = ini_get('soap.wsdl_cache_dir');
         if (!is_dir($cacheDir)) {
             $cacheDir = sys_get_temp_dir();
-            $cacheDirForRegExp = preg_quote( $cacheDir );
+            $cacheDirForRegExp = preg_quote($cacheDir);
         }
 
         $remoteUrlAbsolute = 'http://localhost:8000/wsdlinclude/wsdlinctest_absolute.xml';
@@ -162,10 +163,10 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         );
 
         foreach ($tests as $name => $values) {
-            $wsdl = file_get_contents( $values['source'] );
-            $method->invoke($wd, $wsdl, $values['cacheFile'],$values['remoteParentUrl']);
+            $wsdl = file_get_contents($values['source']);
+            $method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']);
             $result = file_get_contents($values['cacheFile']);
-            $this->assertRegExp($values['assertRegExp'],$result,$name);
+            $this->assertRegExp($values['assertRegExp'], $result, $name);
             unlink($values['cacheFile']);
         }
 
@@ -186,7 +187,7 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         $cacheDir = ini_get('soap.wsdl_cache_dir');
         if (!is_dir($cacheDir)) {
             $cacheDir = sys_get_temp_dir();
-            $cacheDirForRegExp = preg_quote( $cacheDir );
+            $cacheDirForRegExp = preg_quote($cacheDir);
         }
 
         $remoteUrlAbsolute = 'http://localhost:8000/xsdinclude/xsdinctest_absolute.xml';
@@ -219,10 +220,10 @@ class WsdlDownloaderTest extends \PHPUnit_Framework_TestCase
         );
 
         foreach ($tests as $name => $values) {
-            $wsdl = file_get_contents( $values['source'] );
-            $method->invoke($wd, $wsdl, $values['cacheFile'],$values['remoteParentUrl']);
+            $wsdl = file_get_contents($values['source']);
+            $method->invoke($wd, $wsdl, $values['cacheFile'], $values['remoteParentUrl']);
             $result = file_get_contents($values['cacheFile']);
-            $this->assertRegExp($values['assertRegExp'],$result,$name);
+            $this->assertRegExp($values['assertRegExp'], $result, $name);
             unlink($values['cacheFile']);
         }
 

From 7819c316444389df5d6f0ea3f7f3d4ae970139c2 Mon Sep 17 00:00:00 2001
From: Andreas Schamberger 
Date: Sun, 29 Jan 2012 14:38:12 +0100
Subject: [PATCH 2/5] add XML mime filter

---
 src/BeSimple/SoapClient/SoapClient.php    |  2 +
 src/BeSimple/SoapClient/XmlMimeFilter.php | 75 +++++++++++++++++++++++
 tests/AxisInterop/MTOM.php                | 27 +++++++-
 tests/AxisInterop/MTOM.wsdl               |  4 +-
 4 files changed, 104 insertions(+), 4 deletions(-)
 create mode 100644 src/BeSimple/SoapClient/XmlMimeFilter.php

diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php
index c5b9117..d264090 100644
--- a/src/BeSimple/SoapClient/SoapClient.php
+++ b/src/BeSimple/SoapClient/SoapClient.php
@@ -277,6 +277,8 @@ class SoapClient extends \SoapClient
                 $converter = new SwaTypeConverter();
                 $converter->setKernel($this->soapKernel);
             } elseif (Helper::ATTACHMENTS_TYPE_MTOM === $options['attachment_type']) {
+                $xmlMimeFilter = new XmlMimeFilter($options['attachment_type']);
+                $this->soapKernel->registerFilter($xmlMimeFilter);
                 $converter = new MtomTypeConverter();
                 $converter->setKernel($this->soapKernel);
             }
diff --git a/src/BeSimple/SoapClient/XmlMimeFilter.php b/src/BeSimple/SoapClient/XmlMimeFilter.php
new file mode 100644
index 0000000..142a271
--- /dev/null
+++ b/src/BeSimple/SoapClient/XmlMimeFilter.php
@@ -0,0 +1,75 @@
+
+ * (c) Francis Besset 
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace BeSimple\SoapClient;
+
+use BeSimple\SoapCommon\FilterHelper;
+use BeSimple\SoapCommon\Helper;
+use BeSimple\SoapCommon\Mime\MultiPart as MimeMultiPart;
+use BeSimple\SoapCommon\Mime\Parser as MimeParser;
+use BeSimple\SoapCommon\Mime\Part as MimePart;
+use BeSimple\SoapCommon\SoapRequest;
+use BeSimple\SoapCommon\SoapRequestFilter;
+use BeSimple\SoapCommon\SoapResponse;
+use BeSimple\SoapCommon\SoapResponseFilter;
+
+/**
+ * XML MIME filter that fixes the namespace of xmime:contentType attribute.
+ *
+ * @author Andreas Schamberger 
+ */
+class XmlMimeFilter implements SoapRequestFilter
+{
+    /**
+     * Reset all properties to default values.
+     */
+    public function resetFilter()
+    {
+    }
+
+    /**
+     * Modify the given request XML.
+     *
+     * @param \BeSimple\SoapCommon\SoapRequest $request SOAP request
+     *
+     * @return void
+     */
+    public function filterRequest(SoapRequest $request)
+    {
+        // get \DOMDocument from SOAP request
+        $dom = $request->getContentDocument();
+
+        // create FilterHelper
+        $filterHelper = new FilterHelper($dom);
+
+        // add the neccessary namespaces
+        $filterHelper->addNamespace(Helper::PFX_XMLMIME, Helper::NS_XMLMIME);
+
+        // get xsd:base64binary elements
+        $xpath = new \DOMXPath($dom);
+        $xpath->registerNamespace('XOP', Helper::NS_XOP);
+        $query = '//XOP:Include/..';
+        $nodes = $xpath->query($query);
+
+        // exchange attributes
+        if ($nodes->length > 0) {
+            foreach ($nodes as $node) {
+                if ($node->hasAttribute('contentType')) {
+                    $contentType = $node->getAttribute('contentType');
+                    $node->removeAttribute('contentType');
+                    $filterHelper->setAttribute($node, Helper::NS_XMLMIME, 'contentType', $contentType);
+                }
+            }
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/tests/AxisInterop/MTOM.php b/tests/AxisInterop/MTOM.php
index 8f091bc..08d8723 100644
--- a/tests/AxisInterop/MTOM.php
+++ b/tests/AxisInterop/MTOM.php
@@ -21,12 +21,32 @@ class AttachmentRequest extends AttachmentType
 {
 }
 
+class base64Binary
+{
+    public $_;
+    public $contentType;
+}
+
+class AttachmentType
+{
+    public $fileName;
+    public $binaryData;
+}
+
+class AttachmentRequest extends AttachmentType
+{
+}
+
 $options = array(
     'soap_version'    => SOAP_1_1,
     'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
     'trace'           => true, // enables use of the methods  SoapClient->__getLastRequest,  SoapClient->__getLastRequestHeaders,  SoapClient->__getLastResponse and  SoapClient->__getLastResponseHeaders
     'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
     'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
 );
 
 /*
@@ -42,10 +62,13 @@ $sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
 //var_dump($sc->__getTypes());
 
 try {
+    $b64 = new base64Binary();
+    $b64->_ = 'This is a test. :)';
+    $b64->contentType = 'text/plain';
 
-    $attachment = new stdClass();
+    $attachment = new AttachmentRequest();
     $attachment->fileName = 'test123.txt';
-    $attachment->binaryData = 'This is a test.';
+    $attachment->binaryData = $b64;
 
     var_dump($sc->attachment($attachment));
 
diff --git a/tests/AxisInterop/MTOM.wsdl b/tests/AxisInterop/MTOM.wsdl
index 178ee35..f0c9a6d 100644
--- a/tests/AxisInterop/MTOM.wsdl
+++ b/tests/AxisInterop/MTOM.wsdl
@@ -80,10 +80,10 @@
   
   
     
-      
+      
     
     
-      
+      
     
   
 

From 8b10219f7302d7e84e67ac59cba2dc31940c991b Mon Sep 17 00:00:00 2001
From: Andreas Schamberger 
Date: Sat, 21 Apr 2012 20:24:19 +0200
Subject: [PATCH 3/5] =?UTF-8?q?add=20builder=20functions=20f=C3=BCr=20conf?=
 =?UTF-8?q?iguring=20soap=20attachment=20handling?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/BeSimple/SoapClient/SoapClientBuilder.php | 36 +++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/src/BeSimple/SoapClient/SoapClientBuilder.php b/src/BeSimple/SoapClient/SoapClientBuilder.php
index b2ceb61..cce4a9a 100644
--- a/src/BeSimple/SoapClient/SoapClientBuilder.php
+++ b/src/BeSimple/SoapClient/SoapClientBuilder.php
@@ -193,6 +193,42 @@ class SoapClientBuilder extends AbstractSoapBuilder
         return $this;
     }
 
+    /**
+    * SOAP attachment type Base64.
+    *
+    * @return \BeSimple\SoapServer\SoapServerBuilder
+    */
+    public function withBase64Attachments()
+    {
+        $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_BASE64;
+
+        return $this;
+    }
+
+    /**
+     * SOAP attachment type SwA.
+     *
+     * @return \BeSimple\SoapServer\SoapServerBuilder
+     */
+    public function withSwaAttachments()
+    {
+        $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_SWA;
+
+        return $this;
+    }
+
+    /**
+     * SOAP attachment type MTOM.
+     *
+     * @return \BeSimple\SoapServer\SoapServerBuilder
+     */
+    public function withMtomAttachments()
+    {
+        $this->options['attachment_type'] = Helper::ATTACHMENTS_TYPE_MTOM;
+
+        return $this;
+    }
+
     /**
      * Validate options.
      */

From 51a971ed3379a5f000540569ae0d06f8ff445f4b Mon Sep 17 00:00:00 2001
From: Andreas Schamberger 
Date: Sun, 22 Apr 2012 18:08:40 +0200
Subject: [PATCH 4/5] added soap client specific soap kernel

---
 src/BeSimple/SoapClient/SoapClient.php |  6 ++--
 src/BeSimple/SoapClient/SoapKernel.php | 47 ++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 4 deletions(-)
 create mode 100644 src/BeSimple/SoapClient/SoapKernel.php

diff --git a/src/BeSimple/SoapClient/SoapClient.php b/src/BeSimple/SoapClient/SoapClient.php
index d264090..d0d99e8 100644
--- a/src/BeSimple/SoapClient/SoapClient.php
+++ b/src/BeSimple/SoapClient/SoapClient.php
@@ -13,7 +13,6 @@
 namespace BeSimple\SoapClient;
 
 use BeSimple\SoapCommon\Helper;
-use BeSimple\SoapCommon\SoapKernel;
 use BeSimple\SoapCommon\Converter\MtomTypeConverter;
 use BeSimple\SoapCommon\Converter\SwaTypeConverter;
 
@@ -79,7 +78,7 @@ class SoapClient extends \SoapClient
     /**
      * Soap kernel.
      *
-     * @var \BeSimple\SoapCommon\SoapKernel
+     * @var \BeSimple\SoapClient\SoapKernel
      */
     protected $soapKernel = null;
 
@@ -252,7 +251,7 @@ class SoapClient extends \SoapClient
     /**
      * Get SoapKernel instance.
      *
-     * @return \BeSimple\SoapCommon\SoapKernel
+     * @return \BeSimple\SoapClient\SoapKernel
      */
     public function getSoapKernel()
     {
@@ -286,7 +285,6 @@ class SoapClient extends \SoapClient
             if (!isset($options['typemap'])) {
                 $options['typemap'] = array();
             }
-            $soapKernel = $this->soapKernel;
             $options['typemap'][] = array(
                 'type_name' => $converter->getTypeName(),
                 'type_ns'   => $converter->getTypeNamespace(),
diff --git a/src/BeSimple/SoapClient/SoapKernel.php b/src/BeSimple/SoapClient/SoapKernel.php
new file mode 100644
index 0000000..949798e
--- /dev/null
+++ b/src/BeSimple/SoapClient/SoapKernel.php
@@ -0,0 +1,47 @@
+
+ * (c) Francis Besset 
+ * (c) Andreas Schamberger 
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace BeSimple\SoapClient;
+
+use BeSimple\SoapCommon\SoapKernel as CommonSoapKernel;
+use BeSimple\SoapCommon\SoapRequest;
+use BeSimple\SoapCommon\SoapResponse;
+
+/**
+ * SoapKernel for Client.
+ *
+ * @author Andreas Schamberger 
+ */
+class SoapKernel extends CommonSoapKernel
+{
+    /**
+     * {@inheritDoc}
+     */
+    public function filterRequest(SoapRequest $request)
+    {
+        $request->setAttachments($this->attachments);
+        $this->attachments = array();
+
+        parent::filterRequest($request);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function filterResponse(SoapResponse $response)
+    {
+        parent::filterResponse($response);
+
+        $this->attachments = $response->getAttachments();
+    }
+}
\ No newline at end of file

From 64002c61d2dcd7e784b41e91ac6507ab7bc2f335 Mon Sep 17 00:00:00 2001
From: Andreas Schamberger 
Date: Sun, 22 Apr 2012 18:10:21 +0200
Subject: [PATCH 5/5] server interop test

---
 tests/ServerInterop/MTOM.php       | 61 ++++++++++++++++++++
 tests/ServerInterop/MTOM.wsdl      | 89 ++++++++++++++++++++++++++++++
 tests/ServerInterop/MTOMServer.php | 53 ++++++++++++++++++
 3 files changed, 203 insertions(+)
 create mode 100644 tests/ServerInterop/MTOM.php
 create mode 100644 tests/ServerInterop/MTOM.wsdl
 create mode 100644 tests/ServerInterop/MTOMServer.php

diff --git a/tests/ServerInterop/MTOM.php b/tests/ServerInterop/MTOM.php
new file mode 100644
index 0000000..4f815b9
--- /dev/null
+++ b/tests/ServerInterop/MTOM.php
@@ -0,0 +1,61 @@
+ SOAP_1_1,
+    'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
+    'trace'           => true, // enables use of the methods  SoapClient->__getLastRequest,  SoapClient->__getLastRequestHeaders,  SoapClient->__getLastResponse and  SoapClient->__getLastResponseHeaders
+    'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
+    'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
+);
+
+$sc = new BeSimpleSoapClient('MTOM.wsdl', $options);
+
+//var_dump($sc->__getFunctions());
+//var_dump($sc->__getTypes());
+
+try {
+    $b64 = new base64Binary();
+    $b64->_ = 'This is a test. :)';
+    $b64->contentType = 'text/plain';
+
+    $attachment = new AttachmentRequest();
+    $attachment->fileName = 'test123.txt';
+    $attachment->binaryData = $b64;
+
+    var_dump($sc->attachment($attachment));
+
+} catch (Exception $e) {
+    var_dump($e);
+}
+
+// var_dump(
+//     $sc->__getLastRequestHeaders(),
+//     $sc->__getLastRequest(),
+//     $sc->__getLastResponseHeaders(),
+//     $sc->__getLastResponse()
+// );
\ No newline at end of file
diff --git a/tests/ServerInterop/MTOM.wsdl b/tests/ServerInterop/MTOM.wsdl
new file mode 100644
index 0000000..7772015
--- /dev/null
+++ b/tests/ServerInterop/MTOM.wsdl
@@ -0,0 +1,89 @@
+
+
+  
+    
+            
+            
+                
+                    
+                    
+                
+            
+            
+            
+        
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+    
+    
+  
+  
+    
+    
+  
+  
+    
+      
+    
+      
+    
+    
+  
+  
+    
+    
+      
+      
+        
+      
+      
+        
+      
+    
+  
+  
+    
+    
+      
+      
+        
+      
+      
+        
+      
+    
+  
+  
+    
+      
+    
+    
+      
+    
+  
+
diff --git a/tests/ServerInterop/MTOMServer.php b/tests/ServerInterop/MTOMServer.php
new file mode 100644
index 0000000..5deee38
--- /dev/null
+++ b/tests/ServerInterop/MTOMServer.php
@@ -0,0 +1,53 @@
+ SOAP_1_1,
+    'features'        => SOAP_SINGLE_ELEMENT_ARRAYS, // make sure that result is array for size=1
+    'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM,
+    'cache_wsdl'      => WSDL_CACHE_NONE,
+    'classmap'        => array(
+        'base64Binary'      => 'base64Binary',
+        'AttachmentRequest' => 'AttachmentRequest',
+    ),
+);
+
+class Mtom
+{
+    public function attachment(AttachmentRequest $attachment)
+    {
+        $b64 = $attachment->binaryData;
+
+        file_put_contents('test.txt', var_export(array(
+            $attachment->fileName,
+            $b64->_,
+            $b64->contentType
+        ), true));
+
+        return 'done';
+    }
+}
+
+$ss = new BeSimpleSoapServer('MTOM.wsdl', $options);
+$ss->setClass('Mtom');
+$ss->handle();