cvs: pear /SOAP WSDL.php /SOAP/interop client_round2_base.php

From: Date: Tue, 26 Feb 2002 01:29:38 +0000
Subject: cvs: pear /SOAP WSDL.php /SOAP/interop client_round2_base.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-2620@lists.php.net to get a copy of this message
shane Mon Feb 25 20:29:38 2002 EDT Modified files: /pear/SOAP WSDL.php /pear/SOAP/interop client_round2_base.php Log: some wsdl work import works now namespace stuff needs a lot of work still

Index: pear/SOAP/WSDL.php diff -u pear/SOAP/WSDL.php:1.5 pear/SOAP/WSDL.php:1.6 --- pear/SOAP/WSDL.php:1.5 Mon Feb 25 00:06:36 2002 +++ pear/SOAP/WSDL.php Mon Feb 25 20:29:37 2002 @@ -17,9 +17,9 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: WSDL.php,v 1.5 2002/02/25 05:06:36 shane Exp $ +// $Id: WSDL.php,v 1.6 2002/02/26 01:29:37 shane Exp $ // -require_once("SOAP/globals.php"); +require_once('SOAP/globals.php'); /** * SOAP_WSDL @@ -33,7 +33,7 @@ * implement IDL type syntax declaration so we can generate WSDL * * @access public -* @version $Id: WSDL.php,v 1.5 2002/02/25 05:06:36 shane Exp $ +* @version $Id: WSDL.php,v 1.6 2002/02/26 01:29:37 shane Exp $ * @package SOAP::Client * @author Shane Caraveo <shane@php.net> Conversion to PEAR and updates * @author Dietrich Ayala <dietrich@ganx4.com> Original Author @@ -58,8 +58,9 @@ var $depth; var $depth_array = array(); var $tns = NULL; - var $soapns = "soap"; - + var $soapns = 'soap'; + var $fault = FALSE; + // constructor function SOAP_WSDL($wsdl=false) { $this->parse($wsdl); @@ -68,7 +69,14 @@ function parse($wsdl) { // Check whether content has been read. if ($wsdl) { - $wsdl_string = join("",file($wsdl)); + // XXX implement caching + $fd = @file($wsdl); + if (!$fd) { + $this->fault = true; + $this->debug('Unable to retreive WSDL file'); + return false; + } + $wsdl_string = join('',$fd); // Create an XML parser. $parser = xml_parser_create(); // Set the options for parsing the XML data. @@ -77,20 +85,21 @@ // Set the object for the parser. xml_set_object($parser, $this); // Set the element handlers for the parser. - xml_set_element_handler($parser, "startElement","endElement"); - xml_set_character_data_handler($parser,"characterData"); - //xml_set_default_handler($this->parser, "defaultHandler"); + xml_set_element_handler($parser, 'startElement','endElement'); + xml_set_character_data_handler($parser,'characterData'); + //xml_set_default_handler($this->parser, 'defaultHandler'); // Parse the XML file. if (!xml_parse($parser,$wsdl_string,true)) { // Display an error message. - $this->debug(sprintf("XML error on line %d: %s", + $this->debug(sprintf('XML error on line %d: %s', xml_get_current_line_number($parser), xml_error_string(xml_get_error_code($parser)))); $this->fault = true; } xml_parser_free($parser); } + return $this->fault; } // start-element handler @@ -103,153 +112,165 @@ $this->depth_array[$depth] = $pos; // get element prefix - if (strstr($name,":")) { - $s = split(":",$name); + if (strstr($name,':')) { + $s = split(':',$name); $ns = $s[0]; - if ($ns && ((!$this->tns && strcasecmp($s[1],"definitions")==0) || $ns == $this->tns)) { + if ($ns && ((!$this->tns && strcasecmp($s[1],'definitions')==0) || $ns == $this->tns)) { $name = $s[1]; } } // find status, register data switch($this->status) { - case "types": + case 'types': switch($name) { - case "schema": + case 'schema': $this->schema = true; break; - case "complexType": - $this->currentElement = $attrs["name"]; - $this->schemaStatus = "complexType"; + case 'complexType': + $this->currentElement = $attrs['name']; + $this->schemaStatus = 'complexType'; break; - case "element": - $this->complexTypes[$this->currentElement]["elements"][$attrs["name"]] = $attrs; + case 'element': + $this->complexTypes[$this->currentElement]['elements'][$attrs['name']] = $attrs; break; - case "complexContent": + case 'complexContent': break; - case "restriction": - $this->complexTypes[$this->currentElement]["restrictionBase"] = $attrs["base"]; + case 'restriction': + $this->complexTypes[$this->currentElement]['restrictionBase'] = $attrs['base']; break; - case "sequence": - $this->complexTypes[$this->currentElement]["order"] = "sequence"; + case 'sequence': + $this->complexTypes[$this->currentElement]['order'] = 'sequence'; break; - case "all": - $this->complexTypes[$this->currentElement]["order"] = "all"; + case 'all': + $this->complexTypes[$this->currentElement]['order'] = 'all'; break; - case "attribute": - if ($attrs["ref"]) { - $this->complexTypes[$this->currentElement]["attrs"][$attrs["ref"]] = $attrs; - } elseif ($attrs["name"]) { - $this->complexTypes[$this->currentElement]["attrs"][$attrs["name"]] = $attrs; + case 'attribute': + if ($attrs['ref']) { + $this->complexTypes[$this->currentElement]['attrs'][$attrs['ref']] = $attrs; + } elseif ($attrs['name']) { + $this->complexTypes[$this->currentElement]['attrs'][$attrs['name']] = $attrs; } break; } break; - case "message": - if ($name == "part") { - $this->messages[$this->currentMessage][$attrs["name"]] = $attrs["type"]; + case 'message': + if ($name == 'part') { + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; } break; - case "portType": + case 'portType': switch($name) { - case "operation": - $this->currentOperation = $attrs["name"]; - $this->portTypes[$this->currentPortType][$attrs["name"]]["parameterOrder"] = $attrs["parameterOrder"]; + case 'operation': + $this->currentOperation = $attrs['name']; + $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; break; default: $this->portTypes[$this->currentPortType][$this->currentOperation][$name]= $attrs; + $qname = split(':',$attrs['message']); + $qname = array_reverse($qname); // this way, the type will always be zero + $this->portTypes[$this->currentPortType][$this->currentOperation][$name]['message'] = $qname[0]; + $this->portTypes[$this->currentPortType][$this->currentOperation][$name]['namespace'] = $qname[1]; break; } break; - case "binding": + case 'binding': switch($name) { - case $this->soapns.":binding": + case $this->soapns.':binding': $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding],$attrs); break; - case "operation": - $this->currentOperation = $attrs["name"]; - $this->bindings[$this->currentBinding]["operations"][$attrs["name"]] = array(); + case 'operation': + $this->currentOperation = $attrs['name']; + $this->bindings[$this->currentBinding]['operations'][$attrs['name']] = array(); break; - case $this->soapns.":operation": - $this->bindings[$this->currentBinding]["operations"][$this->currentOperation]["soapAction"] = $attrs["soapAction"]; + case $this->soapns.':operation': + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; break; - case "input": - $this->opStatus = "input"; - case $this->soapns.":body": - $this->bindings[$this->currentBinding]["operations"][$this->currentOperation][$this->opStatus] = $attrs; + case 'input': + $this->opStatus = 'input'; + case $this->soapns.':body': + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; break; - case "output": - $this->opStatus = "output"; + case 'output': + $this->opStatus = 'output'; break; } break; - case "service": + case 'service': switch($name) { - case "port": - $this->currentPort = $attrs["name"]; - $this->ports[$attrs["name"]] = $attrs; + case 'port': + $this->currentPort = $attrs['name']; + $this->ports[$attrs['name']] = $attrs; + // XXX hack to deal with binding namespaces + $qname = split(':',$attrs['binding']); + $qname = array_reverse($qname); // this way, the type will always be zero + $this->ports[$attrs['name']]['binding'] = $qname[0]; + $this->ports[$attrs['name']]['namespace'] = $qname[1]; break; - case $this->soapns.":address": - $this->ports[$this->currentPort]["location"] = $attrs["location"]; + case $this->soapns.':address': + $this->ports[$this->currentPort]['location'] = $attrs['location']; break; } - case "import": + case 'import': switch($name) { - case "documentation": - $this->imports[$attrs["namespace"]]["documentation"] = $attrs; + case 'documentation': + $this->imports[$attrs['namespace']]['documentation'] = $attrs; default: - $this->debug("ERROR, only documentation allowed inside IMPORT\n"); + $this->debug('ERROR, only documentation allowed inside IMPORT\n'); } break; } // set status switch($name) { - case "import": + case 'import': //XXX - $import = ""; - if ($attrs["location"]) { - $this->parse($attrs["location"]); + $import = ''; + if ($attrs['location']) { + $this->parse($attrs['location']); } - $this->imports[$attrs["namespace"]] = array( - "location" => $attrs["location"], - "namespace" => $attrs["namespace"]); - $this->currentImport = $attrs["namespace"]; - $this->status = "import"; - case "types": - $this->status = "types"; - break; - case "message": - $this->status = "message"; - $this->messages[$attrs["name"]] = array(); - $this->currentMessage = $attrs["name"]; - break; - case "portType": - $this->status = "portType"; - $this->portTypes[$attrs["name"]] = array(); - $this->currentPortType = $attrs["name"]; - break; - case "binding": - $this->status = "binding"; - $this->currentBinding = $attrs["name"]; - $this->bindings[$attrs["name"]]["type"] = $attrs["type"]; - break; - case "service": - $this->serviceName = $attrs["name"]; - $this->status = "service"; + $this->imports[$attrs['namespace']] = array( + 'location' => $attrs['location'], + 'namespace' => $attrs['namespace']); + $this->currentImport = $attrs['namespace']; + $this->status = 'import'; + case 'types': + $this->status = 'types'; + break; + case 'message': + $this->status = 'message'; + $this->messages[$attrs['name']] = array(); + $this->currentMessage = $attrs['name']; + break; + case 'portType': + $this->status = 'portType'; + $this->portTypes[$attrs['name']] = array(); + $this->currentPortType = $attrs['name']; + break; + case 'binding': + $this->status = 'binding'; + $this->currentBinding = $attrs['name']; + $qname = split(':',$attrs['type']); + $qname = array_reverse($qname); // this way, the type will always be zero + $this->bindings[$attrs['name']]['type'] = $qname[0]; + $this->bindings[$attrs['name']]['namespace'] = $qname[1]; + break; + case 'service': + $this->serviceName = $attrs['name']; + $this->status = 'service'; break; - case "definitions": + case 'definitions': $this->wsdl_info = $attrs; foreach ($attrs as $name=>$value) { if (strcasecmp($value,SOAP_SCHEMA)==0) { - $s = split(":",$name); + $s = split(':',$name); $this->soapns = $s[1]; break; } } if ($ns) { - $namespace = "xmlns:".$ns; + $namespace = 'xmlns:'.$ns; if (!$this->wsdl_info[$namespace]) { $this->debug("WSDL Parse Error, no namespace for $namespace\n"); return; @@ -262,7 +283,7 @@ function getEndpoint($portName) { - if ($endpoint = $this->ports[$portName]["location"]) { + if ($endpoint = $this->ports[$portName]['location']) { return $endpoint; } return false; @@ -272,8 +293,7 @@ function getPortName($operation) { foreach($this->ports as $port => $portAttrs) { - $binding = substr($portAttrs["binding"],4); - if ($this->bindings[$binding]["operations"][$operation] != "") { + if ($this->bindings[$portAttrs['binding']]['operations'][$operation] != '') { return $port; } } @@ -281,46 +301,39 @@ function getOperationData($portName,$operation) { - if ($binding = substr($this->ports[$portName]["binding"],4)) { + if ($binding = $this->ports[$portName]['binding']) { // get operation data from binding - if (is_array($this->bindings[$binding]["operations"][$operation])) { - $opData = $this->bindings[$binding]["operations"][$operation]; + if (is_array($this->bindings[$binding]['operations'][$operation])) { + $opData = $this->bindings[$binding]['operations'][$operation]; } // get operation data from porttype - $portType = substr(strstr($this->bindings[$binding]["type"],":"),1); + $portType = $this->bindings[$binding]['type']; if (is_array($this->portTypes[$portType][$operation])) { - $opData["parameterOrder"] = $this->portTypes[$portType][$operation]["parameterOrder"]; - $opData["input"] = array_merge($opData["input"],$this->portTypes[$portType][$operation]["input"]); - $opData["output"] = array_merge($opData["output"],$this->portTypes[$portType][$operation]["output"]); + $opData['parameterOrder'] = $this->portTypes[$portType][$operation]['parameterOrder']; + $opData['input'] = array_merge($opData['input'],$this->portTypes[$portType][$operation]['input']); + $opData['output'] = array_merge($opData['output'],$this->portTypes[$portType][$operation]['output']); } // message data from messages - $inputMsg = substr(strstr($opData["input"]["message"],":"),1); - $opData["input"]["parts"] = $this->messages[$inputMsg]; - $outputMsg = substr(strstr($opData["output"]["message"],":"),1); - $opData["output"]["parts"] = $this->messages[$outputMsg]; + $inputMsg = $opData['input']['message']; + $opData['input']['parts'] = $this->messages[$inputMsg]; + $outputMsg = $opData['output']['message']; + $opData['output']['parts'] = $this->messages[$outputMsg]; } return $opData; } function getSoapAction($portName,$operation) { - if ($binding = substr($this->ports[$portName]["binding"],4)) { - if ($soapAction = $this->bindings[$binding]["operations"][$operation]["soapAction"]) { - return $soapAction; - } - return false; + if ($soapAction = $this->bindings[$this->ports[$portName]['binding']]['operations'][$operation]['soapAction']) { + return $soapAction; } return false; } function getNamespace($portName,$operation) { - if ($binding = substr($this->ports[$portName]["binding"],4)) { - //$this->debug("looking for namespace using binding '$binding', port '$portName', operation '$operation'"); - if ($namespace = $this->bindings[$binding]["operations"][$operation]["input"]["namespace"]) { - return $namespace; - } - return false; + if ($namespace = $this->bindings[$this->ports[$portName]['binding']]['operations'][$operation]['input']['namespace']) { + return $namespace; } return false; } @@ -338,7 +351,7 @@ function characterData($parser, $data) { $pos = $this->depth_array[$this->depth]; - $this->message[$pos]["cdata"] .= $data; + $this->message[$pos]['cdata'] .= $data; } function debug($string) Index: pear/SOAP/interop/client_round2_base.php diff -u pear/SOAP/interop/client_round2_base.php:1.8 pear/SOAP/interop/client_round2_base.php:1.9 --- pear/SOAP/interop/client_round2_base.php:1.8 Mon Feb 25 13:59:50 2002 +++ pear/SOAP/interop/client_round2_base.php Mon Feb 25 20:29:37 2002 @@ -17,7 +17,7 @@ // | Authors: Dietrich Ayala <dietrich@ganx4.com> Original Author | // +----------------------------------------------------------------------+ // -// $Id: client_round2_base.php,v 1.8 2002/02/25 18:59:50 shane Exp $ +// $Id: client_round2_base.php,v 1.9 2002/02/26 01:29:37 shane Exp $ // require_once("SOAP/Client.php"); require_once("client_params.php"); @@ -27,26 +27,33 @@ $localonly = 0; // set to 1 to test only your local server $usebuiltin = 0; // use builtin list of endpoints +$usewsdl = 1; $test = 'base'; // which test to do: base, GroupB, GroupC $parm = 'soapval'; // use base types: php, soapval $show = 1; $debug = 0; $numservers = 0; // zero for all of them -$testfunc = ""; // test a single function -$specificendpoint = ""; //"http://63.142.188.184:1122/"; // endpoint url +$testfunc = ''; // test a single function +$specificendpoint = ''; //"http://63.142.188.184:1122/"; // endpoint url if ($localonly) { # define your test servers endpointURL here $endpoints[$SOAP_LibraryName] = array( - "endpointURL" => "http://127.0.0.1/soap/interop.php", - "name" => $SOAP_LibraryName); + 'endpointURL' => 'http://127.0.0.1/soap/interop.php', + 'name' => $SOAP_LibraryName); } elseif ($usebuiltin) { - $endpoints["4s4c"] = array( - "endpointURL" => "http://soap.4s4c.com/ilab/soap.asp", - "name" => "4s4c"); - $endpoints["Apache Axis"] = array( - "endpointURL" => "http://nagoya.apache.org:5049/axis/services/echo", - "name" => "Apache Axis"); + $endpoints['4s4c'] = array( + 'endpointURL' => 'http://soap.4s4c.com/ilab/soap.asp', + 'wsdlURL' => 'http://www.pocketsoap.com/services/ilab.wsdl', + 'name' => '4s4c'); + $endpoints['Apache Axis'] = array( + 'endpointURL' => 'http://nagoya.apache.org:5049/axis/services/echo', + 'wsdlURL' => 'http://nagoya.apache.org:5049/axis/services/echo?wsdl', + 'name' => 'Apache Axis'); + $endpoints['Apache SOAP 2.2'] = array( + 'endpointURL' => 'http://nagoya.apache.org:5049/soap/servlet/rpcrouter', + 'wsdlURL' => 'http://www.apache.org/~rubys/ApacheSoap.wsdl', + 'name' => 'Apache SOAP 2.2'); #$endpoints["GLUE"] = array( # "endpointURL" => "http://www.themindelectric.net:8005/glue/round2", # "name" => "GLUE"); @@ -121,7 +128,7 @@ } function do_endpoint_method($endpoint, $method, $method_params, $show = 0, $debug = 0) { - global $endpoints, $method_expect; + global $endpoints, $method_expect,$usewsdl; $success = FALSE; if ($debug) $show = 1; @@ -138,9 +145,29 @@ $endpoint_info = $endpoints[$endpoint]; $endpoints[$endpoint]["methods"][$method] = array(); - $soap = new SOAP_Client($endpoint_info["endpointURL"]); + if ($usewsdl) { + if (array_key_exists('wsdlURL',$endpoint_info)) { + if (!array_key_exists('client',$endpoints[$endpoint])) { + $endpoints[$endpoint]['client'] = new SOAP_Client($endpoint_info['wsdlURL'],1); + } + $soap = $endpoints[$endpoint]['client']; + if ($soap->wsdl->fault) { + echo "WSDL error in $endpoint\n"; + return FALSE; + } + } else { + echo "No WSDL for $endpoint\n"; + return FALSE; + } + } else { + $soap = new SOAP_Client($endpoint_info['endpointURL']); + } $soap->debug_flag = true; - $return = $soap->call($method,$method_params,"http://soapinterop.org/","http://soapinterop.org/"); + if ($usewsdl) { + $return = $soap->call($method,$method_params); + } else { + $return = $soap->call($method,$method_params,'http://soapinterop.org/','http://soapinterop.org/'); + } if(!PEAR::isError($return) && !$soap->fault){ if (is_array($method_params) && count($method_params) == 1) {
« previous php.pear.cvs (#2620) next »