From 2cb99122d3e0a2a8cd4bcb738b009ee5e0553e41 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 21 Sep 2009 09:55:43 +0000 Subject: [PATCH] BUGFIX Fixed content-type for SapphireSoapServer->wsdl() (#4570, thanks Cristian) MINOR Added documentation for SapphireSoapServer git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@86876 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- api/SapphireSoapServer.php | 55 +++++++++++++++++++++------- tests/api/SapphireSoapServerTest.php | 31 ++++++++++++++++ 2 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 tests/api/SapphireSoapServerTest.php diff --git a/api/SapphireSoapServer.php b/api/SapphireSoapServer.php index 73e902f96..cf9dcf79b 100755 --- a/api/SapphireSoapServer.php +++ b/api/SapphireSoapServer.php @@ -1,15 +1,24 @@ 'xsd:int', 'boolean' => 'xsd:boolean', @@ -19,15 +28,25 @@ class SapphireSoapServer extends Controller { function wsdl() { ContentNegotiator::disable(); - header("Content-type: text/xml"); + $this->getResponse()->addHeader("Content-Type", "text/xml"); + return array(); } + /** + * @return string + */ function getWSDLURL() { return Director::absoluteBaseURLWithAuth() . $this->Link() . "wsdl"; } + /** + * @return DataObjectSet Collection of ArrayData elements describing + * the method (keys: 'Name', 'Arguments', 'ReturnType') + */ function Methods() { + $methods = array(); + foreach($this->stat('methods') as $methodName => $arguments) { $returnType = $arguments['_returns']; unset($arguments['_returns']); @@ -49,24 +68,32 @@ class SapphireSoapServer extends Controller { return new DataObjectSet($methods); } + + /** + * @return string + */ function TargetNamespace() { return Director::absoluteBaseURL(); } + + /** + * @return string + */ function ServiceURL() { return Director::absoluteBaseURLWithAuth() . $this->class . '/'; } - function index() { - $wsdl = $this->getViewer('wsdl')->process($this); - $wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class; - $fh = fopen($wsdlFile, 'w'); - fwrite($fh, $wsdl); - fclose($fh); + function index() { + $wsdl = $this->getViewer('wsdl')->process($this); + $wsdlFile = TEMP_FOLDER . '/sapphire-wsdl-' . $this->class; + $fh = fopen($wsdlFile, 'w'); + fwrite($fh, $wsdl); + fclose($fh); - $s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE)); - $s->setClass($this->class); - $s->handle(); - } + $s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE)); + $s->setClass($this->class); + $s->handle(); + } } ?> diff --git a/tests/api/SapphireSoapServerTest.php b/tests/api/SapphireSoapServerTest.php new file mode 100644 index 000000000..52c148c60 --- /dev/null +++ b/tests/api/SapphireSoapServerTest.php @@ -0,0 +1,31 @@ +get('SapphireSoapServerTest_MyServer/wsdl'); + + $this->assertEquals( + $response->getHeader('Content-Type'), + 'text/xml', + 'wsdl request returns with correct XML content type' + ); + } +} + +/** + * @package sapphire + * @subpackage tests + */ +class SapphireSoapServerTest_MyServer extends SapphireSoapServer { + + function Link($action = null) { + return Controller::join_links('SapphireSoapServerTest_MyServer', $action); + } +} \ No newline at end of file