skip to main content

Programming Guides : Web Services with isCOBOL : Building Services : Deploying Legacy COBOL code

Deploying Legacy COBOL code
One very easy way to create a Web service is simply to deploy the isCOBOL Java objects that represent the service. Start with the class, shown below:
Example: Creating the Class UserFunctions
           identification division.
           class-id.   UserFunctions as "server.UserFunctions".
           environment division.
           configuration section.
                class j-string      as "java.lang.String"
           identification division.
           data division.
           working-storage section.
           01 array-data occurs 4 indexed by idx.
              03 a-zipcode pic x(5).
              03 a-city    pic x any length.
              03 a-county  pic x any length.
              03 a-state   pic x any length.
           procedure division.
           identification division.
           method-id. new as "new".
           data division.
           working-storage section.
           procedure division.
              move "94101"         to  a-zipcode(1).      
              move "San Francisco" to  a-city(1).      
              move "San Francisco" to  a-county(1).      
              move "California"    to  a-state(1).      
              move "33040"         to  a-zipcode(2).      
              move "Key West"      to  a-city(2).      
              move "Monroe"        to  a-county(2).      
              move "Florida"       to  a-state(2).      
              move "10001"         to  a-zipcode(3).      
              move "New York"      to  a-city(3).      
              move "New York"      to  a-county(3).      
              move "New York"      to  a-state(3).      
              move "89044"         to  a-zipcode(4).      
              move "Las Vegas"     to  a-city(4).      
              move "Clark"         to  a-county(4).      
              move "Nevada York"   to  a-state(4).      
           identification division.
           method-id. zipCodeSearch as "zipCodeSearch".
           data division.
           working-storage section.
           77 result             pic s9.
           77 w-city             pic x any length.
           77 w-state            pic x any length.
           77  results  object reference j-string.
           linkage section.
           77  city  object reference j-string.
           77  state object reference j-string.
           procedure division using city state returning results.
               set w-city  to city 
               set w-state to state 
               search array-data varying idx
                      at end set results to "-1"
                      when w-city = a-city(idx) and w-state = a-state(idx)
           identification division.
           method-id. reverseZipCodeSearch as "ReversezipCodeSearch".
           data division.
           working-storage section.
           77  results  object reference j-string.
           77  w-zipcode            pic x any length.
           linkage section.
           77  zipcode  object reference j-string.
           procedure division using zipcode returning results.
              set w-zipcode to zipcode
              search array-data varying idx
                      at end set results to "-1"
                      when w-zipcode = a-zipcode(idx) 
           identification division.
           method-id. main as "Hello".
           data division.
           working-storage section.
           01 stringa pic x(100).
           linkage section.
           77  stringa-l        object reference j-string.
           77  results          object reference j-string.
           procedure division using stringa-l        returning results.
              set stringa        to stringa-l
Next, you'll need to tell isCOBOL for Axis2 what class corresponds to what Web service calls. Do this by creating a file called services.xml and adding the following shown below:
Example: Creating services.xml
    <service name="UserFunctions" scope="application">
        <description>
        </description>
        <messageReceivers>
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
                       class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
            <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
                             class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
        </messageReceivers>
        <parameter name="ServiceClass" locked="false">server.UserFunctions</parameter>
        <excludeOperations>
          <operation>finalize</operation>
          <operation>iscobolVersion</operation>
          <operation>iscobolRequired</operation>
          <operation>get$CopyPath</operation>
          <operation>get$Lines</operation>
          <operation>get$Filenames</operation>
          <operation>get$Sourcefile</operation>
          <operation>get$Sourcefile</operation>
          <operation>get$Copyfiles</operation>
          <operation>get$Paragraphs</operation>
        </excludeOperations>
    </service>
This file makes the InOnly and InOut MEPs available to the service and tells Axis2 which class to call; operations must match method names. In other words, isCOBOL for Axis2 automatically sends a call to the multipleParametersAdd operation to the org.apache.axis2.axis2userguide.SampleService.multipleParametersAdd() method.
Now it's time to create the distribution. Arrange your files in the following directory structure:
Example: Create the Directory Structure for the Distribution
Now you need to deploy the service to the server. To do that, generate UserFunctions.aar using jar -cvf UserFunctions.aar *. Copy the UserFunctions.aar file to the WEB-INF/services directory of the application server. (You also have the option to use the administration tools. See the Web Administrator's Guide for more information.)
To verify that the service has been properly deployed, check the list of services at http://<host>:<port>/axis2/services/listServices.
Now you should be able to access the service using any of the clients built in the Generating Clients document.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left