Read Entity
This section provides developers with information on how to read a specified entity. Documentation for the REST protocol, as well as code samples for Java, PHP, and cURL, are provided below.
Also see Read Authenticated Entity
REST
The REST noun (and associated message content) for reading an entity is as follows:
- Relative Noun: AuthenticatedSession/$sessionID/Entity/$entityID. This is the relative path of the URL that should appear after the OTIS server application name. Below is an example of reading the john.doe entity:
AuthenticatedSession/78BD660E0E5F673378BD660E0E5F6733/Entity/john.doe
- HTTP Method: GET.
- Request/Response message details: <Entity> element details.
- Description: Reads the specified entity.
Java
The following is example Java code that demonstrates how to read the specified entity:
//Get an entity and read its attributes' values
IEntity example = session.getEntity("example");
System.out.println("\"example\"s attribute values (first value only) are: ");
Iterator attributes = example.getAttributes();
while(attributes.hasNext()) {
IAttribute exampleAttribute = (IAttribute)attributes.next();
System.out.println("\t" + ((ISimpleAttrValue)exampleAttribute
.getValues().next()).getCanonical()); //only returns the first value in the Iterator
}
To view the complete Java sample code for Attribute/Entity nouns, see the Entity/Attribute Java Sample Code page.
The OTIS client Java library may be downloaded from the OTIS download page.
PHP
THe following is example PHP code that demonstrates how to read the specified entity:
//Get the entity XML.
$entity = getRequest($sessionURL, $sessionSecret, "Entity/otisTest");
//Display the entity xml.
echo $entity;
function getRequest($URL, $secret, $URI){
//Make a request header for the entity.
$getHeader =
"GET $URL/$URI HTTP/1.1\n".
"Host: wag.bandit-project.org\n".
(($secret) ? ("SessionSecret: " . $secret . "\n") : "") .
"Connection: Close\n\n";
$socket = fsockopen("wag.bandit-project.org", 80);
fputs($socket, $getHeader);
$xml = "";
while (!feof($socket))
{
$content = fgets($socket, 256);
//If the line contains an xml tag, add it to the xml var
if(strpos($content, ">")){
$xml .= $content;
}
}
//Return the xml var.
return($xml);
}
To view the complete PHP sample code for Attribute/Entity nouns, see the Entity/Attribute PHP Sample Code page.
cURL
The following command reads the "otistest" entity:
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/Entity/otistest
See the Entity Get Request documentation for further details including expected response codes and message body.