Using a WebSphere® Application Server
API or trace function, you can pass unique client information about
every connection that originates from the same data source.
About this task
Some databases, such as DB2®, support
a data source custom property that triggers your database servers
to extract client information from WebSphere Application
Server connections. (Consult the database documentation to see whether
your product supports this capability and which property the product
requires.) Be aware, however, that these properties introduces limited
functionality in Application Server. Consequently, an application
server connection manager incurs the following risky behaviors, which
can result in the transfer of wrong client information to the database.
- The connection manager cannot change client information about
the data source, or the connections obtained from that data source,
dynamically.
- The connection manager must set the same client information about
all connections that are obtained from that data source. For example,
if you set ApplicationName as part of the data source clientInformation property,
all connections from that data source have the same application name.
Application Server offers two methods of passing client
information that provide the necessary connection management flexibility.
Either method is used to set client information about some connections
and not others, as well as set different client information about
different database connections from the same data source.
Procedure
- Use the IBM® proprietary setClientInformation(Properties)
API. The API is defined on the WSConnection class, which
is part of the plugins_root/com.ibm.ws.runtime.jar file.
- Cast the connection objects in your applications to
com.ibm.websphere.rsadapter.WSConnection before calling the API.
- Optionally, set a properties object for adding new client
information about a connection if and when new information is introduced
by the backend database:
public void setClientInformation (Properties props)throws SQLException;
- You can also activate the function implicitly (that is,
within Application Server) by using the WAS.clientinfo trace string.
Enable this trace dynamically, from the administrative console, just
as you activate any other trace. For more information
about passing client information implicitly, see the topic Implicitly
set client information.
Example: Setting client information with the setClientInformation(Properties)
API.
You can set WebSphere Application Server
client information on connections to pass that information to your
database with this API.
The following example code calls setClientInformation(Properties)
on the com.ibm.websphere.rsadapter.WSConnection object.
import com.ibm.websphere.rsadapter.WSConnection;
.....
try {
InitialContext ctx = new InitialContext();
//Perform a naming service lookup to get the DataSource object.
DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/jdbc/myDS");
}catch (Exception e) {System.out.println("got an exception during lookup: " + e);}
WSConnection conn = (WSConnection) ds.getConnection();
Properties props = new properties();
props.setProperty(WSConnection.CLIENT_ID, "user123");
props.setProperty(WSConnection.CLIENT_LOCATION, "127.0.0.1");
props.setProperty(WSConnection.CLIENT_ACCOUNTING_INFO, "accounting");
props.setProperty(WSConnection.CLIENT_APPLICATION_NAME, "appname");
props.setProperty(WSConnection.CLIENT_OTHER_INFO, "cool stuff");
conn.setClientInformation(props);
conn.close()
Parameters
props contains the client information to
be passed. Possible values are:
- WSConnection.CLIENT_ACCOUNTING_INFO
- WSConnection.CLIENT_LOCATION
- WSConnection.CLIENT_ID
- WSConnection.CLIENT_APPLICATION_NAME
- WSConnection.CLIENT_OTHER_INFO
- WSConnection.OTHER_CLIENT_TYPE
Refer to the WSConnection documentation for more details on which
client information is passed to the backend database. To reset the
client information, call the method with a null parameter.
Exceptions
This
API creates an SQL exception if the database issues an exception when
setting the data.