function parseRequest($data = '', $attachments = null) { /* Parse response, get SOAP_Parser object. */ $parser = new SOAP_Parser($data, $this->xml_encoding, $attachments); if ($parser->fault) { /* Fault occurred during message parsing. */ $this->fault = $parser->fault; return null; } if (!count($parser->root_struct_name)) { /* No method specified. */ $this->_raiseSoapFault('No method specified in request.'); return null; } /* Handle message headers. */ $request_headers = $parser->getHeaders(); $header_results = array(); if ($request_headers) { if (!is_a($request_headers, 'SOAP_Value')) { $this->_raiseSoapFault('Parser did not return SOAP_Value object: ' . $request_headers, '', '', 'Server'); return null; } if ($request_headers->value) { /* Handle headers now. */ foreach ($request_headers->value as $header_val) { $f_exists = $this->validateMethod($header_val->name, $header_val->namespace); /* TODO: this does not take into account message routing * yet. */ $myactor = !$header_val->actor || $header_val->actor == 'http://schemas.xmlsoap.org/soap/actor/next' || $header_val->actor == $this->endpoint; if (!$f_exists && $header_val->mustunderstand && $myactor) { $this->_raiseSoapFault('I don\'t understand header ' . $header_val->name, '', '', 'MustUnderstand'); return null; } /* We only handle the header if it's for us. */ $isok = $f_exists && $myactor; if ($isok) { /* Call our header now! */ $header_method = $header_val->name; $header_data = array($this->_decode($header_val)); /* If there are parameters to pass. */ $hr =& $this->callMethod($header_method, $header_data); if (PEAR::isError($hr)) { $this->_raiseSoapFault($hr); return null; } $results = $this->buildResult($hr, $this->return_type, $header_method, $header_val->namespace); $header_results[] = $results[0]; } } } } /* Handle the method call. */ /* Evaluate message, getting back a SOAP_Value object. */ $this->call_methodname = $this->methodname = $parser->root_struct_name[0]; /* Figure out the method namespace. */ $this->method_namespace = $parser->message[$parser->root_struct[0]]['namespace']; if ($this->_wsdl) { $this->_setSchemaVersion($this->_wsdl->xsd); $dataHandler = $this->_wsdl->getDataHandler($this->methodname, $this->method_namespace); if ($dataHandler) { $this->call_methodname = $this->methodname = $dataHandler; } $this->_portName = $this->_wsdl->getPortName($this->methodname); if (PEAR::isError($this->_portName)) { $this->_raiseSoapFault($this->_portName); return null; } $opData = $this->_wsdl->getOperationData($this->_portName, $this->methodname); if (PEAR::isError($opData)) { $this->_raiseSoapFault($opData); return null; } $this->_options['style'] = $opData['style']; $this->_options['use'] = $opData['output']['use']; $this->_options['parameters'] = $opData['parameters']; } /* Does method exist? */ if (!$this->methodname || !$this->validateMethod($this->methodname, $this->method_namespace)) { $this->_raiseSoapFault('method "' . $this->method_namespace . $this->methodname . '" not defined in service', '', '', 'Server'); return null; } if (!($request_val = $parser->getResponse())) { return null; } if (!is_a($request_val, 'SOAP_Value')) { $this->_raiseSoapFault('Parser did not return SOAP_Value object: ' . $request_val, '', '', 'Server'); return null; } /* Verify that SOAP_Value objects in request match the methods * signature. */ if (!$this->verifyMethod($request_val)) { /* verifyMethod() creates the fault. */ return null; } /* Need to set special error detection inside the value class to * differentiate between no params passed, and an error decoding. */ $request_data = $this->__decodeRequest($request_val); if (PEAR::isError($request_data)) { $this->_raiseSoapFault($request_data); return null; } $method_response =& $this->callMethod($this->call_methodname, $request_data); if (PEAR::isError($method_response)) { $this->_raiseSoapFault($method_response); return null; } if ($this->_options['parameters'] || !$method_response || $this->_options['style'] == 'rpc') { /* Get the method result. */ if (is_null($method_response)) { $return_val = null; } else { $return_val = $this->buildResult($method_response, $this->return_type); } $qn = new QName($this->methodname . 'Response', $this->method_namespace); $methodValue = new SOAP_Value($qn->fqn(), 'Struct', $return_val); } else { $methodValue =& $method_response; } return $this->makeEnvelope($methodValue, $header_results, $this->response_encoding); }
function &__parse(&$response, $encoding, &$attachments) { // parse the response $response = new SOAP_Parser($response, $encoding, $attachments); if ($response->fault) { return $this->_raiseSoapFault($response->fault); } // return array of parameters $return =& $response->getResponse(); $headers =& $response->getHeaders(); if ($headers) { $this->headersIn =& $this->__decodeResponse($headers, false); } return $this->__decodeResponse($return); }
/** * Parses a SOAP response. * * @see SOAP_Parser:: * * @param string $response XML content of SOAP response. * @param string $encoding Character set encoding, defaults to 'UTF-8'. * @param array $attachments List of attachments. */ function parseResponse($response, $encoding, $attachments) { // Parse the response. $response = new SOAP_Parser($response, $encoding, $attachments); if ($response->fault) { $fault = $this->_raiseSoapFault($response->fault); return $fault; } // Return array of parameters. $return = $response->getResponse(); $headers = $response->getHeaders(); if ($headers) { $this->headersIn = $this->_decodeResponse($headers, false); } $decoded = $this->_decodeResponse($return); return $decoded; }
function parseMessage($msg) { // strip line endings // $msg = preg_replace('/\r|\n/', ' ', $msg); $parser = new SOAP_Parser($msg); if ($parser->fault) { return $parser->fault->getFault(); } $response = $parser->getResponse(); $v = $parser->_decode($response); if (gettype($v) == 'array' && count($v) === 1) { return array_shift($v); } return $v; }
/** * parses a soap message * * @param string $data soap message (in xml) * * @return SOAP::Value * @access public */ function parseResponse($data) { $this->debug('Entering parseResponse()'); $this->debug(" w/ data {$data}"); $this->debug('about to create parser instance w/ data'); // parse response $response = new SOAP_Parser($data); // return array of parameters $ret = $response->getResponse(); $this->debug($response->debug_data); return $ret; }
public function __construct($xml, $encoding = SOAP_DEFAULT_ENCODING, $attachments = null) { parent::SOAP_Parser($xml, $encoding, $attachments); }
function parseRequest($data = '') { global $_ENV, $_SERVER; $this->debug('entering parseRequest() on ' . date('H:i Y-m-d')); $this->debug('request uri: ' . $_SERVER['PATH_INFO']); // get headers // get SOAPAction header if ($headers_array['SOAPAction']) { $this->SOAPAction = str_replace('"', '', $_ENV['HTTP_SOAPACTION']); $this->service = $this->SOAPAction; } // get the character encoding of the incoming request if (ereg('=', $_ENV['HTTP_CONTENT_TYPE'])) { $enc = str_replace('"', '', substr(strstr($_ENV['HTTP_CONTENT_TYPE'], '='), 1)); if (eregi("^(ISO-8859-1|US-ASCII|UTF-8)\$", $enc)) { $this->xml_encoding = $enc; } else { $this->xml_encoding = 'us-ascii'; } } $this->debug("got encoding: {$this->xml_encoding}"); $this->request = $dump . "\r\n\r\n" . $data; // parse response, get soap parser obj $parser = new SOAP_Parser($data, $this->xml_encoding); // if fault occurred during message parsing if ($parser->fault()) { // parser debug $this->debug($parser->debug_data); $this->result = 'fault: error in msg parsing'; $this->makeFault('Server', "error in msg parsing:\n" . $parser->getResponse()); // return soapresp return $this->fault(); // else successfully parsed request into SOAP_Value object } else { // evaluate message, getting back a SOAP_Value object $this->debug('calling parser->getResponse()'); $this->methodname = $parser->root_struct_name[0]; $this->debug("method name: {$this->methodname}"); // does method exist? if (!$this->methodname || !$this->validateMethod($this->methodname)) { // "method not found" fault here $this->debug("method '{$this->methodname}' not found!"); $this->result = 'fault: method not found'; $this->makeFault('Server', "method '{$this->methodname}' not defined in service '{$this->service}'"); return $this->fault(); } $this->debug("method '{$this->methodname}' exists"); if (!($request_val = $parser->getResponse())) { return $this->fault(); } // parser debug $this->debug($parser->debug_data); /* set namespaces if ($parser->namespaces['xsd'] != '') { //print 'got '.$parser->namespaces['xsd']; global $SOAP_namespaces; $this->XMLSchemaVersion = $parser->namespaces['xsd']; $tmpNS = array_flip($SOAP_namespaces); $tmpNS['xsd'] = $this->XMLSchemaVersion; $tmpNS['xsi'] = $this->XMLSchemaVersion.'-instance'; $SOAP_namespaces = array_flip($tmpNS); }*/ if (strcasecmp(get_class($request_val), 'SOAP_Value') == 0) { // verify that SOAP_Value objects in request match the methods signature if ($this->verifyMethod($request_val)) { $this->debug("request data - name: {$request_val->name}, type: {$request_val->type}, value: {$request_val->value}"); // need to set special error detection inside the value class // so as to differentiate between no params passed, and an error decoding $request_data = $request_val->decode(); $this->debug($request_val->debug_data); $this->debug("request data: {$request_data}"); $this->debug("about to call method '{$this->methodname}'"); // if there are parameters to pass if ($request_data) { // call method with parameters $this->debug("calling '{$this->methodname}' with params"); if (is_object($this->soapobject)) { $method_response = call_user_func_array(array(&$this->soapobject, $this->methodname), $request_data); } else { $method_response = call_user_func_array($this->methodname, $request_data); } } else { // call method w/ no parameters $this->debug("calling {$this->methodname} w/ no params"); if (is_object($this->soapobject)) { $method_response = call_user_func(array(&$this->soapobject, $this->methodname)); } else { $method_response = call_user_func($this->methodname); } } $this->debug("done calling method: {$this->methodname}"); // if return val is SOAP_Message if (strcasecmp(get_class($method_response), 'SOAP_Message') == 0) { if (eregi('fault', $method_response->value->name)) { $this->fault = true; } $return_msg = $method_response; } else { // if return val is SOAP_Value object if (strcasecmp(get_class($method_response), 'SOAP_Value') == 0) { $return_val = array($method_response); // create soap_val object w/ return values from method, use method signature to determine type } else { $this->debug("creating new SOAP_Value to return, of type {$this->return_type}"); if (is_array($this->return_type) && is_array($method_response)) { $i = 0; foreach ($this->return_type as $key => $type) { if (is_numeric($key)) { $key = 'item'; } $return_val[] = new SOAP_Value($key, $type, $method_response[$i++]); } } else { $return_name = 'return'; if (is_array($this->return_type)) { $keys = array_keys($this->return_type); if (!is_numeric($keys[0])) { $return_name = $keys[0]; } $values = array_values($this->return_type); $this->return_type = $values[0]; } $return_val = array(new SOAP_Value($return_name, $this->return_type, $method_response)); } } if ($this->debug_flag) { $this->debug($return_val->debug_data); } $this->debug("creating return soap_msg object: " . $this->methodname . 'Response'); // response object is a soap_msg object $return_msg = new SOAP_Message($this->methodname . 'Response', $return_val, "{$this->service}"); } if ($this->debug_flag) { $return_msg->debug_flag = true; } $this->result = 'successful'; return $return_msg; } else { // debug $this->debug('ERROR: request not verified against method signature'); $this->result = 'fault: request failed validation against method signature'; // return soapresp return $this->fault(); } } else { // debug $this->debug("ERROR: parser did not return SOAP_Value object: {$request_val} " . get_class($request_val)); $this->result = "fault: parser did not return SOAP_Value object: {$request_val}"; // return fault $this->makeFault('Server', "parser did not return SOAP_Value object: {$request_val}"); return $this->fault(); } } }