Question
· Jun 14, 2018

How to call a rest service with Basic authentication

Hi,

I'm getting mad trying to get data from an external REST service that uses Basic Authentication from Ensemble. The BO worked fine when I was using a test server without authentification, but as soon as we need to go to production I cannot have it working.

So far, I've created the username/password at the credentials page (Ensemble-Configure-Credentials). I've setup the BO to use this credentials. But nothing happens.

I've tried with the Rest Client (addon for Mozilla), and using the same address, port and user/pwd works just fine.

So, the question is: how can I use the Basic authentication in a BO in Ensemble? Any help woul be highly appreciated :)

SOLVED: It was my fault... it was failing because of the proxy :P

Discussion (8)1
Log in or sign up to continue

Everything seems fine.

I'd recommend checking with HTTP Debugging proxy what request actually gets sent. Article on that.

tl;dr plan:

  1. Install Charles proxy (or Fiddler).
  2. Start it.
  3. Redirect your BO traffic to the proxy port.
  4. Check what is actually sent.

Alternatively if you can run the BO locally you can modify the outbound adapter to send the request with Test=1 value and check what's sent.

I have a working operation that uses the EnsLib.HTTP.OutboundAdapter.

The operation settings that I use are:

1. HTTP Server set to appropriate address

2. Credentials set to an entry in the Ensemble/Configure/Credentials where the username and password are set.

3. Connection Settings/SSL Configuration set to a very basic SSL/TLS Configuration. (This is in System Administrator/Security/SSL-TLS Configurations). By very basic what I mean is that it has a name and that is it. No other details or credentials or anything.

My code then looks like this:

Method GetId(objRequest As test.Message.RequestId, objResponse As test.Message.ResponseId) As %Status
{
set objResponse = ##class(test.Message.ResponseId).%New()
set objResponse.SubjectId = objRequest.SubjectId

set ..Adapter.URL = ..IdQueryURL // Property of the operation, setup in the configuration page
set status = ..Adapter.Get(.HttpResponse,"subjectId,subjectNamespace",objRequest.SubjectId,..IdNamespace)
if status {
     set objResponse.StatusCode = HttpResponse.StatusCode
     if HttpResponse.StatusCode = 200 {
          do HttpResponse.Data.Rewind()
          set string = HttpResponse.Data.Read()
          set objDyn = ##class(%DynamicAbstractObject).%FromJSON(string)
          set objItr = objDyn.%GetIterator()
          while objItr.%GetNext(.key,.value) {
               if key = "Id" set objResponse.Id = value quit
          }
     }
}
quit status
}