Ejemplo n.º 1
0
 protected virtual void OnBadResponseEvent(BadResponseEventArgs args)
 {
     if (BadResponse != null)
     {
         BadResponse.Invoke(this, args);
     }
 }
Ejemplo n.º 2
0
        private static string GetMessage(HttpResponseMessage response)
        {
            string errorResponse = response.Content.ReadAsStringAsync().Result;

            BadResponse error = null;

            try
            {
                error = JsonConvert.DeserializeObject <BadResponse>(errorResponse);
            }
            catch (JsonReaderException)
            {
                if (parseCopyleaksErrorCode(response) != UNDEFINED_COPYLEAKS_HEADER_ERROR_CODE)
                {
                    return(errorResponse);
                }
            }

            if (error == null)
            {
                return("The application has encountered an unknown error. Please try again later.");
            }
            else
            {
                return(error.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Call Apps (Azure Functions or Custom App) with HTTP
        /// </summary>
        /// <param name="rbh"></param>
        /// <param name="rbBodyString"></param>
        /// <param name="partitionId"></param>
        /// <returns>Task<JArray></returns>
        private async Task <JArray> CallAppsWithHttp(RbHeader rbh, string rbBodyString, string partitionId)
        {
            // Get App Master Info
            RbAppMasterCache rbappmc = GetAppMasterInfo(rbh);
            // Get App Routing Info
            RbAppRouterCache rbapprc = GetAppRoutingInfo(rbh);

            JArray    ja_messages = new JArray();
            RbMessage message     = new RbMessage();

            message.RbHeader = rbh;
            message.RbBody   = (JObject)JsonConvert.DeserializeObject(rbBodyString);
            var strMessage = (string)JsonConvert.SerializeObject(message);

            // HTTP Client
            var client = new HttpClient();

            // Create request body
            byte[] byteData = Encoding.UTF8.GetBytes(strMessage);
            var    content  = new ByteArrayContent(byteData);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            // Call REST API
            var response = await client.PostAsync(rbapprc.HttpUri, content);

            if (response.IsSuccessStatusCode)
            {
                var responseText = await response.Content.ReadAsStringAsync();

                try
                {
                    message.RbBody = (JObject)JsonConvert.DeserializeObject(responseText);
                }
                catch
                {
                    var badResponse = new BadResponse();
                    badResponse.StatusCode   = "Parse Error";
                    badResponse.ReasonPhrase = "HTTP response is not regular JSON format";
                    message.RbBody           = badResponse;
                }
            }
            else
            {
                var badResponse = new BadResponse();
                badResponse.StatusCode   = response.StatusCode.ToString();
                badResponse.ReasonPhrase = response.ReasonPhrase.ToString();
                message.RbBody           = badResponse;
            }
            message.RbHeader = rbh;

            string  json_message = JsonConvert.SerializeObject(message);
            JObject jo           = (JObject)JsonConvert.DeserializeObject(json_message);

            ja_messages.Add(jo);

            return(ja_messages);
        }
Ejemplo n.º 4
0
        public void Error500()
        {
            var logger = NLog.LogManager.GetCurrentClassLogger();

            BadResponse badResponse = new BadResponse();

            badResponse.ErrorCode    = "InternalError";
            badResponse.ErrorStatus  = 500;
            badResponse.ErrorMessage = "Unable to process request";


            logger.Info("ERROR, no se pudo procesar la petición.");

            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            var json3 = JsonConvert.SerializeObject(badResponse);

            Response.WriteAsync(json3);
        }
Ejemplo n.º 5
0
        public String  NotFoundRequest()
        {
            var logger = NLog.LogManager.GetCurrentClassLogger();

            BadResponse badResponse = new BadResponse();

            badResponse.ErrorCode    = "NotFound";
            badResponse.ErrorStatus  = 400;
            badResponse.ErrorMessage = "Unable to Process Request: " + Request.Path.ToString();


            logger.Info("ERROR, petición no encontrada.");

            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            var json3 = JsonConvert.SerializeObject(badResponse);

            Response.WriteAsync(json3);

            return("ErrorController");
        }
Ejemplo n.º 6
0
 static void HandleBadResponse(Connection connection, BadResponse session)
 {
     Console.WriteLine("Bad response received");
 }
Ejemplo n.º 7
0
        public static string CreateBadResponse(int statusCode, int errorCode, string details)
        {
            BadResponse badResponse = new BadResponse(statusCode, errorCode, details);

            return(JsonConvert.SerializeObject(badResponse));
        }