BEA Logo BEA WebLogic Server Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

Using Jolt for WebLogic

I. Introduction
Key features
How Jolt for WebLogic works

II. The Jolt for WebLogic API
The Jolt for WebLogic API

III. Implementing with Jolt for WebLogic
Importing packages
Configuring a session pool
Obtaining a ServletSessionPool.
Using a ServletSessionPool
Accessing a TUXEDO service through Jolt
Converting Java data types to TUXEDO data types
Receiving results from a service
Using a transaction
Handling exceptions
A simple example

IV. Change history

Other related documents
Installing WebLogic (non-Windows)
Installing WebLogic (Windows)
Developers Guides
API Reference Manual
Using WebLogic HTTP Servlets
Setting WebLogic properties
Using WebLogic JNDI
Code examples
Glossary

Top

I. Introduction

Jolt for WebLogic is an extension to the Jolt 1.1 Java class library that allows the Jolt client class library to be used in HTTP servlets running in the WebLogic Server to provide an interface between HTML browser clients and BEA TUXEDO services. From here onwards, we shall refer to BEA TUXEDO simply as TUXEDO for readability. Jolt for WebLogic allows TUXEDO applications to be web-enabled, using the WebLogic Server as an HTTP and application server.

Key features

Key features of this architecture include:
  • Enables use of Java HTTP servlets to provide a dynamic HTML front-end for TUXEDO applications
  • Provides session pooling to use TUXEDO resources efficiently
  • Supports transactions
  • Integrates session pool management into the WebLogic Console

Note that Jolt for WebLogic does not provide access to asynchronous TUXEDO event notifications.

Top

How Jolt for WebLogic works

First, we shall describe the major components used for communication in Jolt. To describe how Jolt for WebLogic works, we shall then follow the journey of how the connection is initialized when the server is started, and describe the flow of information between an end-user web browser, the WebLogic Server, and the TUXEDO transaction processing system.

What are the clients and servers in the system?

Jolt for Weblogic allows you to access your underlying TUXEDO system from the web. This gives you the opportunity to write web-enabled applications with the functionality to interact with the other systems and databases in your TUXEDO domain. The system we shall describe here is accessed via a standard web-browser. The web-browser is served by the WebLogic Server, and uses a customized Java HTTP servlet to handle the interactive HTTP requests of the browser. The custom HTTP servlet uses the Jolt for WebLogic API to talk to a Jolt Server, which may be on a remote machine or behind a security firewall. The Jolt Server lives within the TUXEDO domain, and determines which TUXEDO services are accessible and which are not to each client. The Jolt Server invokes the requested TUXEDO service, and sends any results back to the WebLogic Server. The results may then be compiled into a servlet generated web page, and sent back to the browser. The result is a highly accessible and user friendly interface to TUXEDO services from anywhere on the internet or intranet.

Essential components of the Jolt architecture

Before we follow the flow of information we should describe the fundamental object types in Jolt that maintain the communications connection from our WebLogic Servlet to the Jolt Server, through to TUXEDO.

Session
A session object represents a physical connection with the TUXEDO system.

Session pools
A session pool contains one or more sessions as described above. The sessions in the session pool are reused for efficiency. Your WebLogic servlet uses sessions to invoke services in TUXEDO via the methods of a session pool. Session pools are initialized by the WebLogic server at startup, configured by properties in the weblogic.properties file.

Session pool manager
The session pool manager is used to get a reference to a session pool, and create, administer, or remove session pools. It is created just before the WebLogic server initializes the first Session pool, and is registered under a well known name as a JNDI entry, so that your application can obtain a reference to it later via a JNDI lookup.

What happens when the WebLogic Server starts up?

The WebLogic Server is configured to initialize the session pools at startup via the weblogic.properties file. A special startup class called PoolManagerStartUp is invoked by the WebLogic Server with a number of parameters. This class creates a session pool manager if one does not already exist, registers it with JNDI, creates a session pool according to the given parameters, and adds the new session pool to the pool manager. Each successive call to this startup class adds another session pool to the same pool manager.

Connecting to the WebLogic Server from a client browser

