How to "Post" a URL based on the Alert Message

I am trying to create a URL for Spoke Mobile to page users when our email system is down and we can't use the normal email alerts.

I was directed to http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EHTTP_outbound and tried to create something.  The best I got was a response from the webpage that told me there was an error.

I want to be able to have a default pager number when we don't have an oncall schedule and grab information from Ens.AlertMessage.

 

I thought this would work:

Class User.NewClass21 Extends Ens.BusinessOperation
{

Parameter ADAPTER = "EnsLib.HTTP.OutboundAdapter";

Property Adapter As EnsLib.HTTP.OutboundAdapter;

Parameter INVOCATION = "Queue";

/// Analyst Pager number
Property PIN As %String;

Parameter SETTINGS As %String = "PIN";

/// Alert Message
Property MSSG As %String;

Method OnD03Alert(pReq As User.Alert, Output pResp As %String) As %Status
{
            
        Set httprequest = ##class(%Net.HttpRequest).%New()
                
        Do httprequest.SetParam("PIN",..PIN)
        
        Do httprequest.SetParam("MSSG","motogplay")

        Do httprequest.Post(,1,0)
        set stream = httprequest.HttpResponse.Data
            
        while 'stream.AtEnd {
                Set pResp = stream.Read($$$MaxStringLength)
        }
    
    Quit $$$OK
}

XData MessageMap
{
<MapItems>
    <MapItem MessageType="User.Alert">
        <Method>OnD03Alert</Method>
    </MapItem>
</MapItems>
}

}
 

put get an error the my function needs to return a response.

here is the URL I am trying to get to http://www.usamobility.net/cgi-bin/wwwpage.exe?PIN=nnnnnnnnnn&MSSG=motoplay where nnnnnnnnnn is the pager number

 

Thanks for your time.

  • 0
  • 0
  • 107
  • 3
  • 1

Answers

You need to specify where you want to send your request. Something like this should work.

Method OnD03Alert(req As User.Alert, Output resp As Ens.StreamContainer) As %Status
{
    #Dim sc As %Status = $$$OK      
    #Dim test As %Integer = 0
    
    Set httprequest = ##class(%Net.HttpRequest).%New()   
    Set httprequest.Server =  "www.usamobility.net"
    Set httprequest.Location = "cgi-bin/wwwpage.exe"
    
    Do httprequest.SetParam("PIN", ..PIN)
    Do httprequest.SetParam("MSSG", "motogplay")
    
    Set sc = httprequest.Post(, test, $$$NO)
    
    If $$$ISOK(sc) {
        Set stream = httprequest.HttpResponse.Data
        Set resp = ##class(Ens.StreamContainer).%New(stream)
    }
    Quit sc
}

Also Ensemble operations must return persistent objects so I replaced string with Ens.StreamResponse.

Compiling class User.NewClass21
ERROR #5373: Class 'Ens.StreamResponse', used by 'User.NewClass21:OnD03Alert:FormalSpec', does not exist
  > ERROR #5030: An error occurred while compiling class 'User.NewClass21'
Dropping orphaned procedure: SQLUSER.NEWCLASS21_ENUMERATESETTINGS
Detected 1 errors during compilation in 0.657s.

I am using HealthShare Health Connect 2018.1

Also here is the User.Alert

Class User.Alert Extends Ens.Request
{

/// Analyst Pager number
Property PIN As %String;

/// Alert Message
Property MSSG As %String;

Storage Default
{
<Data name="AlertDefaultData">
<Subscript>"Alert"</Subscript>
<Value name="1">
<Value>PIN</Value>
</Value>
<Value name="2">
<Value>MSSG</Value>
</Value>
</Data>
<DefaultData>AlertDefaultData</DefaultData>
<Type>%Library.CacheStorage</Type>
}

}
 

Sorry, I meant Ens.StreamContainer class.

Updated snippet code.

Comments

So from a network capture if I use out of the box operation EnsLib.http.operation the URL is correct

So now I am wondering if I need to get my proxy setup.

Here is the response from the trace:

<?xml version="1.0" ?>
<!-- type: EnsLib.HTTP.GenericMessage id: 55 -->
<HTTPMessage xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Stream>
<![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Wireless Messaging</title> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1" /> <link href='/message/stylesheets/OpenSans.css' rel='stylesheet' type='text/css'> <link href="/message/stylesheets/spok_1.css" rel="stylesheet" type="text/css" /> <script language=JavaScript> <!-- function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } //--> </script> </head> <body leftMargin=0 topMargin=0 marginheight="0" marginwidth="0"> <table width=750 border=0 align="center" cellPadding=0 cellSpacing=0> <tbody> <tr> <td align="center" class=text-12>&nbsp;</td> </tr> <tr> <td align="center" class=text-12> Your page has been sent to <span class="TDBOLD"> Cannot process that request. Try Again. @page.metrocall.com</span>. <p>&nbsp;</p> <span class="TDBOLD"><a href="#" onclick="window.open('','_self',''); window.top.close();">Close [X]</a></span><br><br> <span class="TDBOLD"><a href="#" onclick="document.location.href='/message/index.html';">Send Another Page</a></span><br><br> <p class="TDBOLD">Thank you for using Spok.</p></td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td> <p align=center><a href="javascript:history.go(-1)">Back</a></p></td> </tr> </tbody> </table> </body> </html> ]]>
</Stream>
<Type>
BG
</Type>
<HTTPHeaders>
<HTTPHeadersItem HTTPHeadersKey="CONTENT-TYPE">
text/html; charset=UTF-8
</HTTPHeadersItem>
<HTTPHeadersItem HTTPHeadersKey="DATE">
Sat, 11 May 2019 13:00:14 GMT
</HTTPHeadersItem>
<HTTPHeadersItem HTTPHeadersKey="SERVER">
Apache
</HTTPHeadersItem>
<HTTPHeadersItem HTTPHeadersKey="StatusLine">
HTTP/1.1 200 OK
</HTTPHeadersItem>
<HTTPHeadersItem HTTPHeadersKey="TRANSFER-ENCODING">
chunked
</HTTPHeadersItem>
</HTTPHeaders>
</HTTPMessage>