Main Menu
Lecture 1
Lecture 2
Lecture 4
Lecture 5
Lecture 6
Lecture 7
 

 

 

Transaction Objects

Data involved in each request-responae cycle is encapsulated in 3 transaction objects

  1. WOContext - contains
    1. URL
    2. contextID
    3. applicatoin
    4. session
    5. component
    6. request -> WORequest
    7. response -> WOResponse
  2. WORequest - contains
    1. sessionID
    2. headers
    3. cookies
    4. form values
  3. WOResponse
    1. headers
    2. cookies
    3. status
    4. HTML content

In most applications you don't need to interact with these objects

However, sometimes you want to

Know the original URL and the HTTP data that made up the user's cgi request

Examine or customise the data in the response

headers, cookies, HTTP status or the HTML content

Each request-response cycle takes place in a unique context

WO assignes a unique number to each transaction called a contextID

This ID makes each instance of the WOContext class unique

The instance contains all the data required to complete a specific transaction

Session page cache is a cache of context objects, each accessed by their contextID

Accessing request and response objects

invokeAction(), appendToResponse() and takeValuesFromRequest() pass these objects so you can access them directly

awake(), sleep() and the components constructor must request them explicitly

Not available to the application constructor or the session constructor because they don't exist yet

They only exist in any context after the 1st awake()

Accessible to any method via the context

WORequest request = context().request();

WOResponse response = context().response();

HTTP headers

in the request object

a header is a key/value pair

String value = request().headerForKey("key");

NSArray keys = request().headerKeys();

Some common headers contain the user language preferences and the identity of the browser

You can set headers in the response object

Cookies

You can add a cookie to the response at any time

WOCookie cookie = WOCookie.cookieWithName(name, value);

response().addCookie(cookie);

You can get a cookie back from a new request

String value = request.cookieValueForKey(key);

NSDictionary values = request.cookieValues();

A cookie you generate in a response is only useful if it comes back to your application to communicate data about this user

Problem - cookies can outlive individual sessions or even application instances