In addition to its other Java services, the WebLogic Server is a fully functional HTTP Server that supports Java HTTP servlets. In general, each servlet must be registered in the weblogic.properties file with a virtual name.

A servlet may be invoked directory, that is, may actually present HTML to the browser, or may be invoked indirectly from an HTML form when the user submits the form. When the WebLogic Server receives a request containing the registered virtual name of a servlet, it invokes the appropriate servlet's service method. For more information on HTTP Servlets see Using WebLogic HTTP Servlets.

The HTTP servlet's service() method (which invokes either the servlet's doPost() or doGet() methods, depending on the context), is invoked and passed an HttpServletRequest object containing the HTTP data sent from the browser. In our case, we shall use the client's query data in a transaction call to TUXEDO and build the response into the new HTML page.

How a servlet connects to TUXEDO

First, using a JNDI lookup, a servlet obtains a reference to the session pool manager that was created and initialized by the WebLogic Server when it started. The session pool manager is always registered in the WLInitialContext JNDI context under the name defined by the SessionPoolManager.POOLMANAGER_NAME final (constant) static variable.

The pool manager is used to retrieve the session pool that was configured in the weblogic.properties file. This session pool references the appropriate Jolt Server in a TUXEDO domain. A servlet uses the session pool to invoke a specific TUXEDO service.

TUXEDO services are described and exported (declared accessible) on the Jolt Server in the Jolt Repository. Here, the service's expected input and output parameter types are declared. A servlet must supply the expected input parameters; Jolt for WebLogic uses specialized ServletSessionPool objects that can accept their input directly from an HttpServletRequest object. The output is returned in a ServletResult object.

What if the request fails?

The session pool distributes the requests equally amongst the sessions in the pool. It picks the least busy session to call the TUXEDO service. If the selected session is terminated before the service is called, the session pool will redirect the service call to a different session and then establish a new session to replace the disconnected one. To establish a connection to a Jolt Server, the session pool uses round-robin algorithm to select a primary Jolt Server. If none of the primary Jolt Servers responds, the session pool will connect to one of the failover servers.

If no sessions are available from a session pool, or the session pool is suspended, then a SessionPoolException is thrown.

Multiple requests can be grouped into a single transaction. When an transaction fails, a TransactionException is thrown, which should be caught by the servlet and handled appropriately; usually, a rollback should be performed.

Responding to the client browser

Provided the service call was successful, the following is performed:

  • The desired results are extracted from the ServletResult object.
  • The results are processed by the servlet and incorporated into an HTML page for presentation to the user's browser. The HTML page can be built either:
    • With WebLogic's easy-to-use JSP service, that lets you embed Java in a standard HTML page.
    • Using a more sophisticated programmatic approach with WebLogic htmlKona.
  • The HTML page is returned by the WebLogic Server to the client via the HttpServletResponse object.

A diagram of the architecture for Jolt for WebLogic is shown below.

Jolt for
WebLogic architecture

Disconnecting from the Jolt Server

The WebLogic Server is also configured to shut down the existing session pool connections to TUXEDO via the weblogic.properties file.

Use the weblogic.system.shutdownClass property to register the class PoolManagerShutDown so that the Jolt session pool is cleaned up properly when the WebLogic Server shuts down. The PoolManagerShutDown accepts the name of the session pool to be closed as shutdownArgs parameters, also configured in the weblogic.properties file.

Top

II. The Jolt for WebLogic API

Package-bea.jolt.pool
Package-bea.jolt.pool.servlet
Class java.lang.Object
    Class bea.jolt.pool.Connection
    Class java.util.Dictionary
        Class java.util.Hashtable
	 (implements java.lang.Cloneable,
	  java.io.Serializable)
          Class bea.jolt.pool.DataSet
            Class bea.jolt.pool.Result
              Class bea.jolt.pool.servlet.ServletResult
            Class bea.jolt.pool.servlet.ServletDataSet
          Class bea.jolt.pool.SessionPoolManager
            Class bea.jolt.pool.servlet.ServletSessionPoolManager
    Class bea.jolt.pool.Factory
        Class bea.jolt.pool.SessionPool
          Class bea.jolt.pool.servlet.ServletSessionPool
    Class java.lang.Throwable
     (implements java.io.Serializable)
        Class java.lang.Exception
          Class java.lang.RuntimeException
            Class bea.jolt.pool.ApplicationException
    Class bea.jolt.pool.Transaction
    Class bea.jolt.pool.UserInfo

