SOAP请求发送完成的回调,记录花费时间

@param \Wei\Soap $soap
@param \SoapClient $soapClient
427736
public static function complete(\Wei\Soap $soap, \SoapClient $soapClient = null)
    {
        if ($soapClient && wei()->isDebug()) {
            wei()->logger->debug([
                'Request Body' => $soapClient->__getLastRequest(),
                'Response Body' => $soapClient->__getLastResponse(),
            ]);
        }
    }
158560
protected function connection()
	{
		if (empty($this->connection))
		{
			$this->connection = new \SoapClient($this->resource, $this->options);
		}

		return $this->connection;
	}
1304096
@SuppressWarnings("rawtypes")
	private static SOAPElement setParam(SOAPElement ele, String name, Object value, String prefix) {
		final SOAPElement childEle;
		try {
			if (StrUtil.isNotBlank(prefix)) {
				childEle = ele.addChildElement(name, prefix);
			} else {
				childEle = ele.addChildElement(name);
			}
		} catch (SOAPException e) {
			throw new SoapRuntimeException(e);
		}

		if (value instanceof CharSequence) {
			// 单个值
			childEle.setValue(value.toString());
		} else if (value instanceof SOAPElement) {
			// 单个子节点
			try {
				ele.addChildElement((SOAPElement) value);
			} catch (SOAPException e) {
				throw new SoapRuntimeException(e);
			}
		} else if (value instanceof Map) {
			// 多个字节点
			Entry entry;
			for (Object obj : ((Map) value).entrySet()) {
				entry = (Entry) obj;
				setParam(childEle, entry.getKey().toString(), entry.getValue(), prefix);
			}
		}
		return childEle;
	}
1374437
@Override
  public void clearHeaders(Stub soapClient) {
    soapClient._setProperty(HTTPConstants.REQUEST_HEADERS, new Hashtable<String, String>());
    soapClient.clearHeaders();
  }
603170
protected function initializeSoapClient()
    {
        $this->soap = new SoapClient(
            dirname(__FILE__) . '/assets/services.wsdl',
            array(
                'user' => $this->username,
                'password' => $this->password,
                'location' => 'https://' . $this->server . '/EWS/Exchange.asmx',
                'classmap' => $this->classMap(),
                'curlopts' => $this->curl_options,
                'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
            )
        );

        return $this->soap;
    }
478742
def soap_request(self, url, urn, action, params, body_elem="m"):
        """"""
        soap_body = (
            '<?xml version="1.0" encoding="utf-8"?>'
            '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"'
            ' s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'
            '<s:Body>'
            '<{body_elem}:{action} xmlns:{body_elem}="urn:{urn}">'
            '{params}'
            '</{body_elem}:{action}>'
            '</s:Body>'
            '</s:Envelope>'
        ).format(action=action, urn=urn, params=params, body_elem=body_elem).encode('utf-8')

        headers = {
            'Host': '{}:{}'.format(self._host, self._port),
            'Content-Length': len(soap_body),
            'Content-Type': 'text/xml; charset=utf-8"',
            'SOAPAction': '"urn:{}#{}"'.format(urn, action),
        }

        url = 'http://{}:{}/{}'.format(self._host, self._port, url)

        _LOGGER.debug("Sending to %s:\n%s\n%s", url, headers, soap_body)
        req = Request(url, soap_body, headers)

        res = urlopen(req, timeout=5).read()
        _LOGGER.debug("Response: %s", res)
        return res
1298276
public function call($functionname, $params) {
        if ($this->token) {
            $this->serverurl->param('wstoken', $this->token);
        }
        $this->serverurl->param('wsdl', 1);

        $opts = array(
            'http' => array(
                'user_agent' => 'Moodle SOAP Client'
            )
        );
        $context = stream_context_create($opts);
        $this->options['stream_context'] = $context;
        $this->options['cache_wsdl'] = WSDL_CACHE_NONE;

        $client = new SoapClient($this->serverurl->out(false), $this->options);

        return $client->__soapCall($functionname, $params);
    }
