@param Message $message

@throws ConnectionException
@throws ConnectionHandlerException

@return Response
359709
public function sendAndReceive(Message $message): Response
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification" />');
        $toast = $xml->addChild('wp:Toast');
        foreach ($message->getMessage() as $element => $value) {
            $toast->addChild($element, htmlspecialchars($value, ENT_XML1 | ENT_QUOTES));
        }
        $response = new ConnectionResponseImpl();

        $request = new Request('POST', $message->getIdentifier(), [], $xml->asXML());
        try {
            $clientResponse = $this->client->send($request);
            // check against headers? X-NotificationStatus / X-SubscriptionStatus / X-DeviceConnectionStatus
            // @see https://msdn.microsoft.com/en-us/library/windows/apps/ff941100(v=vs.105).aspx
            $response->setResponse($clientResponse->getBody()->getContents());
        } catch (RequestException $e) {
            $response->setErrorResponse($e);
        }

        return $response;
    }
377605
protected function doSendRequest(MessageInterface $message)
    {
        $status = $this->driver->doSendRequest(
            array(
                static::PARAM_Username   => $this->username,
                static::PARAM_Password   => $this->password,
                static::PARAM_Test       => $this->test,
                static::PARAM_Recipients => $message->getRecipient(),
                static::PARAM_Message    => $message->getMessage(),
            )
        );

        if ($status[DriverInterface::NORMALIZED_CODE] !== DriverInterface::STATUS_OK) {
            throw new DeliveryException(
                $message,
                $status[DriverInterface::NORMALIZED_MESSAGE],
                $status[DriverInterface::NORMALIZED_CODE]
            );
        }

        $this->lastStatus = $status;

        return true;
    }
373127
public function sendMessage(Message $message)
    {
        $payload = $this->preparePayload($message);

        $encoded = json_encode($payload, JSON_UNESCAPED_UNICODE);

        if ($encoded === false) {
            throw new RuntimeException(sprintf('JSON encoding error %s: %s', json_last_error(), json_last_error_msg()));
        }

        $this->guzzle->post($this->endpoint, ['body' => $encoded]);
    }
185914
public function execute($query = null)
    {
        try {
            $event = new ConnectionEvent($this, $query);
            $this->container->getDispatcher()->dispatch(ConnectionEvent::ON_QUERY, $event);
            $this->affectedRows = parent::exec($query);
        } catch (\Exception $exception) {
            throw new ConnectionException('Executing query has error: [:code] ":error"', [
                'code'  => $exception->getCode(),
                'error' => $exception->getMessage(),
            ]);
        }
        
        return $this;
    }
342709
public function send($message)
    {
        return $this->response->hydrate(
            $this->getPromise($message)
                ->receive()
                ->getBody()
        );
    }
1319880
public function call(Message $message) : Message
    {
        $aggregate = $message->getHeaders()->containsKey(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER)
                            ? $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER)
                            : null;
        $methodInvoker = MethodInvoker::createWith(
            $aggregate ? $aggregate : $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_CLASS_NAME_HEADER),
            $message->getHeaders()->get(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_METHOD_HEADER),
            $this->messageToParameterConverters
        );

        $resultMessage = MessageBuilder::fromMessage($message);
        try {
            $result = $methodInvoker->processMessage($message);

            if (!$aggregate) {
                $resultMessage = $resultMessage
                    ->setHeader(CqrsMessagingModule::INTEGRATION_MESSAGING_CQRS_AGGREGATE_HEADER, $result);
            }
        } catch (\Throwable $e) {
            throw MessageHandlingException::fromOtherException($e, $message);
        }

        if (!is_null($result)) {
            $resultMessage = $resultMessage
                ->setPayload($result);
        }

        return $resultMessage
                ->build();
    }
568182
public function send(Message $message)
	{
		// Queue the message and flush the associated gateway
		$messageEnvelope = $this->queue($message);
		$this->flush( $message->getCertificate() );

		// Return the envelope
		return $messageEnvelope;
	}
263887
public function publish(Message $message): ChannelInformation
    {
        $response = $this->client->post(
            new Request(
                $this->channelUrl,
                [
                    'Accept'              => 'application/json',
                    'Content-Type'        => $message->contentType(),
                    'X-EventSource-Event' => $message->name()
                ],
                $message->content()
            )
        );

        if (!in_array($response->statusCode(), [Response::CREATED, Response::ACCEPTED])) {
            throw new NchanException(
                sprintf(
                    'Unable to publish to channel. Maybe the channel does not exists. HTTP status code was %s.',
                    $response->statusCode()
                )
            );
        }

        return ChannelInformation::fromJson($response->body());
    }
334917
public function handles(Message $message): bool
    {
        try {
            $this->getNotifierForMessage($message);

            return true;
        } catch (NotifierNotFoundException $e) {
            return false;
        }
    }
1043772
public function fromMessage($message)
    {
        static $parser;
        if (!$parser) {
            $parser = new MessageParser();
        }

        // Parse a response
        if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
            $data = $parser->parseResponse($message);
            return $this->createResponse(
                $data['code'],
                $data['headers'],
                $data['body'] === '' ? null : $data['body'],
                $data
            );
        }

        // Parse a request
        if (!($data = ($parser->parseRequest($message)))) {
            throw new \InvalidArgumentException('Unable to parse request');
        }

        return $this->createRequest(
            $data['method'],
            Url::buildUrl($data['request_url']),
            [
                'headers' => $data['headers'],
                'body' => $data['body'] === '' ? null : $data['body'],
                'config' => [
                    'protocol_version' => $data['protocol_version']
                ]
            ]
        );
    }