Top

III. Implementing with Jolt for WebLogic

This section describes the steps involved to use Jolt to connect to TUXEDO from your WebLogic application or servlet. In the last section, we provide a step-by-step description of a very simple example that establishes a connection and accesses a TUXEDO service from an HTTP servlet.

Importing packages
Configuring a session pool
Obtaining a ServletSessionPool.
Using a ServletSessionPool
Calling a TUXEDO service
Sending a ServletDataSet
Adding parameters to the DataSet
Accessing a TUXEDO service through Jolt
Converting Java data types to TUXEDO data types
Receiving results from a service
Using the Result.getValue() methods
Using the ServletResult.getStringValue() methods
Using a transaction
Handling exceptions
A simple example
Overview
Step 1. Getting started checklist
Step 2. Setting up the WebLogic environment
Step 3. Starting the WebLogic Server
Step 4. Displaying the simpapp.html form
Step 5. Posting the FORM data from the browser
Step 6. Processing the request
Step 7. Returning the results to the client

Top

Importing packages

To use Jolt for WebLogic, import the following into your servlet:

bea.jolt.pool.*
bea.jolt.pool.servlet.*
weblogic.jndi.*

You must import the JNDI package to look up the SessionPoolManager.

There are other classes you must import into any servlet; for more information on writing Java servlets, read the Developers Guide Using WebLogic HTTP Servlets.

Top

Configuring a session pool

Session pools are created and accessed via the SessionPoolManager class. You can use the SessionPoolManager to create a session pool from within your application code, or have the WebLogic Server perform this task for you on startup, by setting a property in the weblogic.properties file. The latter is recommended since it provides a soft-coded configuration that is not part of your application logic, which means you can administer it without changing and recomping your code. That's the method we assume you are using in these instructions.

The WebLogic Server uses a derivative of the SessionPool called a ServletSessionPool. The ServletSessionPool provides some extra functionality that is convenient for use inside an HTTP Servlet.

A ServletSessionPool is configured in the weblogic.properties file by adding a set of properties as shown below:

weblogic.system.startupClass.joltpool=\
	bea.jolt.pool.servlet.weblogic.PoolManagerStartUp

weblogic.system.startupArgs.joltpool=\
    poolname=joltpoolname,\
    appaddrlist=//hostname:port;//hostname:port,\
    failoverlist=//hostname:port,\
    minpoolsize=1
    maxpoolsize=3

When WebLogic is either started or restarted, it will invoke the PoolManagerStartUp class with the associated startupArgs. This association is made via a virtual name binding; in this example, we used joltpool. For more information on virtual names and the WebLogic properties file, see the Administrators Guide document, Setting WebLogic Properties.

On the first invocation, the PoolManagerStartUp class creates a ServletSessionPoolManager, which contains every ServletSessionPool configured in the WebLogic properties file. Subsequent calls will add another ServletSessionPool to the same ServletSessionPoolManager. You must add registrations to the WebLogic properties file for each session pool using a unique virtual name binding for each, as shown in the properties example above.

The ServletSessionPoolManager object is always bound to the name defined by SessionPoolManager.POOLMANAGER_NAME, and added to WebLogic's JNDI tree, so that it may be retrieved by your application code later. This process is described under Obtaining a ServletSessionPool, later in this document.