1345466
public function __soapCall($methodName, $arguments, $options = null, $inputHeaders = null, &$outputHeaders = null)
    {
        if ($this->isFinancialMethod($methodName, $arguments)) {
            $usedMethod = $methodName;

            if ($methodName === 'AccountManagement') {
                $usedMethod .= $arguments[0]->getAction();
            }

            $operationNum = time();
            $financeToken = $this->user->createFinanceToken($usedMethod, $operationNum);

            if (!is_array($inputHeaders)) {
                $inputHeaders = [];
            }

            $inputHeaders[] = new \SoapHeader('API', 'finance_token', $financeToken);
            $inputHeaders[] = new \SoapHeader('API', 'operation_num', $operationNum);
        }

        return parent::__soapCall($methodName, $arguments, $options, $inputHeaders, $outputHeaders);
    }
1327831
def send_using_soap(self, request, destination, headers=None, sign=False):
        

        # _response = self.server.post(soap_message, headers, path=path)
        try:
            args = self.use_soap(request, destination, headers, sign)
            args["headers"] = dict(args["headers"])
            response = self.send(**args)
        except Exception as exc:
            logger.info("HTTPClient exception: %s", exc)
            raise

        if response.status_code == 200:
            logger.info("SOAP response: %s", response.text)
            return response
        else:
            raise HTTPError("%d:%s" % (response.status_code, response.content))
684462
@Override
  public void clearHeaders(BindingProvider soapClient) {
    getContextHandlerFromClient(soapClient).clearHeaders();
    soapClient.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
        new HashMap<String, List<String>>());
  }
718216
@Override
  public Object getHeader(BindingProvider soapClient, String headerName) {
    for (SOAPElement addedHeader : getContextHandlerFromClient(soapClient).getAddedHeaders()) {
      if (addedHeader.getNodeName().equals(headerName)) {
        return addedHeader;
      }
    }
    return null;
  }
847581
public function __soapCall(
        $function_name,
        $arguments,
        $options = null,
        $input_headers = null,
        &$output_headers = null
    ) {
        $class = get_class($this);


        $service = strtr(substr($class, strrpos($class, '\\') + 1), ['ServiceService' => 'Service']);
        $this->__setCookie('timestamp', $timestamp = time());
        $this->__setCookie('nonce', $nonce = uniqid('', true));
        $this->__setCookie('signature', $this->urlEncode($this->sign(array_merge($arguments, [
            '__method' => $function_name,
            '__service' => $service,
            '__hostname' => $this->endpoint,
            '__timestamp' => $timestamp,
            '__nonce' => $nonce,

        ]))));
        return parent::__soapCall($function_name, $arguments, $options, $input_headers, $output_headers);
    }
1300649
protected function performSoapRequest($function, $params)
  {
    if (true ===  $this->requestConfig['requestDelay']) {
      sleep(1);
    }

    $soapClient = new SoapClient(
      $this->webserviceWsdl,
      array('exceptions' => 1)
    );

    $soapClient->__setLocation(str_replace(
      '%%COUNTRY%%',
      $this->responseConfig['country'],
      $this->webserviceEndpoint
    ));

    $soapClient->__setSoapHeaders($this->buildSoapHeader($function));

    return $soapClient->__soapCall($function, array($params));
  }
1368385
def soap_action(self, service, action, payloadbody):
        
        payload = self.soapenvelope.format(body=payloadbody).encode('utf-8')
        headers = ['SOAPAction: ' + action,
                   'Content-Type: application/soap+xml; charset=UTF-8',
                   'Content-Length: ' + str(len(payload))]

        try:
            curl = pycurl.Curl()
            curl.setopt(pycurl.SSL_CIPHER_LIST, "AES256-SHA")
            curl.setopt(pycurl.SSLVERSION, pycurl.SSLVERSION_TLSv1_0)
    #        self.curl.setopt(pycurl.CAINFO,'ihc.crt')
            curl.setopt(pycurl.SSL_VERIFYPEER, 0)
            curl.setopt(pycurl.SSL_VERIFYHOST, 0)
            curl.setopt(pycurl.POST, 1)
            curl.setopt(pycurl.HEADERFUNCTION, IHCCurlConnection._write_header)

            curl.setopt(pycurl.HTTPHEADER, headers)
            inbuffer = BytesIO(payload)
            curl.setopt(pycurl.READDATA, inbuffer)
            buffer = BytesIO()
            curl.setopt(pycurl.WRITEDATA, buffer)
            curl.setopt(pycurl.URL, self.url + service)
            curl.setopt(pycurl.COOKIE, IHCCurlConnection.cookies)
    #        curl.setopt(pycurl.VERBOSE,1)
            curl.perform()
            body = buffer.getvalue().decode('utf-8')
            code = curl.getinfo(pycurl.HTTP_CODE)
            curl.close()
        except Exception as exp:
            return False
        if code != 200:
            return False
        try:
            xdoc = xml.etree.ElementTree.fromstring(body)
        except xml.etree.ElementTree.ParseError:
            return False
        return xdoc
