public WriteString ( string text ) : void | ||
text | string | /// The text to write. Encoding will be solved automatically. /// |
return | void |
private void HandleRequest(WoopsaVerb verb, HTTPRequest request, HTTPResponse response) { try { // This is the first thing we do, that way even 404 errors have the right headers if (AllowCrossOrigin) { // TODO: constantes symboliques response.SetHeader("Access-Control-Allow-Origin", "*"); } string result = null; ExecuteBeforeWoopsaModelAccess(); try { switch (verb) { case WoopsaVerb.Meta: result = GetMetadata(request.Subroute); break; case WoopsaVerb.Read: result = ReadValue(request.Subroute); break; case WoopsaVerb.Write: result = WriteValue(request.Subroute, request.Body["value"]); break; case WoopsaVerb.Invoke: result = InvokeMethod(request.Subroute, request.Body); break; } } finally { ExecuteAfterWoopsaModelAccess(); } response.SetHeader(HTTPHeader.ContentType, MIMETypes.Application.JSON); if (result != null) { response.WriteString(result); } } catch (WoopsaNotFoundException e) { response.WriteError(HTTPStatusCode.NotFound, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (WoopsaInvalidOperationException e) { response.WriteError(HTTPStatusCode.BadRequest, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (WoopsaException e) { response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (Exception e) { response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } }
private void HandleRequest(WoopsaVerb verb, HTTPRequest request, HTTPResponse response) { try { _currentWoopsaServer = this; try { string result = null; ExecuteBeforeWoopsaModelAccess(); try { switch (verb) { case WoopsaVerb.Meta: result = GetMetadata(request.Subroute); break; case WoopsaVerb.Read: result = ReadValue(request.Subroute); break; case WoopsaVerb.Write: result = WriteValue(request.Subroute, request.Body["value"]); break; case WoopsaVerb.Invoke: result = InvokeMethod(request.Subroute, request.Body); break; } } finally { ExecuteAfterWoopsaModelAccess(); } response.SetHeader(HTTPHeader.ContentType, MIMETypes.Application.JSON); if (result != null) { response.WriteString(result); } } finally { _currentWoopsaServer = null; } } catch (WoopsaNotFoundException e) { response.WriteError(HTTPStatusCode.NotFound, e.GetFullMessage(), e.Serialize(), MIMETypes.Application.JSON); OnHandledException(e); } catch (WoopsaInvalidOperationException e) { response.WriteError(HTTPStatusCode.BadRequest, e.GetFullMessage(), e.Serialize(), MIMETypes.Application.JSON); OnHandledException(e); } catch (WoopsaException e) { response.WriteError(HTTPStatusCode.InternalServerError, e.GetFullMessage(), e.Serialize(), MIMETypes.Application.JSON); OnHandledException(e); } catch (Exception e) { response.WriteError(HTTPStatusCode.InternalServerError, e.GetFullMessage(), e.Serialize(), MIMETypes.Application.JSON); OnHandledException(e); } }
private void HandleRequest(WoopsaVerb verb, HTTPRequest request, HTTPResponse response) { try { // This is the first thing we do, that way even 404 errors have the right headers if (AllowCrossOrigin) // TODO: constantes symboliques response.SetHeader("Access-Control-Allow-Origin", "*"); string result = null; ExecuteBeforeWoopsaModelAccess(); try { switch (verb) { case WoopsaVerb.Meta: result = GetMetadata(request.Subroute); break; case WoopsaVerb.Read: result = ReadValue(request.Subroute); break; case WoopsaVerb.Write: result = WriteValue(request.Subroute, request.Body["value"]); break; case WoopsaVerb.Invoke: result = InvokeMethod(request.Subroute, request.Body); break; } } finally { ExecuteAfterWoopsaModelAccess(); } response.SetHeader(HTTPHeader.ContentType, MIMETypes.Application.JSON); if (result != null) response.WriteString(result); } catch (WoopsaNotFoundException e) { response.WriteError(HTTPStatusCode.NotFound, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (WoopsaInvalidOperationException e) { response.WriteError(HTTPStatusCode.BadRequest, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (WoopsaException e) { response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } catch (Exception e) { response.WriteError(HTTPStatusCode.InternalServerError, e.Message, WoopsaFormat.Serialize(e), MIMETypes.Application.JSON); } }