The WebLogic Server creates a new ServletSessionPool as defined by the startupArgs you supply in the properties file. These are defined as follows:

    poolname
    Defines a name for this session pool that must be unique from other session pools. In general, we consider this attribute to be required, although the SessionPoolManager allows a single session pool to be unnamed. We strongly recommend that you name every session pool. (You may access the single unnamed session pool from your application by supplying null in place of the poolname argument to the getSessionPool() method.)

    appaddrlist
    (Required) Defines a list of the addresses of the primary Jolt Server Listeners (JSLs) on the TUXEDO system. It is the JSLs that service your servlet's Jolt requests. These are defined in the format:
      //hostname:port

    where hostname is the name of the server where the JSL is running, and port is the port on which the JSL is configured to listen for requests.

    You may specify multiple addresses in a semicolon-separated (;) list. You must specify at least one primary JSL hostname:port address.

    failoverlist
    (Optional) You may specify a list of failover Jolt Server Listeners in the same format as for appaddrlist above. Jolt will attempt to use these failover JSL(s) if the primary JSLs listed above fail. These JSL need not reside on the same host as the primary JSLs.

    minpoolsize
    (Required) Specifies the initial session pool size when the session pool is created.

    maxpoolsize
    (Required) Specifies the maximum session pool size.

    username
    (Optional) TUXEDO user name. This is required only if TUXEDO authentication level is USER_AUTH.

    userpassword
    (Optional) TUXEDO user password. This is required only if TUXEDO authentication level is USER_AUTH.

    userrole
    (Optional) TUXEDO user role. This is required only if TUXEDO authentication level is USER_AUTH or APP_PW.

    apppassword
    (Optional) TUXEDO application password. This is required only if TUXEDO authentication level is USER_AUTH or APP_PW.

Top

Obtaining a ServletSessionPool

Now that you have configured the WebLogic Server to set up a Jolt SessionPool on start up, you will want to access it, and make use of it from your Java application or servlet.

As we described above, in the WebLogic Server all ServletSessionPool objects are managed by the same ServletSessionPoolManager. You can look up the pool manager in the WebLogic JNDI InitialContext using the following code:


  // Create the InitialContext
  Context ctx = 
    WLInitialContextFactory.newInstance(new Environment());
  // Lookup the pool manager
  ServletSessionPoolManager poolMgr = (ServletSessionPoolManager) 
    ctx.lookup(SessionPoolManager.POOLMANAGER_NAME);

The WebLogic Server uses a ServletSessionPoolManager class, which is derived from SessionPoolManager. The ServletSessionPoolManager manages ServletSessionPool objects, which offer additional HTTP servlet methods.

The SessionPoolManager provides several methods for managing the administration of a SessionPool. Here, the SessionPoolManager is used to retrieve the SessionPool that has been named joltpoolname :

  SessionPool sPool = poolMgr.getSessionPool("joltpoolname");

Since the WebLogic Server uses the subclass ServletSessionPoolManager, however, this in fact returns a ServletSessionPool object in the guise of a SessionPool. You must cast the SessionPool to a ServletSessionPool, as illustrated in this code example:

  ServletSessionPool ssPool =
    (ServletSessionPool) poolMgr.getSessionPool("joltpoolname");

Since the WebLogic Server creates and configures the ServletSessionPoolManager for us, it is likely that this is the only method you shall use. Other methods of the SessionPoolManager allow you to create, suspend, stop, or shut down individual or all session pools it manages. We recommend that you leave these administrative operations to the WebLogic Server, by configure and managing your session pools via the WebLogic properties file.

Top

Using a ServletSessionPool

The reference to the named ServletSessionPool from the pool manager represents a pool of sessions (or connections) to the Jolt Server in TUXEDO. The size of this pool and the TUXEDO system it connects to are abstracted from our application code and are defined in the WebLogic properties file. When we initiate a request, the SessionPool uses the least busy connection available.

Calling a TUXEDO service

A Jolt request usually consists of a single call to a TUXEDO service, using the call() method of the SessionPool. You supply the name of the TUXEDO service and a set of parameters to the call() method, and it returns a set of results from the TUXEDO service. It is possible to make multiple calls within a single transaction, which allows a servlet to comply with transactional demands of a TUXEDO application or preserve integrity between databases. This is described in more detail later under the section Using a Transaction.

Sending a ServletDataSet

The ServletSessionPool provides overloaded call() methods for use inside an HTTP servlet. These methods accept their input parameters in terms of an HttpServletRequest object, and hence can conveniently be passed the same HttpServletRequest object that was passed into your HTTP servlet's doPost() or doGet() methods. However, in this instance, you must ensure that the names of the HTTP posted name=value pairs correspond to those expected by the TUXEDO service. The ordering is not important, since the data is ultimately converted into a Java Hashtable. Other non-related data in the HttpServletRequest will not disrupt the TUXEDO service.

