programatically logon to HTTP resource through ObjectScript

13 views
Skip to first unread message

sween

unread,
Nov 23, 2009, 3:05:40 PM11/23/09
to InterSystems: Ensemble in Healthcare
How do I programatically logon to an Ensemble resource with HTTP ?

-I have tried supplying properties to the request.

-I have tried params to the url.

-I couldnt find a solid example for the .Authorization property.

Basically what I am trying to do is grab the html DOM of a web page,
and utilize it in an html email. Im almost there if I could logon to
the ensemble resource through cache.

Any code laying around that shows how to do this ?

/// Here is my method
Property html As %String(MAXLEN = 999999999999999999999); //eleventy
billion
/// Fetch Summary Email
Method FetchDashPage() As %Status [ WebMethod ]
{
Set sc = $$$OK

Set responseStream = ##class(%Stream.GlobalBinary).%New()

Set request = ##class(%Net.HttpRequest).%New()
Set request.Server = "integration.hospital.org"
Set request.Port = "57772"

//set request.Username = "ensembleusername"
//set request.Password = "ensemblepassowrd"

//Here was an attempt at passing params, much like a WSDL
//Set sc = request.Get("/csp/prod/
Spectrum.Support.IntegrationDashboards.ChargeBalancesWmJ.cls&CacheUserName=sweerj&CachePassword=password")

Set sc = request.Get("/csp/prod/
Spectrum.Support.IntegrationDashboards.ChargeBalancesWmJ.cls")

// Copy the response stream back into responseStream
Set sc = responseStream.CopyFrom(request.HttpResponse.Data)

//$$$LOGINFO("Checking what we get back: " _
request.HttpResponse.Data.Read())
//Set html = request.HttpResponse.Data.Read()
Set ..html = request.HttpResponse.Data.Read()

$$$LOGINFO("GAR: "_..html)
do ..SendOutDashMail("TESTING", ..html)

Quit sc
}

Alex Schaefer

unread,
Nov 23, 2009, 3:17:42 PM11/23/09
to ensemble-in...@googlegroups.com
Username and Password properties should be sufficient. What's the authentication for your /csp/prod application set to?
--
You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
To post to this group, send email to Ensemble-in...@googlegroups.com
To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en

sween

unread,
Nov 23, 2009, 3:32:27 PM11/23/09
to InterSystems: Ensemble in Healthcare
'password'

Is this what I pass to the Authorization property for the request ?

On Nov 23, 3:17 pm, Alex Schaefer <Alex.Schae...@intersystems.com>
wrote:
> Spectrum.Support.IntegrationDashboards.ChargeBalancesWmJ.cls&CacheUserName=­sweerj&CachePassword=password")
>
> Set sc = request.Get("/csp/prod/
> Spectrum.Support.IntegrationDashboards.ChargeBalancesWmJ.cls")
>
>         // Copy the response stream back into responseStream
>         Set sc = responseStream.CopyFrom(request.HttpResponse.Data)
>
>     //$$$LOGINFO("Checking what we get back: " _
> request.HttpResponse.Data.Read())
>         //Set html = request.HttpResponse.Data.Read()
>         Set ..html = request.HttpResponse.Data.Read()
>
>         $$$LOGINFO("GAR: "_..html)
>         do ..SendOutDashMail("TESTING", ..html)
>
>         Quit sc
> }
>
> --
> You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
> To post to this group, send email to Ensemble-in...@googlegroups.com
> To unsubscribe from this group, send email to Ensemble-in-Healt...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/Ensemble-in-Healthcare?hl=en- Hide quoted text -
>
> - Show quoted text -

Alex Schaefer

unread,
Nov 23, 2009, 3:51:01 PM11/23/09
to ensemble-in...@googlegroups.com
I don't think you need to set Authorization... what's the error message you get back?

sween

unread,
Nov 23, 2009, 4:01:39 PM11/23/09
to InterSystems: Ensemble in Healthcare
It doesnt error out, however the html DOM I get back is the
redirection to the CSP Login....

On Nov 23, 3:51 pm, Alex Schaefer <Alex.Schae...@intersystems.com>
wrote:
> > For more options, visit this group athttp://groups.google.com/group/Ensemble-in-Healthcare?hl=en-Hide quoted text -

Jill Goldberg

