How to use <esi:environment> tag to include custom
environment variables
After completing this How-To you should be able
to:
Use <esi:environment> tag to include custom environment
variables
ESI is an open specification for assembling dynamic
pages on the edge of the network. ESI is an XML based markup language. It
enables dynamic content assembly of fragments by ESI compliant servers like
OracleAS Web Cache.
ESI supports HTTP request variables and custom environment
variables to be used within esi tags. Some of the HTTP request variables
include $(HTTP_COOKIE{username}), $(QUERY_STRING{searchstring}), $(HTTP_HOST).
These variables can be used in the esi tags. For example,
These included variables can be used within esi tags
just like the HTTP request variables.
The opinion poll sample application accepts opinion
from the users and displays poll results. The poll results page retrieves
poll results as XML from the servlet and it is included in the page as custom
environment variables. Following code snippet shows how to include custom
environment variables.
The time stamp in the poll results page, shows the
time, when the page was cached. The dynamic data, poll results alone is
refreshed for every request using the <esi:environment> tag.
Pre-requisites for running the example
You will need the following to run this example -
Oracle Application Server (10g or above). This can be downloaded
from here
Oracle JDeveloper (9.0.3 or above). This can be downloaded from here.
This is optional and required only if you wish to deploy from JDeveloper.
Deploying the Sample
The complete source code for this sample is available
here. This section discusses the instruction
to run the sample application
Step 1
Unjar esienvironment.jar
using Winzip, or using the following command:
> jar xvf esienvironment.jar
This creates a directory esienvironment.
Step 2
If you are using JDeveloper then, follow these steps
Open Oracle9i JDeveloper and use File/Open option to select the esienvironment.jws from the esienvironment directory.
Next, select Project/Make esienvironment.jpr
from main menu.
Create an application server connection
Go to Connections -> Application Server Connection. Right Click
and click New connection..
In step 1, enter connection name and select Oracle9i Application
Server
In step 2, enter user name and password
In step 3, enter Enterprise Manager's host name, port number
and Remote Oracle AS home directory(required only if deployed on remote
machine).
In step 4, click Next and Test the connection. Click Finish
button.
Now, Right click esienvironment.deploy
and select Deploy to <connection name>, to the application server
connection, which you have created in the previous step.
Step 3
To deploy the application using EM. follow
the steps.
Go to EM web site -> default oc4j home.,
Choose Deploy EAR file
Enter J2EE Application name, Click the Browse button and choose
esienvironment.ear from <SAMPLE_HOME>/deploy/esienvironment.ear
Enter the Application name as esienvironment and click next
Enter URL mapping as /esienvironment and click Finish
Click Deploy to deploy the application.
Running the Sample
Access the page on the browser, using the following
URL
http://<host_name>:<port>/esienvironment/poll.jsp
where, <host_name> is the machine on which Web
Cache is installed and <port> is the port on which Web Cache listener
is running.
For Example, http://incq185b.idc.oracle.com:7777/esienvironment/poll.jsp