You invoke a TUXEDO service from within an HTTP servlet with the following method:


    ssPool.call("serviceName", request);

where ssPool is a reference to a ServletSessionPool, "serviceName" is the name the TUXEDO service you wish to call, and the request argument is the HttpServletRequest object associated with the servlet.

Internally, the ServletSessionPool.call() method converts the HttpServletRequest into a ServletDataSet, which may be submitted to a regular SessionPool.

Adding parameters to the DataSet

You may wish to add extra data to the parameter set before calling the TUXEDO service. For example, you may need to add a parameter representing the date and time of the request. You would not expect to receive this parameter from the FORM data in the HttpServletRequest, better that you add it in the servlet, then submit the augmented data set to the TUXEDO service. The following example illustrates how to achieve this.

  // Create a new dataset
  ServletDataSet dataset = new ServletDataSet();
  // Import the HttpServletRequest into the dataset.
  dataset.importRequest(request);
  // Insert an extra parameter into the dataset.
  dataset.setValue("REQUEST_TIME", (new Date()).toString());
  // Send the dataset to the named service.
  ssPool.call("service_name", dataset, null);

Here we manually convert the HttpServletRequest object into a ServletDataSet object. In this new format, we can add extra parameters, using the setValue() method. The new value is associated with a key, represented by a String. Then, we invoke the call() method that is inherited from the SessionPool. This method accepts the ServletDataSet class, but requires an extra argument for use with transactions. We supply null for this last parameter, indicating that we are not using a transaction to group multiple session calls. See Using transactions later for more details.

Top

Accessing a TUXEDO service through Jolt

To access an existing TUXEDO service via Jolt, you must define and export the service in the Jolt Repository. For details on this, refer to the Jolt Repository Editor, or the Jolt Bulk Loader, in the Jolt User's Guide. The Jolt service definition defines the parameters that are expected by the TUXEDO application service.

Top

Converting Java data types to TUXEDO data types

The following table is a mapping between Java types and TUXEDO parameter types required by a TUXEDO service. Use the appropriate Java types for the value to the DataSet or ServletDataSet. If you specify any parameter as a Java String, it is translated automatically to the appropriate type according to the service definition in the Jolt repository. This feature is also used to convert all of the data inside an HttpServletRequest object, since all parameters associated with the request are represented in string format. Otherwise, you should use the type specified in the table below. Providing the correct data-type may improve efficiency since no lookup is required to convert from a string.

BEA TUXEDO Type Java Type
char Byte
short Short
long Integer
float Float
double Double
char* String
CARRAY byte[ ]

A TUXEDO CARRAY is specified in a Java String by describing each byte value as a two digit hexadecimal number. You specify multiple bytes by concatenating these hexadecimal digit-pairs together. For example, the string "FF0A20" would represent the TUXEDO type CARRAY { 255, 10, 32 }.

Top

Receiving results from a service

The ServletSessionPool.call() method returns a ServletResult object that contains the results from the TUXEDO service. If the service call fails, an Exception is thrown. You should always attempt to catch Exceptions and handle them appropriately. Refer to the Jolt WAS Developer's Guide for details about the possible exceptions that can occur.

Here is an example that retrieves a ServletResult using the ServletSessionPool.call() method in an HTTP servlet:

  ServletResult sResult = ssPool.call("service_name", request);

Here, ssPool is a ServletSessionPool, and request is an HttpServletRequest.

The ServletSessionPool.call() method returns a Result object that you must cast as a ServletResult object. The ServletResult object provides extra methods for retrieving data as Java Strings.

Using the Result.getValue() methods

Provided the call was successful, the individual parameters may be retrieved from the Result or ServletResult object using various forms of the getValue() method.

The data is retrieved from a ServletResult by providing a key that corresponds to the parameter names of the TUXEDO service, as defined in the Jolt Repository. You supply the key to the appropriate getValue() method, which returns the corresponding value object.

