3.7.  Configure application resources (e.g., data sources, JNDI, class paths, J2C providers) as required by an enterprise application.

[Note]

Introducing the WebSphere administrative consoles

The WebSphere Integrated Solutions Console, often referred to as the administrative console, is a graphical, web-based tool that you use to configure and manage the resources within your WebSphere environment. The administrative console application name is isclite, and it is a system application. A system application indicates that the application is central to a WebSphere Application Server product and it is installed when the product is installed. In this case, the administrative console application is installed during profile creation if selected, or afterwards using the command line. You do not see system applications in the list of installed applications when using the administrative console. As a system application, you cannot stop or start the application directly, nor can you uninstall the application.

With the introduction of the flexible management topologies, there are multiple administrative consoles available in a WebSphere solution:

Finding the URL for the console

Each server process that hosts the administrative console has two admin ports that are used to access the administrative console. These ports are referred to as:

These ports are assigned at profile creation. If you do not know what the port number is for the administrative console, you can look in the following location:

profile_home/properties/portdef.props
					

test317:/opt/IBM/WebSphere/AppServer/profiles/Dmgr01 # cat properties/portdef.props
#Generated by PMT GUI
#Tue May 21 08:35:09 EDT 2013
IPC_CONNECTOR_ADDRESS=9632
CSIV2_SSL_SERVERAUTH_LISTENER_ADDRESS=9404
WC_adminhost=9061
DataPowerMgr_inbound_secure=5555
DCS_UNICAST_ADDRESS=9352
BOOTSTRAP_ADDRESS=9809
SAS_SSL_SERVERAUTH_LISTENER_ADDRESS=9405
CELL_DISCOVERY_ADDRESS=7277
SOAP_CONNECTOR_ADDRESS=8879
ORB_LISTENER_ADDRESS=9101
CSIV2_SSL_MUTUALAUTH_LISTENER_ADDRESS=9406
WC_adminhost_secure=9044
					

You can always use the following URL to access the administrative console:

http://hostname:WC_adminhost/ibm/console
					

If administrative security is enabled, you will automatically be redirected to the secure port.

Logging in to an administrative console

When you access the administrative console, you need to log in by providing a user ID. If WebSphere administrative security is enabled, you also need to provide a password.

The user ID specified during login is used to track configuration changes made by the user. This allows you to recover from unsaved session changes made under the same user ID, for example, when a session times out or the user closes the web browser without saving. The configuration files are copied from the master repository and cached in the temporary workspace, as you navigate through different console areas. Configuration changes are stored in the wstemp temporary workspace directory until the changes are merged with the master repository during a save operation in the administrative console. Workspaces are not removed when you log out, so they can be reused in another login session for the same login user ID.

test317:/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/wstemp # ls -l
total 20
drwxr-xr-x 3 root root 4096 May 30 16:55 0
drwxr-xr-x 2 root root 4096 May 29 18:42 1539225627
drwxr-xr-x 3 root root 4096 May 21 09:28 appmgmt
drwxr-xr-x 3 root root 4096 May 30 16:44 com.ibm.ws.wlm.clusterMgr
drwxr-xr-x 2 root root 4096 May 30 16:44 events
					

Recovering from an interrupted session

Until you save the configuration changes you make during a session, the changes do not become effective. During a save operation, the changes propagate and merge with the master configuration repository. If a session is closed without saving the configuration changes made during the session, these changes are remembered and you are given the chance to pick up where you left off. The changes are currently stored in the wstemp temporary workspace directory.

When unsaved changes for the user ID exist during login, you are prompted to complete one of the following actions:

As you work with the configuration, the original configuration file and the new configuration file are stored in a folder at profile_home/wstemp.

After you save the changes, these files are removed from the wstemp directory and merged with the master configuration repository.

The wsadmin tool management objects

The wsadmin tool has the following administrative objects that provide server configuration and management capabilities:

Properties file based configuration

Using complex scripts requires knowledge of the Jacl or Jython scripting languages and the public MBean interfaces. The use of a properties file based configuration provides a way to simplify administrative tasks using wsadmin.sh.

