First Publication: 10-Oct-05
Last Update: 16-Jan-06
Author: Frances Zhao
Oracle Application Server and OC4J 10g (10.1.3) provide the HTTPClient Java package as a complete HTTP client library. It currently implements most of the relevant parts of the HTTP/1.0 and HTTP/1.1 protocols, including the request methods HEAD, GET, POST and PUT, and automatic handling of authorization, redirection requests, and cookies. Furthermore the included Codecs class contains coders and decoders for the base64, quoted-printable, URL-encoding, chunked and the multipart/form-data encodings.
This how-to illustrates a few basic features of the HTTPClient package with different JSPs, like the GET method and cookies.
This demo requires that the following sofware components are installed and configured correctly:
Using the HTTPClient is quite simple and usually involves the following steps:
You must include the %ORACLE_HOME%/j2ee/home/lib/http_client.jar in your application's classpath in order to use the HTTPClient package. This how-to uses JSPs that utilize the HTTPClient after deployment, thus making it necessary to add the above jar to this application's orion-application.xml, using the <library> element.
Here is the additional classpath declaration, which can be found in the orion-application.xml under %HOWTO_HOME%/etc.
This JSP illustrates the basic features of HTTPClient. It uses the HTTP GET method to first retrieve an existing HTML page and displays it, and then retrieves a non-existing HTML page to correctly report an error. The JSP is under %HOWTO_HOME%/src/web/content/httpclient_basic.jsp.
Here are the key operations in this JSP code:
This JSP illustrates HTTPClient cookie handling functions, which are available in HTTPClient.CookieModule, such as cookie creation, storage, retrieval, and policy handler setting. The JSP is under %HOWTO_HOME%/src/web/content/httpclient_cookie.jsp.
Here are some key operations in this JSP code:
This JSP is invoked by httpclient_cookie.jsp. It stores a new cookie with the HTTP response, for the invoking JSP to check. In doing so, it uses the standard javax.servlet.* APIs, and does not use the HTTPClient package. The JSP also outputs to OC4J console the cookies set from HTTPClient before sending response back.
For more examples on HTTPClient's basic and advanced features, check out the following link:
The following instructions are for running this demonstration on a standalone instance of Oracle Containers for J2EE 10g (10.1.3).
Please check to make sure that the following properties are configured correctly in the ant-oracle.properties file located in the root of the sample's distribution (NOTE: Some of these properties will default to the values of corresponding environment variables as noted below. If you have these variables setup in your environment you may not have to alter the values in the file). If necessary, modify these variable to the proper values for you environment:
Stand Alone Installation: %ORACLE_HOME%/bin/oc4j start
Note that the oc4j command expects the JAVA_HOME environment variable to point to a full JDK installation.
OracleAS Managed Installation: %ORACLE_HOME%/opmn/bin/opmnctl startall
Ensure Ant 1.6.2 or above is installed on your machine and configured correctly. On some operating systems Ant does not currently support the use of environment variables. If this is the case for your operating system, please modify the common.xml file located in the top-level %HOWTO_HOME% directory.
In the top-level %HOWTO_HOME% directory, type the command:
You should now have newly created httpclient_demo.ear in your %HOWTO_HOME%/dist directory.
This command would also attempt to deploy the application if the build is successful. It will first test whether OC4J is running.
You can also deploy and bind the application separately by using the following command. Make sure the %ORACLE_HOME% environment variable is defined. In the top-level %HOWTO_HOME% directory, type the command:
In a browser window, browse to:
If the website hostname or port number are different, then use those values instead.
There are two buttons shown. Clicking the first button would invoke a JSP testing the basic feature of HTTPClient; clicking the second button would invoke a JSP testing the cookie functions provided in HTTPClient. A new page would show the test logs, or if an exception has occurred. There would be a back link on the new page that brings you back to this page.
In this document, you should have: