Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Tutorial: SQL - Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server

Tutorial: SQL - Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server

Introduction

As an extension to Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server, this tutorial shows you how to do the same thing with a SQL Server COBOL application using the Red Hat JBoss application server.
The code logic in this tutorial differs from the Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server tutorial in that it uses a SQL Server SELECT statement in a COBOL file that does not use a FROM clause. This SELECT statement replaces a COMPUTE statement using an expression for the conversion calculation.

Restrictions

For a list of restrictions that apply to JVM COBOL and application server support, see the Application Servers section of the JVM COBOL Support topic under Known Issues and Restrictions > JVM Code.

Prerequisite

This tutorial begins where Tutorial: Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server left off, using the JBoss application server, and the same TemperatureConverter, TemperatureConverterEJB, and TemperatureConverterPrj projects. Therefore, you must complete that tutorial in its entirety, using the JBoss application server, before starting this tutorial. See Tutorial: Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server for complete instructions.

You must also install Microsoft SQL Server 2008 or later, configured for SQL Server authentication.

Outline

After completing the prerequisite tutorial, complete this tutorial by following the instructions in the following topics:

  1. Install and Configure a JDBC Driver.

    Download and install a SQL Server JDBC driver to use in this tutorial; then make the driver available to the JBoss application server.

  2. Create and Load a SQL Server Database.

    Create a SQL Server database and define a database connection.

  3. Modify COBOL Source.

    Modify the COBOL source code in the TemperatureConverter project with new code to access your SQL Server database.

  4. Deploy the COBOL JVM Runtime.

    Deploy the COBOL JVM runtime with the SQL runtime required to run the application.

  5. Run the JSP Application.

    Run the TemperatureConverterJsp application on JBoss.

Install and Configure a JDBC Driver

Download and install a SQL Server JDBC driver to use in this tutorial; then make the driver available to the JBoss application server.

Install a JDBC Driver

As this tutorial uses SQL Server, you need a SQL Server-compatible JDBC driver. Download a Microsoft JDBC SQL Server Type 4 driver using this link, and install it using the Install Instructions on the download page:

Download JDBC Drivers

The name of the driver file is sqljdbc4.jar where n is a single digit and is appended to the filename for some versions of the driver. Be sure to take note of the location of this file after installing it.

Configure the JDBC Driver in JBoss

To make the JDBC driver available to JBoss, you must place it in the appropriate directory, and configure it by creating an XML configuration file.

Copy the JDBC Driver to JBoss

To run your application, the JBoss application server must find an SQL Server JDBC driver file in a specific subdirectory of your JBoss installation directory. You must create the subdirectory and copy the sqljdbc4.jar file as follows:

  1. At a command prompt or using Explorer, change to your JBoss installation's modules\com directory.
  2. Create the following subdirectory structure:

    microsoft\sqlserver\main

  3. Change to the modules\com\microsoft\sqlserver\main directory.
  4. Copy the downloaded sqljdbc4.jar file to the modules\com\microsoft\sqlserver\main directory.

Create a module.xml file

The module.xml file provides JDBC driver configuration required by JBoss.

  1. In the modules\com\microsoft\sqlserver\main directory, create a new file, module.xml, using any text editor.
  2. Copy the following contents into the file:
    <module xmlns="urn:jboss:module:1.0" name="com.microsoft.sqlserver">
         <resources>
              <resource-root path="sqljdbc4.jar"/>
         </resources>
         <dependencies>
              <module name="javax.api"/>
              <module name="javax.transaction.api"/>
         </dependencies>
    </module>
    
  3. Save the file and exit the editor.

Create and Load a SQL Server Database

Create a SQL Server database and define a database connection.

Create the PUBS SQL Server Database

Using SQL Server Management Studio, create a new SQL Server database, PUBS, on your local default instance of SQL Server, and configure it to use SQL Server authentication by providing a user ID and password. See your SQL Server documentation for instructions.

Start Enterprise Developer

If you have closed Enterprise Developer since completing Tutorial: Reusing Existing COBOL Programs in a Java Environment, open it again; then open the Java EE perspective and the Project Explorer.

Catalog a JDBC Connection in JBoss

Now that the JDBC driver is available for JBoss, you must catalog a connection that uses the driver, providing a DSN for the connection that you specify in an EXEC SQL CONNECT statement:

  1. Using any text editor, edit the standalone.xml located in your JBoss installation's standalone\configuration directory.
  2. In the editor, locate the following set of tags:
    <subsystem xmlns="urn:jboss:domain:datasources:1.0">
        <datasources>
  3. To define a JDBC connection named pubs, add the following code just below <datasources>, replacing SQLServerUserName and SQLServerPassword respectively with the user name and password required for SQL Server authentication:
    <datasource jndi-name="java:/pubs" pool-name="pubs-Pool">
         <connection-url>jdbc:sqlserver://localhost:1433;databaseName=Pubs</connection-url>
         <driver>sqlserver</driver>
         <pool>
              <min-pool-size>10</min-pool-size>
              <max-pool-size>10</max-pool-size>
              <prefill>true</prefill>
         </pool>
         <security>
              <user-name>SQLServerUserName</user-name>
              <password>SQLServerPassword</password>
         </security>
    </datasource>
  4. Locate the <drivers> tag just before the closing </datasources> tag.
  5. Just below the <drivers> tag, add the following:
    <driver name="sqlserver" module="com.microsoft.sqlserver"/>
  6. Save and close the file.

 Modify COBOL Source

