1 About This Book
4.3 Setting up Appeon Server data sources
4.3.3 Setting up data source for JBoss
4.3.3.1 Setting up data source for JBoss 7
Data source configuration in JBoss AS 7 is different from that in the older versions. Please follow instructions below to create the data source in JBoss AS 7 (or refer to the Web site http://community.jboss.org/wiki/DataSourceConfigurationInAS7).
The following section will take one database type (ASA/SQL Anywhere database with Sybase jConnect JDBC driver) as an example to show you how to create a data source for JBoss AS 7, you can later create data sources for other database types by taking the same steps below but specifying different parameters according to Data source parameters. You need to perform two main tasks to define a data source in JBoss AS 7. First, you must make the JDBC driver available to the application server; then you need to configure the data source that references the driver you installed.
4.3.3.1.1 Method 1
Installing a JDBC driver via the configuration file
Step 1: Go to the "modules\com" directory under the root directory of the JBoss application server (e.g. jboss-as-7.1.1.Final\modules\com), create a "asa" subdirectory and a "asa\main" subdirectory, so the directory looks like the following: jboss-as-7.1.1.Final\modules\com\asa \main.
Step 2: Go to the "main" directory, paste the driver JAR file there, in this example, the jconn3.jar file.
Step 3: Go to the "main" directory, create a module.xml file, and define the file as follows.
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.asa"> <resources>
<resource-root path="jconn3.jar"/> <!-- Insert resources here --> </resources>
<dependencies>
<module name="javax.api"/> </dependencies>
</module>
As you can see from above, in this example, set the module name to "com.asa", which matches the directory structure you had created under the "modules" directory. Set resource- root path to the JAR file name, the path appears to be relative, and default to the "main" directory under the directory structure you created, which is "com/asa" in this example. Finally, define any dependencies you might have. In this case, as the case with all JDBC data sources, we would be dependent on the Java JDBC API's, which in this case is defined in another module called javax.api, which you can find under modules/javax/api/main as you would expect.
Different database drivers might require different dependencies. For example, the IBM DB2 database working with the IBM JDBC driver requires the following dependencies:
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
<module name="javax.servlet.api" optional="true"/> </dependencies>
And the following class name (specified in the standalone.xml file later in the next section):
<driver name="db2jdbc" module="com.ibm.db2">
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class> <xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa- datasource-class>
</driver>
You can check the documents provided by the corresponding database driver vendor to find out the dependencies and the class name.
Step 4: Modify the JAR file.
1. Under the same directory as the jconn3.jar file, create a "META-INF" subdirectory and a "META-INF\services" subdirectory.
2. Under the "META-INF\services" directory, create a java.sql.Driver file which
contains one line - the fully-qualified class name of the JDBC driver, in this example, com.sybase.jdbc3.jdbc.SybDriver.
3. Execute the "jar" command to update the JAR file: "jar -uf jconn3.jar META-INF/
services/java.sql.Driver". You can also use WinRAR tool to add the java.sql.Driver file to the "MEAT-INF\services" directory in jconn3.jar, as shown in the following figure.
Figure 4.50: Modify the jar file
Configuring the data source for JBoss AS 7 via the configuration file
Step 5: Open the standalone.xml file under the <jboss_installation_root>\standalone
\configuration folder, find the related datasource, and then add the prefix "java:/" to the jndi-
name value if there is not such prefix in it, as shown in the following sample code.
You will need to check the documents provided by the corresponding database driver vendor to find out the class name.
<datasources>
<datasource jndi-name="java:/AppeonSample" pool-name="AppeonSample" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:sybase:Tds:192.0.3.150:2638/AppeonSample </connection-url> <driver>jconnect3</driver> <security> <user-name>dba</user-name> <password>sql</password> </security> </datasource> <drivers>
<driver name="jconnect3" module="com.asa">
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class> </driver> ... </drivers> ... </datasources>
4.3.3.1.2 Method 2
Installing a JDBC driver via the Web console
Step 1: To directly access the Management Console, point your browser at: http:// localhost:8080/ or http://127.0.0.1:8080/. If you want to access the console via LAN or WAN (or call EJB), you will need to modify the standalone.xml to add a new interface. For example: <interfaces> <interface name="management"> <inet-address value="127.0.0.1"/> </interface> <interface name="public"> <inet-address value="127.0.0.1"/> </interface> <!-- Equivalent of -b 0.0.0.0 --> <interface name="any"> <any-address/> </interface> </interfaces>
And use this new interface in the socket-binding-group:
<!-- Use the "any" interface -->
<socket-binding-group name="standard-sockets" default-interface="any"> <socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="jmx-connector-registry" port="1090"/> <socket-binding name="jmx-connector-server" port="1091"/> <socket-binding name="jndi" port="1099"/>
<socket-binding name="osgi-http" port="8090"/> <socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/> <socket-binding name="txn-status-manager" port="4713"/> </socket-binding-group>
Step 2: If you have not yet added at least one management user, an error page will be
displayed asking you to add a new user. You can run the add-user.bat (add-user.sh for Linux) in the jboss-as-7.1.1.Final\bin folder. For details, please refer to the Managing your JBoss
Application Server 7 | Authentication section at https://docs.jboss.org/author/display/AS71/ Getting+Started+Guide.
Figure 4.51: Add a new user
Figure 4.52: Datasources Configuration page
Figure 4.53: Manage Deployments page
Step 5: Modify the JAR file, refer to Step 4 in "Installing a JDBC driver via the configuration file" for details. Click Add Content to deploy this .jar file.
Figure 4.54: Upload the jar file
2. Verify the deployment names and click Save.
Figure 4.55: Verify the deployment name
Figure 4.56: Enable the jar file
Configuring the datasource for JBoss AS 7 via the Web console
Step 7: Set up the target database as a service, and start the service SQLAnywhere- appeonsample by inputting the following command lines in the sqlAnywhere.bat:
"C:\Program Files\SQL Anywhere 12\Bin32\dbsrv12.exe" -x tcpip(port=2698) -n duanserv2 "D:\jboss711-hsqldb-2\AppeonSample.db".
Step 8: Switch to the Profile tab, and click Add to create a new datasource, as shown in the following figure.
Figure 4.57: Add a new datasource
1. Input any text as the data source name and the JNDI name. For example, "java:/ appeonsample". Click Next.
Figure 4.58: Specify datasource attributes
Figure 4.59: Specify JDBC driver
3. Specify the connection information and click Done.
The following table describes how to specify the connection information for Sybase ASA/ SQL Anywhere databases. The values are different according to database types. You can refer to Data source parameters.
Table 4.14: Connection properties Connection
URL
For example, jdbc:sybase:Tds:192.0.2.204:2698? ServiceName=appeonsample
Username Type the database login username. The username is set on the database server.
Password Type the database login password. The password is set on the database server.
Figure 4.60: Specify connection information
Step 9: After the data source is created successfully, you will be redirected to the
Figure 4.61: Datasource list