The Result.getValue() method also expects a default value object; this is returned if the key lookup fails. It is your responsibility to cast the returned object to the appropriate type, as defined by the TUXEDO service. Refer to the table above for the Java equivalents of the TUXEDO types. For example:

  Integer answer = (Integer) resultSet.getValue("Age", null);

This will set the Integer answer to the returned value in the ServletResult identified by the key "Age", or null if this key does not exist in the ServletResult.

It is possible to have an array of values associated with a key. In that case, the simple getValue() method will return the first element of an array in this instance. Use this method signature in that case:

  public Object getValue(String name, int index, Object defVal)
to reference a particular indexed element in an array value.

Using the ServletResult.getStringValue() methods

ServletResult extends Result, and provides the extra methods:

  public String getStringValue(String name,
                               int index,
                               String defVal)

  public String getStringValue(String name,
                               String defVal)

These methods behave like the getValue() methods of the Result class, except that they always return a Java string equivalent of the value object expected. The CARRAY is converted into a string of two digit hexadecimal byte values as described earlier in Converting Java data types to TUXEDO data types.

Top

Using a transaction

You can use a Transaction object to group multiple service calls into an atomic action, maintaining data integrity within your application logic. You obtain a Transaction from a session pool with the method:

  Transaction trans = ssPool.startTransaction(timeout);
where the Transaction object trans holds the reference to the transaction, ssPool is the SessionPool or ServletSessionPool object, and the timeout argument for the transaction is specified in seconds.

Once a transaction has obtained a session, that session cannot be used by other transactions until the transaction is committed, aborted, or times out. The session may, however, still be used by single requests that are not part of a transaction. If a transaction fails to obtain a session from the pool, this method will throw a bea.jolt.pool.TransactionException. If the session pool is suspended, the method will throw a bea.jolt.pool.SessionPoolException.

Each time your application uses the call() method, you should supply the Transaction object as the last parameter. For instance:

  ssPool.call("svcName", request, trans);

You can make multiple calls in the same transaction. The calls will not complete until you either commit or rollback the transaction using the methods of the Transaction object. The trans.commit() method completes the transaction. The method returns 0 if the commit was successful, or throws a TransactionException if the transaction failed to commit.

If you need to abort the transaction, use the Transaction.rollback() method. This attempts to abort the transaction. It returns 0 if successful, or throws a TransactionException otherwise.

Top

Handling exceptions

Errors or failures that may occur when Jolt initiates a TUXEDO service call are reported to your application via Java exceptions. You should always enclose the call() method within a try / catch block and attempt to deal with any exceptions appropriately. The call() method can throw any of the following exceptions for the following reasons:
bea.jolt.pool.ApplicationException
Thrown when an error occurs in the logic of the TUXEDO service. For example, a client illegally attempts to use a withdrawal service to withdraw more money from an account than the current balance. The ApplicationException is thrown when the TUXEDO service returns a TPESVCFAIL. Application-specific information about the error can be included in the Result object that was returned from the service invocation. You can access the Result object via the ApplicationException.getResult() method.

Be sure to use the full package name of the bea.jolt.pool.ApplicationException because Jolt defines another exception whose full package name is bea.jolt.ApplicationException.

bea.jolt.JoltException
A JoltException is the super class of all the following exceptions. These exceptions all signify that a system error has occured that is not part of the application logic. This is documented in the Jolt Users Guide under Appendix A.

bea.jolt.pool.SessionPoolException
Thrown when an error occurs in the Jolt SessionPool. For example, this may occur if all sessions are busy, or if the session pool is suspended.

bea.jolt.ServiceException
Thrown when an error occurs related to invoking the TUXEDO service that contains the application. For example, a service time-out, or a non existent service is called.

bea.jolt.TransactionException
Thrown when a transaction cannot be either started, committed, or aborted.

Top

A simple example

This section provides step-by-step instructions on running the Jolt simpapp example, which uses a servlet to access a TUXEDO service that converts a string to uppercase.