Modify the COBOL source code in the TemperatureConverter project with new code to access your SQL Server database.

Here you replace the COBOL source in the TemperatureConverter.cbl file with COBOL source that accesses the SQL Server database.

  1. In the Project Explorer under TemperatureConverter > src > com.microfocus.converter, double-click TemperatureConverter.cbl to open it in the file editor.
  2. Replace the entire contents of the file with the following:
    $set sql(dbman=jdbc)      
      class-id com.microfocus.converter.TemperatureConverter public.
      01 text1 pic x(10). *> to force implements IObjectControl
      exec sql include sqlca end-exec.
      method-id toCelsius.
      procedure division using by value fahrenheit as float-short returning celsius as float-short.
      exec sql connect to pubs end-exec.
          exec sql
               select (:fahrenheit - 32) * 5 / 9 into :celsius
          end-exec.
          exec sql disconnect pubs end-exec.
          goback.
     end method.
     method-id toFahrenheit.
     procedure division using by value celsius as float-short returning fahrenheit as float-short.
          exec sql connect to pubs end-exec.             
          exec sql
               select (:celsius * 9 / 5) + 32 into :fahrenheit
          end-exec.
          exec sql disconnect pubs end-exec.
          goback
     end method.       
     end class.
  3. Click File > Save to save your changes.

Deploy the COBOL JVM Runtime

Deploy the COBOL JVM runtime with the SQL runtime required to run the application.

The Deploying an Enterprise JavaBean Containing JVM COBOL to a JBoss Application Server tutorial walks you through deploying the COBOL JVM Runtime System using a per-bean model. The COBOL JVM Runtime System library that is added to the TemperatureConverterPrj deployment project as a deployment assembly contains several .jar files comprising the runtime. In this tutorial, the mfsqljvm.jar file makes up the SQL runtime. The following instructions enhance the instructions provided in the original tutorial by describing additional changes needed to deploy the SQL runtime using a shared model for JBoss AS 7.1:

  1. At a command prompt or using Explorer, go to your %JBOSS_HOME%\modules\com\microfocus directory.
  2. Create a subdirectory named openesql.
  3. Under the new openesql subdirectory, create a subdirectory named main.
  4. Copy mfsqljvm.jar from the %ProgramFiles(x86)%\Micro Focus\Enterprise Developer\bin directory to the %JBOSS_HOME%\modules\com\microfocus\openesql\main directory.
  5. In the %JBOSS_HOME%\modules\com\microfocus\openesql\main directory, create a new module.xml file that contains the following code, which names the SQL runtime mfsqljvm.jar file as a resource:
    <module xmlns="urn:jboss:module:1.1" name="com.microfocus.openesql">
      <dependencies>
        <module name="javaee.api"/>
        <module name="com.microfocus.cobol.runtime"/>
      </dependencies>
      <resources>
        <resource-root path="mfsqljvm.jar"/>
      </resources>
    </module>

    Unlike the non-SQL version of this tutorial, with SQL you must update the MANIFEST.FM file to list the SQL runtime namespace as a dependency.

  6. In the Eclipse Navigator pane, navigate to TemperatureConverterPrj > WebContent > META-INF; then double-click MANIFEST.MF to open it in the editor.
  7. Either add a Dependencies: line or edit the existing Dependencies: line to read as follows:
    Dependencies: com.microfocus.cobol.runtime, com.microfocus.openesql
  8. Save the file and close the editor.

Run the JSP Application

Run the TemperatureConverterJsp application on JBoss:

  1. In the Project Explorer, right-click the TemperatureConverterPrj project; then select Run As > Run on Server from the context menu.
  2. On the Run On Server dialog box, be sure that JBoss AS 7.1 is selected; then click Finish.

    Eclipse generates an HTTP Status 404 message, indicating that it is unable to find the http://localhost:8080/TemperatureConverterPrj/ URL. This is expected because the application uses two different URLs to call the two conversion routines with arguments.

    Eclipse has a built-in browser window that opens when the server is started, but you can use any external browser to enter the URLs.

  3. In the Eclipse browser address field, enter the following to run the Fahrenheit to Celsius conversion:
    http://localhost:8080/TemperatureConverterPrj/RestApp1/getCelsius?fahrenheit=212

    Eclipse presents a .json file dialog box.

  4. Click Open to view the results of the method call.
  5. Repeat steps 3 and 4, substituting the following URL to test the Celsius to Fahrenheit conversion:
    http://localhost:8080/TemperatureConverterPrj/RestApp1/getFahrenheit?celsius=36.8
    Note: You can change the values of the fahrenheit and celsius arguments to see different results.
  6. To test in an external browser, open a browser of your choice; then enter each of the same URLs.

    Depending on your browser, the results are either returned in the browser or you are prompted to save the results to a text file.

Attachments

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Version history
Revision #:
1 of 1
Last update:
‎2018-10-15 12:01
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.