unread,
Nov 23, 2009, 5:22:15 PM11/23/09
to ensemble-in...@googlegroups.com

Hi Ron,

In 2010.1 Username and Password are sufficient (I didn't check 2008.2 or 2009.1). However, I tried this in 2008.1 and ran into problems. Here's a workaround:

-Make use of the CacheUserName and CachePassword URL parameters
-After you call the Get() method, the response contains a redirection message indicating a successful login (but the redirect doesn't work)
-Call the Get() method again and you'll get the HTML you're looking for

Here's an example:

USER>s req=##class(%Net.HttpRequest).%New()

USER>s req.Port=57773

USER>s req.Server="127.0.0.1"

USER>d req.SetParam("CacheUserName","_SYSTEM")

USER>d req.SetParam("CachePassword","SYS")

USER>w req.Get("/csp/sys/UtilHome.csp/")
1

USER>d req.HttpResponse.OutputToDevice()
HTTP/1.0 302 Redirect
CACHE-CONTROL: no-cache,no-store
CONNECTION: close
CONTENT-TYPE: text/html; charset=UTF-8
EXPIRES: Thu, 29 Oct 1998 17:04:19 GMT
LOCATION: /csp/sys/UtilHome.csp?CSPCHD=00000001000017kaxlxe000000Yfkx1VFPo0wb8oNAVlYMqA--
PRAGMA: no-cache

<HTML><HEAD>
<TITLE>Redirect</TITLE>
</HEAD><BODY>
<H1>Redirect</H1>
If you are not redirected automatically click <a href="/csp/sys/UtilHome.csp">here</a>
</BODY></HTML>


USER>w req.Get("/csp/sys/UtilHome.csp/")
1
USER>d req.HttpResponse.OutputToDevice()
HTTP/1.1 200 OK
CACHE-CONTROL: no-cache
CONNECTION: Close
CONTENT-TYPE: text/html; charset=UTF-8
DATE: Mon, 23 Nov 2009 21:46:54 GMT
EXPIRES: Thu, 29 Oct 1998 17:04:19 GMT
PRAGMA: no-cache

<!--
Home page for System Management Utilities
-->
<html><head>
<script language="JavaScript" type="text/javascript" src="/csp/broker/cspbroker.js"></script>
<script type="text/javascript">

var xenAutoLogoutTimerID = self.setTimeout("xenAutoLogout()",28815000);
function xenAutoLogout()
{
top.document.location.reload();
}
.
.
.

I cut the rest of the output, but you get the idea.

I hope that helps.

--Jill

sween

unread,
Nov 24, 2009, 3:23:34 PM11/24/09
to InterSystems: Ensemble in Healthcare
Thanks! ... this worked like a champ.

On Nov 23, 5:22 pm, Jill Goldberg <Jill.Goldb...@intersystems.com>
wrote:
> Hi Ron,
>
> In 2010.1 Username and Password are sufficient (I didn't check 2008.2 or 2009.1).  However, I tried this in 2008.1 and ran into problems.  Here's a workaround:
>
> -Make use of the CacheUserName and CachePassword URL parameters
> -After you call the Get() method, the response contains a redirection message indicating a successful login (but the redirect doesn't work)
> -Call the Get() method again and you'll get the HTML you're looking for
>
> Here's an example:
>
> USER>s req=##class(%Net.HttpRequest).%New()
>
> USER>s req.Port=57773    
>
> USER>s req.Server="127.0.0.1"  
>
> USER>d req.SetParam("CacheUserName","_SYSTEM")  
>
> USER>d req.SetParam("CachePassword","SYS")  
>
> USER>w req.Get("/csp/sys/UtilHome.csp/")    
>  1
>
> USER>d req.HttpResponse.OutputToDevice()                                          
> HTTP/1.0 302 Redirect
> CACHE-CONTROL: no-cache,no-store
> CONNECTION: close
> CONTENT-TYPE: text/html; charset=UTF-8
> EXPIRES: Thu, 29 Oct 1998 17:04:19 GMT
> LOCATION: /csp/sys/UtilHome.csp?CSPCHD=00000001000017kaxlxe000000Yfkx1VFPo0wb8oNAVlYM­qA--
> >>> For more options, visit this group athttp://groups.google.com/group/Ensemble-in-Healthcare?hl=en-Hidequoted text -
Reply all
Reply to author
Forward
0 new messages