Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
6970b7bbef | |||
b650254d54 | |||
668f2dd258 |
@ -21,6 +21,16 @@
|
|||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory>src</directory>
|
||||||
|
<exclude>
|
||||||
|
<directory>src/BeSimple/SoapBundle</directory>
|
||||||
|
<directory>src/BeSimple/SoapCommon/Type</directory>
|
||||||
|
</exclude>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
|
||||||
<logging>
|
<logging>
|
||||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
|
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
|
||||||
<log type="coverage-clover" target="cache/clover.xml"/>
|
<log type="coverage-clover" target="cache/clover.xml"/>
|
||||||
|
@ -95,7 +95,7 @@ class SoapClient extends \SoapClient
|
|||||||
|
|
||||||
} catch (SoapFault $soapFault) {
|
} catch (SoapFault $soapFault) {
|
||||||
if (SoapFaultSourceGetter::isNativeSoapFault($soapFault)) {
|
if (SoapFaultSourceGetter::isNativeSoapFault($soapFault)) {
|
||||||
$soapFault = $this->decorateNativeSoapFault($soapFault);
|
$soapFault = $this->decorateNativeSoapFaultWithSoapResponseTracingData($soapFault);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $soapFault;
|
throw $soapFault;
|
||||||
@ -257,6 +257,23 @@ class SoapClient extends \SoapClient
|
|||||||
return $loadedWsdlFilePath;
|
return $loadedWsdlFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getHttpHeadersBySoapVersion(SoapRequest $soapRequest)
|
||||||
|
{
|
||||||
|
if ($soapRequest->getVersion() === SOAP_1_1) {
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Content-Type: ' . $soapRequest->getContentType(),
|
||||||
|
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
||||||
|
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Content-Type: ' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
||||||
|
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
private function getAttachmentFilters()
|
private function getAttachmentFilters()
|
||||||
{
|
{
|
||||||
$filters = [];
|
$filters = [];
|
||||||
@ -277,7 +294,6 @@ class SoapClient extends \SoapClient
|
|||||||
array $soapAttachments = []
|
array $soapAttachments = []
|
||||||
) {
|
) {
|
||||||
if ($this->soapClientOptions->getTrace() === true) {
|
if ($this->soapClientOptions->getTrace() === true) {
|
||||||
|
|
||||||
return SoapResponseFactory::createWithTracingData(
|
return SoapResponseFactory::createWithTracingData(
|
||||||
$soapRequest,
|
$soapRequest,
|
||||||
$curlResponse->getResponseBody(),
|
$curlResponse->getResponseBody(),
|
||||||
@ -288,10 +304,8 @@ class SoapClient extends \SoapClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
return SoapResponseFactory::create(
|
return SoapResponseFactory::create(
|
||||||
|
$soapRequest,
|
||||||
$curlResponse->getResponseBody(),
|
$curlResponse->getResponseBody(),
|
||||||
$soapRequest->getLocation(),
|
|
||||||
$soapRequest->getAction(),
|
|
||||||
$soapRequest->getVersion(),
|
|
||||||
$curlResponse->getHttpResponseContentType(),
|
$curlResponse->getHttpResponseContentType(),
|
||||||
$soapAttachments
|
$soapAttachments
|
||||||
);
|
);
|
||||||
@ -320,68 +334,43 @@ class SoapClient extends \SoapClient
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function decorateNativeSoapFault(SoapFault $nativePhpSoapFault)
|
private function decorateNativeSoapFaultWithSoapResponseTracingData(SoapFault $nativePhpSoapFault)
|
||||||
{
|
{
|
||||||
$soapResponse = $this->getSoapResponseFromStorage();
|
return $this->throwSoapFaultByTracing(
|
||||||
if ($soapResponse instanceof SoapResponse) {
|
$nativePhpSoapFault->faultcode,
|
||||||
$soapFault = $this->throwSoapFaultByTracing(
|
$nativePhpSoapFault->getMessage(),
|
||||||
SoapFaultPrefixEnum::PREFIX_PHP . '-' . $nativePhpSoapFault->getCode(),
|
$this->getSoapResponseTracingDataFromNativeSoapFaultOrStorage($nativePhpSoapFault)
|
||||||
$nativePhpSoapFault->getMessage(),
|
);
|
||||||
$this->getSoapResponseTracingDataFromNativeSoapFault(
|
|
||||||
$nativePhpSoapFault,
|
|
||||||
new SoapResponseTracingData(
|
|
||||||
'Content-Type: '.$soapResponse->getRequest()->getContentType(),
|
|
||||||
$soapResponse->getRequest()->getContent(),
|
|
||||||
'Content-Type: '.$soapResponse->getContentType(),
|
|
||||||
$soapResponse->getResponseContent()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$soapFault = $this->throwSoapFaultByTracing(
|
|
||||||
$nativePhpSoapFault->faultcode,
|
|
||||||
$nativePhpSoapFault->getMessage(),
|
|
||||||
$this->getSoapResponseTracingDataFromNativeSoapFault(
|
|
||||||
$nativePhpSoapFault,
|
|
||||||
new SoapResponseTracingData(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $soapFault;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSoapResponseTracingDataFromNativeSoapFault(
|
private function getSoapResponseTracingDataFromNativeSoapFaultOrStorage(SoapFault $nativePhpSoapFault)
|
||||||
SoapFault $nativePhpSoapFault,
|
{
|
||||||
SoapResponseTracingData $defaultSoapFaultTracingData
|
|
||||||
) {
|
|
||||||
if ($nativePhpSoapFault instanceof SoapFaultWithTracingData) {
|
if ($nativePhpSoapFault instanceof SoapFaultWithTracingData) {
|
||||||
|
|
||||||
return $nativePhpSoapFault->getSoapResponseTracingData();
|
return $nativePhpSoapFault->getSoapResponseTracingData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $defaultSoapFaultTracingData;
|
return $this->getSoapResponseTracingDataFromRequestStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getHttpHeadersBySoapVersion(SoapRequest $soapRequest)
|
private function getSoapResponseTracingDataFromRequestStorage()
|
||||||
{
|
{
|
||||||
if ($soapRequest->getVersion() === SOAP_1_1) {
|
$lastResponseHeaders = $lastResponse = $lastRequestHeaders = $lastRequest = null;
|
||||||
|
$soapResponse = $this->getSoapResponseFromStorage();
|
||||||
|
if ($soapResponse instanceof SoapResponse) {
|
||||||
|
$lastResponseHeaders = 'Content-Type: ' . $soapResponse->getContentType();
|
||||||
|
$lastResponse = $soapResponse->getResponseContent();
|
||||||
|
|
||||||
return [
|
if ($soapResponse->hasRequest() === true) {
|
||||||
'Content-Type: ' . $soapRequest->getContentType(),
|
$lastRequestHeaders = 'Content-Type: ' . $soapResponse->getRequest()->getContentType();
|
||||||
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
$lastRequest = $soapResponse->getRequest()->getContent();
|
||||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
}
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return new SoapResponseTracingData(
|
||||||
'Content-Type: ' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
$lastRequestHeaders,
|
||||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
$lastRequest,
|
||||||
];
|
$lastResponseHeaders,
|
||||||
|
$lastResponse
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class SoapClientOptionsBuilder
|
|||||||
public static function createWithDefaults()
|
public static function createWithDefaults()
|
||||||
{
|
{
|
||||||
return new SoapClientOptions(
|
return new SoapClientOptions(
|
||||||
SoapClientOptions::SOAP_CLIENT_TRACE_OFF,
|
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
|
||||||
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||||
CurlOptions::DEFAULT_USER_AGENT,
|
CurlOptions::DEFAULT_USER_AGENT,
|
||||||
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE
|
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE
|
||||||
|
@ -44,6 +44,11 @@ class SoapResponse extends CommonSoapResponse
|
|||||||
$this->tracingData = $tracingData;
|
$this->tracingData = $tracingData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function hasRequest()
|
||||||
|
{
|
||||||
|
return $this->request !== null;
|
||||||
|
}
|
||||||
|
|
||||||
public function setRequest(SoapRequest $request)
|
public function setRequest(SoapRequest $request)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
@ -27,27 +27,24 @@ class SoapResponseFactory
|
|||||||
/**
|
/**
|
||||||
* Factory method for SoapClient\SoapResponse.
|
* Factory method for SoapClient\SoapResponse.
|
||||||
*
|
*
|
||||||
|
* @param SoapRequest $soapRequest related request object
|
||||||
* @param string $content Content
|
* @param string $content Content
|
||||||
* @param string $location Location
|
|
||||||
* @param string $action SOAP action
|
|
||||||
* @param string $version SOAP version
|
|
||||||
* @param string $contentType Content type header
|
* @param string $contentType Content type header
|
||||||
* @param SoapAttachment[] $attachments SOAP attachments
|
* @param SoapAttachment[] $attachments SOAP attachments
|
||||||
* @return SoapResponse
|
* @return SoapResponse
|
||||||
*/
|
*/
|
||||||
public static function create(
|
public static function create(
|
||||||
|
SoapRequest $soapRequest,
|
||||||
$content,
|
$content,
|
||||||
$location,
|
|
||||||
$action,
|
|
||||||
$version,
|
|
||||||
$contentType,
|
$contentType,
|
||||||
array $attachments = []
|
array $attachments = []
|
||||||
) {
|
) {
|
||||||
$response = new SoapResponse();
|
$response = new SoapResponse();
|
||||||
|
$response->setRequest($soapRequest);
|
||||||
$response->setContent($content);
|
$response->setContent($content);
|
||||||
$response->setLocation($location);
|
$response->setLocation($soapRequest->getLocation());
|
||||||
$response->setAction($action);
|
$response->setAction($soapRequest->getAction());
|
||||||
$response->setVersion($version);
|
$response->setVersion($soapRequest->getVersion());
|
||||||
$response->setContentType($contentType);
|
$response->setContentType($contentType);
|
||||||
if (count($attachments) > 0) {
|
if (count($attachments) > 0) {
|
||||||
$response->setAttachments(
|
$response->setAttachments(
|
||||||
@ -82,9 +79,7 @@ class SoapResponseFactory
|
|||||||
$response->setAction($soapRequest->getAction());
|
$response->setAction($soapRequest->getAction());
|
||||||
$response->setVersion($soapRequest->getVersion());
|
$response->setVersion($soapRequest->getVersion());
|
||||||
$response->setContentType($contentType);
|
$response->setContentType($contentType);
|
||||||
if ($tracingData !== null) {
|
$response->setTracingData($tracingData);
|
||||||
$response->setTracingData($tracingData);
|
|
||||||
}
|
|
||||||
if (count($attachments) > 0) {
|
if (count($attachments) > 0) {
|
||||||
$response->setAttachments(
|
$response->setAttachments(
|
||||||
PartFactory::createAttachmentParts($attachments)
|
PartFactory::createAttachmentParts($attachments)
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
namespace BeSimple\SoapClient;
|
namespace BeSimple\SoapClient;
|
||||||
|
|
||||||
use BeSimple\SoapClient\Curl\Curl;
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\Xml\RemoteFileResolver;
|
||||||
|
use BeSimple\SoapClient\Xml\XmlFileDomDocumentProcessor;
|
||||||
use BeSimple\SoapCommon\Cache;
|
use BeSimple\SoapCommon\Cache;
|
||||||
use BeSimple\SoapCommon\Helper;
|
use BeSimple\SoapCommon\Helper;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
@ -30,6 +32,11 @@ use Exception;
|
|||||||
*/
|
*/
|
||||||
class WsdlDownloader
|
class WsdlDownloader
|
||||||
{
|
{
|
||||||
|
public static function instantiateDownloader()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Curl $curl
|
* @param Curl $curl
|
||||||
* @param string $wsdlPath WSDL file URL/path
|
* @param string $wsdlPath WSDL file URL/path
|
||||||
@ -39,10 +46,10 @@ class WsdlDownloader
|
|||||||
*/
|
*/
|
||||||
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
|
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
|
||||||
{
|
{
|
||||||
$isRemoteFile = $this->isRemoteFile($wsdlPath);
|
$isRemoteFile = RemoteFileResolver::instantiateResolver()->isRemoteFile($wsdlPath);
|
||||||
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
|
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
|
||||||
if ($isCacheEnabled === true) {
|
if ($isCacheEnabled === true) {
|
||||||
$cacheFilePath = Cache::getDirectory().DIRECTORY_SEPARATOR.'wsdl_'.md5($wsdlPath).'.cache';
|
$cacheFilePath = Cache::getDirectory() . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdlPath) . '.cache';
|
||||||
$isCacheExisting = file_exists($cacheFilePath);
|
$isCacheExisting = file_exists($cacheFilePath);
|
||||||
if ($isCacheExisting) {
|
if ($isCacheExisting) {
|
||||||
$fileModificationTime = filemtime($cacheFilePath);
|
$fileModificationTime = filemtime($cacheFilePath);
|
||||||
@ -54,46 +61,17 @@ class WsdlDownloader
|
|||||||
$isCacheExisting = $isCacheValid = false;
|
$isCacheExisting = $isCacheValid = false;
|
||||||
}
|
}
|
||||||
if ($isCacheExisting === false || $isCacheValid === false) {
|
if ($isCacheExisting === false || $isCacheValid === false) {
|
||||||
$this->writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
|
XmlFileDomDocumentProcessor::writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getLocalWsdlPath($cacheFilePath);
|
return $this->getLocalWsdlPath($cacheFilePath);
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($isRemoteFile === true) {
|
|
||||||
return $wsdlPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getLocalWsdlPath($wsdlPath);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private function writeCacheFile(Curl $curl, $cacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile)
|
|
||||||
{
|
|
||||||
if ($isRemoteFile === true) {
|
if ($isRemoteFile === true) {
|
||||||
$curlResponse = $curl->executeCurlWithCachedSession($wsdlPath);
|
return $wsdlPath;
|
||||||
if ($curlResponse->curlStatusSuccess()) {
|
|
||||||
if (mb_strlen($curlResponse->getResponseBody()) === 0) {
|
|
||||||
throw new Exception('Could not write WSDL cache file: empty curl response from: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
if ($resolveRemoteIncludes === true) {
|
|
||||||
$document = $this->getXmlFileDomDocument($curl, $cacheType, $curlResponse->getResponseBody(), $wsdlPath);
|
|
||||||
$this->saveXmlDomDocument($document, $cacheFilePath);
|
|
||||||
} else {
|
|
||||||
file_put_contents($cacheFilePath, $curlResponse->getResponseBody());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Exception('Could not write WSDL cache file: Download failed with message: '.$curlResponse->getCurlErrorMessage());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (file_exists($wsdlPath)) {
|
|
||||||
$document = $this->getXmlFileDomDocument($curl, $cacheType, file_get_contents($wsdlPath));
|
|
||||||
$this->saveXmlDomDocument($document, $cacheFilePath);
|
|
||||||
} else {
|
|
||||||
throw new Exception('Could write WSDL cache file: local file does not exist: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->getLocalWsdlPath($wsdlPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLocalWsdlPath($wsdlPath)
|
private function getLocalWsdlPath($wsdlPath)
|
||||||
@ -104,164 +82,6 @@ class WsdlDownloader
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Exception('Could not download WSDL: local file does not exist: '.$wsdlPath);
|
throw new Exception('Could not download WSDL: local file does not exist: ' . $wsdlPath);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $wsdlPath File URL/path
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
private function isRemoteFile($wsdlPath)
|
|
||||||
{
|
|
||||||
$parsedUrlOrFalse = @parse_url($wsdlPath);
|
|
||||||
if ($parsedUrlOrFalse !== false) {
|
|
||||||
if (isset($parsedUrlOrFalse['scheme']) && substr($parsedUrlOrFalse['scheme'], 0, 4) === 'http') {
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception('Could not determine wsdlPath is remote: '.$wsdlPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves remote WSDL/XSD includes within the WSDL files.
|
|
||||||
*
|
|
||||||
* @param Curl $curl
|
|
||||||
* @param int $cacheType
|
|
||||||
* @param string $xmlFileSource XML file contents
|
|
||||||
* @param boolean $parentFilePath Parent file name
|
|
||||||
* @return DOMDocument
|
|
||||||
*/
|
|
||||||
private function getXmlFileDomDocument(Curl $curl, $cacheType, $xmlFileSource, $parentFilePath = null)
|
|
||||||
{
|
|
||||||
$document = new DOMDocument('1.0', 'utf-8');
|
|
||||||
if ($document->loadXML($xmlFileSource) === false) {
|
|
||||||
throw new Exception('Could not save downloaded WSDL cache: '.$xmlFileSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
$xpath = new DOMXPath($document);
|
|
||||||
$this->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_WSDL, Helper::NS_WSDL, 'location', $parentFilePath);
|
|
||||||
$this->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA, 'schemaLocation', $parentFilePath);
|
|
||||||
|
|
||||||
return $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saveXmlDomDocument(DOMDocument $document, $cacheFilePath)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$xmlContents = $document->saveXML();
|
|
||||||
if ($xmlContents === '') {
|
|
||||||
throw new Exception('Could not write WSDL cache file: DOMDocument returned empty XML file');
|
|
||||||
}
|
|
||||||
file_put_contents($cacheFilePath, $xmlContents);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
unlink($cacheFilePath);
|
|
||||||
throw new Exception('Could not write WSDL cache file: save method returned error: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function updateXmlDocument(
|
|
||||||
Curl $curl,
|
|
||||||
$cacheType,
|
|
||||||
DOMXPath $xpath,
|
|
||||||
$schemaPrefix,
|
|
||||||
$schemaUrl,
|
|
||||||
$locationAttributeName,
|
|
||||||
$parentFilePath = null
|
|
||||||
) {
|
|
||||||
$xpath->registerNamespace($schemaPrefix, $schemaUrl);
|
|
||||||
$nodes = $xpath->query('.//'.$schemaPrefix.':include | .//'.$schemaPrefix.':import');
|
|
||||||
if ($nodes->length > 0) {
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
/** @var DOMElement $node */
|
|
||||||
$locationPath = $node->getAttribute($locationAttributeName);
|
|
||||||
if ($locationPath !== '') {
|
|
||||||
if ($this->isRemoteFile($locationPath)) {
|
|
||||||
$node->setAttribute(
|
|
||||||
$locationAttributeName,
|
|
||||||
$this->getWsdlPath(
|
|
||||||
$curl,
|
|
||||||
$locationPath,
|
|
||||||
$cacheType,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} elseif ($parentFilePath !== null) {
|
|
||||||
$node->setAttribute(
|
|
||||||
$locationAttributeName,
|
|
||||||
$this->getWsdlPath(
|
|
||||||
$curl,
|
|
||||||
$this->resolveRelativePathInUrl($parentFilePath, $locationPath),
|
|
||||||
$cacheType,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resolves the relative path to base into an absolute.
|
|
||||||
*
|
|
||||||
* @param string $base Base path
|
|
||||||
* @param string $relative Relative path
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function resolveRelativePathInUrl($base, $relative)
|
|
||||||
{
|
|
||||||
$urlParts = parse_url($base);
|
|
||||||
|
|
||||||
// combine base path with relative path
|
|
||||||
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && '/' === $relative{0}) {
|
|
||||||
// $relative is absolute path from domain (starts with /)
|
|
||||||
$path = $relative;
|
|
||||||
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
|
|
||||||
// base path is directory
|
|
||||||
$path = $urlParts['path'].$relative;
|
|
||||||
} elseif (isset($urlParts['path'])) {
|
|
||||||
// strip filename from base path
|
|
||||||
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
|
||||||
} else {
|
|
||||||
// no base path
|
|
||||||
$path = '/'.$relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
// foo/./bar ==> foo/bar
|
|
||||||
// remove double slashes
|
|
||||||
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
|
|
||||||
|
|
||||||
// split path by '/'
|
|
||||||
$parts = explode('/', $path);
|
|
||||||
|
|
||||||
// resolve /../
|
|
||||||
foreach ($parts as $key => $part) {
|
|
||||||
if ($part === '..') {
|
|
||||||
$keyToDelete = $key - 1;
|
|
||||||
while ($keyToDelete > 0) {
|
|
||||||
if (isset($parts[$keyToDelete])) {
|
|
||||||
unset($parts[$keyToDelete]);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$keyToDelete--;
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($parts[$key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
|
|
||||||
if (isset($urlParts['port'])) {
|
|
||||||
$hostname .= ':'.$urlParts['port'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $hostname.implode('/', $parts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
75
src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php
Normal file
75
src/BeSimple/SoapClient/Xml/Path/RelativePathResolver.php
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml\Path;
|
||||||
|
|
||||||
|
class RelativePathResolver
|
||||||
|
{
|
||||||
|
public static function instantiateResolver()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the relative path to base into an absolute.
|
||||||
|
*
|
||||||
|
* @param string $base Base path
|
||||||
|
* @param string $relative Relative path
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function resolveRelativePathInUrl($base, $relative)
|
||||||
|
{
|
||||||
|
$urlParts = parse_url($base);
|
||||||
|
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..');
|
||||||
|
|
||||||
|
// combine base path with relative path
|
||||||
|
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) {
|
||||||
|
// $relative is absolute path from domain (starts with /)
|
||||||
|
$path = $relative;
|
||||||
|
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
|
||||||
|
// base path is directory
|
||||||
|
$path = $urlParts['path'].$relative;
|
||||||
|
} elseif (isset($urlParts['path'])) {
|
||||||
|
// strip filename from base path
|
||||||
|
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
||||||
|
} else {
|
||||||
|
// no base path
|
||||||
|
$path = '/'.$relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
// foo/./bar ==> foo/bar
|
||||||
|
// remove double slashes
|
||||||
|
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
|
||||||
|
|
||||||
|
// split path by '/'
|
||||||
|
$parts = explode('/', $path);
|
||||||
|
|
||||||
|
// resolve /../
|
||||||
|
foreach ($parts as $key => $part) {
|
||||||
|
if ($part === '..') {
|
||||||
|
$keyToDelete = $key - 1;
|
||||||
|
while ($keyToDelete > 0) {
|
||||||
|
if (isset($parts[$keyToDelete])) {
|
||||||
|
unset($parts[$keyToDelete]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keyToDelete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($parts[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
|
||||||
|
if (isset($urlParts['port'])) {
|
||||||
|
$hostname .= ':'.$urlParts['port'];
|
||||||
|
}
|
||||||
|
$implodedParts = implode('/', $parts);
|
||||||
|
if (substr($implodedParts, 0, 1) !== '/') {
|
||||||
|
$implodedParts = '/'.$implodedParts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hostname.$implodedParts;
|
||||||
|
}
|
||||||
|
}
|
32
src/BeSimple/SoapClient/Xml/RemoteFileResolver.php
Normal file
32
src/BeSimple/SoapClient/Xml/RemoteFileResolver.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class RemoteFileResolver
|
||||||
|
{
|
||||||
|
public static function instantiateResolver()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $wsdlPath File URL/path
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isRemoteFile($wsdlPath)
|
||||||
|
{
|
||||||
|
$parsedUrlOrFalse = @parse_url($wsdlPath);
|
||||||
|
if ($parsedUrlOrFalse !== false) {
|
||||||
|
if (isset($parsedUrlOrFalse['scheme']) && strpos($parsedUrlOrFalse['scheme'], 'http') === 0) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception('Could not determine wsdlPath is remote: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
}
|
122
src/BeSimple/SoapClient/Xml/XmlDomDocumentImportReplacer.php
Normal file
122
src/BeSimple/SoapClient/Xml/XmlDomDocumentImportReplacer.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\WsdlDownloader;
|
||||||
|
use DOMElement;
|
||||||
|
use DOMXPath;
|
||||||
|
|
||||||
|
class XmlDomDocumentImportReplacer
|
||||||
|
{
|
||||||
|
public static function instantiateReplacer()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateXmlDocument(
|
||||||
|
Curl $curl,
|
||||||
|
$cacheType,
|
||||||
|
DOMXPath $xpath,
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath = null
|
||||||
|
) {
|
||||||
|
$xpath->registerNamespace($schemaPrefix, $schemaUrl);
|
||||||
|
$nodes = $xpath->query('.//'.$schemaPrefix.':include | .//'.$schemaPrefix.':import');
|
||||||
|
if ($nodes->length > 0) {
|
||||||
|
foreach ($nodes as $node) {
|
||||||
|
/** @var DOMElement $node */
|
||||||
|
$locationPath = $node->getAttribute($locationAttributeName);
|
||||||
|
if ($locationPath !== '') {
|
||||||
|
if (RemoteFileResolver::instantiateResolver()->isRemoteFile($locationPath)) {
|
||||||
|
$node->setAttribute(
|
||||||
|
$locationAttributeName,
|
||||||
|
WsdlDownloader::instantiateDownloader()->getWsdlPath(
|
||||||
|
$curl,
|
||||||
|
$locationPath,
|
||||||
|
$cacheType,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} elseif ($parentFilePath !== null) {
|
||||||
|
$node->setAttribute(
|
||||||
|
$locationAttributeName,
|
||||||
|
WsdlDownloader::instantiateDownloader()->getWsdlPath(
|
||||||
|
$curl,
|
||||||
|
self::resolveRelativePathInUrl($parentFilePath, $locationPath),
|
||||||
|
$cacheType,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves the relative path to base into an absolute.
|
||||||
|
*
|
||||||
|
* @param string $base Base path
|
||||||
|
* @param string $relative Relative path
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function resolveRelativePathInUrl($base, $relative)
|
||||||
|
{
|
||||||
|
$urlParts = parse_url($base);
|
||||||
|
$isRelativePathAbsolute = 0 === strpos($relative, '/') || 0 === strpos($relative, '..');
|
||||||
|
|
||||||
|
// combine base path with relative path
|
||||||
|
if (isset($urlParts['path']) && mb_strlen($relative) > 0 && $isRelativePathAbsolute) {
|
||||||
|
// $relative is absolute path from domain (starts with /)
|
||||||
|
$path = $relative;
|
||||||
|
} elseif (isset($urlParts['path']) && strrpos($urlParts['path'], '/') === (strlen($urlParts['path']) )) {
|
||||||
|
// base path is directory
|
||||||
|
$path = $urlParts['path'].$relative;
|
||||||
|
} elseif (isset($urlParts['path'])) {
|
||||||
|
// strip filename from base path
|
||||||
|
$path = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')).'/'.$relative;
|
||||||
|
} else {
|
||||||
|
// no base path
|
||||||
|
$path = '/'.$relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
// foo/./bar ==> foo/bar
|
||||||
|
// remove double slashes
|
||||||
|
$path = preg_replace(array('#/\./#', '#/+#'), '/', $path);
|
||||||
|
|
||||||
|
// split path by '/'
|
||||||
|
$parts = explode('/', $path);
|
||||||
|
|
||||||
|
// resolve /../
|
||||||
|
foreach ($parts as $key => $part) {
|
||||||
|
if ($part === '..') {
|
||||||
|
$keyToDelete = $key - 1;
|
||||||
|
while ($keyToDelete > 0) {
|
||||||
|
if (isset($parts[$keyToDelete])) {
|
||||||
|
unset($parts[$keyToDelete]);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$keyToDelete--;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($parts[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostname = $urlParts['scheme'].'://'.$urlParts['host'];
|
||||||
|
if (isset($urlParts['port'])) {
|
||||||
|
$hostname .= ':'.$urlParts['port'];
|
||||||
|
}
|
||||||
|
if (substr($hostname, -1) !== '/') {
|
||||||
|
$hostname .= '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $hostname.implode('/', $parts);
|
||||||
|
}
|
||||||
|
}
|
77
src/BeSimple/SoapClient/Xml/XmlFileDomDocumentProcessor.php
Normal file
77
src/BeSimple/SoapClient/Xml/XmlFileDomDocumentProcessor.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapCommon\Helper;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class XmlFileDomDocumentProcessor
|
||||||
|
{
|
||||||
|
public static function writeCacheFile(Curl $curl, $cacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile)
|
||||||
|
{
|
||||||
|
if ($isRemoteFile === true) {
|
||||||
|
$curlResponse = $curl->executeCurlWithCachedSession($wsdlPath);
|
||||||
|
if ($curlResponse->curlStatusSuccess()) {
|
||||||
|
if (mb_strlen($curlResponse->getResponseBody()) === 0) {
|
||||||
|
throw new Exception('Could not write WSDL cache file: empty curl response from: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
if ($resolveRemoteIncludes === true) {
|
||||||
|
$document = self::getXmlFileDomDocument($curl, $cacheType, $curlResponse->getResponseBody(), $wsdlPath);
|
||||||
|
self::saveXmlDomDocument($document, $cacheFilePath);
|
||||||
|
} else {
|
||||||
|
file_put_contents($cacheFilePath, $curlResponse->getResponseBody());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception('Could not write WSDL cache file: Download failed with message: '.$curlResponse->getCurlErrorMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (file_exists($wsdlPath)) {
|
||||||
|
$document = self::getXmlFileDomDocument($curl, $cacheType, file_get_contents($wsdlPath));
|
||||||
|
self::saveXmlDomDocument($document, $cacheFilePath);
|
||||||
|
} else {
|
||||||
|
throw new Exception('Could write WSDL cache file: local file does not exist: '.$wsdlPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves remote WSDL/XSD includes within the WSDL files.
|
||||||
|
*
|
||||||
|
* @param Curl $curl
|
||||||
|
* @param int $cacheType
|
||||||
|
* @param string $xmlFileSource XML file contents
|
||||||
|
* @param boolean $parentFilePath Parent file name
|
||||||
|
* @return DOMDocument
|
||||||
|
*/
|
||||||
|
private static function getXmlFileDomDocument(Curl $curl, $cacheType, $xmlFileSource, $parentFilePath = null)
|
||||||
|
{
|
||||||
|
$document = new DOMDocument('1.0', 'utf-8');
|
||||||
|
if ($document->loadXML($xmlFileSource) === false) {
|
||||||
|
throw new Exception('Could not save downloaded WSDL cache: '.$xmlFileSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xpath = new DOMXPath($document);
|
||||||
|
$xmlDomDocumentImportReplacer = XmlDomDocumentImportReplacer::instantiateReplacer();
|
||||||
|
$xmlDomDocumentImportReplacer->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_WSDL, Helper::NS_WSDL, 'location', $parentFilePath);
|
||||||
|
$xmlDomDocumentImportReplacer->updateXmlDocument($curl, $cacheType, $xpath, Helper::PFX_XML_SCHEMA, Helper::NS_XML_SCHEMA, 'schemaLocation', $parentFilePath);
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function saveXmlDomDocument(DOMDocument $document, $cacheFilePath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$xmlContents = $document->saveXML();
|
||||||
|
if ($xmlContents === '') {
|
||||||
|
throw new Exception('Could not write WSDL cache file: DOMDocument returned empty XML file');
|
||||||
|
}
|
||||||
|
file_put_contents($cacheFilePath, $xmlContents);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
unlink($cacheFilePath);
|
||||||
|
throw new Exception('Could not write WSDL cache file: save method returned error: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml\Path;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class RelativePathResolverTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/** @var RelativePathResolver */
|
||||||
|
private $relativePathResolver;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->relativePathResolver = new RelativePathResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $base
|
||||||
|
* @param string $relative
|
||||||
|
* @param string $assertPath
|
||||||
|
* @dataProvider providePathInfo
|
||||||
|
*/
|
||||||
|
public function testResolveRelativePathInUrl($base, $relative, $assertPath)
|
||||||
|
{
|
||||||
|
$path = $this->relativePathResolver->resolveRelativePathInUrl($base, $relative);
|
||||||
|
|
||||||
|
self::assertEquals($assertPath, $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providePathInfo()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd/',
|
||||||
|
'Document1.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document1.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/',
|
||||||
|
'../Schemas/Common/Document2.xsd',
|
||||||
|
'http://endpoint-location.ltd:8080/Schemas/Common/Document2.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd/',
|
||||||
|
'../Schemas/Common/Document3.xsd',
|
||||||
|
'http://endpoint-location.ltd/Schemas/Common/Document3.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd/',
|
||||||
|
'/Document4.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document4.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd',
|
||||||
|
'/Document5.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document5.xsd',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'http://endpoint-location.ltd',
|
||||||
|
'Document6.xsd',
|
||||||
|
'http://endpoint-location.ltd/Document6.xsd',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
42
tests/BeSimple/SoapClient/Xml/RemoteFileResolverTest.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class RemoteFileResolverTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
const FILE_IS_REMOTE = true;
|
||||||
|
const FILE_IS_NOT_REMOTE = false;
|
||||||
|
|
||||||
|
/** @var RemoteFileResolver */
|
||||||
|
private $remoteFileResolver;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->remoteFileResolver = new RemoteFileResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $wsdlPath
|
||||||
|
* @param bool $assertIsRemoteFile
|
||||||
|
* @dataProvider provideWsdlPaths
|
||||||
|
*/
|
||||||
|
public function testIsRemoteFile($wsdlPath, $assertIsRemoteFile)
|
||||||
|
{
|
||||||
|
$isRemoteFile = $this->remoteFileResolver->isRemoteFile($wsdlPath);
|
||||||
|
|
||||||
|
self::assertEquals($assertIsRemoteFile, $isRemoteFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideWsdlPaths()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['http://endpoint.tld/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||||
|
['http://endpoint.tld:1944/path/to/wsdl.wsdl', self::FILE_IS_REMOTE],
|
||||||
|
['path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
['../../path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
['/path/to/wsdl.wsdl', self::FILE_IS_NOT_REMOTE],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BeSimple\SoapClient\Xml;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\Curl;
|
||||||
|
use BeSimple\SoapClient\Curl\CurlOptionsBuilder;
|
||||||
|
use BeSimple\SoapCommon\Cache;
|
||||||
|
use BeSimple\SoapCommon\Helper;
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMXPath;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class XmlDomDocumentImportReplacerTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
const NO_PARENT_FILE_PATH = null;
|
||||||
|
|
||||||
|
/** @var XmlDomDocumentImportReplacer */
|
||||||
|
private $xmlDomDocumentImportReplacer;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->xmlDomDocumentImportReplacer = new XmlDomDocumentImportReplacer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $xmlSource
|
||||||
|
* @param Curl $curl
|
||||||
|
* @param string $schemaPrefix
|
||||||
|
* @param string $schemaUrl
|
||||||
|
* @param string $locationAttributeName
|
||||||
|
* @param string|null $parentFilePath
|
||||||
|
* @param string|null $assertImportXmlSource
|
||||||
|
* @dataProvider provideXmlDocumentData
|
||||||
|
*/
|
||||||
|
public function testUpdateXmlDocument(
|
||||||
|
$xmlSource,
|
||||||
|
Curl $curl,
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath = null,
|
||||||
|
$assertImportXmlSource = null
|
||||||
|
) {
|
||||||
|
$wsdl = new DOMDocument();
|
||||||
|
$wsdl->loadXML($xmlSource);
|
||||||
|
|
||||||
|
$this->xmlDomDocumentImportReplacer->updateXmlDocument(
|
||||||
|
$curl,
|
||||||
|
Cache::TYPE_NONE,
|
||||||
|
new DOMXPath($wsdl),
|
||||||
|
$schemaPrefix,
|
||||||
|
$schemaUrl,
|
||||||
|
$locationAttributeName,
|
||||||
|
$parentFilePath
|
||||||
|
);
|
||||||
|
$wsdlSource = $wsdl->saveHTML();
|
||||||
|
|
||||||
|
self::assertContains(
|
||||||
|
$assertImportXmlSource,
|
||||||
|
$wsdlSource
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideXmlDocumentData()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'wsdlWithoutParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_WSDL,
|
||||||
|
Helper::NS_WSDL,
|
||||||
|
'location',
|
||||||
|
self::NO_PARENT_FILE_PATH,
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'schemaWithoutParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_XML_SCHEMA,
|
||||||
|
Helper::NS_XML_SCHEMA,
|
||||||
|
'schemaLocation',
|
||||||
|
self::NO_PARENT_FILE_PATH,
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'wsdlWithParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_WSDL,
|
||||||
|
Helper::NS_WSDL,
|
||||||
|
'location',
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/',
|
||||||
|
'<xs:include schemaLocation="../Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
'schemaWithParentPath' => [
|
||||||
|
file_get_contents(__DIR__.'/testUpdateXmlDocument.wsdl'),
|
||||||
|
new Curl(CurlOptionsBuilder::buildDefault()),
|
||||||
|
Helper::PFX_XML_SCHEMA,
|
||||||
|
Helper::NS_XML_SCHEMA,
|
||||||
|
'schemaLocation',
|
||||||
|
'http://endpoint-location.ltd:8080/endpoint/',
|
||||||
|
'<xs:include schemaLocation="http://endpoint-location.ltd:8080/Schemas/Common/Document1.xsd"></xs:include>'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
51
tests/BeSimple/SoapClient/Xml/testUpdateXmlDocument.wsdl
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<wsdl:definitions
|
||||||
|
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
|
||||||
|
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
|
||||||
|
xmlns:ns="http://location.ltd/namespace1"
|
||||||
|
xmlns:ns2="http://location.ltd/namespace2"
|
||||||
|
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||||
|
xmlns:tns="http://endpoint-location.tld:7654/ws"
|
||||||
|
xmlns:xs="http://www.w3.org/2001/XMLSchema" name="PushServerWSDL"
|
||||||
|
targetNamespace="http://location.ltd/target-namespace">
|
||||||
|
<wsdl:types>
|
||||||
|
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace1">
|
||||||
|
<xs:include schemaLocation="../Schemas/Common/Document1.xsd"/>
|
||||||
|
</xs:schema>
|
||||||
|
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://location.ltd/namespace2">
|
||||||
|
<xs:include schemaLocation="../Schemas/Common/Document2.xsd"/>
|
||||||
|
</xs:schema>
|
||||||
|
</wsdl:types>
|
||||||
|
<wsdl:message name="ServerHeader">
|
||||||
|
<wsdl:part element="ns:serverHeader" name="serverHeader"/>
|
||||||
|
</wsdl:message>
|
||||||
|
|
||||||
|
<wsdl:portType name="Server">
|
||||||
|
<wsdl:operation name="SendPushMessage">
|
||||||
|
<wsdl:documentation>TEST-OPERATION-1</wsdl:documentation>
|
||||||
|
<wsdl:input message="tns:SendPushMessageRequest" name="SendPushMessageRequest"/>
|
||||||
|
<wsdl:output message="tns:SendPushMessageResponse" name="SendPushMessageResponse"/>
|
||||||
|
<wsdl:fault message="tns:SystemFault" name="systemFault"/>
|
||||||
|
</wsdl:operation>
|
||||||
|
</wsdl:portType>
|
||||||
|
<wsdl:binding name="ServerBinding" type="tns:Server">
|
||||||
|
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
|
||||||
|
<wsdl:operation name="DummyMethod">
|
||||||
|
<soap:operation soapAction="http://endpoint-location.tld:7654/ep/v1" style="document"/>
|
||||||
|
<wsdl:input name="DummyMethodRequest">
|
||||||
|
<soap:body use="literal"/>
|
||||||
|
</wsdl:input>
|
||||||
|
<wsdl:output name="DummyMethodResponse">
|
||||||
|
<soap:body use="literal"/>
|
||||||
|
</wsdl:output>
|
||||||
|
<wsdl:fault name="soapServerFault">
|
||||||
|
<soap:fault name="soapServerFault" use="literal"/>
|
||||||
|
</wsdl:fault>
|
||||||
|
</wsdl:operation>
|
||||||
|
</wsdl:binding>
|
||||||
|
<wsdl:service name="ServerServices">
|
||||||
|
<wsdl:port binding="tns:ServerBinding" name="ServerServicesEndpoint">
|
||||||
|
<soap:address location="http://endpoint-location.tld:7654/ws/"/>
|
||||||
|
</wsdl:port>
|
||||||
|
</wsdl:service>
|
||||||
|
</wsdl:definitions>
|
@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
namespace BeSimple;
|
namespace BeSimple;
|
||||||
|
|
||||||
|
use BeSimple\SoapClient\Curl\CurlOptions;
|
||||||
use BeSimple\SoapClient\SoapClientBuilder;
|
use BeSimple\SoapClient\SoapClientBuilder;
|
||||||
use BeSimple\SoapClient\SoapClientOptionsBuilder;
|
use BeSimple\SoapClient\SoapClientOptionsBuilder;
|
||||||
use BeSimple\SoapClient\SoapFaultWithTracingData;
|
use BeSimple\SoapClient\SoapFaultWithTracingData;
|
||||||
|
use BeSimple\SoapClient\SoapOptions\SoapClientOptions;
|
||||||
use BeSimple\SoapCommon\ClassMap;
|
use BeSimple\SoapCommon\ClassMap;
|
||||||
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||||
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
||||||
@ -34,6 +36,55 @@ class SoapServerAndSoapClientCommunicationSoapFaultsTest extends PHPUnit_Framewo
|
|||||||
pclose($this->localWebServerProcess);
|
pclose($this->localWebServerProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSoapCallSwaWithLargeSwaResponseWithSoapFaultAndTracingOff()
|
||||||
|
{
|
||||||
|
$soapClient = $this->getSoapClientBuilder()->buildWithSoapHeader(
|
||||||
|
new SoapClientOptions(
|
||||||
|
SoapClientOptions::SOAP_CLIENT_TRACE_OFF,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||||
|
CurlOptions::DEFAULT_USER_AGENT,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_AUTHENTICATION_NONE,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
|
||||||
|
self::TEST_HTTP_URL.'/SwaSenderSoapFaultEndpoint.php'
|
||||||
|
),
|
||||||
|
SoapOptionsBuilder::createSwaWithClassMap(
|
||||||
|
self::TEST_HTTP_URL.'/SwaSenderEndpoint.php?wsdl',
|
||||||
|
new ClassMap([
|
||||||
|
'GenerateTestRequest' => GenerateTestRequest::class,
|
||||||
|
]),
|
||||||
|
SoapOptions::SOAP_CACHE_TYPE_NONE
|
||||||
|
),
|
||||||
|
new SoapHeader('http://schema.testcase', 'SoapHeader', [
|
||||||
|
'user' => 'admin',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->setExpectedException(SoapFault::class);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$soapClient->soapCall('dummyServiceMethodWithOutgoingLargeSwa', []);
|
||||||
|
} catch (SoapFault $e) {
|
||||||
|
self::assertNotInstanceOf(
|
||||||
|
SoapFaultWithTracingData::class,
|
||||||
|
$e,
|
||||||
|
'SoapClient must not return tracing data when SoapClientOptions::trace is off.'
|
||||||
|
);
|
||||||
|
self::assertEquals(
|
||||||
|
'911',
|
||||||
|
$e->faultcode
|
||||||
|
);
|
||||||
|
self::assertContains(
|
||||||
|
'with HTTP response code 500 with Message: This is a dummy SoapFault. and Code: 911',
|
||||||
|
$e->getMessage()
|
||||||
|
);
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
self::fail('Expected SoapFault was not thrown');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSoapCallSwaWithLargeSwaResponseWithSoapFault()
|
public function testSoapCallSwaWithLargeSwaResponseWithSoapFault()
|
||||||
{
|
{
|
||||||
$soapClient = $this->getSoapClientBuilder()->buildWithSoapHeader(
|
$soapClient = $this->getSoapClientBuilder()->buildWithSoapHeader(
|
||||||
@ -59,7 +110,8 @@ class SoapServerAndSoapClientCommunicationSoapFaultsTest extends PHPUnit_Framewo
|
|||||||
} catch (SoapFault $e) {
|
} catch (SoapFault $e) {
|
||||||
self::assertInstanceOf(
|
self::assertInstanceOf(
|
||||||
SoapFaultWithTracingData::class,
|
SoapFaultWithTracingData::class,
|
||||||
$e
|
$e,
|
||||||
|
'SoapClient must return tracing data when SoapClientOptions::trace is on.'
|
||||||
);
|
);
|
||||||
/** @var SoapFaultWithTracingData $e */
|
/** @var SoapFaultWithTracingData $e */
|
||||||
self::assertEquals(
|
self::assertEquals(
|
||||||
|
@ -3,12 +3,15 @@
|
|||||||
namespace BeSimple;
|
namespace BeSimple;
|
||||||
|
|
||||||
use BeSimple\SoapBundle\Soap\SoapAttachment;
|
use BeSimple\SoapBundle\Soap\SoapAttachment;
|
||||||
|
use BeSimple\SoapClient\Curl\CurlOptions;
|
||||||
use BeSimple\SoapClient\SoapClientBuilder;
|
use BeSimple\SoapClient\SoapClientBuilder;
|
||||||
use BeSimple\SoapClient\SoapClientOptionsBuilder;
|
use BeSimple\SoapClient\SoapClientOptionsBuilder;
|
||||||
use BeSimple\SoapClient\SoapFaultWithTracingData;
|
use BeSimple\SoapClient\SoapFaultWithTracingData;
|
||||||
|
use BeSimple\SoapClient\SoapOptions\SoapClientOptions;
|
||||||
use BeSimple\SoapCommon\ClassMap;
|
use BeSimple\SoapCommon\ClassMap;
|
||||||
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||||
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
||||||
|
use BeSimple\SoapCommon\SoapRequest;
|
||||||
use BeSimple\SoapServer\SoapServerBuilder;
|
use BeSimple\SoapServer\SoapServerBuilder;
|
||||||
use BeSimple\SoapServer\SoapServerOptionsBuilder;
|
use BeSimple\SoapServer\SoapServerOptionsBuilder;
|
||||||
use Fixtures\DummyService;
|
use Fixtures\DummyService;
|
||||||
@ -108,6 +111,65 @@ class SoapServerAndSoapClientCommunicationTest extends PHPUnit_Framework_TestCas
|
|||||||
self::assertContains('</dummyServiceReturn>', $soapResponse->getResponseContent());
|
self::assertContains('</dummyServiceReturn>', $soapResponse->getResponseContent());
|
||||||
self::assertTrue($soapResponse->hasAttachments(), 'Response should contain attachments');
|
self::assertTrue($soapResponse->hasAttachments(), 'Response should contain attachments');
|
||||||
self::assertCount(3, $attachments);
|
self::assertCount(3, $attachments);
|
||||||
|
self::assertInstanceOf(
|
||||||
|
SoapRequest::class,
|
||||||
|
$soapResponse->getRequest(),
|
||||||
|
'SoapResponse::request must be SoapRequest for SoapClient calls with enabled tracing'
|
||||||
|
);
|
||||||
|
|
||||||
|
file_put_contents(self::CACHE_DIR . '/multipart-message-soap-client-response.xml', $soapResponse->getContent());
|
||||||
|
foreach ($soapResponse->getAttachments() as $attachment) {
|
||||||
|
$fileName = preg_replace('/\<|\>/', '', $attachment->getContentId());
|
||||||
|
file_put_contents(self::CACHE_DIR . DIRECTORY_SEPARATOR . 'attachment-client-response-' . $fileName, $attachment->getContent());
|
||||||
|
|
||||||
|
self::assertRegExp('/filename\.(docx|html|txt)/', $fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
self::assertEquals(
|
||||||
|
filesize(self::LARGE_SWA_FILE),
|
||||||
|
filesize(self::CACHE_DIR.'/attachment-client-response-filename.docx'),
|
||||||
|
'File cannot differ after transport from SoapClient to SoapServer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSoapCallSwaWithLargeSwaResponseAndTracingOff()
|
||||||
|
{
|
||||||
|
$soapClient = $this->getSoapBuilder()->buildWithSoapHeader(
|
||||||
|
new SoapClientOptions(
|
||||||
|
SoapClientOptions::SOAP_CLIENT_TRACE_OFF,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||||
|
CurlOptions::DEFAULT_USER_AGENT,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_AUTHENTICATION_NONE,
|
||||||
|
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
|
||||||
|
self::TEST_HTTP_URL.'/SwaSenderEndpoint.php'
|
||||||
|
),
|
||||||
|
SoapOptionsBuilder::createSwaWithClassMap(
|
||||||
|
self::TEST_HTTP_URL.'/SwaSenderEndpoint.php?wsdl',
|
||||||
|
new ClassMap([
|
||||||
|
'GenerateTestRequest' => GenerateTestRequest::class,
|
||||||
|
]),
|
||||||
|
SoapOptions::SOAP_CACHE_TYPE_NONE
|
||||||
|
),
|
||||||
|
new SoapHeader('http://schema.testcase', 'SoapHeader', [
|
||||||
|
'user' => 'admin',
|
||||||
|
])
|
||||||
|
);
|
||||||
|
|
||||||
|
$request = new DummyServiceMethodWithOutgoingLargeSwaRequest();
|
||||||
|
$request->dummyAttribute = 1;
|
||||||
|
|
||||||
|
$soapResponse = $soapClient->soapCall('dummyServiceMethodWithOutgoingLargeSwa', [$request]);
|
||||||
|
$attachments = $soapResponse->getAttachments();
|
||||||
|
|
||||||
|
self::assertContains('</dummyServiceReturn>', $soapResponse->getResponseContent());
|
||||||
|
self::assertTrue($soapResponse->hasAttachments(), 'Response should contain attachments');
|
||||||
|
self::assertCount(3, $attachments);
|
||||||
|
self::assertInstanceOf(
|
||||||
|
SoapRequest::class,
|
||||||
|
$soapResponse->getRequest(),
|
||||||
|
'SoapResponse::request must be SoapRequest for SoapClient calls with disabled tracing'
|
||||||
|
);
|
||||||
|
|
||||||
file_put_contents(self::CACHE_DIR . '/multipart-message-soap-client-response.xml', $soapResponse->getContent());
|
file_put_contents(self::CACHE_DIR . '/multipart-message-soap-client-response.xml', $soapResponse->getContent());
|
||||||
foreach ($soapResponse->getAttachments() as $attachment) {
|
foreach ($soapResponse->getAttachments() as $attachment) {
|
||||||
@ -164,6 +226,7 @@ class SoapServerAndSoapClientCommunicationTest extends PHPUnit_Framework_TestCas
|
|||||||
self::assertContains('</dummyServiceReturn>', $soapResponse->getResponseContent());
|
self::assertContains('</dummyServiceReturn>', $soapResponse->getResponseContent());
|
||||||
self::assertTrue($soapResponse->getRequest()->hasAttachments(), 'Response MUST contain attachments');
|
self::assertTrue($soapResponse->getRequest()->hasAttachments(), 'Response MUST contain attachments');
|
||||||
self::assertFalse($soapResponse->hasAttachments(), 'Response MUST NOT contain attachments');
|
self::assertFalse($soapResponse->hasAttachments(), 'Response MUST NOT contain attachments');
|
||||||
|
self::assertInstanceOf(SoapRequest::class, $soapResponse->getRequest());
|
||||||
|
|
||||||
foreach ($soapResponse->getRequest()->getAttachments() as $attachment) {
|
foreach ($soapResponse->getRequest()->getAttachments() as $attachment) {
|
||||||
file_put_contents(self::CACHE_DIR . '/attachment-client-request-'.trim($attachment->getContentId(), '<>'), $attachment->getContent());
|
file_put_contents(self::CACHE_DIR . '/attachment-client-request-'.trim($attachment->getContentId(), '<>'), $attachment->getContent());
|
||||||
|
Reference in New Issue
Block a user