Properties file based configuration extracts configuration data to one file that is easy to read using any editor tool. The configuration attributes are provided as key/value pairs, as shown below:

test317:/opt/IBM/WebSphere/AppServer/bin # tail -10 myNodeProperties.props
#Environment Variables
hostName=test317.java.boot.by
serverName=dmgr
cellName=test317Cell01
hostName2=*
hostName1=${LOCALHOST_NAME}
coreGroup=DefaultCoreGroup
nodeName=test317CellManager01
USER_INSTALL_ROOT=/opt/IBM/WebSphere/AppServer/profiles/Dmgr01
WAS_INSTALL_ROOT=/opt/IBM/WebSphere/AppServer
					

The following commands in the PropertiesBasedConfiguration command group implement this type of configuration:

Managing WebSphere using script libraries

You can use script libraries to perform a higher level of wsadmin functions than when using a single wsadmin.sh command. Only a single line from a library function is needed to perform complex functions. Each script is written in Jython and is often referred to as the Jython script. The script libraries are categorized into six types:

The script libraries are located in the install_root/scriptLibraries directory.

test317:~ # cd /opt/IBM/WebSphere/AppServer/scriptLibraries/
test317:/opt/IBM/WebSphere/AppServer/scriptLibraries # ls -l
total 32
drwxr-xr-x 3 root root 4096 Jul 12  2012 application
drwxr-xr-x 2 root root 4096 Sep 19  2012 osgi
drwxr-xr-x 3 root root 4096 Jul 12  2012 perfTuning
drwxr-xr-x 6 root root 4096 Jul 12  2012 resources
drwxr-xr-x 3 root root 4096 Jul 12  2012 security
drwxr-xr-x 3 root root 4096 Jul 12  2012 servers
drwxr-xr-x 3 root root 4096 Jul 12  2012 system
drwxr-xr-x 3 root root 4096 Jul 12  2012 utilities
					

These libraries are loaded when wsadmin.sh starts and are readily available from the wsadmin.sh command prompt or to be used from the customized scripts. You can invoke the scripts in interactive mode or script (-f) mode.

Interactive mode is suitable for simple tasks and testing. Using this mode allows you to get the results directly. To invoke a script interactively, start a wsadmin session and enter the script name, procedure, and arguments at the wsadmin> prompt.

Resource script library

The Resource script library provides a set of scripts to manage WebSphere resources. The library provides script functions for J2C resources, JDBC providers, and JMS resources at the server scope. If you need to configure resources at the cell, node, or cluster level, you can customize the scripts for this purpose.

The script library is located in the install_root/scriptLibraries/resources directory. It contains the following:

test317:/opt/IBM/WebSphere/AppServer/scriptLibraries/resources # ls -l
total 16
drwxr-xr-x 3 root root 4096 Jul 12  2012 J2C
drwxr-xr-x 3 root root 4096 Jul 12  2012 JDBC
drwxr-xr-x 3 root root 4096 Jul 12  2012 JMS
drwxr-xr-x 3 root root 4096 Jul 12  2012 Provider
					

test317:/opt/IBM/WebSphere/AppServer/scriptLibraries/resources/JDBC/V70 # ls -l
total 148
-rw-r--r-- 1 root root 65528 Jul 23  2012 AdminJDBC$py.class
-rwxr-xr-x 1 root root 76493 Jul 11  2012 AdminJDBC.py
					

You can use the listDataSources and listJDBCProviders procedures of the AdminJDBC script to display a list of configuration IDs for the JDBC providers and data sources in your environment.

test317:/opt/IBM/WebSphere/AppServer/bin # ./wsadmin.sh -lang jython
WASX7209I: Connected to process "dmgr" on node test317CellManager01 using SOAP connector;  The type of process is: DeploymentManager
WASX8011W: AdminTask object is not available.
WASX7031I: For help, enter: "print Help.help()"
wsadmin>AdminJDBC.listDataSources()
---------------------------------------------------------------
 AdminJDBC:               listDataSources
 Optional parameter:
 DataSource name:
 Usage: AdminJDBC.listDataSources()
 Return: List the Data source connection configuration ID of the requested data source name or list all of the available data source
 	connection configuration IDs if a data source connection name is not specified in the respective cell
