Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
21d705bbfa | |||
0e2c33faf8 | |||
cf6e147c26 | |||
f276a30a47 | |||
4edc46e67f | |||
a76526a5b6 | |||
baf32c1350 | |||
5c0bf914e3 | |||
01d10b89fd | |||
e1b50ce914 |
@ -62,7 +62,7 @@ class Curl
|
||||
curl_setopt_array($curlSession, [
|
||||
CURLOPT_ENCODING => '',
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_FAILONERROR => true,
|
||||
CURLOPT_FAILONERROR => false,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||
CURLOPT_HEADER => true,
|
||||
@ -147,6 +147,8 @@ class Curl
|
||||
$headerSize = curl_getinfo($curlSession, CURLINFO_HEADER_SIZE);
|
||||
$httpResponseCode = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);
|
||||
$httpResponseContentType = curl_getinfo($curlSession, CURLINFO_CONTENT_TYPE);;
|
||||
$responseBody = substr($executeSoapCallResponse, $headerSize);
|
||||
$responseHeaders = substr($executeSoapCallResponse, 0, $headerSize);
|
||||
preg_match('/HTTP\/(1\.[0-1]+) ([0-9]{3}) (.*)/', $executeSoapCallResponse, $httpResponseMessages);
|
||||
$httpResponseMessage = trim(array_pop($httpResponseMessages));
|
||||
$curlErrorMessage = sprintf(
|
||||
@ -156,7 +158,7 @@ class Curl
|
||||
$location
|
||||
);
|
||||
|
||||
if ($executeSoapCallResponse === false) {
|
||||
if (!is_integer($httpResponseCode) || $httpResponseCode >= 400 || $httpResponseCode === 0) {
|
||||
|
||||
return new CurlResponse(
|
||||
$httpRequestHeadersAsString,
|
||||
@ -164,6 +166,8 @@ class Curl
|
||||
$httpResponseMessage,
|
||||
$httpResponseContentType,
|
||||
self::CURL_FAILED,
|
||||
$responseHeaders,
|
||||
$responseBody,
|
||||
$curlErrorMessage
|
||||
);
|
||||
}
|
||||
@ -174,9 +178,8 @@ class Curl
|
||||
$httpResponseMessage,
|
||||
$httpResponseContentType,
|
||||
self::CURL_SUCCESS,
|
||||
null,
|
||||
substr($executeSoapCallResponse, 0, $headerSize),
|
||||
substr($executeSoapCallResponse, $headerSize)
|
||||
$responseHeaders,
|
||||
$responseBody
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use BeSimple\SoapClient\SoapServerProxy\SoapServerProxy;
|
||||
|
||||
class CurlOptions
|
||||
{
|
||||
const DEFAULT_USER_AGENT = 'BeSimpleSoap';
|
||||
const DEFAULT_USER_AGENT = 'PhpBeSimpleSoap';
|
||||
const SOAP_COMPRESSION_NONE = null;
|
||||
const SOAP_COMPRESSION_GZIP = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP;
|
||||
const SOAP_COMPRESSION_DEFLATE = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE;
|
||||
|
@ -13,7 +13,7 @@ use Exception;
|
||||
class CurlOptionsBuilder
|
||||
{
|
||||
const DEFAULT_MAX_REDIRECTS = 10;
|
||||
const DEFAULT_CONNECTION_TIMEOUT = 10;
|
||||
const DEFAULT_CONNECTION_TIMEOUT = 120;
|
||||
|
||||
public static function buildDefault()
|
||||
{
|
||||
|
@ -19,9 +19,9 @@ class CurlResponse
|
||||
$httpResponseStatusMessage,
|
||||
$httpResponseContentType,
|
||||
$curlStatus,
|
||||
$curlErrorMessage = null,
|
||||
$responseHeader = null,
|
||||
$responseBody = null
|
||||
$responseHeader,
|
||||
$responseBody,
|
||||
$curlErrorMessage = null
|
||||
) {
|
||||
$this->httpRequestHeaders = $httpRequestHeaders;
|
||||
$this->httpResponseStatusCode = $httpResponseStatusCode;
|
||||
@ -78,21 +78,11 @@ class CurlResponse
|
||||
return $this->curlErrorMessage;
|
||||
}
|
||||
|
||||
public function hasResponseHeader()
|
||||
{
|
||||
return $this->responseHeader !== null;
|
||||
}
|
||||
|
||||
public function getResponseHeader()
|
||||
{
|
||||
return $this->responseHeader;
|
||||
}
|
||||
|
||||
public function hasResponseBody()
|
||||
{
|
||||
return $this->responseBody !== null;
|
||||
}
|
||||
|
||||
public function getResponseBody()
|
||||
{
|
||||
return $this->responseBody;
|
||||
|
@ -71,7 +71,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter
|
||||
$soapPart = $multiPartMessage->getMainPart();
|
||||
$attachments = $multiPartMessage->getAttachments();
|
||||
|
||||
$response->setContent($this->sanitizePhpExceptionOnHrefs($soapPart));
|
||||
$response->setContent($soapPart->getContent());
|
||||
$response->setContentType($soapPart->getHeader('Content-Type'));
|
||||
if (count($attachments) > 0) {
|
||||
$response->setAttachments($attachments);
|
||||
|
@ -41,6 +41,10 @@ class SoapClient extends \SoapClient
|
||||
protected $soapClientOptions;
|
||||
protected $soapOptions;
|
||||
private $curl;
|
||||
/** @var SoapAttachment[] */
|
||||
private $soapAttachmentsOnRequestStorage;
|
||||
/** @var SoapResponse */
|
||||
private $soapResponseStorage;
|
||||
|
||||
public function __construct(SoapClientOptions $soapClientOptions, SoapOptions $soapOptions)
|
||||
{
|
||||
@ -54,7 +58,8 @@ class SoapClient extends \SoapClient
|
||||
$wsdlPath = $this->loadWsdl(
|
||||
$this->curl,
|
||||
$soapOptions->getWsdlFile(),
|
||||
$soapOptions->getWsdlCacheType()
|
||||
$soapOptions->getWsdlCacheType(),
|
||||
false
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
throw new SoapFault(
|
||||
@ -90,11 +95,11 @@ class SoapClient extends \SoapClient
|
||||
*/
|
||||
public function __soapCall($function_name, $arguments, $options = null, $input_headers = null, &$output_headers = null)
|
||||
{
|
||||
return $this->soapCall($function_name, $arguments, $options, $input_headers, $output_headers)->getContent();
|
||||
return $this->soapCall($function_name, $arguments, $options, $input_headers, $output_headers)->getResponseContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $functionName
|
||||
* @param string $functionName
|
||||
* @param array $arguments
|
||||
* @param array|null $options
|
||||
* @param SoapAttachment[] $soapAttachments
|
||||
@ -104,17 +109,13 @@ class SoapClient extends \SoapClient
|
||||
*/
|
||||
public function soapCall($functionName, array $arguments, array $soapAttachments = [], array $options = null, $inputHeaders = null, array &$outputHeaders = null)
|
||||
{
|
||||
ob_start();
|
||||
parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders);
|
||||
$nativeSoapClientRequest = $this->mapNativeDataJsonToDto(ob_get_clean());
|
||||
$this->setSoapAttachmentsOnRequestToStorage($soapAttachments);
|
||||
$soapResponseAsObject = parent::__soapCall($functionName, $arguments, $options, $inputHeaders, $outputHeaders);
|
||||
|
||||
return $this->performSoapRequest(
|
||||
$nativeSoapClientRequest->request,
|
||||
$nativeSoapClientRequest->location,
|
||||
$nativeSoapClientRequest->action,
|
||||
$nativeSoapClientRequest->version,
|
||||
$soapAttachments
|
||||
);
|
||||
$soapResponse = $this->getSoapResponseFromStorage();
|
||||
$soapResponse->setResponseObject($soapResponseAsObject);
|
||||
|
||||
return $soapResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,34 +131,16 @@ class SoapClient extends \SoapClient
|
||||
*/
|
||||
public function __doRequest($request, $location, $action, $version, $oneWay = 0)
|
||||
{
|
||||
$soapClientNativeDataTransferObject = new SoapClientNativeDataTransferObject(
|
||||
$soapResponse = $this->performSoapRequest(
|
||||
$request,
|
||||
$location,
|
||||
$action,
|
||||
$version
|
||||
$version,
|
||||
$this->getSoapAttachmentsOnRequestFromStorage()
|
||||
);
|
||||
echo json_encode($soapClientNativeDataTransferObject);
|
||||
$this->setSoapResponseToStorage($soapResponse);
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom request method to be able to modify the SOAP messages.
|
||||
* $oneWay parameter is not used at the moment.
|
||||
*
|
||||
* @param mixed $request Request object
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param int $version SOAP version
|
||||
* @param SoapAttachment[] $soapAttachments SOAP attachments array
|
||||
*
|
||||
* @return SoapResponse
|
||||
*/
|
||||
public function performSoapRequest($request, $location, $action, $version, array $soapAttachments = [])
|
||||
{
|
||||
$soapRequest = $this->createSoapRequest($location, $action, $version, $request, $soapAttachments);
|
||||
|
||||
return $this->performHttpSoapRequest($soapRequest);
|
||||
return $soapResponse->getResponseContent();
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
@ -200,6 +183,25 @@ class SoapClient extends \SoapClient
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom request method to be able to modify the SOAP messages.
|
||||
* $oneWay parameter is not used at the moment.
|
||||
*
|
||||
* @param mixed $request Request object
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
* @param int $version SOAP version
|
||||
* @param SoapAttachment[] $soapAttachments SOAP attachments array
|
||||
*
|
||||
* @return SoapResponse
|
||||
*/
|
||||
private function performSoapRequest($request, $location, $action, $version, array $soapAttachments = [])
|
||||
{
|
||||
$soapRequest = $this->createSoapRequest($location, $action, $version, $request, $soapAttachments);
|
||||
|
||||
return $this->performHttpSoapRequest($soapRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $location Location
|
||||
* @param string $action SOAP action
|
||||
@ -242,12 +244,14 @@ class SoapClient extends \SoapClient
|
||||
{
|
||||
if ($soapRequest->getVersion() === SOAP_1_1) {
|
||||
$headers = [
|
||||
'Content-Type:' . $soapRequest->getContentType(),
|
||||
'Content-Type: ' . $soapRequest->getContentType(),
|
||||
'SOAPAction: "' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
} else {
|
||||
$headers = [
|
||||
'Content-Type:' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
||||
'Content-Type: ' . $soapRequest->getContentType() . '; action="' . $soapRequest->getAction() . '"',
|
||||
'Connection: ' . ($this->soapOptions->isConnectionKeepAlive() ? 'Keep-Alive' : 'close'),
|
||||
];
|
||||
}
|
||||
$curlResponse = $this->curl->executeCurlWithCachedSession(
|
||||
@ -336,18 +340,6 @@ class SoapClient extends \SoapClient
|
||||
return $filters;
|
||||
}
|
||||
|
||||
private function mapNativeDataJsonToDto($nativeDataJson)
|
||||
{
|
||||
$nativeData = json_decode($nativeDataJson);
|
||||
|
||||
return new SoapClientNativeDataTransferObject(
|
||||
$nativeData->request,
|
||||
$nativeData->location,
|
||||
$nativeData->action,
|
||||
$nativeData->version
|
||||
);
|
||||
}
|
||||
|
||||
private function returnSoapResponseByTracing(
|
||||
$isTracingEnabled,
|
||||
SoapRequest $soapRequest,
|
||||
@ -405,4 +397,33 @@ class SoapClient extends \SoapClient
|
||||
throw new Exception('SoapClientOptions tracing disabled, turn on trace attribute');
|
||||
}
|
||||
}
|
||||
|
||||
private function setSoapResponseToStorage(SoapResponse $soapResponseStorage)
|
||||
{
|
||||
$this->soapResponseStorage = $soapResponseStorage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SoapAttachment[] $soapAttachments
|
||||
*/
|
||||
private function setSoapAttachmentsOnRequestToStorage(array $soapAttachments)
|
||||
{
|
||||
$this->soapAttachmentsOnRequestStorage = $soapAttachments;
|
||||
}
|
||||
|
||||
private function getSoapAttachmentsOnRequestFromStorage()
|
||||
{
|
||||
$soapAttachmentsOnRequest = $this->soapAttachmentsOnRequestStorage;
|
||||
$this->soapAttachmentsOnRequestStorage = null;
|
||||
|
||||
return $soapAttachmentsOnRequest;
|
||||
}
|
||||
|
||||
private function getSoapResponseFromStorage()
|
||||
{
|
||||
$soapResponse = $this->soapResponseStorage;
|
||||
$this->soapResponseStorage = null;
|
||||
|
||||
return $soapResponse;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace BeSimple\SoapClient;
|
||||
|
||||
class SoapClientNativeDataTransferObject
|
||||
{
|
||||
public $request;
|
||||
public $location;
|
||||
public $action;
|
||||
public $version;
|
||||
|
||||
public function __construct($request, $location, $action, $version)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->location = $location;
|
||||
$this->action = $action;
|
||||
$this->version = $version;
|
||||
}
|
||||
}
|
@ -45,6 +45,19 @@ class SoapClientOptionsBuilder
|
||||
);
|
||||
}
|
||||
|
||||
public static function createWithEndpointLocation($endpointLocation)
|
||||
{
|
||||
return new SoapClientOptions(
|
||||
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
|
||||
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||
CurlOptions::DEFAULT_USER_AGENT,
|
||||
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
|
||||
SoapClientOptions::SOAP_CLIENT_AUTHENTICATION_NONE,
|
||||
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
|
||||
$endpointLocation
|
||||
);
|
||||
}
|
||||
|
||||
public static function createWithAuthentication(SoapServerAuthenticationInterface $authentication)
|
||||
{
|
||||
return new SoapClientOptions(
|
||||
@ -55,4 +68,17 @@ class SoapClientOptionsBuilder
|
||||
$authentication
|
||||
);
|
||||
}
|
||||
|
||||
public static function createWithAuthenticationAndEndpointLocation($endpointLocation, SoapServerAuthenticationInterface $authentication)
|
||||
{
|
||||
return new SoapClientOptions(
|
||||
SoapClientOptions::SOAP_CLIENT_TRACE_ON,
|
||||
SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON,
|
||||
CurlOptions::DEFAULT_USER_AGENT,
|
||||
SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE,
|
||||
$authentication,
|
||||
SoapClientOptions::SOAP_CLIENT_PROXY_NONE,
|
||||
$endpointLocation
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ class SoapClientOptions
|
||||
const SOAP_CLIENT_COMPRESSION_NONE = CurlOptions::SOAP_COMPRESSION_NONE;
|
||||
const SOAP_CLIENT_COMPRESSION_GZIP = CurlOptions::SOAP_COMPRESSION_GZIP;
|
||||
const SOAP_CLIENT_COMPRESSION_DEFLATE = CurlOptions::SOAP_COMPRESSION_DEFLATE;
|
||||
const SOAP_CLIENT_AUTHENTICATION_NONE = null;
|
||||
const SOAP_CLIENT_PROXY_NONE = null;
|
||||
|
||||
private $trace;
|
||||
private $exceptions;
|
||||
@ -24,23 +26,33 @@ class SoapClientOptions
|
||||
private $compression;
|
||||
private $authentication;
|
||||
private $proxy;
|
||||
private $location;
|
||||
|
||||
/**
|
||||
* @param bool $trace = SoapClientOptions::SOAP_CLIENT_TRACE_ON|SoapClientOptions::SOAP_CLIENT_TRACE_OFF
|
||||
* @param bool $exceptions = SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_ON|SoapClientOptions::SOAP_CLIENT_EXCEPTIONS_OFF
|
||||
* @param string $userAgent
|
||||
* @param int $compression = SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE|SoapClientOptions::SOAP_CLIENT_COMPRESSION_GZIP|SoapClientOptions::SOAP_CLIENT_COMPRESSION_DEFLATE
|
||||
* @param SoapServerAuthenticationInterface $authentication = null
|
||||
* @param SoapServerProxy $proxy = null
|
||||
* @param int|null $compression = SoapClientOptions::SOAP_CLIENT_COMPRESSION_NONE|SoapClientOptions::SOAP_CLIENT_COMPRESSION_GZIP|SoapClientOptions::SOAP_CLIENT_COMPRESSION_DEFLATE
|
||||
* @param SoapServerAuthenticationInterface|null $authentication
|
||||
* @param SoapServerProxy|null $proxy
|
||||
* @param string|null $location
|
||||
*/
|
||||
public function __construct($trace, $exceptions, $userAgent, $compression = null, SoapServerAuthenticationInterface $authentication = null, SoapServerProxy $proxy = null)
|
||||
{
|
||||
public function __construct(
|
||||
$trace,
|
||||
$exceptions,
|
||||
$userAgent,
|
||||
$compression = null,
|
||||
SoapServerAuthenticationInterface $authentication = null,
|
||||
SoapServerProxy $proxy = null,
|
||||
$location = null
|
||||
) {
|
||||
$this->trace = $trace;
|
||||
$this->exceptions = $exceptions;
|
||||
$this->userAgent = $userAgent;
|
||||
$this->compression = $compression;
|
||||
$this->authentication = $authentication;
|
||||
$this->proxy = $proxy;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
public function getTrace()
|
||||
@ -88,6 +100,11 @@ class SoapClientOptions
|
||||
return $this->proxy !== null;
|
||||
}
|
||||
|
||||
public function hasLocation()
|
||||
{
|
||||
return $this->location !== null;
|
||||
}
|
||||
|
||||
public function getAuthentication()
|
||||
{
|
||||
return $this->authentication;
|
||||
@ -98,6 +115,11 @@ class SoapClientOptions
|
||||
return $this->proxy;
|
||||
}
|
||||
|
||||
public function getLocation()
|
||||
{
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$optionsAsArray = [
|
||||
@ -114,6 +136,9 @@ class SoapClientOptions
|
||||
if ($this->hasProxy()) {
|
||||
$optionsAsArray += $this->getProxy()->toArray();
|
||||
}
|
||||
if ($this->hasLocation()) {
|
||||
$optionsAsArray['location'] = $this->getLocation();
|
||||
}
|
||||
|
||||
return $optionsAsArray;
|
||||
}
|
||||
|
@ -6,8 +6,38 @@ use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
||||
|
||||
class SoapResponse extends CommonSoapResponse
|
||||
{
|
||||
/** @var mixed */
|
||||
protected $responseObject;
|
||||
/** @var SoapResponseTracingData */
|
||||
protected $tracingData;
|
||||
|
||||
public function getResponseContent()
|
||||
{
|
||||
return $this->getContent();
|
||||
}
|
||||
|
||||
public function getResponseObject()
|
||||
{
|
||||
return $this->responseObject;
|
||||
}
|
||||
|
||||
public function setResponseObject($responseObject)
|
||||
{
|
||||
$this->responseObject = $responseObject;
|
||||
}
|
||||
|
||||
public function hasTracingData()
|
||||
{
|
||||
return $this->tracingData !== null;
|
||||
}
|
||||
|
||||
public function getTracingData()
|
||||
{
|
||||
return $this->tracingData;
|
||||
}
|
||||
|
||||
public function setTracingData(SoapResponseTracingData $tracingData)
|
||||
{
|
||||
$this->tracingData = $tracingData;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ use BeSimple\SoapCommon\ClassMap;
|
||||
use BeSimple\SoapCommon\SoapOptions\SoapOptions;
|
||||
use BeSimple\SoapCommon\SoapOptionsBuilder;
|
||||
use Exception;
|
||||
use SoapClient;
|
||||
use SoapHeader;
|
||||
|
||||
class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
@ -30,6 +31,7 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
const TEST_ENDPOINT_UK = 'http://www.webservicex.net/uklocation.asmx';
|
||||
const TEST_REMOTE_WSDL_UK = 'http://www.webservicex.net/uklocation.asmx?WSDL';
|
||||
const TEST_LOCAL_WSDL_UK = __DIR__.'/localWsdl.wsdl';
|
||||
const TEST_REMOTE_ENDPOINT_NOT_WORKING = 'http://www.nosuchserverexist.tld/doesnotexist.endpoint';
|
||||
const TEST_REMOTE_WSDL_NOT_WORKING = 'http://www.nosuchserverexist.tld/doesnotexist.endpoint?wsdl';
|
||||
const TEST_ENDPOINT_SWA = 'https://demo2815480.mockable.io/soap/testGenerator';
|
||||
const TEST_REMOTE_WSDL_SWA = 'https://demo2815480.mockable.io/soap/testGenerator?WSDL';
|
||||
@ -101,7 +103,7 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
$soapOptions
|
||||
);
|
||||
|
||||
self::assertInstanceOf(\SoapClient::class, $soapClient);
|
||||
self::assertInstanceOf(SoapClient::class, $soapClient);
|
||||
}
|
||||
|
||||
public function testSoapCall()
|
||||
@ -119,6 +121,53 @@ class SoapClientBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
self::assertEquals(self::TEST_ENDPOINT_UK, $soapResponse->getLocation());
|
||||
}
|
||||
|
||||
public function testSoapCallWithCustomEndpointValid()
|
||||
{
|
||||
$soapClient = $this->getSoapBuilder()->build(
|
||||
SoapClientOptionsBuilder::createWithEndpointLocation(self::TEST_ENDPOINT_UK),
|
||||
SoapOptionsBuilder::createWithDefaults(self::TEST_REMOTE_WSDL_UK)
|
||||
);
|
||||
$getUKLocationByCountyRequest = new GetUKLocationByCounty();
|
||||
$getUKLocationByCountyRequest->County = 'London';
|
||||
$soapResponse = $soapClient->soapCall('GetUKLocationByCounty', [$getUKLocationByCountyRequest]);
|
||||
|
||||
self::assertContains('Connection: close', $soapResponse->getTracingData()->getLastRequestHeaders());
|
||||
self::assertContains('County>London</', $soapResponse->getTracingData()->getLastRequest());
|
||||
self::assertContains('GetUKLocationByCountyResult', $soapResponse->getContent());
|
||||
self::assertContains('</GetUKLocationByCountyResponse>', $soapResponse->getContent());
|
||||
self::assertEquals(self::TEST_ENDPOINT_UK, $soapResponse->getLocation());
|
||||
}
|
||||
|
||||
public function testSoapCallWithKeepAliveTrue()
|
||||
{
|
||||
$soapClient = $this->getSoapBuilder()->build(
|
||||
SoapClientOptionsBuilder::createWithEndpointLocation(self::TEST_ENDPOINT_UK),
|
||||
SoapOptionsBuilder::createWithDefaultsKeepAlive(self::TEST_REMOTE_WSDL_UK)
|
||||
);
|
||||
$getUKLocationByCountyRequest = new GetUKLocationByCounty();
|
||||
$getUKLocationByCountyRequest->County = 'London';
|
||||
$soapResponse = $soapClient->soapCall('GetUKLocationByCounty', [$getUKLocationByCountyRequest]);
|
||||
|
||||
self::assertContains('Connection: Keep-Alive', $soapResponse->getTracingData()->getLastRequestHeaders());
|
||||
self::assertContains('County>London</', $soapResponse->getTracingData()->getLastRequest());
|
||||
self::assertContains('GetUKLocationByCountyResult', $soapResponse->getContent());
|
||||
self::assertContains('</GetUKLocationByCountyResponse>', $soapResponse->getContent());
|
||||
self::assertEquals(self::TEST_ENDPOINT_UK, $soapResponse->getLocation());
|
||||
}
|
||||
|
||||
public function testSoapCallWithCustomEndpointInvalidShouldFail()
|
||||
{
|
||||
$this->setExpectedException(Exception::class, 'Could not resolve host');
|
||||
|
||||
$soapClient = $this->getSoapBuilder()->build(
|
||||
SoapClientOptionsBuilder::createWithEndpointLocation(self::TEST_REMOTE_ENDPOINT_NOT_WORKING),
|
||||
SoapOptionsBuilder::createWithDefaults(self::TEST_REMOTE_WSDL_UK)
|
||||
);
|
||||
$getUKLocationByCountyRequest = new GetUKLocationByCounty();
|
||||
$getUKLocationByCountyRequest->County = 'London';
|
||||
$soapClient->soapCall('GetUKLocationByCounty', [$getUKLocationByCountyRequest]);
|
||||
}
|
||||
|
||||
public function testSoapCallWithCacheEndpointDownShouldFail()
|
||||
{
|
||||
$this->setExpectedException(Exception::class, 'Could not write WSDL cache file: Download failed with message');
|
||||
|
@ -75,7 +75,7 @@ class WsdlDownloader
|
||||
$curlResponse = $curl->executeCurlWithCachedSession($wsdlPath);
|
||||
if ($curlResponse->curlStatusSuccess()) {
|
||||
if (mb_strlen($curlResponse->getResponseBody()) === 0) {
|
||||
throw new Exception('Could not write WSDL cache file: curl response empty');
|
||||
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);
|
||||
|
@ -110,7 +110,8 @@ class Parser
|
||||
}
|
||||
if (strpos($currentHeader, ':') !== false) {
|
||||
list($headerName, $headerValue) = explode(':', $currentHeader, 2);
|
||||
$headerValue = iconv_mime_decode($headerValue, 0, Part::CHARSET_UTF8);
|
||||
$headerValueWithNoCrAtTheEnd = trim($headerValue);
|
||||
$headerValue = iconv_mime_decode($headerValueWithNoCrAtTheEnd, 0, Part::CHARSET_UTF8);
|
||||
$parsedMimeHeaders = ContentTypeParser::parseContentTypeHeader($headerName, $headerValue);
|
||||
foreach ($parsedMimeHeaders as $parsedMimeHeader) {
|
||||
$currentPart->setHeader(
|
||||
|
@ -30,6 +30,14 @@ class SoapOptionsBuilder
|
||||
return self::createWithClassMap($wsdlFile, new ClassMap(), $wsdlCacheType, $wsdlCacheDir);
|
||||
}
|
||||
|
||||
public static function createWithDefaultsKeepAlive(
|
||||
$wsdlFile,
|
||||
$wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE,
|
||||
$wsdlCacheDir = null
|
||||
) {
|
||||
return self::createWithClassMapKeepAlive($wsdlFile, new ClassMap(), $wsdlCacheType, $wsdlCacheDir);
|
||||
}
|
||||
|
||||
public static function createSwaWithClassMap(
|
||||
$wsdlFile,
|
||||
ClassMap $classMap,
|
||||
@ -92,6 +100,38 @@ class SoapOptionsBuilder
|
||||
);
|
||||
}
|
||||
|
||||
public static function createWithClassMapKeepAlive(
|
||||
$wsdlFile,
|
||||
ClassMap $classMap,
|
||||
$wsdlCacheType = SoapOptions::SOAP_CACHE_TYPE_NONE,
|
||||
$wsdlCacheDir = null,
|
||||
$attachmentType = null
|
||||
) {
|
||||
if (!Cache::hasType($wsdlCacheType)) {
|
||||
throw new InvalidArgumentException('Invalid cache type');
|
||||
}
|
||||
if ($wsdlCacheType !== SoapOptions::SOAP_CACHE_TYPE_NONE) {
|
||||
if ($wsdlCacheDir === null) {
|
||||
throw new InvalidArgumentException('Cache dir must be set for this wsdl cache type');
|
||||
}
|
||||
}
|
||||
|
||||
return new SoapOptions(
|
||||
SoapOptions::SOAP_VERSION_1_2,
|
||||
SoapOptions::SOAP_ENCODING_UTF8,
|
||||
SoapOptions::SOAP_CONNECTION_KEEP_ALIVE_ON,
|
||||
new SoapFeatures([
|
||||
SoapFeatures::SINGLE_ELEMENT_ARRAYS
|
||||
]),
|
||||
$wsdlFile,
|
||||
$wsdlCacheType,
|
||||
$wsdlCacheDir,
|
||||
$classMap,
|
||||
new TypeConverterCollection(),
|
||||
$attachmentType
|
||||
);
|
||||
}
|
||||
|
||||
public static function createWithClassMapV11(
|
||||
$wsdlFile,
|
||||
ClassMap $classMap,
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
namespace BeSimple\SoapCommon;
|
||||
|
||||
use BeSimple\SoapClient\SoapResponseTracingData;
|
||||
|
||||
/**
|
||||
* SOAP response message.
|
||||
*
|
||||
@ -23,21 +21,4 @@ use BeSimple\SoapClient\SoapResponseTracingData;
|
||||
*/
|
||||
class SoapResponse extends SoapMessage
|
||||
{
|
||||
/** @var SoapResponseTracingData */
|
||||
protected $tracingData;
|
||||
|
||||
public function hasTracingData()
|
||||
{
|
||||
return $this->tracingData !== null;
|
||||
}
|
||||
|
||||
public function getTracingData()
|
||||
{
|
||||
return $this->tracingData;
|
||||
}
|
||||
|
||||
public function setTracingData(SoapResponseTracingData $tracingData)
|
||||
{
|
||||
$this->tracingData = $tracingData;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class MimeFilter implements SoapRequestFilter, SoapResponseFilter
|
||||
$soapPart = $multiPartMessage->getMainPart();
|
||||
$attachments = $multiPartMessage->getAttachments();
|
||||
|
||||
$request->setContent($this->sanitizePhpExceptionOnHrefs($soapPart));
|
||||
$request->setContent($soapPart->getContent());
|
||||
$request->setContentType($soapPart->getHeader('Content-Type'));
|
||||
if (count($attachments) > 0) {
|
||||
$request->setAttachments($attachments);
|
||||
|
Reference in New Issue
Block a user