987929
protected function createWSDL_binding()
    {
        /*
        <binding name="myServiceBinding" type="typens:myServicePort">
            <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
                <operation name="hello">
                    <soap:operation soapAction="urn:myServiceAction"/>
                    <input>
                        <soap:body use="encoded" namespace="urn:myService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                    </input>
                    <output>
                        <soap:body use="encoded" namespace="urn:myService" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                    </output>
            </operation>
        </binding>
        */
        $binding = $this->wsdl->createElement('binding');
        $binding->setAttribute('name', $this->wsdlclassname . 'Binding');
        $binding->setAttribute('type', 'typens:' . $this->wsdlclassname . 'Port');
        $soap_binding = $this->wsdl->createElement('soap:binding');
        $soap_binding->setAttribute('style', 'rpc');
        $soap_binding->setAttribute('transport', self::SCHEMA_SOAP_HTTP);
        $binding->appendChild($soap_binding);
        foreach ($this->wsdlStruct[$this->wsdlclassname]['method'] as $name => $vars) {
            $operation = $this->wsdl->createElement('operation');
            $operation->setAttribute('name', $name);
            $binding->appendChild($operation);
            $soap_operation = $this->wsdl->createElement('soap:operation');
            $soap_operation->setAttribute(
                'soapAction',
                'urn:'.$this->wsdlclassname.'Action'
            );
            $operation->appendChild($soap_operation);
            $input  = $this->wsdl->createElement('input');
            $output = $this->wsdl->createElement('output');
            $operation->appendChild($input);
            $operation->appendChild($output);
            $soap_body = $this->wsdl->createElement('soap:body');
            $soap_body->setAttribute('use', 'encoded');
            $soap_body->setAttribute('namespace', 'urn:'.$this->namespace);
            $soap_body->setAttribute('encodingStyle', self::SOAP_SCHEMA_ENCODING);
            $input->appendChild($soap_body);
            $soap_body = $this->wsdl->createElement('soap:body');
            $soap_body->setAttribute('use', 'encoded');
            $soap_body->setAttribute('namespace', 'urn:'.$this->namespace);
            $soap_body->setAttribute('encodingStyle', self::SOAP_SCHEMA_ENCODING);
            $output->appendChild($soap_body);
        }
        $this->wsdl_definitions->appendChild($binding);
    }
208921
public function request($class, $service, $method, $arguments = [])
    {
        // Get WSDL URL
        $wsdl = $this->getWsdlUri($class);

        // Init SOAP client
        $this->client = new SoapClient($wsdl, [
            'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
            'trace' => true,
            'exceptions' => true,
            'cache_wsdl' => WSDL_CACHE_MEMORY,
        ]);

        // Add authentication to the query
        $request = $this->addAuthHeader($arguments);

        $result = $this->client->__soapcall($service, array($method => $request));

        if (!isset($result->ReturnValue)) {
            return;
        } else {
            // If more than one, return all return values
            if (is_array($result->ReturnValue) && count($result->ReturnValue) > 1) {
                return $result;
            } else {
                return $result->ReturnValue;
            }
        }
    }
1206036
def use_soap(self, request, destination="", soap_headers=None, sign=False,
                 **kwargs):
        
        headers = [("content-type", "application/soap+xml")]

        soap_message = make_soap_enveloped_saml_thingy(request, soap_headers)

        logger.debug("SOAP message: %s", soap_message)

        if sign and self.sec:
            _signed = self.sec.sign_statement(soap_message,
                                              class_name=class_name(request),
                                              node_id=request.id)
            soap_message = _signed

        return {"url": destination, "method": "POST",
                "data": soap_message, "headers": headers}