public RequestStatus login([BodyParam()] User dtls, HttpResp response) { RequestStatus sts = new RequestStatus(); sts.Message = "Login success"; response.StatusCode = 200; return(sts); }
internal static object[] Extract(HttpRequest request, BodyBinaryExtractor[] BodyArguments, HttpResp response, List <BaseAttribute> parameters, MediaType consumes ) { String uri = request.getRequestURI(); List <Object> objects = new List <object>(); Object ParamToAdd = null; Int32 len; foreach (BaseAttribute p in parameters) { if (p is HttpResp) { objects.Add(response); //special handling !! continue; } if (p is PathVariable) { Int32 pos = ((PathVariable)p).getPosInURL(); String[] spit = uri.Substring(pos).Split('/'); ParamToAdd = spit[0]; } if (p is PathQueryVariable) { String V_Name = ((PathQueryVariable)p).getName(); Regex parser = new Regex("(" + V_Name + "=.*)"); MatchCollection splits = parser.Matches(uri); if (splits.Count == 1) { String[] split = splits[0].Value.Split(ExtractMethodParams.m_PathQueryVarSplitter); ParamToAdd = split[1]; } } if (p is HeaderParam) { String headerval = request.GetHeaderValue(p.getName()); //it could be JSON if (MediaType.APPLICATION_JSON == consumes) { JSON Deser = new JSON(p.getType()); MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(headerval)); ParamToAdd = Deser.ReadObject(stream); } else { ParamToAdd = headerval; } } if (p is BodyParam || p is BodyQueryParam) { //the body can be MultiPart Form Data. If so extract from the Body //else tje body itself denotes the data ParamToAdd = ExtractBodyParameter(request, BodyArguments, p); } objects.Add(ChangeType(ParamToAdd, p.getType(), consumes)); } return(objects.ToArray()); }
override public Byte[] Process(HttpRequest Request) { //transform the body part BodyBinaryExtractor[] body = TransformBody(Request); byte[] responseStream = null; var response = new HttpResp(); var mthd = Request.getMethod(); Object[] ret = Program.getControllerFactory().getMethodMapper(mthd, Request.getRequestURI()); var mpr = ret[1] as ComponentMethodMapper; Object retVal = null; if (null != mpr) { try { Object[] parameters = ExtractMethodParams.Extract(Request, body, response, mpr.getParamList(), mpr.Consumes); /* Invoke using MethodInfo is way faster than a delegate * * Object retVal = mpr.DynamicInvoke(parameters); */ retVal = mpr.GetMethodInfo().Invoke(mpr.GetObject(), parameters); } catch (UnsupportedMediaType err) { response.StatusCode = 415; response.ContentType = MediaType.TEXT_PLAIN; retVal = "Error during deserialising to JSON"; } catch (Exception err) { response.StatusCode = 500; response.ContentType = MediaType.TEXT_PLAIN; retVal = "Internal Error " + err.Message; } } else { response.StatusCode = 404; response.ContentType = MediaType.TEXT_PLAIN; retVal = "Mapper for URL " + Request.getRequestURI() + " not found"; } try { //marshall the response //check if the response was passed to user code responseStream = MarshallOctet.marshall(response, retVal, mpr.Produces); } catch (ArgumentNullException err) { //TODO } catch (SocketException err) { //TODO } catch (ObjectDisposedException err) { //TODO } catch (Exception err) { //TODO } return(responseStream); }