There are two parts to the simpapp example: the HTTP servlet that is shipped with the WebLogic examples, and the TUXEDO service application that is shipped with the TUXEDO examples. The TUXEDO simpapp server contains the TOUPPER service, which transposes a given string to uppercase.

You can find the source code for the simpapp example in the examples/jolt/servlet/simpapp directory, included in the WebLogic distribution.

Here is what you will find in the simpapp example directory:

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

A complete listing of the TUXEDO server-side source code of the simpapp application service is located in the TUXEDO distribution in the >$TUXDIR/apps/simpapp where $TUXDIR is the TUXEDO home directory.

To run this example, you should be familiar with:

  • The TUXEDO architecture and the sample application, simpapp
  • BEA Jolt 1.1
  • HTML
  • Java language and Servlet API
  • WebLogic HTTP Servlets

Overview

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.

Step 1. Getting started checklist

  1. Check that you have a supported browser (Netscape or IE, later than 3.2) installed on your client machine. The client machine must have a network connection to the WebLogic Server that is used to connect to the TUXEDO environment.

  2. Configure and boot TUXEDO and the simpapp example.

  3. Follow the directions in the TUXEDO user documentation to bring up the server-side simpapp application. Make sure the TOUPPER service is available.

  4. Set up the Jolt Server. Refer to the Jolt User's Guide for information about how to configure a Jolt Server.
    • Note the hostname and port number associated with your Jolt Server Listener (JSL).
    • Ensure that the TOUPPER service is defined in the Jolt Repository using the Jolt Repository Bulk Loader file.

    The simpapp example directory a simpapp.rep file that contains the TOUPPER service definition. Your system administrator should use the Jolt Repository Bulk Loader to add this service definition to the existing Jolt Repository on the TUXEDO server. The Jolt Repository Bulk Loader package is supplied with the Jolt distribution for TUXEDO. Refer to the Jolt User's Guide for details on how to install this. On the TUXEDO server, the following code example uses the Jolt Bulk Loader to add the TOUPPER service definition:

     $ java bea.joltadm.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 Bulk Loader file provided by BEA, located in the examples/jolt/servlet/simpapp directory of your WebLogic installation.

  5. Confirm that you have properly set up your CLASSPATH during installation. The WebLogic classes directory contains the bea.jolt.* packages that you will need to run this example.

Step 2. Setting up the WebLogic environment

Place a copy of the simpapp.html page in your WebLogic Server document root, then edit the weblogic.properties file to set up the WebLogic environment. You must add three registrations:

  • A property to invoke the pool manager which will initialize a session pool of connections to TUXEDO when the WebLogic Server starts up.
  • A property to shut down the pool manager and close the session pools it manages when the WebLogic Server shuts down.
  • A property to register the simpapp servlet with the WebLogic HTTP Server.

