コード例 #1
0
        /// <summary>
        /// Process an inboound request.
        /// Search the collected APIPaths for a path match and do the operation
        ///     appropriate for that request.
        /// </summary>
        /// <param name="pReq">The wrapper for ListernerHttpContext</param>
        /// <returns></returns>
        public RESTReplyData ProcessInbound(RESTRequestData pReq)
        {
            RESTReplyData _replyData = null;

            APIPath foundPath = FindPathProcessor(pReq.RawURL, pReq.Method, out List <string> oArguments);

            if (foundPath != null)
            {
                // Found the matching, process the request
                Context.Log.Debug("{0} Processing '{1}:{2} from {3}:{4}' with {5}", _logHeader,
                                  pReq.Method, pReq.RawURL,
                                  pReq.RemoteUser, pReq.RemotePort,
                                  foundPath.AssignedMethod.Name);
                try
                {
                    object _method = Activator.CreateInstance(foundPath.AssignedMethod.DeclaringType);
                    _replyData = (RESTReplyData)foundPath.AssignedMethod.Invoke(_method,
                                                                                new object[] { pReq, oArguments });
                }
                catch (Exception e)
                {
                    Context.Log.Error("{0} Exception processing: {1}", _logHeader, e.ToString());
                    _replyData = null;
                }
            }
            // If we didn't get a reply constructed, tell the requestor some error nonsense.
            if (_replyData == null)
            {
                // The request does not match any path, return error
                _replyData = new RESTReplyData
                {
                    Status = 200
                };
                Dictionary <string, string> notFoundDefault = new Dictionary <string, string>
                {
                    { "status", "not_found" },
                    { "data", "Needs more water!" }
                };
                string notFoundDef = JsonConvert.SerializeObject(notFoundDefault);
                _replyData.Body = notFoundDef;
            }

            return(_replyData);
        }
コード例 #2
0
        /// <summary>
        /// Process an inboound request.
        /// Search the collected APIPaths for a path match and do the operation
        ///     appropriate for that request.
        /// </summary>
        /// <param name="pReq">The wrapper for ListernerHttpContext</param>
        /// <returns></returns>
        public RESTReplyData ProcessInbound(RESTRequestData pReq)
        {
            RESTReplyData _replyData = null;

            APIPath foundPath = FindPathProcessor(pReq.RawURL, pReq.Method, out List <string> oArguments);

            if (foundPath != null)
            {
                // Found the matching, process the request
                if (Context.Params.P <bool>(AppParams.P_DEBUG_PROCESSING))
                {
                    Context.Log.Debug("{0} Processing '{1}:{2} from {3}:{4}' with {5}", _logHeader,
                                      pReq.Method, pReq.RawURL,
                                      pReq.RemoteUser, pReq.RemotePort,
                                      foundPath.AssignedMethod.Name);
                }
                try
                {
                    object _method = Activator.CreateInstance(foundPath.AssignedMethod.DeclaringType);
                    _replyData = (RESTReplyData)foundPath.AssignedMethod.Invoke(_method,
                                                                                new object[] { pReq, oArguments });
                }
                catch (Exception e)
                {
                    Context.Log.Error("{0} Exception processing: {1}", _logHeader, e.ToString());
                    _replyData = null;
                }
            }
            // If we didn't get a reply constructed, tell the requestor some error nonsense.
            if (_replyData == null)
            {
                // The request does not match any path, return error
                _replyData = new RESTReplyData();
                ResponseBody respBody = new ResponseBody();

                respBody.RespondFailure("operation not found");

                _replyData.SetBody(respBody, pReq);
            }

            return(_replyData);
        }