Skip to content

Commit

Permalink
Allows the user to set the name of the response body tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
joan-ricart authored Jun 13, 2022
1 parent e83219e commit 50c021f
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions src/nusoap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,13 @@ class nusoap_server extends nusoap_base
* @access private
*/
var $methodname = '';
/**
* name of the response tag name
*
* @var string
* @access private
*/
var $responseTagName = '';
/**
* method parameters from request
*
Expand Down Expand Up @@ -4297,15 +4304,15 @@ function serialize_return()
if ($this->opData['output']['use'] == 'literal') {
// http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
if ($this->methodURI) {
$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . "Response>";
$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
} else {
$payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
$payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . 'Response>';
}
} else {
if ($this->methodURI) {
$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . "Response>";
$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
} else {
$payload = '<' . $this->methodname . 'Response>' . $return_val . '</' . $this->methodname . 'Response>';
$payload = '<' . $this->responseTagName . '>' . $return_val . '</' . $this->responseTagName . '>';
}
}
} else {
Expand All @@ -4314,7 +4321,7 @@ function serialize_return()
}
} else {
$this->debug('do not have WSDL for serialization: assume rpc/encoded');
$payload = '<ns1:' . $this->methodname . 'Response xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->methodname . "Response>";
$payload = '<ns1:' . $this->responseTagName . ' xmlns:ns1="' . $this->methodURI . '">' . $return_val . '</ns1:' . $this->responseTagName . ">";
}
$this->result = 'successful';
if ($this->wsdl) {
Expand Down Expand Up @@ -4483,6 +4490,12 @@ function parseRequest($headers, $data)
$this->methodURI = $parser->root_struct_namespace;
$this->methodname = $parser->root_struct_name;
$this->debug('methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);

// get/set custom response tag name
$outputMessage = $this->wsdl->getOperationData($this->methodname)['output']['message'];
$this->responseTagName = $outputMessage;
$this->debug('responseTagName: ' . $this->responseTagName . ' methodURI: ' . $this->methodURI);

$this->debug('calling parser->get_soapbody()');
$this->methodparams = $parser->get_soapbody();
// get SOAP headers
Expand Down Expand Up @@ -4559,9 +4572,10 @@ function add_to_map($methodname, $in, $out)
* @param mixed $use optional (encoded|literal) or false
* @param string $documentation optional Description to include in WSDL
* @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
* @param string $customResponseTagName optional Name of the outgoing response, default $name . 'Response'
* @access public
*/
function register($name, $in = array(), $out = array(), $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '')
function register($name, $in = array(), $out = array(), $namespace = false, $soapaction = false, $style = false, $use = false, $documentation = '', $encodingStyle = '', $customResponseTagName = '')
{
global $HTTP_SERVER_VARS;

Expand Down Expand Up @@ -4607,16 +4621,21 @@ function register($name, $in = array(), $out = array(), $namespace = false, $soa
if ($use == 'encoded' && $encodingStyle == '') {
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
}
if (!$customResponseTagName) {
$customResponseTagName = $name . 'Response';
}

$this->operations[$name] = array(
'name' => $name,
'in' => $in,
'out' => $out,
'namespace' => $namespace,
'soapaction' => $soapaction,
'style' => $style);
'style' => $style,
'outputMessage' => $customResponseTagName,
);
if ($this->wsdl) {
$this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle);
$this->wsdl->addOperation($name, $in, $out, $namespace, $soapaction, $style, $use, $documentation, $encodingStyle, $customResponseTagName);
}
return true;
}
Expand Down Expand Up @@ -6614,9 +6633,10 @@ function addElement($attrs)
* @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
* @param string $documentation optional The description to include in the WSDL
* @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
* @param string $customResponseTagName optional Name of the outgoing response
* @access public
*/
function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '')
function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '', $customResponseTagName = '')
{
if ($use == 'encoded' && $encodingStyle == '') {
$encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
Expand All @@ -6636,8 +6656,8 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa
$elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
}
$this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
$this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified'));
$out = array('parameters' => 'tns:' . $name . 'Response' . '^');
$this->addElement(array('name' => $customResponseTagName, 'type' => $name . 'ResponseType', 'form' => 'qualified'));
$out = array('parameters' => 'tns:' . $customResponseTagName . '^');
}

// get binding
Expand All @@ -6652,13 +6672,13 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa
'use' => $use,
'namespace' => $namespace,
'encodingStyle' => $encodingStyle,
'message' => $name . 'Request',
'message' => $name,
'parts' => $in),
'output' => array(
'use' => $use,
'namespace' => $namespace,
'encodingStyle' => $encodingStyle,
'message' => $name . 'Response',
'message' => $customResponseTagName,
'parts' => $out),
'namespace' => $namespace,
'transport' => 'http://schemas.xmlsoap.org/soap/http',
Expand All @@ -6670,20 +6690,20 @@ function addOperation($name, $in = false, $out = false, $namespace = false, $soa
if (strpos($pType, ':')) {
$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
}
$this->messages[$name . 'Request'][$pName] = $pType;
$this->messages[$name][$pName] = $pType;
}
} else {
$this->messages[$name . 'Request'] = '0';
$this->messages[$name] = '0';
}
if ($out) {
foreach ($out as $pName => $pType) {
if (strpos($pType, ':')) {
$pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType);
}
$this->messages[$name . 'Response'][$pName] = $pType;
$this->messages[$customResponseTagName][$pName] = $pType;
}
} else {
$this->messages[$name . 'Response'] = '0';
$this->messages[$customResponseTagName] = '0';
}
return true;
}
Expand Down

0 comments on commit 50c021f

Please sign in to comment.