public function testSigEnc() { $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/WsSecuritySigEnc.wsdl', $this->options); $wssFilter = new BeSimpleWsSecurityFilter(); // user key for signature and encryption $securityKeyUser = new BeSimpleWsSecurityKey(); $securityKeyUser->addPrivateKey(XmlSecurityKey::RSA_SHA1, __DIR__ . '/Fixtures/clientkey.pem', true); $securityKeyUser->addPublicKey(XmlSecurityKey::RSA_SHA1, __DIR__ . '/Fixtures/clientcert.pem', true); $wssFilter->setUserSecurityKeyObject($securityKeyUser); // service key for encryption $securityKeyService = new BeSimpleWsSecurityKey(); $securityKeyService->addPrivateKey(XmlSecurityKey::TRIPLEDES_CBC); $securityKeyService->addPublicKey(XmlSecurityKey::RSA_1_5, __DIR__ . '/Fixtures/servercert.pem', true); $wssFilter->setServiceSecurityKeyObject($securityKeyService); // TOKEN_REFERENCE_SUBJECT_KEY_IDENTIFIER | TOKEN_REFERENCE_SECURITY_TOKEN | TOKEN_REFERENCE_THUMBPRINT_SHA1 $wssFilter->setSecurityOptionsSignature(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_SECURITY_TOKEN); $wssFilter->setSecurityOptionsEncryption(BeSimpleWsSecurityFilter::TOKEN_REFERENCE_THUMBPRINT_SHA1); $soapKernel = $sc->getSoapKernel(); $soapKernel->registerFilter($wssFilter); $gb = new getBook(); $gb->isbn = '0061020052'; $result = $sc->getBook($gb); $this->assertInstanceOf('BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\BookInformation', $result->getBookReturn); $ab = new addBook(); $ab->isbn = '0445203498'; $ab->title = 'The Dragon Never Sleeps'; $ab->author = 'Cook, Glen'; $ab->type = 'scifi'; $this->assertTrue((bool) $sc->addBook($ab)); // getBooksByType("scifi"); }
protected function call($function, array $params) { if (empty($this->shopId) || empty($this->login) || empty($this->pwd)) { throw new \Exception('Missing auth params'); } $authParams = array('pid_loja' => $this->shopId, 'plogin' => $this->login, 'psenha' => $this->pwd); return $this->soapClient->__soapCall($function, $authParams + $params); }
public function testUploadDownloadImage() { $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/SwA.wsdl', $this->options); $upload = new uploadFile(); $upload->name = 'image.jpg'; $upload->data = file_get_contents(__DIR__ . '/Fixtures/image.jpg'); // source: http://www.freeimageslive.com/galleries/light/pics/swirl3768.jpg; $result = $sc->uploadFile($upload); $this->assertEquals('File saved succesfully.', $result->return); $download = new downloadFile(); $download->name = 'image.jpg'; $result = $sc->downloadFile($download); $this->assertEquals($upload->data, $result->data); }
public function testAttachment() { $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/MTOM.wsdl', $this->options); $b64 = new base64Binary(); $b64->_ = 'This is a test. :)'; $b64->contentType = 'text/plain'; $attachment = new AttachmentRequest(); $attachment->fileName = 'test123.txt'; $attachment->binaryData = $b64; $this->assertEquals('File saved succesfully.', $sc->attachment($attachment)); $fileCreatedByServer = __DIR__ . '/' . $attachment->fileName; $this->assertEquals($b64->_, file_get_contents($fileCreatedByServer)); unlink($fileCreatedByServer); }
public function testSession() { $sc = new BeSimpleSoapClient('http://localhost:8080/axis2/services/Version2?wsdl', $this->options); $soapKernel = $sc->getSoapKernel(); $wsaFilter = new BeSimpleWsAddressingFilter(); $soapKernel->registerFilter($wsaFilter); $wsaFilter->setReplyTo(BeSimpleWsAddressingFilter::ENDPOINT_REFERENCE_ANONYMOUS); $wsaFilter->setMessageId(); $version = $sc->getVersion(); $soapSessionId1 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId'); $wsaFilter->addReferenceParameter('http://ws.apache.org/namespaces/axis2', 'axis2', 'ServiceGroupId', $soapSessionId1); $version = $sc->getVersion(); $soapSessionId2 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId'); $this->assertEquals($soapSessionId1, $soapSessionId2); }
public function testUserPassDigest() { $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/WsSecurityUserPass.wsdl', $this->options); $wssFilter = new BeSimpleWsSecurityFilter(true, 600); $wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_DIGEST); $soapKernel = $sc->getSoapKernel(); $soapKernel->registerFilter($wssFilter); $gb = new getBook(); $gb->isbn = '0061020052'; $result = $sc->getBook($gb); $this->assertInstanceOf('BeSimple\\SoapClient\\Tests\\AxisInterop\\Fixtures\\BookInformation', $result->getBookReturn); $ab = new addBook(); $ab->isbn = '0445203498'; $ab->title = 'The Dragon Never Sleeps'; $ab->author = 'Cook, Glen'; $ab->type = 'scifi'; $this->assertTrue((bool) $sc->addBook($ab)); // getBooksByType("scifi"); }
<?php require '../../../../../vendor/autoload.php'; use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient; use BeSimple\SoapClient\WsSecurityFilter as BeSimpleWsSecurityFilter; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\getBook; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\getBookResponse; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\getBooksByType; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\getBooksByTypeResponse; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBook; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\addBookResponse; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\BookInformation; use BeSimple\SoapClient\Tests\ServerInterop\TestCase; $options = array('soap_version' => SOAP_1_2, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => true, 'classmap' => array('getBook' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\getBook', 'getBookResponse' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\getBookResponse', 'getBooksByType' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\getBooksByType', 'getBooksByTypeResponse' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\getBooksByTypeResponse', 'addBook' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\addBook', 'addBookResponse' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\addBookResponse', 'BookInformation' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\BookInformation'), 'cli_webserver_workaround' => true); $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/WsSecurityUserPass.wsdl', $options); //var_dump($sc->__getFunctions()); //var_dump($sc->__getTypes()); try { $wssFilter = new BeSimpleWsSecurityFilter(true, 600); $wssFilter->addUserData('libuser', 'books', BeSimpleWsSecurityFilter::PASSWORD_TYPE_DIGEST); $soapKernel = $sc->getSoapKernel(); $soapKernel->registerFilter($wssFilter); $gb = new getBook(); $gb->isbn = '0061020052'; $result = $sc->getBook($gb); var_dump($result->getBookReturn); $ab = new addBook(); $ab->isbn = '0445203498'; $ab->title = 'The Dragon Never Sleeps'; $ab->author = 'Cook, Glen'; $ab->type = 'scifi';
<?php require '../../../../../vendor/autoload.php'; use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper; use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\base64Binary; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\AttachmentRequest; $options = array('soap_version' => SOAP_1_1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => true, 'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_MTOM, 'cache_wsdl' => WSDL_CACHE_NONE, 'classmap' => array('base64Binary' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\base64Binary', 'AttachmentRequest' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\AttachmentRequest'), 'cli_webserver_workaround' => true, 'connection_timeout' => 1); $sc = new BeSimpleSoapClient('Fixtures/MTOM.wsdl', $options); //var_dump($sc->__getFunctions()); //var_dump($sc->__getTypes()); try { $b64 = new base64Binary(); $b64->_ = 'This is a test. :)'; $b64->contentType = 'text/plain'; $attachment = new AttachmentRequest(); $attachment->fileName = 'test123.txt'; $attachment->binaryData = $b64; var_dump($sc->attachment($attachment)); } catch (Exception $e) { var_dump($e); } // var_dump( // $sc->__getLastRequestHeaders(), // $sc->__getLastRequest(), // $sc->__getLastResponseHeaders(), // $sc->__getLastResponse() // );
/** * Constructor. * * @param string $wsdl WSDL file * @param array(string=>mixed) $options Options array */ public function __construct($wsdl, array $options = array()) { // tracing enabled: store last request/response header and body if (isset($options['trace']) && $options['trace'] === true) { $this->tracingEnabled = true; } // store SOAP version if (isset($options['soap_version'])) { $this->soapVersion = $options['soap_version']; } $this->curl = new Curl($options); $wsdlFile = $this->loadWsdl($wsdl, $options); // TODO $wsdlHandler = new WsdlHandler($wsdlFile, $this->soapVersion); $this->soapKernel = new SoapKernel(); // set up type converter and mime filter $this->configureMime($options); // we want the exceptions option to be set $options['exceptions'] = true; // disable obsolete trace option for native SoapClient as we need to do our own tracing anyways $options['trace'] = false; // disable WSDL caching as we handle WSDL caching for remote URLs ourself $options['cache_wsdl'] = WSDL_CACHE_NONE; parent::__construct($wsdlFile, $options); }
<?php require '../../../../../vendor/autoload.php'; use BeSimple\SoapCommon\Helper as BeSimpleSoapHelper; use BeSimple\SoapClient\SoapClient as BeSimpleSoapClient; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFile; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\uploadFileResponse; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\downloadFile; use BeSimple\SoapClient\Tests\ServerInterop\Fixtures\downloadFileResponse; use BeSimple\SoapClient\Tests\ServerInterop\TestCase; $options = array('soap_version' => SOAP_1_1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_SWA, 'cache_wsdl' => WSDL_CACHE_NONE, 'trace' => true, 'classmap' => array('downloadFile' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\downloadFile', 'downloadFileResponse' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\downloadFileResponse', 'uploadFile' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\uploadFile', 'uploadFileResponse' => 'BeSimple\\SoapClient\\Tests\\ServerInterop\\Fixtures\\uploadFileResponse'), 'cli_webserver_workaround' => true); $sc = new BeSimpleSoapClient(__DIR__ . '/Fixtures/SwA.wsdl', $options); try { $upload = new uploadFile(); $upload->name = 'upload.txt'; $upload->data = 'This is a test. :)'; $result = $sc->uploadFile($upload); var_dump($result); $download = new downloadFile(); $download->name = 'upload.txt'; var_dump($sc->downloadFile($download)); } catch (Exception $e) { var_dump($e); } // var_dump( // $sc->__getLastRequestHeaders(), // $sc->__getLastRequest(), // $sc->__getLastResponseHeaders(), // $sc->__getLastResponse() // );
* enabled. * * 1) Go to $AXIS_HOME/samples/version and edit the following files: * * resources/META-INF/services.xml: * <service name="Version2" scope="soapsession"> * ... * </service> * * build.xml: * replace version.aar with version2.aar * * 2) Run ant build.xml in "$AXIS_HOME/samples/version" * */ $sc = new BeSimpleSoapClient('http://localhost:8080/axis2/services/Version2?wsdl', $options); $soapKernel = $sc->getSoapKernel(); $wsaFilter = new BeSimpleWsAddressingFilter(); $soapKernel->registerFilter($wsaFilter); //var_dump($sc->__getFunctions()); //var_dump($sc->__getTypes()); try { $wsaFilter->setReplyTo(BeSimpleWsAddressingFilter::ENDPOINT_REFERENCE_ANONYMOUS); $wsaFilter->setMessageId(); var_dump($sc->getVersion()); $soapSessionId1 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId'); echo 'ID1: ' . $soapSessionId1 . PHP_EOL; $wsaFilter->addReferenceParameter('http://ws.apache.org/namespaces/axis2', 'axis2', 'ServiceGroupId', $soapSessionId1); var_dump($sc->getVersion()); $soapSessionId2 = $wsaFilter->getReferenceParameter('http://ws.apache.org/namespaces/axis2', 'ServiceGroupId'); echo 'ID2: ' . $soapSessionId2 . PHP_EOL;
require '../bootstrap.php'; $options = array('soap_version' => SOAP_1_1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => true, 'attachment_type' => BeSimpleSoapHelper::ATTACHMENTS_TYPE_SWA, 'cache_wsdl' => WSDL_CACHE_NONE); /* * Deploy "axis_services/besimple-swa.aar" to Apache Axis2 to get this * example to work. * * Run ant to rebuild aar. * * Example based on: * http://axis.apache.org/axis2/java/core/docs/mtom-guide.html#a3 * http://wso2.org/library/1675 * * Doesn't work directly with ?wsdl served by Apache Axis! * */ $sc = new BeSimpleSoapClient('SwA.wsdl', $options); //var_dump($sc->__getFunctions()); //var_dump($sc->__getTypes()); try { $file = new stdClass(); $file->name = 'upload.txt'; $file->data = 'This is a test text!'; $result = $sc->uploadFile($file); var_dump($result->return); $file = new stdClass(); $file->name = 'upload.txt'; $result = $sc->downloadFile($file); var_dump($result->data); $file = new stdClass(); $file->name = 'image.jpg'; // source: http://www.freeimageslive.com/galleries/light/pics/swirl3768.jpg
/** * Handles soap call and return weather array * @param string $country * @param string $city * @return array */ public function soapClientCall($country, $city) { $url = $this->url; $client = new SoapClient($url); if (!$city) { $city = ''; } if (!$country) { $country = ''; } $serviceParams = array(self::SOAPAPIPARAM => array("CityName" => $city, "CountryName" => $country)); $result = $client->__soapCall(self::SOAPAPIPARAM, $serviceParams); $weatherResult = $result->GetWeatherResult; //converting xml to json and then to array if ($weatherResult != 'Data Not Found') { $responseXml = simplexml_load_string(preg_replace('/(<\\?xml[^?]+?)utf-16/i', '$1utf-8', $weatherResult)); $responseJson = json_encode($responseXml); $responseArray = json_decode($responseJson, TRUE); } else { $responseArray = 'Data not found'; } return $responseArray; }
/** * Runs the request * @param $request * @param $location * @param $action * @param $version * @param null $one_way * @return string * @throws Exceptions\CybersourceException * @codeCoverageIgnore */ public function doRequest($request, $location, $action, $version, $one_way = null) { $header = self::SOAP_HEADER_PRE_USER . $this->merchantId . self::SOAP_HEADER_PRE_PASS . $this->transactionId . self::SOAP_HEADER_FINAL; $requestDOM = new \DOMDocument(self::DOM_VERSION); $soapHeaderDOM = new \DOMDocument(self::DOM_VERSION); try { $requestDOM->loadXML($request); $soapHeaderDOM->loadXML($header); $node = $requestDOM->importNode($soapHeaderDOM->firstChild, true); $requestDOM->firstChild->insertBefore($node, $requestDOM->firstChild->firstChild); $request = $requestDOM->saveXML(); } catch (\DOMException $e) { \Log::error($e); throw new CybersourceException(); } return parent::__doRequest($request, $location, $action, $version, $one_way); }
/** * {@inheritDoc} */ public function doCall($method, array $parameters = []) { // open connection if needed if (($this->soapClient === null || $this->token === null) && $this->login !== null) { $this->openApiConnection(); } // parameters strings should be UTF8 foreach ($parameters as $key => $value) { if ('string' === gettype($value) && 'UTF-8' !== mb_detect_encoding($value)) { $parameters[$key] = utf8_encode($value); } } $parameters['token'] = $this->token; try { $response = $this->soapClient->__soapCall($method, [$parameters]); if (!isset($response->return)) { return null; } return $response->return; } catch (\SoapFault $fault) { throw new APIException('CampaignCommander API operation error', 0, $fault); } }