Consuming an AIM REST API from with AIM app

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Consuming an AIM REST API from with AIM app

Post by Jaymer »

Dave,
I had a Skype convo with Vlad.
In it, he said 1 important thing:
"When you make a normal REST call from Aware IM it is done from the backend - there is no UI involved. If you are calling from the UI it's a lot more complicated, like I explained. "

Well, I think he misinterpreted this post from the very beginning.

A "normal" REST call from Aware (like calling WeatherAPI) is done in a Rule with "REQUEST SERVICE".
This is NOT how I'm doing it.
Am unclear what John (OP) meant.
And I know thats not how you are doing it, since its part of stuff inside Kendo HTML, that you've injected via Init/Render script.

But if he's now reading this correctly, then he's thinking we are doing REQUEST SERVICE - And I'll buy that, that you can't call your same app from a Rule in that same app.

So, what i'm trying to point out is that since we are NOT calling "ourselves" that way, the calling script DOES NOT NEED a JSESSIONID generated (which cancels the prior one) and returned to it with the content.
Here's is the Response Header from Aware to a Postman call:

Code: Select all

Set-Cookie:"JSESSIONID=60493D89C5B28AF52EF01684453EA166; Path=/oem; HttpOnly"
Content-Type:"application/json;charset=UTF-8"
Transfer-Encoding:"chunked"
Date:"Thu, 26 Sep 2019 14:34:06 GMT"
Since its possible to override this cookie, and since we dont need it, then that should be our focus.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: Consuming an AIM REST API from with AIM app

Post by aware_support »

Once again to recap this for relatively advanced users:

If you want to communicate to an Aware IM backend from Javascript (i.e from the UI front end which is part of the UI of your Aware IM application), then there are two ways to go about it:

1) You can go directly to a URL (for example, to call an Aware IM REST service)
2) You can use the Javascript XMLHttp object (which is the basis for the AJAX technology)

When an Aware IM backend receives a call from the UI it has to identify the current user. Tomcat does it by using a special parameter called JSESSIONID. So ALL requests from the UI must have this parameter, otherwise the backend loses the user making the call.

Approach in 1) does not include this parameter unless you get it from the browser cookie yourself and provide it as part of the call. Approach 2) AUTOMATICALLY does it because the XMLHttp object collects browser cookies automatically. Note, that this is not an issue when a REST service is called from rules (REQUEST SERVICE) because the call is initiated from the backend and there is no user involved.

So the right way to go is approach 2). Note that you do not have to use XMLHttp object directly as Kendo UI and Aware IM has a lot of more convenient wrappers around this object.

In Aware IM there are two ways to communicate with AJAX:
a) For simple requests that send some parameters to the backend and return the result (for example to read the value of an object's attribute) you can use the Actions framework that I have mentioned before
b) If you want to run queries that return multiple records you need to use Kendo UI data source objects that communicate with the Aware IM backend. If you look at the aware_kendo/parsers directory you will find examples of this - for example, customLayoutParser uses a datasource to communicate with an Aware IM backend and display the results as a "custom query" (Kendo UI ListView widget).

One day we will document this in detail. In the meantime you can study the code.
Aware IM Support Team
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Consuming an AIM REST API from with AIM app

Post by Jaymer »

aware_support wrote: 1) You can go directly to a URL (for example, to call an Aware IM REST service)
<snip>
Approach in 1) does not include this parameter (JSESSIONID) unless you get it from the browser cookie yourself and provide it as part of the call.
<snip>
So the right way to go is approach 2)
I don't see why Approach 1 is not valid. You prefer # 2, but you already said I can use # 1.
If I go to a URL right now that activates an Aware REST service, it sends me data back. I did not have a JSESSIONID, nor did ANY user out there consuming my REST service. No one is "providing it as part of the call" and yet I still got a reply.

The only issue is that the programming servlet that responded to the REST request generated a JSESSIONID when it didn't need to.
And you can see from the Tomcat manager that even if it creates a JSESSIONID (which it did), its not keeping it as an active session.
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Jaymer
Posts: 2430
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: Consuming an AIM REST API from with AIM app

Post by Jaymer »

@Dave
whats your status on this type of activity now?
whats with the autocomplete widget you referred to?
J
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Post Reply