Exemple #1
0
        public async Task Send(CommandMessage commandMessage)
        {
            string correlationId = "";

            try {
                correlationId = commandMessage.HeaderCollection.GetHeader(CommandMessageHeaderNames.CorrelationId).Value;
            } catch {
                correlationId = Guid.NewGuid().ToString();
            }
            JsonRpcRequest jsonRpcRequest = new JsonRpcRequest()
            {
                id      = 1,
                jsonrpc = "2.0",
                method  = "ExecuteWithCorrelationAndHeaders",
                Params  = new JsonRpcGatewayExecuteParams()
                {
                    routingKey = commandMessage.HeaderCollection.GetHeader(CommandMessageHeaderNames.RoutingKey).Value,
                    command    = new JsonRpcGatewayCommand()
                    {
                        name = commandMessage.CommandMessageBody.CommandName,
                        data = commandMessage.CommandMessageBody.Command
                    },
                    authorizationToken = commandMessage.HeaderCollection.GetHeader(CommandMessageHeaderNames.AuthorizationToken).Value,
                    correlationId      = correlationId,
                    headers            = commandMessage.HeaderCollection.ToDictionary(h => h.Name, h => h.Value)
                }
            };

            using (HttpClient httpClient = new HttpClient()) {
                HttpResponseMessage httpResponse = await httpClient.PostAsync(
                    _configuration.GatewayUrl + "/api/rpc.json",
                    new StringContent(_serializationService.SerializeToString(jsonRpcRequest), Encoding.UTF8, "application/json")
                    );

                httpResponse.EnsureSuccessStatusCode();
                JsonRpcResponse jsonRpcResponse = _serializationService.DeserializeFromString <JsonRpcResponse>(
                    await httpResponse.Content.ReadAsStringAsync()
                    );
                if (jsonRpcResponse.error != null)
                {
                    throw new Exception($"JSON RPC Error {jsonRpcResponse.error.code}: {jsonRpcResponse.error.message}");
                }
            }
        }
Exemple #2
0
        public async Task <CommandMessage> Send(CommandMessage commandMessage)
        {
            Header             authorizationTokenHeader = commandMessage.HeaderCollection.GetHeader(CommandMessageHeaderNames.AuthorizationToken);
            AuthorizationToken authorizationToken;

            try {
                authorizationToken = await _authorizationTokenClientProvider.ParseAuthorizationToken(new SerializedAuthorizationToken(authorizationTokenHeader.Value));
            } catch {
                throw new Exception("Authorization Token is not valid.");
            }
            commandMessage.HeaderCollection.AddHeader(new Header(CommandMessageHeaderNames.AuthorizationContext, _serializationService.SerializeToString(authorizationToken)));
            return(commandMessage);
        }