예제 #1
0
        private void handleSingleRequest(HttpRequest servletRequest,
                                         HttpResponse servletResponse, ISecurityToken token, BeanConverter converter)
        {
            RestfulRequestItem requestItem = new RestfulRequestItem(servletRequest, token, converter);
            var asyncResult = HandleRequestItem(requestItem);

            // handle just the one case where we can't find a handler
            if (asyncResult == null)
            {
                sendError(servletResponse, new ResponseItem((int)HttpStatusCode.InternalServerError,
                                                            "The service " + requestItem.getService() + " is not implemented"));
                return;
            }
            ResponseItem responseItem = getResponseItem(asyncResult);

            servletResponse.ContentType = converter.GetContentType();
            if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400)
            {
                Object resp = responseItem.getResponse();
                // put single object responses into restfulcollection
                if (!(resp is DataCollection) && !(resp is IRestfulCollection))
                {
                    switch (requestItem.getService())
                    {
                    case IHandlerDispatcher.ACTIVITY_ROUTE:
                        if (resp is Activity)
                        {
                            resp = new RestfulCollection <Activity>((Activity)resp);
                        }

                        break;

                    case IHandlerDispatcher.PEOPLE_ROUTE:
                        if (resp is Person)
                        {
                            resp = new RestfulCollection <Person>((Person)resp);
                        }
                        break;

                    case IHandlerDispatcher.APPDATA_ROUTE:
                        if (requestItem.getOperation() != "POST")
                        {
                            resp = new DataCollection(new Dictionary <string, Dictionary <string, string> > {
                                { "entry", (Dictionary <string, string>)resp }
                            });
                        }
                        break;

                    default:
                        resp = new Dictionary <string, object> {
                            { "entry", resp }
                        };
                        break;
                    }
                }

                servletResponse.Output.Write(converter.ConvertToString(resp, requestItem));
            }
            else
            {
                sendError(servletResponse, responseItem);
            }
        }
예제 #2
0
        private void handleSingleRequest(HttpRequest servletRequest,
                HttpResponse servletResponse, ISecurityToken token, BeanConverter converter)
        {
            RestfulRequestItem requestItem = new RestfulRequestItem(servletRequest, token, converter);
            var asyncResult = HandleRequestItem(requestItem);
            
            // handle just the one case where we can't find a handler
            if (asyncResult == null)
            {
                sendError(servletResponse, new ResponseItem((int)HttpStatusCode.InternalServerError,
                                    "The service " + requestItem.getService() + " is not implemented"));
                return;
            }
            ResponseItem responseItem = getResponseItem(asyncResult);

            servletResponse.ContentType = converter.GetContentType();
            if (responseItem.getErrorCode() >= 200 && responseItem.getErrorCode() < 400) 
            {
                Object resp = responseItem.getResponse();
                // put single object responses into restfulcollection
                if (!(resp is DataCollection) && !(resp is IRestfulCollection))
                {
                    switch (requestItem.getService())
                    {
                        case IHandlerDispatcher.ACTIVITY_ROUTE:
                            if (resp is Activity)
                            {
                                resp = new RestfulCollection<Activity>((Activity)resp);
                            }

                            break;
                        case IHandlerDispatcher.PEOPLE_ROUTE:
                            if (resp is Person)
                            {
                                resp = new RestfulCollection<Person>((Person)resp);
                            }
                            break;
                        case IHandlerDispatcher.APPDATA_ROUTE:
                            if (requestItem.getOperation() != "POST")
                                resp = new DataCollection(new Dictionary<string, Dictionary<string, string>> { { "entry", (Dictionary<string, string>)resp } });
                            break;
                        default:
                            resp = new Dictionary<string, object> { { "entry", resp } };
                            break;
                    }
                }

                servletResponse.Output.Write(converter.ConvertToString(resp, requestItem));
            }
            else
            {
                sendError(servletResponse, responseItem);
            }
        }