|
3 | 3 | <Class name="SQLKPI.AbstractREST">
|
4 | 4 | <Super>%CSP.REST</Super>
|
5 | 5 | <TimeCreated>64244,40123.382009</TimeCreated>
|
| 6 | + |
| 7 | +<Parameter name="UseSession"> |
| 8 | +<Type>Integer</Type> |
| 9 | +<Default>1</Default> |
| 10 | +</Parameter> |
| 11 | + |
| 12 | +<Method name="outputStatus"> |
| 13 | +<Description> |
| 14 | +This method takes a status, renders it as jason (if requested) and outputs the result</Description> |
| 15 | +<Internal>1</Internal> |
| 16 | +<ClassMethod>1</ClassMethod> |
| 17 | +<FormalSpec>pSC:%Status</FormalSpec> |
| 18 | +<ReturnType>%Status</ReturnType> |
| 19 | +<Implementation><![CDATA[ |
| 20 | + #dim tSC As %Status = $$$OK |
| 21 | + #dim e As %Exception.AbstractException |
| 22 | + |
| 23 | + Try { |
| 24 | + |
| 25 | + #dim tJSON As %ZEN.proxyObject |
| 26 | + |
| 27 | + If ..AcceptsContentType("application/json") { |
| 28 | + |
| 29 | + Set %response.ContentType = ..#CONTENTTYPEJSON |
| 30 | + |
| 31 | + #; Convert the exception to a status and render to JSON |
| 32 | + Set tSC = ..StatusToProxyObject(pSC, .tJSON) |
| 33 | + Set tJSON.stack = ..getDebugInfo() |
| 34 | + If $$$ISERR(tSC) Quit |
| 35 | +
|
| 36 | + #; Write the JSON to the output device |
| 37 | + Set tSC = tJSON.%ToJSON(, "aeloqutwc") |
| 38 | + If $$$ISERR(tSC) Quit |
| 39 | + |
| 40 | + } else { |
| 41 | + |
| 42 | + #; Set plain text |
| 43 | + Set %response.ContentType = ..#CONTENTTYPETEXT |
| 44 | + |
| 45 | + #; Write out a simple text message |
| 46 | + Do ##class(%Exception.StatusException).CreateFromStatus(pSC).OutputToDevice() |
| 47 | + } |
| 48 | + |
| 49 | + } Catch (e) { |
| 50 | + |
| 51 | + #; Oops |
| 52 | + Set tSC = e.AsStatus() |
| 53 | + } |
| 54 | + Quit $$$OK |
| 55 | +]]></Implementation> |
| 56 | +</Method> |
| 57 | + |
| 58 | +<Method name="getDebugInfo"> |
| 59 | +<ClassMethod>1</ClassMethod> |
| 60 | +<ReturnType>%ZEN.proxyObject</ReturnType> |
| 61 | +<Implementation><![CDATA[ |
| 62 | + set obj = ##class(%ZEN.proxyObject).%New() |
| 63 | + set obj.stack = ..getStackInfo() |
| 64 | + set obj.objlasterror = $system.Status.GetErrorText($get(%objlasterror)) |
| 65 | + set obj.request = %request |
| 66 | + set obj.responce = %response |
| 67 | + set obj.session = %session |
| 68 | + set obj.user = $username |
| 69 | + |
| 70 | + return obj |
| 71 | +]]></Implementation> |
| 72 | +</Method> |
| 73 | + |
| 74 | +<Method name="getStackInfo"> |
| 75 | +<ClassMethod>1</ClassMethod> |
| 76 | +<ReturnType>%ListOfDataTypes</ReturnType> |
| 77 | +<Implementation><![CDATA[ |
| 78 | +
|
| 79 | + set ex = ##class(%Exception.SystemException).%New() |
| 80 | + do ex.StackAsArray(.stack) |
| 81 | + set list = ##class(%ListOfObjects).%New() |
| 82 | + for i=1:1:stack { |
| 83 | + set obj = ##class(%ZEN.proxyObject).%New() |
| 84 | + set obj.line = stack(i,"PLACE") |
| 85 | + set obj.call = stack(i) |
| 86 | + set obj.part = $piece($piece(stack(i,"PLACE"), "^", *), " ", 1) |
| 87 | + do list.Insert(obj) |
| 88 | + } |
| 89 | + |
| 90 | + return list |
| 91 | +]]></Implementation> |
| 92 | +</Method> |
| 93 | + |
| 94 | +<Method name="OnPreDispatch"> |
| 95 | +<Description> |
| 96 | +This method Gets called prior to dispatch of the request. Put any common code here |
| 97 | +that you want to be executed for EVERY request. If pContinue is set to 0, the |
| 98 | +request will NOT be dispatched according to the UrlMap. If this case it's the |
| 99 | +responsibility of the user to return a response.</Description> |
| 100 | +<ClassMethod>1</ClassMethod> |
| 101 | +<FormalSpec><![CDATA[pUrl:%String,pMethod:%String,&pContinue:%Boolean]]></FormalSpec> |
| 102 | +<ReturnType>%Status</ReturnType> |
| 103 | +<Implementation><![CDATA[ Quit ..convertRequestBody() |
| 104 | +]]></Implementation> |
| 105 | +</Method> |
| 106 | + |
| 107 | +<Method name="convertRequestBody"> |
| 108 | +<Description> |
| 109 | +Конвертируем %request.Content в UTF8 и в объект класса %ZEN.proxyObject</Description> |
| 110 | +<ClassMethod>1</ClassMethod> |
| 111 | +<ReturnType>%Status</ReturnType> |
| 112 | +<Implementation><![CDATA[ |
| 113 | + #dim %request As %CSP.Request |
| 114 | + #dim obj As %ZEN.proxyObject |
| 115 | + |
| 116 | + return:'$isObject(%request.Content) $$$OK // нет тела запроса |
| 117 | + return:'$$$classIsStream($className(%request.Content)) $$$OK // уже сконвертировали |
| 118 | + // Конвертируем объект в UTF8 %ZEN.proxyObject |
| 119 | + set content = %request.Content.Read($$$MaxStringLength) |
| 120 | + set content = $ZCVT(content,"I","UTF8") |
| 121 | + set sс = ##class(Form.JSON.OBJ).%ConvertJSONToObject(content,,.obj,1) |
| 122 | +
|
| 123 | + return:$$$ISERR(sс) sс |
| 124 | + return:'$isObject(obj) $$$ERROR($$$ArgumentIsNotAnObject,"Body") |
| 125 | + |
| 126 | + set %request.Content = obj // obj это валидный UTF8 %ZEN.proxyObject |
| 127 | + return $$$OK |
| 128 | +]]></Implementation> |
| 129 | +</Method> |
6 | 130 | </Class>
|
7 | 131 | </Export>
|
0 commit comments