Get Session Property

This section provides developers with information on how to get properties of a session. Documentation for the REST protocol, as well as code samples for Java, PHP, and cURL, are provided below.

REST

The REST noun (and associated message content) for getting a property on a session is as follows:

  • Relative Noun: AuthenticatedSession/$sessionID/Properties[/$propertyName]. This is the relative path of the URL that should appear after the OTIS server application name. The $sessionID variable identifies the authenticated session whose properties are to be retrieved. The $propertyName variable identifies the property to be retrieved. It is optional. If omitted, ALL session properties will be returned. For example:

Get the "Property1" property:

https://wag.bandit-project.org/otis/AuthenticatedSession/AB6745EDF9A32BCEAB6745EDF9A32BCE/Properties/Property1

Get ALL session properties:

https://wag.bandit-project.org/otis/AuthenticatedSession/AB6745EDF9A32BCEAB6745EDF9A32BCE/Properties
  • HTTP Method: GET.
  • Request/Response message details: click here
  • Description: Retrieves properties for the authenticated session (specified by the $sessionID variable). The content of the request message (see here) contains the requested property or properties.

Java

The following is example Java code that demonstrates how to get properties of a session:

import java.util.Map;

try
{

   // The session variable is an IAuthSession object. -- It is assumed that the "SimpleString" property is a String object.
			
   String strSimpleStringProperty = (String)session.getProperty( "SimpleString");

   // Get All session properties - always returned as a Map object.

   Map allProperties = session.getAllProperties();
}
catch (AuthSessionException exception)
{
    System.out.println("AuthSessionException: " + exception);
}

The OTIS client Java library may be downloaded from the OTIS download page.

PHP

The following is PHP example code of how to get a single session property named "Property1". It is assumed that the $sessionURI variable contains the URI for the authenticated session:

$Host = "wag.bandit-project.org";

// Generate the request header using an xml 
$ReqHeader =
"GET /otis/AuthenticatedSession/" . $sessionURI . "/Properties/Property1 HTTP/1.1\n".
"Host: $Host\n".
(($sessionSecret) ? ("SessionSecret: " . $sessionSecret . "\n") : "") .
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: 0\n".
"Connection: Close\n\n";

// Open the connection to the host
$socket = fsockopen("wag.bandit-project.org", 80);

// Do the GET; store in "Result".  "Result" can be looked at to see what the property's value is.
fputs($socket, $ReqHeader);
while (!feof($socket)) 
{
   $tmp = fgets($socket, 128);
   //if the line contains an xml tag, add it
   if(strpos($tmp, ">"))
   {
      $Result .= $tmp;
   }
}

The following is PHP example code of how to get ALL session properties. It is assumed that the $sessionURI variable contains the URI for the authenticated session:

$Host = "wag.bandit-project.org";

// Generate the request header using an xml 
$ReqHeader =
"GET /otis/AuthenticatedSession/" . $sessionURI . "/Properties HTTP/1.1\n".
"Host: $Host\n".
(($sessionSecret) ? ("SessionSecret: " . $sessionSecret . "\n") : "") .
"Content-Type: application/x-www-form-urlencoded\n".
"Content-Length: 0\n".
"Connection: Close\n\n";

// Open the connection to the host
$socket = fsockopen("wag.bandit-project.org", 80);

// Do the GET; store in "Result".  "Result" can be looked at to see what properties were returned.
fputs($socket, $ReqHeader);
while (!feof($socket)) 
{
   $tmp = fgets($socket, 128);
   //if the line contains an xml tag, add it
   if(strpos($tmp, ">"))
   {
      $Result .= $tmp;
   }
}

cURL

The following is example cURL code that demonstrates how to retrieve ALL session properties:

if [ -e secret.hdr ] ; then secret=`cat secret.hdr` ; else secret="nosecret: none" ; fi
curl -b cookies.txt -H "${secret}" https://wag.bandit-project.org/otis/Properties

This assumes you have already set up an authenticated session and are using a cookies.txt file to store/retrieve the otisSessionID cookie and that the session secret has been stored in a file called secret.hdr (See AuthenticateUser for details).

Expected response:

<otis:PropertyList xmlns:otis="http://code.bandit-project.org/schemas/2008/otis">

    <!-- There will be zero or more Property elements - one for each session property -->

   <otis:Property Name="$propertyName" Type="$propertyValueType">

       <!-- There will be one or more PropertyValue elements -->
       <!-- Property value depends on the Type attribute of the Property element -->
       <!-- For simple types, it will be a simple value.  If the type is "Map" -->
       <!-- it will be one or more nested Property elements -->

      <otis:PropertyValue> ... </otis:PropertyValue>

   </otis:Property>

</otis:PropertyList>

The following is example cURL code that demonstrates how to retrieve a single session property called "SimpleStringProperty":

curl -b cookies.txt https://wag.bandit-project.org/otis/Properties/SimpleStringProperty

This assumes you have already set up an authenticated session and are using a cookies.txt file to store/retrieve the otisSessionID cookie (see Authenticate User for details).

Expected response (assuming that SimpleStringProperty is a "string" type):

<otis:Property Name="SimpleStringProperty" Type="string" xmlns:otis="http://code.bandit-project.org/schemas/2008/otis">

   <!-- There will be one or more PropertyValue elements -->
   <!-- Property value depends on the Type attribute of the Property element -->
   <!-- For simple types, it will be a simple value.  If the type is "Map" -->
   <!-- it will be one or more nested Property elements -->

   <otis:PropertyValue>StringValue1</otis:PropertyValue>
   <otis:PropertyValue>StringValue2</otis:PropertyValue>

</otis:Property>