Session Host Object

1.0 Introduction

The 'session' host object provides the ability for the users to share objects across different service invocations. The session object is global and thus does not need to be instantiated explicitly.

1.1 Example

                this.serviceName = "ApplicationScopeService";
                this.scope="application";
                
                var key = "number";

                function putValue(param) {
                    session.put(key,2);
                    return <success/>;
                }

                function getValue(param) {
                    var number = session.get(key);
                    return <number>{number}</number>;
                }

                function removeValue(param) {
                    session.remove(key);
                    return <success/>;
                }

                function clearSession(param) {
                    session.clear();
                    return <success/>;
                }
            

2.0 Session Object

Session scope for a deployed mashup can be given using the "scope" service property annotation. Following are the set of supported scopes.

'request' - The state date stored in the session object will be available only for the current invocation of the service. In other words the session object has no effect in this scope.

'transportsession' - The state date stored in the session object will be available only for the life time of the transport session used for invoking this service. This can be used to store data across invocations for a specific client.

'application' - The state date stored in the session object will be available throughout the life time of the service.

'soapsession' - WS-Addressing is required for this. < Not Implemented as yet >

By default, Mashup services deployed in the WSO2 Mashup Server are running in the "request" scope.

2.1 Session Object Interface

                {
                    function void put(key,object);
                    function object get(key);
                    function void remove(key);
                    function void clear();
                    function int size();
                    function String[] getKeys();
                }
            

2.2 API Documentation

Member Description Supported in version
function void put(key,object); Puts the key value pair in to the session object. This pair will be available for the service invocations across the session.

session.put("name", "WSO2 Mashup Server");
0.1
function object get(key); Retrieves the value associated with the given "key" from the current session object.

session.get("name");
0.1
function void remove(key); Removes the value associated with the given "key" from the current session object.

session.remove("name");
1.0
function void clear(); Removes all values from the current session object.

session.clear();
1.0
function int size(); Returns the number of entries in the current session.

var size = session.size();
1.5
function String[] getKeys(); Returns an array of strings containing all the key values, which represent the entries stored in the current session.\

var keys = session.getKeys();
1.5

3.0 References