/**
  * Triggers the SOAP request over HTTP.
  * Sent request by cURL instead of native SOAP request.
  *
  * @param string      $request
  * @param string      $location
  * @param string      $action
  * @param int         $version
  * @param string|null $one_way
  *
  * @return string The XML SOAP response.
  * @throws WsClientException
  * @throws NoServerAvailableException
  * @throws \InvalidArgumentException
  * @throws \SoapFault
  */
 public function __doRequest($request, $location, $action, $version, $one_way = null)
 {
     $active = $this->manager->getActiveEndpoint();
     try {
         $response = $this->doHttpRequest($request, (string) $active->getUri(), $action);
         $this->manager->updateLastConnected();
         return $response;
     } catch (ConnectException $exception) {
         $active->setStatus('error');
         $this->log('Endpoint is not responding', 'error', ['endpoint' => $active]);
         return $this->__doRequest($request, $location, $action, $version, $one_way);
     }
 }
 /**
  * @throws \Exception
  * @throws \InvalidArgumentException
  * @throws \WebservicesNl\Common\Exception\Server\NoServerAvailableException
  * @throws \WebservicesNl\Common\Exception\Client\InputException
  * @throws \SoapFault
  */
 public function testSoapClientInstanceBadCallWithMultipleEndpoints()
 {
     $manager = new Manager();
     $manager->createEndpoint('https://ws1.webservices.nl/soap_doclit');
     $manager->createEndpoint('https://ws2.webservices.nl/soap_doclit');
     // Create a mock and queue a bad and successful response.
     $mock = new MockHandler([new ConnectException('Error Communicating with Server', new Request('GET', 'login')), new Response(202, ['Content-Length' => 0])]);
     $handler = HandlerStack::create($mock);
     $curlClient = new Client(['handler' => $handler]);
     $instance = new SoapClient($this->settings, $manager, $curlClient);
     $instance->setLogger($this->logger);
     $instance->call(['functionName' => 'login']);
     static::assertTrue($manager->getEndpoints()->first()->isError());
     static::assertTrue($this->testHandler->hasError('Endpoint is not responding'));
 }
 /**
  * Creates and configures a EndpointManager.
  *
  * If url key is present in settings array, this url will be set to the active endpoint.
  *
  * @param array $settings optional settings
  *
  * @return Manager Endpoint manager
  *
  * @throws \InvalidArgumentException
  * @throws InputException
  */
 private function createEndpointManager(array $settings = [])
 {
     // get the default end points from config object
     $endPoints = $this->getConfig()->getEndPoints();
     // merge defaults urls with custom url if present, custom url is set to active
     if (array_key_exists('url', $settings) && filter_var($settings['url'], FILTER_VALIDATE_URL) !== false) {
         array_unshift($endPoints, $settings['url']);
     }
     // Create EndPoint Manager
     $manager = new Manager();
     foreach ($endPoints as $endPoint) {
         $manager->createEndpoint($endPoint);
     }
     if ($this->hasLogger() === true) {
         $this->logger->info('Created endpoint manager', ['endpoint count' => $manager->getEndpoints()->count()]);
     }
     return $manager;
 }
Example #4
0
 /**
  * Test if endpoint last connected is updated
  *
  * @throws InputException
  * @throws NoServerAvailableException
  */
 public function testUpdateEndpoint()
 {
     $manager = new Manager();
     /** @var Endpoint[] $endpoints */
     $endpoints = FactoryMuffin::seed(3, 'WebservicesNl\\Common\\Endpoint\\Endpoint');
     foreach ($endpoints as $endpoint) {
         $manager->addEndpoint($endpoint);
     }
     $endpoint = $manager->updateLastConnected();
     $dateTime = new \DateTime();
     self::assertInstanceOf('\\DateTime', $manager->getActiveEndpoint()->getLastConnected());
     self::assertEquals($dateTime, $endpoint->getLastConnected(), 'DateTimes should be close to each other', 5);
 }