Broadcast on Broadcast off
The Documentation for Project Zero has moved. Please update your bookmarks to: http://www.projectzero.org/documentation/
Table of
Contents...
Hide

Project Zero Developer’s Guide

Concepts and components
Basic concepts overview
Event processing
Writing Java handlers
Writing Groovy handlers
Firing events
Global Context
Global Context reference
Application directory layout
Virtualized directories
Assemble
PHP
Features and configuration
Configuration
Debugging
Dependencies
Packaging
Application classpath
Logging and tracing
RESTful resources
RESTful documentation
File serving
Response rendering
Validators and validation
HTTP error handling
Calling a remote resource
Using the Connection API
Sending an email using EmailConnection
Configuring destinations
Configuring protocols
Configuring connection handlers
Creating a connection handler
Creating a custom protocol transport
Simple logging connection handlers
Protocol reference
Client programming with Dojo
Runtime options
Deployment modifications
HTTP configuration
SSL configuration
Proxy configuration
Extending the CLI
Security considerations
Authentication
OpenID authentication
Extending security
Security tokens
CSRF prevention support
Extending token support
Leveraging TAI
User service
File based user service
LDAP user service
Extending user service
Security Utilities
Leveraging XOREncoder
Extensions
Atom support
RSS support
JSON support
XMLEncoder
REST to SOAP extension
URIUtils
Developer Web tools
Database setup tools
Configuring data access
Common query patterns
Advanced query patterns
Update patterns
Local database transactions
Extending data access
Configuration vendor differences
PHP data access
Resource model
Configuring ZRM
Resource model declaration
Programmatic model API
HTTP REST API
A ZRM mini tutorial
Active content filtering support
Default filters
Custom filters
Runtime management
Management commands
Zero socket opener
Other extension modules
Amazon E-commerce service
Flickr service
WeatherZero forecast service
Wikipedia service
Reference
Zero command line interface
JavaDoc - Public API
JavaDoc - Public SPI
JavaDoc - All Classes

 

Validators and validation

Caching in HTTP gains improved efficiency through validation mechanisms, including entity tags (Etags) and last-modified dates. This section describes the high-level support for validation available in Zero.

Within Zero, static-file serving supports ETags and caching.

Validators

Etags

Entity tags (etags) are opaque strings associated with a representation (HTTP response body); an etag changes only when the representation changes.

An etag is commonly a hash of the information that affects your resource's representation. For example, for a representation derived from a database query and a rendering template, the associated etag might be a hash of the last-update time from the database and the template's last-modified time.

Zero provides utility APIs for hashing and setting the Etag response header. In Java:

import zero.core.etags.Etag;

...
String concatenatedInformation = ... /* contains the distinguishing information */
String etag = Etag.computeHashedValue(concatenatedInformation);
...
Etag.setEtagHeader(etag);

Last-modified date

Zero automatically adds a Last-Modified response header when serving static files. The value is the last modified time of the served file, formatted according to RFC1123 (e.g. Wed, 22 May 1996 12:06:00 GMT).

For other cases where you want to manually set the Last-Modified header, you can do so with the Global Context and the HttpDateFormat utility formatter. For example, in Java:

zput(Request.Headers.out + "/Last-Modified",
    new zero.util.HttpDateFormat().format(new java.util.Date()));

And in Groovy:

headers.out.['Last-Modified'] = new zero.util.HttpDateFormat().format(new Date()))

Validation

"Validation" is the process of checking whether validators (presented by the client) match the current state. Validation can be used as the basis of conditional GET and PUT requests. For example, the response to a "conditional GET", if the representation hasn't changed, could be a bandwidth-saving 304 Not Modified. Also, a "conditional PUT" could be denied if the submitted etag no longer matches -- which prevents the "lost update" problem.

Zero provides the PreconditionValidator utility, which enables you to integrate validation into your handlers:

boolean valid = PreconditionValidator.validate(String etag);
boolean valid = PreconditionValidator.validate(String etag, Date lastModified);

This table represents the possible results of evaluating precondition headers. If multiple headers are present they all must agree that the conditions are not met, otherwise true will be returned to indicate the request should be executed.

Header Type Condition Met Condition Not Met
if-match return true status code set to 412, return false
if-none-match (GET/HEAD) return true status code set to 304, return false
if-none-match (other HTTP methods) return true status code set to 412, return false
if-modified-since return true status code set to 304, return false
if-unmodified-since return true status code set to 304, return false

r7 - 09 Nov 2007 - 12:05:48 - steveims
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site