Outstanding article, congratulations Kurro! 👏

Just one note on base64 conversion.
In fact you don't need to worry about the base64 conversion, all you need is to set ContentTransferEncoding to "base64" and then %Net.MIME* will take care of it, including adding the header "Content-Transfer-Encoding: base64" in the mime part header.

So, all you need is:

set content.ContentTransferEncoding = "base64"
set content.Body = pImage ; pImage is binary stream

Enrico

I think to remember (I might be wrong) that Service Unavailable error can be caused by a license limit and using csp pages/application can consume license slots quickly due to the sessions not being cleared and license grace period.

Maybe you are using IRIS Community Edition (limited number of connections/license), if so, try to restart and see if it works right after restart.

You may also check in Management Portal in System Operation -> License usage

Again, I'm guessing! I might be wrong.

Enrico

I would create my "custom" datatype extending %Library.DateTime:

Class Community.dt.CustomDateTime Extends %Library.DateTime
{

ClassMethod LogicalToXSD(%val As %TimeStamp) As %String [ ServerOnly = 1 ]
{
    Set %val=##class(%Library.TimeStamp).LogicalToXSD(%val)
    Quit $translate(%val,"TZ"," ")
}

ClassMethod XSDToLogical(%val As %String) As %TimeStamp [ ServerOnly = 1 ]
{
    Set $e(%val,11)="T"
    Quit ##class(%Library.TimeStamp).XSDToLogical(%val)
}

}

Then in your class define your property as:

Property OPDT As Community.dt.CustomDateTime;

Are you sure you really need %Library.DateTime and not %Library.TimeStamp?
The difference is the JDBC/ODBC format. From the documetation:

%DateTime is the same as %TimeStamp (is a sub-class or %TimeStamp) with extra logic in the DisplayToLogical and OdbcToLogical methods to handle imprecise datetime input T-SQL applications are accustomed to.

If you prefer using %Library.TimeStamp, then change the superclass in my sample code.

After that:

USER>Set reader = ##class(%XML.Reader).%New()
 
USER>Set sc=reader.OpenString("<NewClass2><OPDT>2023-11-30 11:07:02</OPDT></NewClass2>")
 
USER>Do reader.CorrelateRoot("Samples.NewClass2")
 
USER>Do reader.Next(.ReturnObject,.sc)
 
USER>Do ReturnObject.XMLExport(,",indent")
<NewClass2>
  <OPDT>2023-11-30 11:07:02</OPDT>
</NewClass2>
 
USER>Write ReturnObject.OPDT
2023-11-30 11:07:02
USER>

Enrico

You have setup your REST Web application "Allowed Authentication Method" as "Unauthenticated", therefore your REST code/application runs under the "UnknownUser" account/user.

My guess is that the UnknownUser user does not have enough privilege (Role(s)) to run your code.
If this is just a private, isolated test system, try adding %All role to the UnknownUser user account.

Enrico

"CALL returns an empty result"

How did you determine that? After that 3 lines, run this:

For  {Set rset=sqlResult.%NextResult() q:rset=""  do rset.%Display() Write !}

I get:

1 Row Affected
1 Row Affected
1 Row Affected
1 Row Affected
name    age     home_city
Jorge   32      Tampa
Enrico  29      Turin
Dan     25      Miami
Alexy   21      London
 
4 Rows(s) Affected

You may want to check the documentation:

Returning Multiple Result Sets

Enrico

I don't have details of your project but when you say  "I want to use %SYSTEM.Event to process queues" and ask "Is there a way to store the queue with their messages in a Global?" I think that what you describe is exactly what an IRIS interoperability production does.

In fact, an IRIS interoperability production internally use %SYSTEM.Event to process queues and messages are indeed queued and persisted (in globals).
Within an IRIS interoperability production queued messages are preserved across system restart (and crash!), in addition messages are traced, can be resent etc etc.

So my question is, given your requirements, why not using an interoperability production instead of reinventing (or reimplementing) the wheel?

Enrico

Hi Luis,

how can you possibly get a <MAXSTRING> error extracting a stream from a base64 encoded property that is imported from a JSON string that is limited itself by the MAXSTRING value?

In the line:

set bodyJson = %request.Content.Read()

You get the whole JSON into a string limited to string max size.

To avoid this, you can import directly the content stream into a dynamic object:

set dynamicBody = {}.%FromJSON(%request.Content)

Enrico

Your question reports:

Product version: Ensemble 2018.1

My answer is for that version.

Sorry, I don't have any 2014 version available and I really don't remember if/what something is available in that old version regarding JSON.

For sure I can tell you that ##class(%Object).%FromJSON(pInput) makes no sense.
I pretty sure that %DynamicObject was not available back then (so, no {} object).

It's about time to upgrade or in fact, migrate to IRIS. 😊

Enrico