CometD handshake
CometD handshake, see https://docs.cometd.org/current/reference/#_bayeux_meta_handshake
@return ApiResponse&lt;Void&gt;
@throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
971973
public ApiResponse<Void> getHandshakeWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getHandshakeValidateBeforeCall(null, null);
        return apiClient.execute(call);
    }
263436
public ApiResponse<GetSubResponse> getSubWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getSubValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<GetSubResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
137327
public static function exception(ApiException $exception)
    {
        $returnResponse = \Response::make($exception->jsonSerialize());

        $returnResponse->setStatusCode($exception->getStatusCode());

        return $returnResponse;
    }
49523
public function indexAction()
    {
        $templates = $this->get('doctrine.orm.entity_manager')->getRepository('VictoireTemplateBundle:Template')->findByTemplate(null, ['position' => 'ASC']);

        return new JsonResponse(
            [
                'success' => true,
                'html'    => $this->container->get('templating')->render(
                    'VictoireTemplateBundle:Template:index.html.twig',
                    ['templates' => $templates]
                ),
            ]
        );
    }
714479
private function parseExceptionForErrorMessages(Exception $e)
    {
        if (! $e instanceof BadResponseException) {
            throw new ApiException($e->getMessage());
        }

        $response = $e->getResponse();
        Psr7\rewind_body($response);
        $responseBody = $response->getBody()->getContents();
        $decodedResponseBody = json_decode($responseBody, true);

        if (! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) {
            $errorMessage = $decodedResponseBody['error']['message']['value'];
        } else {
            $errorMessage = $responseBody;
        }

        throw new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage, $response->getStatusCode());
    }
1346460
public function getBearerToken()
	{	
		try { 

			$response = $this->client->request('POST', self::$api_base.'oauth2/token', [
			    'query' => ['grant_type' => 'client_credentials'],
			    'headers' => [
			        'Authorization' => 'Basic ' . base64_encode($this->app_key.':'.$this->app_secret),
			        'Content-Type'     => 'application/x-www-form-urlencoded;charset=UTF-8'
			    ]
			]);

 			$this->setStatusCode($response->getStatusCode());
 			$response_body = json_decode($response->getBody());
 			$this->bearer_token = $this->isBearer($response_body);

 		} catch (\Exception $e) {

			$this->setStatusCode($e->getCode());
			$this->setResponse($e->getMessage());

		}
		
 	}
149325
protected function getHttpResponse($status, array $headers = [])
    {
        if (array_key_exists($status, self::HTTP_RESPONSES)) {
            $response = self::HTTP_RESPONSES[$status];
        } else {
            $response = self::HTTP_RESPONSES[self::HTTP_NOT_IMPLEMENTED];
        }

        $handshake = [
            sprintf(self::RESPONSE_LINE_FORMAT, $status, $response),
        ];

        foreach ($headers as $name => $value) {
            $handshake[] = sprintf(self::HEADER_LINE_FORMAT, $name, $value);
        }

        return implode($handshake, "\r\n") . "\r\n\r\n";
    }
586878
public MessageIDEnvelope sendMessage(Message data) throws ApiException {
        ApiResponse<MessageIDEnvelope> resp = sendMessageWithHttpInfo(data);
        return resp.getData();
    }
840638
public function apiMerge()
    {
        DB::beginTransaction();

        try {
            $record = $this->__apiMerge();
        } catch (\Exception $e) {
            DB::rollback();

            return HCLog::error('CORE-0007' . $e->getCode(), $e->getMessage());
        }

        DB::commit();

        return $record;
    }
502971
public function sendExceptionResponse(WebHookHandlerException $e) {
		$httpCode = '400 Bad Request';
		switch($e->getCode()) {
			case WebHookHandlerException::NO_PRIVATE_KEY:
				$httpCode = '500 Internal Server Error';
				break;
			case WebHookHandlerException::INVALID_DECRYPTED_JSON:
			case WebHookHandlerException::DECRYPTION_FAILED:
			case WebHookHandlerException::INPUT_FETCH_FAILED:
			case WebHookHandlerException::INPUT_DECODE_FAILED:
			case WebHookHandlerException::NO_ENVELOPE_KEY:
			case WebHookHandlerException::NO_PAYLOAD:
			case WebHookHandlerException::NO_INPUT_HASH:
				$httpCode = '400 Bad Request';
				break;
		}
		$this->sendHTTPResponse($httpCode, ['success' => false, 'errorCode' => $e->getCode(), 'errorDescription' => $e->getMessage()]);
		return $this;
	}
428183
public function getBasicResponse()
    {
        // Default the basic response
        if ($this->basicResponse === null) {
            $this->basicResponse = function () {
                if (headers_sent()) {
                    throw new RuntimeException('Attempting basic auth after headers have already been sent.');
                }

                header('WWW-Authenticate: Basic');
                header('HTTP/1.0 401 Unauthorized');

                echo 'Invalid credentials.';
                exit;
            };
        }

        $response = $this->basicResponse;

        return $response();
    }
