Define Presto Session Attributes
You define Presto session attributes in the request that generates the response with the data to be saved. Session attributes allow you to save data from one request and use it in subsequent requests for the current session. It is useful for sensitive or personal information that should remain in the Presto Server for security or privacy reasons.
You use the optional Presto Header/Parameter x-p-sessionbinding to define session attributes. This header takes an object with attribute definition expressions. Each expression provides the name for a new session attribute and an XPath expression that identifies the node within the response that should be saved in this attribute for the current session.
The XPath expression can identify a node with a simple value, such as '@session.ssn':'/customer/SSN'.
They can also identify nodes sets, such as
'@session.articles':'/rss/channel/item' or one node with complex content, such as
'@session.firstArticle':'/rss/channel/item[1]'. See
A Brief Introduction to XPath 2.0 for more information on XPath expressions.
Note: | The @ symbol defines a session attribute. You refer to session parameters with $, just as you do with global or user parameters. See Define
Presto
Session Attributes for this syntax. |
This first session mapping example takes a query response and maps two nodes with simple content to two Presto session attributes.
Defining Session Attributes with Simple Values
...
connection.request({
url: "/presto/edge/api/rest/CustomerQuery/getCustomer?id=mr321y98&x-presto-resultFormat=
json&x-p-sessionbinding={'@session.ssn':'/customer/SSN','@session.name':'customer/name'},
type: "get",
contentType: "application/x-www-form-urlencoded",
data: requestBody
},
{ onSuccess: function(response, responseHeaders) {
//handle response data
},
onFailure: function(e) {
//handle error message
}
});
A later request then maps these Presto session attributes to mashable input parameters:
Mapping Session Attributes with Simple Values
...
connection.request({
url: "/presto/edge/api/rest/CustomerNotices/renewalNotice?x-presto-resultFormat=
json&custSSN=$session/ssn&custName=$session/name,
type: "get",
contentType: "application/x-www-form-urlencoded",
data: requestBody
},
{ onSuccess: function(response, responseHeaders) {
//handle response data
},
onFailure: function(e) {
//handle error message
}
});
The next session mapping example shows a mapping from an RSS feed. This defines a complex Presto session attribute that contains feed data for the first article from this web feed.
Defining Session Attributes with Complex Content
...
connection.request({
url: "/presto/edge/api/rest/someRSSFeed/getData?x-presto-resultFormat=json&x-p-sessionbinding={'@session.firstArticle':'/rss/channel/item[1]'},
type: "get",
contentType: "application/x-www-form-urlencoded",
data: requestBody
},
{ onSuccess: function(response, responseHeaders) {
//handle response data
},
onFailure: function(e) {
//handle error message
}
});
A later request then maps data from nodes within this Presto session attribute to input parameters:
Mapping Session Attributes with Complex Content
...
connection.request({
url: "/presto/edge/api/rest/myMayshup/Invoke?x-presto-resultFormat=json&article=$session/
firstArticle/item/title&link=$session/firstArticle/rss/channel/item/link,
type: "get",
contentType: "application/x-www-form-urlencoded",
data: requestBody
},
{ onSuccess: function(response, responseHeaders) {
//handle response data
},
onFailure: function(e) {
//handle error message
}
});