Follow these instructions to edit the WebLogic properties file.

  1. Open the weblogic.properties file in any text editor. It's located in the WebLogic home directory, that is, in the root directory where you installed the WebLogic distribution. Look for the section labeled "Jolt for WebLogic."

  2. Add a startup registration for the Jolt pool manager. To do so, make these changes in the existing registration:
    • Change the hostname and portnumber to reflect your particular Jolt Server Listener (JSL) address.
    • Uncomment the lines (remove the leading # marks) to make these properties active.

    Here is an example of the registration for the startup class that creates a pool of TUXEDO connections for use by the Jolt clients in the simpapp example. Uncomment to use:

    weblogic.system.startupClass.simpapp=\
        bea.jolt.pool.servlet.weblogic.PoolManagerStartUp
    weblogic.system.startupArgs.simpapp=\
        poolname=simpapp,\
        appaddrlist=//hostname:portnumber;//hostname:portnumber,\
        failoverlist=//hostname:portnumber,\
        minpoolsize=1
        maxpoolsize=3
    where poolname is the name of the session pool, appaddrlist is a semicolon-delimited list of host and portnumber of JSLs (for example, the registration //angelfish:7500;//tiburon:9000 sets two Jolt Server Listeners), and failoverlist is a list of alternate host or port numbers. If the startup class cannot connect to any of the addresses listed in appaddrlist, it uses the addresses in the failoverlist to establish a new connection. You should also set minpoolsize to the minimum number of connections in session pool, and maxpoolsize to the maximum number of connection in session pool.

  3. Uncomment the registration for the shutdown class to clean up the Jolt connections when the WebLogic Server is shut down. Here is a sample:
    weblogic.system.shutdownClass.simpapp=\
        bea.jolt.pool.servlet.weblogic.PoolManagerShutdown
    weblogic.system.shutdownArgs.simpapp=\
        poolname=simpapp

    where poolname is the same session pool that you registered for startup.

  4. Uncomment the servlet registration that is shipped with the distribution in the WebLogic properties file:
    weblogic.httpd.register.simpapp=\
        examples.jolt.servlet.SimpAppServlet

  5. Save and close the properties file.

  6. Copy the simpapp.html page into your WebLogic document root. By default, this is the myserver/public_html directory in your WebLogic distribution. The HTTP server built into WebLogic looks in this directory for HTML pages and other MIME types.

Step 3. Starting the WebLogic Server

If you are using a Windows system and you installed using the Install Shield, you can start the WebLogic Server from the menu item in the WebLogic Start menu. Otherwise, use the startWebLogic script on the command line, in the root directory of the WebLogic distribution.

For more information on restarting the WebLogic Server, see the Administrators Guide, Setting up and starting the WebLogic Server. For more information on editing the weblogic.properties file, see Setting WebLogic properties.

Step 4. Displaying the simpapp.html form

  1. Start a browser.

  2. Enter the URL for the simpapp.html file. For example:
    http://WebLogicURL:port/simpapp.html
    where WebLogicURL is the hostname of the WebLogic Server, and port is the port at which the WebLogic Server is listening for login requests.

    Here is what you will see:

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

Step 5. Posting 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. Here is the relevant section from the simpapp.html file, describing 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 that 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 inside an HttpServletRequest.

Step 6. Processing the request

Before the first request to the simpapp servlet, WebLogic initializes the servlet by calling its init() method. A reference to the SessionPoolManager is obtained (using a JNDI lookup) in the init() method, which is only invoked once. This reference is placed in the SessionPool Manager b_mgr variable. Here is an example:

  // Get the session pool manager through JNDI
  Context ctx = 
    WLInitialContextFactory.newInstance(new Environment());

  b_mgr =
    (ServletSessionPoolManager)ctx
      .lookup(SessionPoolManager.POOLMANAGER_NAME);

You can read more on using JNDI in the WebLogic framework.

Next, the servlet's doPost() method is executed, which 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. Here is how we retrieve the service name parameter:

  String svcnm[] = req.getParameterValues("SVCNAME");

We retrieve the value of the SVCNAME field in a string array that contains only a single value; we 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 we pass to the call() method as shown below:

  // 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 that 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, i.e. "STRING". Note also that the other data fields like the SVCNAME are not relevant as parameters but do not disrupt the TUXEDO service.

The form parameter is used to actually name the service, which you do not have to pass as a service parameter. It is passed automatically since it is already contained in the HttpServletRequest object.

The TOUPPER service transposes 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 7. Returning the results to the client

The final step constructs and sends an HTML page containing the results of the service call back to the client via the HttpResponse output stream. The uppercase result is retrieved from the ServletResult object using the result.getValue() method. Here is a very unsophisticated 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 that appears like this:

Top

IV. Change history

Release 4.0.3

Fixed a problem with the method ServletDataSet.importRequest() setting the value of a field at an incorrect (higher) index with single occurrence fields whose names do not contain any underscores.

Release 4.0.0

Added an example that demonstrates connecting to TUXEDO via Jolt through a WebLogic Server, using an EJBean. It uses BEA's demo server so that all WebLogic users can try out this new functionality.

Note that grouping multiple HTTP requests in a transaction is not supported in this release. In the clustering environment, each WebLogic Server creates Jolt session pools locally. If a web application (for example, a servlet) starts a transaction using the Jolt session pool as a result of responding to an HTTP request, the application must commit or roll back the transaction before returning an HTTP response.

 

Copyright © 2000 BEA Systems, Inc. All rights reserved.
Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
Last updated 06/04/1999