684403
private function createException($message = '')
    {
        if ($this->pgConn) {
            $this->lastError = pg_last_error($this->pgConn);
        }

        return new DB\Exception($message ?: $this->lastError);
    }
105187
protected function addToQueue(Message $message, string $connectionName = null): MessageEnvelope
    {
        $envelope = $this->createMessageEnvelope($message);
        if ($connectionName === null) {
            $connectionName = $this->connectionHandler->getDefaultConnection()->getType();
        }
        if (!array_key_exists($connectionName, $this->queues)) {
            $this->queues[$connectionName] = new MessageEnvelopeQueueImpl();
        }
        $this->queues[$connectionName]->add($envelope);

        return $envelope;
    }
371169
public function load(Message $message) : ?Message
    {
        $aggregateIdentifiers = [];
        $expectedVersion = null;

        foreach ($this->aggregateIdentifierMapping as $aggregateIdentifierName => $aggregateIdentifierMappingName) {
            $aggregateIdentifiers[$aggregateIdentifierName] = $this->isFactoryMethod ? null : $this->propertyReaderAccessor->getPropertyValue(PropertyPath::createWith($aggregateIdentifierMappingName), $message->getPayload());
        }

        $aggregate = null;
        if (!$this->isFactoryMethod) {

            foreach ($aggregateIdentifiers as $identifierName => $aggregateIdentifier) {
                if (is_null($aggregateIdentifier)) {
                    throw AggregateNotFoundException::create("Aggregate identifier {$identifierName} definition found, but is null. Can't load aggregate {$this->aggregateClassName} to call {$this->aggregateMethod}.");
                }
            }

            $expectedVersion = $this->expectedVersionName ? $this->propertyReaderAccessor->getPropertyValue(PropertyPath::createWith($this->expectedVersionName), $message->getPayload()) : null;
            if ($this->expectedVersionName && !$expectedVersion) {
                throw InvalidArgumentException::create("Aggregate {$this->aggregateClassName}:{$this->aggregateMethod} has defined version locking, but no version during command handling was provided");
            }

            $aggregate = is_null($this->expectedVersionName)
                ? $this->aggregateRepository->findBy($aggregateIdentifiers)
                : $this->aggregateRepository->findWithLockingBy($aggregateIdentifiers, $expectedVersion);

            if (!$aggregate && $this->filterOutOnNotFound) {
                return null;
            }
        }

        $messageBuilder = MessageBuilder::fromMessage($message);
        if ($aggregate) {
            $messageBuilder = $messageBuilder->setHeader(AggregateMessage::AGGREGATE_OBJECT, $aggregate);
        }
        if ($expectedVersion) {
            $messageBuilder = $messageBuilder->setHeader(AggregateMessage::EXPECTED_VERSION, $expectedVersion);
        }

        if (!$message->getHeaders()->containsKey(MessageHeaders::REPLY_CHANNEL)) {
            $messageBuilder = $messageBuilder
                                ->setReplyChannel(NullableMessageChannel::create());
        }

        return $messageBuilder
            ->setHeader(AggregateMessage::CLASS_NAME, $this->aggregateClassName)
            ->setHeader(AggregateMessage::METHOD_NAME, $this->aggregateMethod)
            ->setHeader(AggregateMessage::AGGREGATE_ID, $aggregateIdentifiers)
            ->setHeader(AggregateMessage::IS_FACTORY_METHOD, $this->isFactoryMethod)
            ->setHeader(AggregateMessage::CALLING_MESSAGE, $message)
            ->build();
    }
1368763
public function respondWithMessage($message = "Ok")
    {
        $data = $this->getResponseStructure(true, null, $message);

        return $this->respond($data);
    }
1289206
protected function sendMessage(Message $message, string $connectionName = null): MessageEnvelope
    {
        /* @var AndroidMessage $message */
        $connection = $this->getConnectionHandler()->getConnection($connectionName);
        /* @var AndroidConnection $connection */
        $messageEnvelope = $this->createMessageEnvelope($message);
        /* @var AndroidMessageEnvelope $messageEnvelope */
        $this->sendMessageEnvelope($connection, $messageEnvelope);

        return $messageEnvelope;
    }
823269
public function getException($message)
    {
        // make exception based on the status code
        switch ($this->statusCode) {
            case 400:
                return
                    $message?
                        new PlivoValidationException($message):
                        new PlivoValidationException(
                            "A parameter is missing or ".
                            "is invalid while accessing resource");
                break;
            case 401:
                return
                    $message?
                        new PlivoAuthenticationException($message):
                        new PlivoAuthenticationException(
                        "Failed to authenticate while accessing resource");
                break;
            case 404:
                return
                    $message?
                        new PlivoNotFoundException($message):
                        new PlivoNotFoundException(
                        "Failed to authenticate while accessing resource");
                break;
            case 405:
                return
                    $message?
                        new PlivoRequestException($message):
                        new PlivoRequestException(
                        "HTTP method used is not allowed to access resource");
                break;
            case 500:
                return
                    $message?
                        new PlivoServerException($message):
                        new PlivoServerException(
                        "A server error occurred while accessing resource");
                break;
            default:
                return new PlivoRestException(json_encode($this->responseData));
        }

    }
559380
public function deleteMessageAction(Message $message)
    {
        if ($this->authorization->isGranted('moderate', new ResourceCollection(array($message->getSubject()->getCategory()->getForum()->getResourceNode())))) {
            $this->manager->deleteMessage($message);

            return new RedirectResponse(
                $this->generateUrl('claro_forum_messages', array('subject' => $message->getSubject()->getId()))
            );
        }

        throw new AccessDeniedException();
    }