---------------------------------------------------------------

['"Default Datasource(cells/test317Cell01/nodes/exampleNode01/servers/server1|resources.xml#DataSource_1183122153625)"',
'DefaultEJBTimerDataSource(cells/test317Cell01/applications/commsvc.ear/deployments/commsvc|resources.xml#DataSource_1228749623069)',
'DefaultEJBTimerDataSource(cells/test317Cell01/nodes/exampleNode01/servers/server1|resources.xml#DataSource_1000001)',
'OTiSDataSource(cells/test317Cell01/nodes/test317CellManager01|resources.xml#builtin_DataSource_1169228388285)']
wsadmin>
					

wsadmin>AdminJDBC.listJDBCProviders()
---------------------------------------------------------------
 AdminJDBC:              listJDBCProviders
 Optional parameter:
 JDBC provider name:
 Usage: AdminJDBC.listJDBCProvider()
 Return: List the JDBC provider configuration IDs of the requested Java Database Connectivity (JDBC) name or list all of the available JDBC
 	provider configuration IDs if a JDBC name parameter is not specified in the respective cell
---------------------------------------------------------------

['"Derby JDBC Provider (XA)(cells/test317Cell01/applications/commsvc.ear/deployments/commsvc|resources.xml#builtin_jdbcprovider)"',
'"Derby JDBC Provider (XA)(cells/test317Cell01/nodes/exampleNode01/servers/server1|resources.xml#builtin_jdbcprovider)"',
'"Derby JDBC Provider (XA)(cells/test317Cell01|resources.xml#builtin_jdbcprovider)"',
'"Derby JDBC Provider(cells/test317Cell01/nodes/exampleNode01/servers/server1|resources.xml#JDBCProvider_1183122153343)"',
'OTiSDataSource(cells/test317Cell01/nodes/test317CellManager01|resources.xml#builtin_JDBCProvider_1169228386227)']
					

Configuring the WebSphere Application Server for Database Communications

This section explains how to configure the WAS instance to communicate with the database. This section contains the following steps:

  1. Creating a J2C Authentication Aliases

  2. Creating a JDBC Provider

  3. Creating a JDBC Data Source

  4. Testing Data Source from Java EE application

Before completing the steps in the rest of this chapter, start the following WAS components, in the order shown.

Deployment Manager:

test317:~ # cd /opt/IBM/WebSphere/AppServer/profiles/Dmgr01/bin/
test317:/opt/IBM/WebSphere/AppServer/profiles/Dmgr01/bin # ./startManager.sh
ADMU0116I: Tool information is being logged in file
           /opt/IBM/WebSphere/AppServer/profiles/Dmgr01/logs/dmgr/startServer.log
ADMU0128I: Starting tool with the Dmgr01 profile
ADMU3100I: Reading configuration for server: dmgr
ADMU3200I: Server launched. Waiting for initialization status.
ADMU3000I: Server dmgr open for e-business; process id is 10057
					

Node Agent:

test317:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin # ./startNode.sh
ADMU0116I: Tool information is being logged in file
           /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/nodeagent/startServer.log
ADMU0128I: Starting tool with the AppSrv01 profile
ADMU3100I: Reading configuration for server: nodeagent
ADMU3200I: Server launched. Waiting for initialization status.
ADMU3000I: Server nodeagent open for e-business; process id is 10336
					

Application Server:

test317:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin # ./startServer.sh server1
ADMU0116I: Tool information is being logged in file
           /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/server1/startServer.log
ADMU0128I: Starting tool with the AppSrv01 profile
ADMU3100I: Reading configuration for server: server1
ADMU3200I: Server launched. Waiting for initialization status.
ADMU3000I: Server server1 open for e-business; process id is 11599
					

Creating a J2C Authentication Aliases

The J2C authentication contains the login information that WAS will use to connect to the Content Server database.

