/** * Log the last soap call as request and response XML files. * * @param \SoapClient $client * @param string $operation */ public function logSoapCall($client, $operation) { if (file_exists($this->path)) { $fileName = "ryanwinchester-netsuite-php-" . date("Ymd.His") . "-" . $operation; $logFile = $this->path . "/" . $fileName; // REQUEST $request = $logFile . "-request.xml"; $Handle = fopen($request, 'w'); $Data = $client->__getLastRequest(); $Data = cleanUpNamespaces($Data); $xml = simplexml_load_string($Data, 'SimpleXMLElement', LIBXML_NOCDATA); $privateFieldXpaths = array('//password', '//password2', '//currentPassword', '//newPassword', '//newPassword2', '//ccNumber', '//ccSecurityCode', '//socialSecurityNumber'); $privateFields = $xml->xpath(implode(" | ", $privateFieldXpaths)); foreach ($privateFields as &$field) { $field[0] = "[Content Removed for Security Reasons]"; } $stringCustomFields = $xml->xpath("//customField[@xsitype='StringCustomFieldRef']"); foreach ($stringCustomFields as $field) { $field->value = "[Content Removed for Security Reasons]"; } $xml_string = str_replace('xsitype', 'xsi:type', $xml->asXML()); fwrite($Handle, $xml_string); fclose($Handle); // RESPONSE $response = $logFile . "-response.xml"; $Handle = fopen($response, 'w'); $Data = $client->__getLastResponse(); fwrite($Handle, $Data); fclose($Handle); } }
public function prepSoapStringForLog($soapString) { $soapString = cleanUpNamespaces($soapString); $xml = simplexml_load_string($soapString, 'SimpleXMLElement', LIBXML_NOCDATA); $passwordFields = $xml->xpath("//password | //password2 | //currentPassword | //newPassword | //newPassword2 | //ccNumber | //ccSecurityCode | //socialSecurityNumber"); foreach ($passwordFields as &$pwdField) { (string) ($pwdField[0] = "[Content Removed for Security Reasons]"); } $stringCustomFields = $xml->xpath("//customField[@xsitype='StringCustomFieldRef']"); foreach ($stringCustomFields as $field) { (string) ($field->value = "[Content Removed for Security Reasons]"); } $xml_string = str_replace('xsitype', 'xsi:type', $xml->asXML()); return $xml_string; }
protected function makeSoapCall($operation, $parameter) { if ($this->userequest) { // use request level credentials, add passport as a SOAP header $this->addHeader("passport", $this->passport); // SoapClient, even with keep-alive set to false, keeps sending the JSESSIONID cookie back to the server on subsequent requests. Unsetting the cookie to prevent this. $this->client->__setCookie("JSESSIONID"); } else { $this->clearHeader("passport"); } $response = $this->client->__soapCall($operation, array($parameter), NULL, $this->soapHeaders); if (file_exists(dirname(__FILE__) . '/nslog')) { // log the request and response into the nslog directory. Code taken from PHP toolkit // REQUEST $req = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-request.xml"; $Handle = fopen($req, 'w'); $Data = $this->client->__getLastRequest(); $Data = cleanUpNamespaces($Data); $xml = simplexml_load_string($Data, 'SimpleXMLElement', LIBXML_NOCDATA); $passwordFields = $xml->xpath("//password | //password2 | //currentPassword | //newPassword | //newPassword2 | //ccNumber | //ccSecurityCode | //socialSecurityNumber"); foreach ($passwordFields as &$pwdField) { (string) ($pwdField[0] = "[Content Removed for Security Reasons]"); } $stringCustomFields = $xml->xpath("//customField[@xsitype='StringCustomFieldRef']"); foreach ($stringCustomFields as $field) { (string) ($field->value = "[Content Removed for Security Reasons]"); } $xml_string = str_replace('xsitype', 'xsi:type', $xml->asXML()); fwrite($Handle, $xml_string); fclose($Handle); // RESPONSE $resp = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-response.xml"; $Handle = fopen($resp, 'w'); $Data = $this->client->__getLastResponse(); fwrite($Handle, $Data); fclose($Handle); } return $response; }