Using Oracle Jolt with Oracle WebLogic Server

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Simple Servlet Example

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:

 


Example Components and Prerequisites

There are two parts to the simpapp example for Jolt for WebLogic Server:

The source code for the Jolt servlet simpapp example is located in the /samples/jolt/wls/servlet/ directory in the Tuxedo distribution.

The simpapp sample directory contains the following files:

File Name
Description
SimpAppServlet.java
Sample source code that issues a call to Tuxedo and returns an HTML page with the results
simpapp.html
HTML form for user input
simpapp.rep
REP file for repository bulk loading
web.xml
Configuration XML file for Web applications

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:

 


Using the Example

The 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.

Configuring the simpapp servlet example requires the following steps:

Step 1. Perform Preparatory Steps

  1. Check that you have a supported browser installed on your client machine:
    • Netscape Communicator 4.7 or later
    • Internet Explorer 5.0 or later
  2. The client machine must have a network connection to the WebLogic Server that is used to connect to the Tuxedo environment.
  3. Configure and boot Tuxedo and the simpapp example.
  4. Follow the directions in the Tuxedo user documentation to bring up the server-side simpapp application. Make sure the TOUPPER service is available.
  5. Set up the Jolt Server. Refer to the Using Oracle Jolt for information about how to configure a Jolt Server.
    • Note the hostname and port number associated with your Jolt Server Listener (JSL).
    • Use the Jolt Repository BulkLoader file to ensure that the TOUPPER service is defined in the Jolt Repository.
    • The 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.

      On the Tuxedo server, the following code example uses the Jolt BulkLoader to add the TOUPPER service definition:

      $ java bea.jolt.admin.jbld //host:port simpapp.rep

      where host and port are the hostname and port number of your Jolt Server Listener (JSL), and the simpapp.rep is the BulkLoader file provided by Oracle Jolt, located in one of the following locations:

      $TUXDIR/samples/jolt/wls/servlet/ on UNIX

      %TUXDIR%\samples\jolt\wls\servlet\ on Windows 2003

  6. Confirm that you have properly set up your CLASSPATH during installation. The WebLogic Server classes library contains the three .jar files that you will need to run this example:
    • jolt.jar
    • joltjse.jar
    • joltwls.jar.

Step 2. Start the WebLogic Server

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.

Step 3. Configure the Servlet in WebLogic Server

Configuration of the Jolt connection pool and startup class MBeans for WebLogic Server 6.0 or later is done through Administration Console.

  1. Copy the simpapp.html page into your WebLogic document root directory.
  2. 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.

  3. Start the WebLogic Server Administration Console by typing the following address in your browser:
  4. http://hostname:listenport#/console

  5. Open the Services folder in the left frame of the console, and then click the Jolt folder. The Jolt Connection Pools table displays in the right frame showing all the Jolt connection pools defined in the domain.
  6. Click the Create a New Jolt Connection Pool link. A tabbed dialog box displays in the right frame for configuring a new connection pool.
  7. On the General tab, complete the following information:
    1. Enter values in the Name, Minimum Pool Size, Maximum Pool Size, and the Recv Timeout attribute fields.
    2. Select the Security Context Enabled check box to enable security context (to propagate the security information from the WebLogic Server environment to the Tuxedo environment).
    3. Click Create to create a connection pool instance with the name that you specified in the Name field. The new instance is added under the Jolt node in the left frame.
  8. Click the Config-Addresses and the Config-User tabs individually to change the attribute fields or accept the default values as assigned, and then click Apply to save your changes.
  9. Click the Targets tab and select an available server where you want the Jolt connection pool started.
  10. Under the Deployments folder in the left frame, click the Startup & Shutdown folder. The Startup and Shutdown table displays in the right frame showing all the startup classes defined for your domain.
  11. Click the Create a New Startup Class link. In the tabbed dialog box that displays in the right frame, configure a new startup class, as follows.
    1. Enter values in the Name, Class Name, and Arguments attribute fields.
    2. Select the Abort Startup on Failure check box to prevent starting the WebLogic Server whenever a failure occurs.
    3. For the Class Name, enter the following name: bea.jolt.pool.servlet.weblogic.PoolManagerStartUp
      There are no arguments for this startup class.
    4. Click Create to create a startup-class instance with the name that you specified in the Name field. The new instance is added under the Startup & Shutdown folder in the left frame.
  12. Register the simpapp servlet as a Web application, as follows:
    1. Open the Deployments folder in the left frame of the console, and then click the Web Applications icon.
    2. On the Install or Update an Application dialog box, click the Install a New Web Application link.
    3. For Step 1, either accept the default a destination directory for the simpapp servlet or select a different one.
    4. For Step 2, enter the path to the simpapp servlet (or use the Browse feature), and then click the Upload button.
    5. The simpapp servlet is registered as a Web application in WebLogic and appears as an icon under the Deployments\Web Applications folder.

Step 4. Stop and Restart the WebLogic Server

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.

Step 5. Compile the Servlet

After restarting the WebLogic Server, compile the SimpAppServlet file, as follows:

  1. Under your WebLogic \config\mydomain\applications\simpapp document root directory, create a new WEB-INF directory.
  2. Copy the web.xml file from the Tuxedo installation directory \samples\jolt\wls\servlet\ into the new WEB-INF directory.
  3. Compile the SimpAppServlet.java file, as follows:
  4. javac -d %WL.HOME%\config\mydomain\applications\simpapp\WEB-INF\classes SimpAppServlet.java

    This step also copies the necessary java classes into a WEB-INF\classes directory.

Step 6. Display the simpapp.html Form

  1. Open your browser.
  2. Enter the URL for the simpapp.html file. For example, the default URL is:
  3. http://localhost:port/simpapp/simpapp.html

    where localhost is the host name of the WebLogic Server, and port is the port at which the WebLogic Server is listening for login requests.

    A page similar to the one shown in Figure B-1 is displayed:

    Figure B-1 simpapp.html Example


    simpapp.html Example

If you have problems displaying the form, be sure that the simpapp.html file is in the WebLogic document root.

Step 7. Post the FORM Data from the Browser

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>
<tr>
<td>Type some text here and click the Post button:
<input type="text" name="string">
</td></tr>

<tr>
<td align=center><input type="submit" value="Post!">
</td></tr>
</table>
</form>

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 HttpServletRequest.

Step 8. Process the Request

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 =
(ServletSessionPoolManager).SessionPoolManager.poolmanager;

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 =
(ServletSessionPool) b_mgr.getSessionPool("simpapp");

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[0], req);

The 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 TOUPPER service.

Note: The TOUPPER service expects a case-sensitive parameter called "STRING", so it is essential for the text field within the HTML form to be labeled exactly the same, that is, "STRING". Note also that the other data fields, such as the SVCNAME, are not relevant as parameters but don't disrupt the Tuxedo service.

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 HttpServletRequest object.

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.

Step 9. Return the Results to the Client

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 result.getValue() method.

The following is a simple example of passing this data back as HTML that the browser can display:

  out.println("<p><center><font size=+1><b>"+
result.getValue("STRING", "")+
"</b></font></center><p><hr
width=80%>");

The output stream produces a page similar to the one shown in Figure B-2:

Figure B-2 Output Stream Results Example

Output Stream Results Example


  Back to Top       Previous  Next