User bio
404 bio not found
Member since Jun 6, 2021
Posts:
Replies:
You can override the Page() method of %CSP.Page and redirect output to a stream, process the resulting stream and write it to the original device the page is using to send data back to client.
Here is a quick and dirty example, using IO-Redirect package available on OpenExchange.
The redirecting page :
Class test.src.RedirectedPage Extends %CSP.Page
{
ClassMethod Page(skipHeader As %Boolean = 1) As %Status [ ServerOnly = 1 ]
{
#dim sc as %Status
#dim ex as %Exception.AbstractException
#dim pageStream,processedPageStream As %Stream.Object
#dim len as %Integer
#dim buffer as %String
s sc = $$$OK
try {
Set pageStream = ##class(%Stream.GlobalCharacter).%New()
Do ##class(IORedirect.Redirect).ToStream(pageStream)
$$$TOE(sc,##super(skipHeader))
Do ##class(IORedirect.Redirect).RestoreIO()
Set pageStream = ##class(IORedirect.Redirect).Get()
$$$TOE(sc,..ProcessPageStream(pageStream,.processedPageStream))
while 'processedPageStream.AtEnd {
s len = 32768
s buffer = processedPageStream.Read(.len,.sc)
$$$TOE(sc,sc)
write buffer
}
} catch (ex) {
s sc = ex.AsStatus()
}
return sc
}
ClassMethod ProcessPageStream(pageStream As %Stream.Object, Output processedPageStream As %Stream.Object) As %Status
{
#dim sc as %Status
#dim ex as %Exception.AbstractException
s sc = $$$OK
try {
s processedPageStream = ##class(%Stream.TmpCharacter).%New()
$$$TOE(sc,processedPageStream.CopyFrom(pageStream))
d processedPageStream.Write("<div><span>original page had "_pageStream.Size_" bytes </span></div>")
} catch (ex) {
s sc = ex.AsStatus()
}
return sc
}
}
The original page :
Class test.src.OriginalPage Extends test.src.RedirectedPage
{
ClassMethod OnPage() As %Status [ ServerOnly = 1 ]
{
&html<
<div>
<span>Hello, world, again</span>
</div>
>
return $$$OK
}
To see the content, the CSP Gateway has an HTTP trace facility, see documentation.
To access the response just before it is sent back to client, override methods of %CSP.Page
Open Exchange applications:
Certifications & Credly badges:
Robert has no Certifications & Credly badges yet.
Global Masters badges:
![DC Commenter](https://community.intersystems.com/sites/default/files/badges/dc_commenter_1.png)
![InterSystems Researcher](https://community.intersystems.com/sites/default/files/badges/researcher.png)
![DC Recruiter](https://community.intersystems.com/sites/default/files/badges/dc_recruiter_0.png)
![The First Tech Quiz](https://community.intersystems.com/sites/default/files/badges/quiz_question.png)
Followers:
Following:
Robert has not followed anybody yet.
Another approach would be to write a custom router class extending EnsLib.MsgRouter.RoutingEngine, overriding OnRequest() method.
In OnRequest(), before calling ##super(), assign the JSON %DynamicAbstractObject build from the input request stream to a property.
Use the property in the router rules.