private void ProcessJsvRequest(string url, string operationName, string httpMethod, NameValueCollection queryString, Stream inputStream, HttpListenerResponseWrapper response) { try { var request = JsvHandlerBase.CreateRequest(operationName, httpMethod, queryString, null, inputStream); var isDebugRequest = queryString["debug"] != null; var writeFn = isDebugRequest ? (Func<object, string>)JsvFormatter.SerializeAndFormat : TypeSerializer.SerializeToString; var contentType = isDebugRequest ? ContentType.PlainText : ContentType.JsvText; if (url.Contains("/jsv/syncreply/")) { var result = ExecuteService(request, EndpointAttributes.SyncReply | EndpointAttributes.Jsv | HttpMethods.GetEndpointAttribute(httpMethod)); response.WriteToResponse(result, writeFn, contentType); } else if (url.Contains("/jsv/asynconeway/")) { ExecuteService(request, EndpointAttributes.AsyncOneWay | EndpointAttributes.Jsv | HttpMethods.GetEndpointAttribute(httpMethod)); } } catch (Exception ex) { log.Error(ex); response.WriteJsvErrorToResponse(operationName, ex.Message, ex); } }
protected override void ProcessRequest(HttpListenerContext context) { if (string.IsNullOrEmpty(context.Request.RawUrl)) return; var operationName = context.Request.GetOperationName(); var httpReq = new HttpListenerRequestWrapper(operationName, context.Request); var httpRes = new HttpListenerResponseWrapper(context.Response); try { var handler = ServiceStackHttpHandlerFactory.GetHandler(httpReq); var serviceStackHandler = handler as IServiceStackHttpHandler; if (serviceStackHandler != null) { var restHandler = serviceStackHandler as RestHandler; if (restHandler != null) { httpReq.OperationName = operationName = restHandler.RestPath.RequestType.Name; } serviceStackHandler.ProcessRequest(httpReq, httpRes, operationName); return; } throw new NotImplementedException("Cannot execute handler: " + handler + " at PathInfo: " + httpReq.PathInfo); } catch (Exception ex) { var sb = new System.Text.StringBuilder(); sb.AppendLine("{"); sb.AppendLine("\"ResponseStatus\":{"); sb.AppendFormat(" \"ErrorCode\":{0},\n", ex.GetType().Name.EncodeJson()); sb.AppendFormat(" \"Message\":{0},\n", ex.Message.EncodeJson()); sb.AppendFormat(" \"StackTrace\":{0}\n", ex.StackTrace.EncodeJson()); sb.AppendLine("}"); sb.AppendLine("}"); httpRes.Clear(); httpRes.Write(sb.ToString()); httpRes.StatusCode = 500; } finally { httpRes.Close(); } }
protected override void ProcessRequest(HttpListenerContext context) { if (string.IsNullOrEmpty(context.Request.RawUrl)) return; var operationName = context.Request.GetOperationName(); var httpMethod = context.Request.HttpMethod; var queryString = context.Request.QueryString; var inputStream = context.Request.InputStream; var response = new HttpListenerResponseWrapper(context.Response); var url = context.Request.Url.PathAndQuery.ToLower(); if (url.Contains("/xml/")) { ProcessXmlRequest(url, operationName, httpMethod, queryString, inputStream, response); } else if (url.Contains("/json/")) { ProcessJsonRequest(url, operationName, httpMethod, queryString, inputStream, response); } else if (url.Contains("/jsv/")) { ProcessJsvRequest(url, operationName, httpMethod, queryString, inputStream, response); } }
private void ProcessJsonRequest(string url, string operationName, string httpMethod, NameValueCollection queryString, Stream inputStream, HttpListenerResponseWrapper response) { try { var request = JsonHandlerBase.CreateRequest(operationName, httpMethod, queryString, null, inputStream); if (url.Contains("/json/syncreply/")) { var result = ExecuteService(request, EndpointAttributes.SyncReply | EndpointAttributes.Json | HttpMethods.GetEndpointAttribute(httpMethod)); response.WriteToResponse(result, x => JsonDataContractSerializer.Instance.Parse(result), ContentType.Json); } else if (url.Contains("/json/asynconeway/")) { var result = ExecuteService(request, EndpointAttributes.AsyncOneWay | EndpointAttributes.Json | HttpMethods.GetEndpointAttribute(httpMethod)); } } catch (Exception ex) { log.Error(ex); response.WriteJsonErrorToResponse(operationName, ex.Message, ex); } }
protected override void ProcessRequest(HttpListenerContext context) { if (string.IsNullOrEmpty(context.Request.RawUrl)) return; var operationName = context.Request.GetOperationName(); var httpReq = new HttpListenerRequestWrapper(operationName, context.Request); var httpRes = new HttpListenerResponseWrapper(context.Response); var handler = ServiceStackHttpHandlerFactory.GetHandler(httpReq); var serviceStackHandler = handler as IServiceStackHttpHandler; if (serviceStackHandler != null) { var restHandler = serviceStackHandler as RestHandler; if (restHandler != null) { httpReq.OperationName = operationName = restHandler.RestPath.RequestType.Name; } serviceStackHandler.ProcessRequest(httpReq, httpRes, operationName); httpRes.Close(); return; } throw new NotImplementedException("Cannot execute handler: " + handler + " at PathInfo: " + httpReq.PathInfo); }