Rubens Silva · Mar 9, 2020

How to create a REST web application using a Installer manifest

Just like the title says, I'm attempting to find a way to create a web application that instead of serving CSP files, it uses a dispatch class.
I searched for clues in the documentation, but the CSPApplication tag seems to be exclusively for CSP file-based applications.

I'm trying to avoid implementing a workaround such as using the Invoke tag to call the Security.Applications to generate the web application but I might be forced to do so, even though it's unpleasant if I had to say...

So, is there an official way to execute this task?

0 480
Discussion (22)3
Log in or sign up to continue

Invoke is the way to go.

ClassMethod CreateWebApp(pVars, pLogLevel, tInstaller) As %Status
    Set Namespace=tInstaller.Evaluate("${Namespace}")
    Do tInstaller.PushNS("%SYS")
    Do ##class(Security.System).GetInstallationSecuritySetting(.security)
    If (security="None") {
        Set cspProperties("AutheEnabled") = $$$AutheUnauthenticated
    } Else {
        Set cspProperties("AutheEnabled") = $$$AutheCache // Password
    Set cspProperties("NameSpace") = Namespace
    Set cspProperties("IsNameSpaceDefault") = $$$YES
    Set cspProperties("DispatchClass") = "MDX2JSON.REST"
        Set cspProperties("UseCookies") = $$$YES
    Set tSC = ##class(Security.Applications).Create("/"_Namespace, .cspProperties)
    Do tInstaller.PopNS()
    If $$$ISERR(tSC) Throw ##class(%Installer.Exception).CreateFromStatus(tSC)
    Quit $$$OK

And invoke with

<RunInstall Class="MDX2JSON.Installer" Method="CreateWebApp"/>

The code for CSPApplication appears to accept DispatchClass (even though documentation does not say it). I have not yet tested it. But in PivotSubscriptions I create my WebApp the way that Eduard says, but I was planning on changing it to use %Installer this week or next.

I might have to check the IRIS version, because my Caché 2018 doesn't have any traces of the DispatchClass configuration.

Method CSPApplication(
pUrl As %String,
pNamespace As %String,
pDescription As %String,
pDirectory As %String,
pResource As %String,
pRecurse As %String,
pLoginClass As %String,
pGrant As %String,
pCookiePath As %String,
pAuthMethods As %Integer,
pLockCSPName As %Boolean,
pEventClass As %String,
pDefaultTimeout As %Integer,
pDefaultSuperclass As %String,
pUseSessionCookie As %Integer,
pServeFiles As %Boolean,
pServeFilesTimeout As %Integer,
pCustomErrorPage As %String,
pPackageName As %String,
pChangePasswordPage As %String,
pGroupById As %String = "",
pCspZenEnabled As %Boolean = 1,
pInboundWebServicesEnabled As %Boolean = 1,
pTwoFactorEnabled As %Boolean = 0,
pIsNameSpaceDefault As %Boolean = 0,
pPermittedClasses As %String = "",
pAutoCompile As %Boolean = 1) [ Internal ]

Yes, it does look like it was included for IRIS

I tried this out and it works as expected:


Wow. This is cool! And what is the version?

I tested this in a 2020.2 IRIS development build.

(Also my code example will be included in PivotSubscriptions v1.6 wink)

I have also tested it in IRIS 2018.1 and 2019.1

After further testing, it looks like this isn't working as I originally thought. It looks like our only option at this point is to use Security.Applications sad

From your code above I see that you attempted to use both Directory and DispatchClass attributes. Have you tried removing the Directory attribute?

I seem to get an error when I do not specify Directory:

2020-03-11 08:29:03 0 PivotSubscriptions.Installer: ERROR #5001: - ERROR when creating Portal application: Application name, namespace and directory must not be null

Indeed, I got this error too. However if I use a dummy directory it accepts.
I haven't used this feature yet because I must change plenty of things to actually consume that REST application. But the way I'm seeing things so far I guess it would work.

So what if you provide a dummy directory like: "/tmp/dummycsp" as well?

Even though it isn't throwing an error it is not creating the Web App correctly. If you view your Web App, the Dispatch class is not set

Can I use the ZPM client like a standalone the same way it works when using the %Installer manifest? Bu that I mean, just calling the ZPM to parse the manifest and install it without relying on the registry and the CLI for now, because all the code I want to import is already local, I just need to create a web application that uses the DispatchClass property.

Looks like the new version of the %Installer for IRIS already supports this setting.

But it might still be helpful to clear that question about the ZPM for other circunstances.

Yes, for sure, you can install any packages locally

ZPM> load /path/to/package -v

it can be as a folder, or as file tgz, which you can get with command

ZPM> package-name package -v

-v is optional, to get more logs for debugging

Agreed, I tend to use zpm for my own projects even if I don't intend to distribute. Between declaring dependencies, simpler running of unit tests, ability to script more things with my project than just "install" - it's just generally handy.