A J2C authentication is the first of the three components required to set up your WAS instance to connect to your database.

If you are creating a Server cluster, the cluster members can share the same J2C authentication.

  1. Log in to the Deployment Manager console: http://test317.java.boot.by:9061/ibm/console/login.do

    Figure 3.13. Integrated Solutions Console

    Integrated Solutions Console


  2. In the left-hand pane, expand the Security node.

    Figure 3.14. Security

    Security


  3. Under the Security node, select Global security.

    Figure 3.15. Global security

    Global security


  4. In the Authentication area in the right-hand pane, expand the Java Authentication and Authorization Service node and click J2C authentication data.

    Figure 3.16. J2C authentication data

    J2C authentication data


    The console displays the JAAS – J2C authentication data screen.

    Figure 3.17. JAAS – J2C authentication data

    JAAS – J2C authentication data


  5. In the JAAS – J2C authentication data screen, click the New... button. The console displays the New ... page.

    Figure 3.18. 


  6. In the New ... page, do the following:

    1. In the Alias field, enter a unique alias for this J2C authentication.

    2. In the User ID and Password fields, enter the credentials of the database user account WAS will use to connect to the database.

    3. When you are finished, click OK. The J2C authentication you created appears in the list in the JAAS – J2C authentication data screen.

      Figure 3.19. 


  7. Restart the application server for the changes to take effect.

Creating a JDBC Provider

  1. Locate DB2 JDBC drivers files:

    test317:/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin # cd /opt/ibm/db2/V9.7/java/
    test317:/opt/ibm/db2/V9.7/java # ls -l
    total 11108
    -rw-rw-rw- 1 root root     168 Jul 10  2012 42E32181339E47B2BF8145FD26612E69.properties
    -r--r--r-- 1 bin  bin  2281470 May 31  2009 Common.jar
    -r--r--r-- 1 bin  bin     4859 May 31  2009 IBMUpdateUtil.jar
    -r--r--r-- 1 bin  bin       58 May 31  2009 IBMUpdateUtil.prop
    -r--r--r-- 1 bin  bin    50812 May 31  2009 db2dbgm.jar
    -r--r--r-- 1 bin  bin   877296 May 31  2009 db2java.zip
    -r--r--r-- 1 bin  bin  3146716 May 31  2009 db2jcc.jar
    -r--r--r-- 1 bin  bin  3312885 May 31  2009 db2jcc4.jar
    -r--r--r-- 1 bin  bin     1015 May 31  2009 db2jcc_license_cu.jar
    -r--r--r-- 1 bin  bin   122221 May 31  2009 db2policy.jar
    -r--r--r-- 1 bin  bin     9455 May 31  2009 db2umplugin.jar
    -r--r--r-- 1 bin  bin   618901 May 31  2009 ib6core.jar
    -r--r--r-- 1 bin  bin    32637 May 31  2009 ib6extra.jar
    -r--r--r-- 1 bin  bin   297505 May 31  2009 ib6js.jar
    -r--r--r-- 1 bin  bin    74756 May 31  2009 ib6swing.jar
    -r--r--r-- 1 bin  bin   103344 May 31  2009 ib6util.jar
    -r--r--r-- 1 bin  bin     3867 May 31  2009 itmagent.jar
    drwxr-xr-x 7 bin  bin     4096 May 31  2009 jdk64
    -r--r--r-- 1 bin  bin   347851 May 31  2009 us.jar
    								

  2. Log in to the Deployment Manager console.

  3. In the left-hand pane, expand the Resources node.

    Figure 3.20. 


  4. Under the Resources node, expand the JDBC node and click JDBC Providers. The console displays the JDBC providers screen.

    Figure 3.21. 


  5. In the Scope area of the JDBC providers screen, select Node=<appserv_node>, Server=<server_name> from the drop-down list and click the New... button.

  6. In the Create a new JDBC provider screen, do the following:

    In the Database type drop-down list, select the database type.

    In the Provider type drop-down list, select the provider.

    In the Implementation type drop-down list, select Connection pool data source.

    In the Name field, enter a unique name for this JDBC provider.

    Click the Next button.

    Figure 3.22. 


  7. In the Enter database class path information screen, provide the classpath.

    Figure 3.23. 


    NOTE: make sure WebSphere Environment Variables point to the correct folders:

    Figure 3.24. 


    Figure 3.25. 


  8. In the Summary screen, review the settings you have chosen, then click the Finish button.

    Figure 3.26. 


