This example demonstrates how to use Oracle Jolt to connect to Oracle Tuxedo from a WebLogic servlet. It uses the WebLogic Server to deliver an HTML FORM front end in a standard Web browser.
Text entered by a user into the FORM is sent back to the WebLogic Server via the HTTP POST method that is serviced by a registered WebLogic HTTP Servlet, which calls a Tuxedo service using Oracle Jolt. The text received by the servlet is sent to a Tuxedo service, where it is transposed to uppercase before being returned to the servlet. The form is compiled into a dynamically-generated HTML page by the servlet, then sent back to the Web browser, where the uppercase version of the original text is displayed.
This topic includes the following sections:
There are two parts to the
simpapp example for Jolt for WebLogic Server:
samplesdirectory where Oracle Tuxedo is installed.
simpappserver contains the
TOUPPERservice, which converts a given string to uppercase.
The source code for the Jolt servlet
simpapp example is located in the
/samples/jolt/wls/servlet/ directory in the Tuxedo distribution.
simpapp sample directory contains the following files:
A complete listing of the Tuxedo server-side source code of the
simpapp application service is located in
$TUXDIR/samples/atmi/simpapp on UNIX systems and in
%TUXDIR%\samples\atmi\simpapp on Windows 2003 systems (where
TUXDIR is the Tuxedo home directory).
To run this example, you should be familiar with:
simpapp example is easy to follow. Just launch the
simpapp.html page from the WebLogic Server. The
simpapp.html page loads an HTML form which contains a text field for entering the string. Type in a string and click the Post button to submit the string as a post request. The
SimpAppServlet formats the string you typed for use with the Jolt for WebLogic class libraries, and then dispatches the request to the Tuxedo
TOUPPER service, which transposes the string to uppercase and returns it for display in the browser.
simpapp servlet example requires the following steps:
TOUPPERservice is available.
TOUPPERservice is defined in the Jolt Repository.
simpapp example directory has a
simpapp.rep file that contains the
TOUPPER service definition. Your system administrator should use the Jolt Repository BulkLoader to add this service definition to the existing Jolt Repository on the Tuxedo server. The Jolt Repository BulkLoader package is supplied with the Jolt distribution for Tuxedo. Refer to Using Oracle Jolt for details on how to install this.
CLASSPATHduring installation. The WebLogic Server classes library contains the three
.jarfiles that you will need to run this example:
If you are using a Windows 2003 system, you can start the WebLogic Server from the Start menu. Otherwise, use the
startWebLogic script on the command line, in the root directory of the WebLogic Server distribution.
For more information on starting the WebLogic Server, see “Starting and Stopping the WebLogic Server” in the Oracle WebLogic Server Administration Guide.
Configuration of the Jolt connection pool and startup class MBeans for WebLogic Server 6.0 or later is done through Administration Console.
simpapp.htmlpage into your WebLogic document root directory.
By default, this is the
\config\mydomain\applications\simpapp directory in your WebLogic Server distribution. The HTTP server built into WebLogic looks in this directory for HTML pages and other MIME types.
simpappservlet as a Web application, as follows:
simpappservlet or select a different one.
simpappservlet (or use the Browse feature), and then click the Upload button.
In order to start the Jolt session pool, you must shut down the WebLogic Server, and then restart it. For more information on restarting the WebLogic Server, see “Starting and Stopping the WebLogic Server” in the Oracle WebLogic Server Administration Guide.
After restarting the WebLogic Server, compile the
SimpAppServlet file, as follows:
\config\mydomain\applications\simpappdocument root directory, create a new
web.xmlfile from the Tuxedo installation directory
\samples\jolt\wls\servlet\into the new
SimpAppServlet.javafile, as follows:
javac -d %WL.HOME%\config\mydomain\applications\simpapp\WEB-INF\classes SimpAppServlet.java
simpapp.htmlfile. For example, the default URL is:
A page similar to the one shown in Figure B-1 is displayed:
If you have problems displaying the form, be sure that the
simpapp.html file is in the WebLogic document root.
Enter some text into the text field on the HTML page and submit it by clicking the POST button. Along with the text you entered, other parameters are submitted to the
simpapp servlet class running in WebLogic Server.
The following is the relevant section from the
simpapp.html file that describes the HTML form:
<form name="simpapp" action="simpapp" method="post">
<input type="hidden" name="SVCNAME" value="TOUPPER">
<table bgcolor=#dddddd border=1>
<td>Type some text here and click the Post button:
<input type="text" name="string">
<td align=center><input type="submit" value="Post!">
This HTML form specifies two input fields: the text you enter and a hidden field. In this example, the value of the hidden field actually specifies the name of the Tuxedo service to be invoked. Although putting the name of the Tuxedo service within the HTML page is flexible and efficient, it is not recommended for production use for security reasons. In this HTML page, you can submit an HTTP request specifying a different service name as the hidden field.
|Note:||Tuxedo service names are case-sensitive.|
When the WebLogic Server receives the HTTP form request, it invokes the
doPost() method of the
simpapp servlet and passes the form data into an
Before the first request to the
simpapp servlet, WebLogic initializes the servlet by calling its
init() method. The Jolt session pool is established in the following manner:
ServletSessionPoolManager b_mgr =
Next, the servlet’s
doPost() method is executed. This method contains the code to get a connection from the
simpapp session pool that was created during the startup of the WebLogic Server. The following code snippet shows the code that is used to retrieve the
simpapp session pool.
// Get the "simpapp" session pool
ServletSessionPool session =
The Tuxedo service that will be called is identified in a hidden field, which is retrievable from the request object. Retrieve the service name parameter as follows:
String svcnm = req.getParameterValues("SVCNAME");
You retrieve the value of the
SVCNAME field in a string array that contains a single value; use only the first element of the array. The value set for the
SVCNAME hidden field in the form is
TOUPPER. This is the name of the Tuxedo service that the servlet invokes, which is passed to the
call() method as follows:
// Invoke a service and get the result.
result = session.call(svcnm, req);
session object in this example is a
ServletSessionPool that can accept the
HttpServletRequest object directly. Internally, it converts the data into a Jolt DataSet object, which contains the parameters for the
The form parameter is used to actually name the service, which you don't have to pass as a service parameter. It is passed automatically because it is already contained in the
TOUPPER service converts the text in the
"STRING" parameter to uppercase text and passes it back to the servlet in a
ServletResult object that contains the results of an executed call, as well as details about exceptions if any are thrown during the service call.
The final step constructs and sends an HTML page, which contains the results of the service call, back to the client through the HttpResponse output stream. The uppercase result is retrieved from the
ServletResult object using the
The following is a simple example of passing this data back as HTML that the browser can display:
The output stream produces a page similar to the one shown in Figure B-2: