]> granicus.if.org Git - php/commitdiff
Allowing to report SOAP Fault with "return new SoapFault(...)"
authorDmitry Stogov <dmitry@php.net>
Mon, 9 Feb 2004 09:31:18 +0000 (09:31 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 9 Feb 2004 09:31:18 +0000 (09:31 +0000)
ext/soap/config.w32
ext/soap/readme.html
ext/soap/soap.c
ext/soap/tests/server016.phpt [new file with mode: 0644]
ext/soap/tests/server017.phpt [new file with mode: 0644]

index cd9353186755eb8ad573662ef89df8e9caf3ae70..048fd70ca133215bce38733fa2512e55153b27cc 100644 (file)
@@ -1,7 +1,7 @@
 // $Id$
 // vim:ft=javascript
 
-ARG_WITH("soap", "SOAP support", "no");
+ARG_ENABLE("soap", "SOAP support", "no");
 
 if (PHP_SOAP != "no" && PHP_LIBXML == "yes") {
        EXTENSION('soap', 'soap.c php_encoding.c php_http.c php_packet_soap.c php_schema.c php_sdl.c php_xml.c');
index cbb38ab77623ab1ef589da26edbde605c5237cab..26770dc9b0476fb79bad9ae94242f8450177cc5d 100644 (file)
@@ -28,7 +28,7 @@ TD:{
 This extension makes use of the <A HREF="http://www.xmlsoft.org" TARGET="_top">GNOME XML library</A>. Download and install this library. You will need at least libxml-2.5.4.
 <HR>
 <H2>Installation</H2>
-This extension is only available if PHP was configured with --with-soap.
+This extension is only available if PHP was configured with --enable-soap.
 <HR>
 <H2>Predefined Constants</H2>
 The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.
@@ -107,6 +107,7 @@ The constants below are defined by this extension, and will only be available wh
 <tr><td><a href="#ref.soap.soapparam">SoapParam</a></td></tr>
 <tr><td><a href="#ref.soap.soapvar">SoapVar</a></td></tr>
 <tr><td><a href="#ref.soap.soapheader">SoapHeader</a></td></tr>
+<tr><td><a href="#ref.soap.soapfault">SoapFault</a></td></tr>
 </table>
 <a name="ref.soap.soapclient">
 <h4>SoapClient class</h4>
@@ -163,6 +164,16 @@ It is just a data holder and it has not any special method except constructor.
 <table border="0">
 <tr><td><a href="#ref.soap.soapheader.soapheader">SoapHeader</a> -- SoapHeader constructor</td></tr>
 </table>
+<a name="ref.soap.soapfault">
+<h4>SoapFault class</h4>
+<p>
+SoapFault is a special class that can be used for error reporting during
+handling of SOAP request (on server). It has not any special methods except
+constructor.
+</p>
+<table border="0">
+<tr><td><a href="#ref.soap.soapfault.soapfault">SoapFault</a> -- SoapFault constructor</td></tr>
+</table>
 <HR>
 <!--
 <H2>Examples</H2>
@@ -186,6 +197,7 @@ It is just a data holder and it has not any special method except constructor.
 <tr><td><a href="#ref.soap.soapparam.soapparam">SoapParam::SoapParam</a> -- SoapParam constructor</td></tr>
 <tr><td><a href="#ref.soap.soapvar.soapvar">SoapVar::SoapVar</a> -- SoapVar constructor</td></tr>
 <tr><td><a href="#ref.soap.soapheader.soapheader">SoapHeader::SoapHeader</a> -- SoapHeader constructor</td></tr>
+<tr><td><a href="#ref.soap.soapfault.soapfault">SoapFault::SoapFault</a> -- SoapFault constructor</td></tr>
 </table>
 
 <a name="ref.soap.is_soap_fault"></a>
@@ -216,7 +228,6 @@ is_soap_fault() functions checks if the given parameter is a SoapFault object.
 <p>SoapClient constructor</p>
 <h3>Description</h3>
 <p><b>SoapClient</b>(mixed wsdl [, array options])</p>
-<h4>Examples</h4>
 <p>
 The constructor allows creating SoapClient objects in WSDL or nonWSDL mode.
 The first case requires URI of WSDL file as first parameter and optional
@@ -230,6 +241,7 @@ Some additional optional options allow using HTTP authentication (<b>login</b>
 and <b>password</b>) and HTTP connection through proxy server (<b>proxy_host</b>,
 <b>proxy_port</b>, <b>proxy_login</b> and <b>proxy_password</b>).
 </p>
+<h4>Examples</h4>
 <TABLE BORDER="0" BGCOLOR="#E0E0E0"><TR><TD><PRE CLASS="php">
     $client = new SoapClient("some.wsdl");
 
@@ -494,6 +506,7 @@ It never returns.
     $server->handle();
 ?&gt;
 </PRE></TD></TR></TABLE>
+<p>See also: <a href="#ref.soap.soapfault.soapfault">SoapFault::SoapFault</a></p>
 
 <a name="ref.soap.soapparam.soapparam"></a>
 <h2>SoapParam::SoapParam</h2>
@@ -580,5 +593,27 @@ Header element.
                                    'hello world'));
 ?&gt;
 </PRE></TD></TR></TABLE>
+
+<a name="ref.soap.soapfault.soapfault"></a>
+<h2>SoapFault::SoapFault</h2>
+<p>(PHP 5)</p>
+<p>SoapFault constructor</p>
+<h3>Description</h3>
+<p><b>SoapFault</b>(string faultcode, string faultstring [, string faultactor [, mixed details]])</p>
+This class is useful when you like to send SOAP fault response from PHP handler.
+<h4>Example</h4>
+<h4>Example</h4>
+<TABLE BORDER="0" BGCOLOR="#E0E0E0"><TR><TD><PRE CLASS="php">
+&lt;?php
+    function test($x) {
+        return new SoapFault("Server","Some error message");
+    }
+
+    $server = new SoapServer(null,array('uri'=>"http://test-uri/"));
+    $server->addFunction("test");
+    $server->handle();
+?&gt;
+</PRE></TD></TR></TABLE>
+<p>See also: <a href="#ref.soap.soapserver.fault">SoapServer::fault</a></p>
 </BODY>
 </HTML>
\ No newline at end of file
index ddda94746d96cc07f3c9808651d5c6a76ffc0ef3..5f96b765794b61f24bd1384fa43248ceedec77b8 100644 (file)
@@ -47,6 +47,7 @@ static void type_to_string(sdlTypePtr type, smart_str *buf, int level);
 static void clear_soap_fault(zval *obj TSRMLS_DC);
 static void set_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail TSRMLS_DC);
 static void soap_server_fault(char* code, char* string, char *actor, zval* details TSRMLS_DC);