Creating a JDBC Data Source

Once you have created the J2C authentication entries and the JDBC provider, you must create a data source.

  1. Log in to the Deployment Manager console.

  2. In the left-hand pane, expand the Resources node.

  3. Under the Resources node, expand the JDBC node, and click Data sources. The console displays the Data sources screen.

    Figure 3.27. 


  4. In the Scope area of the Data sources screen, select Node=<appserv_node>, Server=<server_name> from the drop-down list and click the New... button.

    Note: the default name of the first application server node created is <WAS_host>Node01. The default server name is server1.

  5. In the Enter basic data source information screen, do the following:

    In the Data source name field, enter a unique name for this data source.

    In the JNDI name field, enter the JNDI name for this data source.

    Click the Next button.

    Figure 3.28. 


  6. In the Select JDBC provider screen, do the following:

    Select Select an existing JDBC provider.

    In the drop-down list, select the JDBC provider you created earlier.

    Click the Next button.

    Figure 3.29. 


  7. In the Enter database specific properties for the data source screen, do the following:

    In the Driver type drop-down list, select 4.

    In the Database name field, enter the name of the database you will be using.

    In the Server name field, enter the host name or IP address of the machine running the database.

    In the Port number field, enter the port number on which the database is listening for connections.

    Uncheck the Use this data source in container managed persistence (CMP) check box.

    Click the Next button.

    Figure 3.30. 


  8. In the Setup security aliases screen, do the following:

    In the Component-managed authentication alias drop down list, select the J2C authentication alias you created in previous steps.

    Click the Next button.

    Figure 3.31. 


  9. In the Summary screen, review the settings you have chosen, then click the Finish button.

  10. You can test the data source now:

    Figure 3.32. 


    Figure 3.33. 


Testing Data Source from Java EE application

  1. Create new web project in RAD.

  2. Select context menu: Java EE > Generate Deployment Descriptor Stub

  3. Open deployment descriptor and add data source resource reference:

    Figure 3.34. 


    Figure 3.35. 


    Results:

    Figure 3.36. 


    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app>
    	...
    	<resource-ref>
    		<description />
    		<res-ref-name>jdbc/TestDS_Ref</res-ref-name>
    		<res-type>javax.sql.DataSource</res-type>
    		<res-auth>Container</res-auth>
    		<res-sharing-scope>Shareable</res-sharing-scope>
    	</resource-ref>
    </web-app>
    
    								

  4. Bind reference to global Data Source JNDI name.

    Click the WebSphere Binding Descriptor link:

    Figure 3.37. 


  5. Click the Add button and select the Resource Reference:

    Figure 3.38. 


  6. Fill the details as follows:

    Figure 3.39. 


    Save the changes. Results in ibm-web-bnd.xml as follows:

    
    <resource-ref name="jdbc/TestDS_Ref" binding-name="jdbc/TestDS" />
    
    								

  7. Create new test.jsp JSP with the following content:

    
    <!DOCTYPE HTML><%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ page import ="javax.sql.*, java.sql.*" %>
    <html>
    <head>
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    </head>
    <body>
    <%
    
    DataSource ds = (DataSource) new javax.naming.InitialContext().lookup("java:comp/env/jdbc/TestDS_Ref");
    Connection connection = ds.getConnection();
    out.print("Connect to " + connection + " successfully!");
    
    %>
    </body>
    </html>
    
    								

  8. Export the web project, deploy the WAR file to WebSphere Application Server and open the test.jsp page in web-browser:

    Figure 3.40. 


Professional hosting         Free 'Oracle Certified Expert Web Services Developer 6' Guide     Free SCDJWS 5.0 Guide