940078
public ApiResponse<ModelApiResponse> pingWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = pingValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
368582
private function makeHttpRequest()
    {
        try {
            return $this->client->post($this->apiUrl, [
                $this->httpBodyParam => $this->post->toArray(),
            ])->getBody();
        } catch (HttpClientException $e) {
            throw new \Exception($e->getRequest().' '.$e->getResponse());
        } catch (HttpServerException $e) {
            throw new \Exception($e->getRequest().' '.$e->getResponse());
        } catch (HttpBadResponseException $e) {
            throw new \Exception($e->getRequest().' '.$e->getResponse());
        }
    }
1365394
public function callbackResponse()
    {
        // cleanup
        $this->getCaller()->setParameter("VERSION", null);
        $this->getCaller()->setParameter("PWD", null);
        $this->getCaller()->setParameter("USER", null);
        $this->getCaller()->setParameter("SIGNATURE", null);

        return $this->getCaller()->getCallBackResponse("CallbackResponse");
    }
312099
public ApiResponse<UserEnvelope> getSelfWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = getSelfValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<UserEnvelope>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
284716
public function handshake(Request $request, Response $response): array
    {
        try {
            $path = $request->getUri()->getPath();
            list($className,) = $this->getHandler($path);
        } catch (\Throwable $e) {
            /* @var ErrorHandler $errorHandler */
            // $errorHandler = \bean(ErrorHandler::class);
            // $response = $errorHandler->handle($e);
            if ($e instanceof WsRouteException) {
                return [
                    HandlerInterface::HANDSHAKE_FAIL,
                    $response->withStatus(404)->withAddedHeader('Failure-Reason', 'Route not found')
                ];
            }

            // other error
            throw $e;
        }

        /** @var HandlerInterface $handler */
        $handler = \bean($className);

        if (!\method_exists($handler, 'checkHandshake')) {
            return [
                HandlerInterface::HANDSHAKE_OK,
                $response->withAddedHeader('swoft-ws-handshake', 'auto')
            ];
        }

        return $handler->checkHandshake($request, $response);
    }
1302555
function _handshake(handshakeProps, handshakeCallback) {
        if (_isFunction(handshakeProps)) {
            handshakeCallback = handshakeProps;
            handshakeProps = undefined;
        }

        _clientId = null;

        _clearSubscriptions();

        // Reset the transports if we're not retrying the handshake
        if (_isDisconnected()) {
            _transports.reset(true);
            _updateAdvice(_config.advice);
        } else {
            // We are retrying the handshake, either because another handshake failed
            // and we're backing off, or because the server timed us out and asks us to
            // re-handshake: in both cases, make sure that if the handshake succeeds
            // the next action is a connect.
            _updateAdvice(_cometd._mixin(false, _advice, {reconnect: 'retry'}));
        }

        _batch = 0;

        // Mark the start of an internal batch.
        // This is needed because handshake and connect are async.
        // It may happen that the application calls init() then subscribe()
        // and the subscribe message is sent before the connect message, if
        // the subscribe message is not held until the connect message is sent.
        // So here we start a batch to hold temporarily any message until
        // the connection is fully established.
        _internalBatch = true;

        // Save the properties provided by the user, so that
        // we can reuse them during automatic re-handshake
        _handshakeProps = handshakeProps;
        _handshakeCallback = handshakeCallback;

        var version = '1.0';

        // Figure out the transports to send to the server
        var url = _cometd.getURL();
        var transportTypes = _transports.findTransportTypes(version, _crossDomain, url);

        var bayeuxMessage = {
            id: _nextMessageId(),
            version: version,
            minimumVersion: version,
            channel: '/meta/handshake',
            supportedConnectionTypes: transportTypes,
            advice: {
                timeout: _advice.timeout,
                interval: _advice.interval
            }
        };
        // Do not allow the user to override important fields.
        var message = _cometd._mixin(false, {}, _handshakeProps, bayeuxMessage);

        // Save the callback.
        _cometd._putCallback(message.id, handshakeCallback);

        // Pick up the first available transport as initial transport
        // since we don't know if the server supports it
        if (!_transport) {
            _transport = _transports.negotiateTransport(transportTypes, version, _crossDomain, url);
            if (!_transport) {
                var failure = 'Could not find initial transport among: ' + _transports.getTransportTypes();
                _cometd._warn(failure);
                throw failure;
            }
        }

        _cometd._debug('Initial transport is', _transport.getType());

        // We started a batch to hold the application messages,
        // so here we must bypass it and send immediately.
        _setStatus('handshaking');
        _cometd._debug('Handshake sent', message);
        _send(false, [message], false, 'handshake');
    }