+static void soap_server_fault_ex(zval* fault TSRMLS_DC);
 
 static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int index, int);
 static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name);
@@ -1274,6 +1275,11 @@ PHP_METHOD(soapserver, handle)
        if (call_status == SUCCESS) {
                char *response_name;
 
+               if (Z_TYPE(retval) == IS_OBJECT &&
+                   Z_OBJCE(retval) == soap_fault_class_entry) {
+                       soap_server_fault_ex(&retval TSRMLS_CC);
+               }
+
                if (function && function->responseName) {
                        response_name = estrdup(function->responseName);
                } else {
@@ -1361,21 +1367,16 @@ PHP_METHOD(soapserver, fault)
        SOAP_SERVER_END_CODE();
 }
 
-static void soap_server_fault(char* code, char* string, char *actor, zval* details TSRMLS_DC)
+static void soap_server_fault_ex(zval* fault TSRMLS_DC)
 {
        int soap_version;
        xmlChar *buf, cont_len[30];
        int size;
-       zval ret;
        xmlDocPtr doc_return;
 
        soap_version = SOAP_GLOBAL(soap_version);
 
-       INIT_ZVAL(ret);
-
-       set_soap_fault(&ret, code, string, actor, details TSRMLS_CC);
-
-       doc_return = seralize_response_call(NULL, NULL, NULL, &ret, NULL, soap_version TSRMLS_CC);
+       doc_return = seralize_response_call(NULL, NULL, NULL, fault, NULL, soap_version TSRMLS_CC);
 
        xmlDocDumpMemory(doc_return, &buf, &size);
 
@@ -1398,6 +1399,16 @@ static void soap_server_fault(char* code, char* string, char *actor, zval* detai
        zend_bailout();
 }
 
+static void soap_server_fault(char* code, char* string, char *actor, zval* details TSRMLS_DC)
+{
+       zval ret;
+
+       INIT_ZVAL(ret);
+
+       set_soap_fault(&ret, code, string, actor, details TSRMLS_CC);
+       soap_server_fault_ex(&ret TSRMLS_CC);
+}
+
 static void soap_error_handler(int error_num, const char *error_filename, const uint error_lineno, const char *format, va_list args)
 {
        TSRMLS_FETCH();
diff --git a/ext/soap/tests/server016.phpt b/ext/soap/tests/server016.phpt
new file mode 100644 (file)
index 0000000..77bce9f
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+SOAP Server 16: user fault
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function test() {
+       global $server;
+       $server->fault("MyFault","My fault string");
+}
+
+$server = new soapserver(null,array('uri'=>"http://testuri.org"));
+$server->addfunction("test");
+
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<SOAP-ENV:Envelope
+  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:si="http://soapinterop.org/xsd">
+  <SOAP-ENV:Body>
+    <ns1:test xmlns:ns1="http://testuri.org"/>
+  </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+EOF;
+
+$server->handle();
+echo "ok\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>MyFault</faultcode><faultstring>My fault string</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
diff --git a/ext/soap/tests/server017.phpt b/ext/soap/tests/server017.phpt
new file mode 100644 (file)
index 0000000..2f5dd6b
--- /dev/null
@@ -0,0 +1,33 @@
+--TEST--
+SOAP Server 17: user fault (through return)
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function test() {
+       return new SoapFault("MyFault","My fault string");
+}
+
+$server = new soapserver(null,array('uri'=>"http://testuri.org"));
+$server->addfunction("test");
+
+$HTTP_RAW_POST_DATA = <<<EOF
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<SOAP-ENV:Envelope
+  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:si="http://soapinterop.org/xsd">
+  <SOAP-ENV:Body>
+    <ns1:test xmlns:ns1="http://testuri.org"/>
+  </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
+EOF;
+
+$server->handle();
+echo "ok\n";
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8"?>
+<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>MyFault</faultcode><faultstring>My fault string</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>