In this tutorial, you use the top-down method to create a RESTful Web service provider that receives 
               		GET and PUT 
                  		requests. These requests are sent to a wrapper program that passes the requests on to the 
               		Book program. The 
               		Book program 
               		returns a book record on a GET request, and creates a new book record on a PUT request. 
               	 
            
 
            	 
            
               Prerequisites
 
               		 
               		
               If you have not done so already, you must install the IBM-37, IBM-437, and 002501B5 CCSID tables before attempting this tutorial.
                  See 
                  		  To install CCSID tables for instructions. 
                  		
               
 
               		
               To complete the 
                  		  Test the 
                     			 BookWeb service provider section of this tutorial, we recommend that you install a JSON requester tool. 
                  		
               
 
               		 
               	 
              
            	  
            	 
            
               Create the BookREST project 
 
               		 
               		
               Use the CWSProject demonstration project to create a project for your CICS Web service provider. 
                  		
               
 
               		
                
                  		  
                  - Using Windows Explorer or at a command prompt, create a project directory named 
                     			 BookREST. 
                     		  
                  
- Extract the 
                     			 CICSWebServicesProjectTemplate_VS.zip file, located in the 
                     			 %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\CICS\Classic\CWS directory by default, to the new 
                     			 BookREST project directory. 
                     		  
                  
- From the 
                     			 Enterprise Developer 
                     			 for Visual Studio 2015 main menu, click 
                     			 File > Open > Project/Solution. 
                     		  
                  
- Browse to the new 
                     			 BookREST project directory, and select the 
                     			 CWSProject.cblproj project file; then click 
                     			 Open. This starts the Solution Explorer. 
                     			 
                     Here, you rename the project to match the name of the service interface you are going to create. This is not mandatory in
                        general, but done here to differentiate between tutorial projects. 
                        			 
                      
- In the Solution Explorer, right-click the 
                     			 CWSProject project; then select 
                     			 Rename. 
                     		  
                  
- Type 
                     			 BookREST; then press 
                     			 Enter. 
                     		  
                  
  
            	 
            
               Generate CICS Web Service provider components
 
               		 
               		
               Use the 
                  		  Generate Web Service dialog box to generate the components of your Web service provider. 
                  		
               
 
                
                  		
                   
                     		  
                     - From the Solution Explorer, expand the 
                        			 BookREST project's 
                        			 json folder. 
                        		  
                     
- Right-click the 
                        			 BookREST.json file; then select 
                        			 Generate Web Service from the context menu. 
                        		  
                     
- In the Generate Web Service dialog box, ensure that 
                        			 BookREST.json populates the 
                        			 (for request) field, and that the 
                        			 (for response) field is set to 
                        			 <None>. 
                        		  
                     
- In the 
                        			 Generate group, select the 
                        			 Service radio button. 
                        		  
                     
- In the 
                        			 Program group, check 
                        			 CICS. 
                        		  
                     
- Click 
                        			 OK. 
                        		  
                     
Enterprise Developer generates the following CICS Web service components in the 
                        			 BookREST project folder: 
                     		
                  
 
                  		
                   
                     		   
                     			 
                     - BookREST.cbl 
                        			 
                     
- A skeleton CICS program. 
                        			 
                     
- BookREST.svi 
                        			 
                     
- A service interface. 
                        			 
                     
- BookR01.cpy 
                        			 
                     
- A copybook containing data structures. This file does not show on the Solution Explorer. 
                        			 
                     
  
               	 
              
            	 
            
               Generate and move the 
                  		  BookREST.wsbind file
               
 
               		 
               		
                
                  		  
                  -  In the Solution Explorer, right-click the 
                     			 BookREST.svi file; then select 
                     			 Generate WSBIND. 
                     			 
                     Because the 
                        				BookREST.wsbind file is generated to the 
                        				BookREST project's 
                        				json\BookREST directory, but the output path is set to the 
                        				BookREST project's 
                        				loadlib directory, you need to move the file from the project's 
                        				json\BookREST directory to the project's 
                        				loadlib directory so that 
                        				Enterprise Server finds the correct file. 
                        			 
                      
- Using Windows Explorer or at a command prompt, change to the 
                     			 BookREST project directory. 
                     		  
                  
- Copy or move the 
                     			 BookREST.wsbind file from the 
                     			 json\BookREST directory to the 
                     			 loadlib directory. 
                     		  
                  
  
            	 
            
               Implement the service
 
               		 
               		
                The generated skeleton program, 
                  		  BookREST.cbl, contains some basic functionality that is common to any CICS Web service that uses the Channel interface, such as: 
                  		
               
 
               		
                
                  		  
                  - It retrieves the type of request being made from the DFHHTTPMETHOD container, and evaluates it. 
                     		  
                  
- For a GET request, it populates the DFHWS-DATA container with the content of the response data structure (in 
                     			 film01.cpy). 
                     		  
                  
- For a POST or PUT request, it populates the request data structure (in 
                     			 BookR01.cpy) with the contents of the DFHWS-DATA container. 
                     		  
                  
To provide the required operation logic, you must code it manually by editing the program. 
                  		
               
 
               		
                
                  		  
                  - From the 
                     			 Solution Explorer, double-click 
                     			 BookREST.cbl to open it in the COBOL editor. 
                     		  
                  
- Declare the following two variables in the 
                     			 Working-Storage section: 
                     			 01 ws-function                 pic x.
01 ws-file-status              pic xx value "00". 
- Scroll down to the 
                     			 when "GET" statement, and add the following lines between it and the 
                     			 move "DFHWS-DATA" to ls-container-name statement: 
                     			                initialize lnk-b-details
               move "1" to ws-function
               move ls-uri-resid to lnk-b-stockno
               call "book" using ws-function
                                 lnk-b-details
                                 ws-file-statusNote: BookREST.cbl contains a comment line between the two statements. You can replace the comment line with this block of code. 
                        			 
                      
-  At the next commented line below an 
                     			 EXEC CICS GET statement, add the following lines to create a new record: 
                     			                move "2" to ws-function
               call "book" using ws-function
                                 lnk-b-details
                                 ws-file-status
- Near the bottom of the program, in the second 
                     			 MOVE statement in the 
                     			 put-DFHRESPONSE paragraph, replace the 
                     			 ls-uri-resid variable with the 
                     			 ws-file-status variable. 
                     		  
                  
- Click 
                     			 File > Save BookREST.cbl. 
                     		  
                  
- Close the COBOL editor. 
                     			  
                     		  
                  
  
            	 
            
               Build the BookREST project
 
               		 
               		
                
                  		  
                  - From the Solution Explorer, right-click the 
                     			 BookREST project; then select 
                     			 Build. 
                     		  
                  
  
            	 
            
               Create an enterprise server region
 
               		 
               		
               Here you use 
                  		  Enterprise Server to create an 
                  		  enterprise server region on which to run the Web service. 
                  		
               
 
               		
                
                  		  
                  - In 
                     			 Enterprise Developer 
                     			 for Visual Studio 2015, activate the Server Explorer. 
                     			  
                     		  
                  
- Expand 
                     			 Micro Focus Servers. 
                     		  
                  
- Right-click 
                     			 localhost; then select 
                     			 New Enterprise Server. 
                     		  
                  
- In the 
                     			 Name field, type 
                     			 CWSREST. This is the name for the new 
                     			 enterprise server region. 
                     		  
                  
- Click the 
                     			 browse button that corresponds to the 
                     			 Template field, and navigate to the 
                     			 CICSWebServicesProjectTemplate.xml file located in the 
                     			 BookREST\ESTemplates 
                        			 project folder. 
                     		  
                  
- Double-click 
                     			 CICSWebServicesProjectTemplate.xml. This populates the 
                     			 Template field. 
                     		  
                  
- On the list next to 
                     			 Associate with projects, check 
                     			 BookREST. 
                     		  
                  
- Click 
                     			 OK. 
                     			 
                     The Server Explorer should now show the 
                        				CWSREST 
                           				enterprise server region listed under 
                        				localhost. 
                        			 
                      Note:  If 
                           				  CWSREST doesn't immediately appear, right-click 
                           				  Micro Focus Servers; then select 
                           				  Refresh from the context menu. 
                        			 
                      
  
            	 
            
               Configure CWSREST resources
 
               		 
               		
               All 
                  		  Enterprise Server regions require access to certain resources, depending on the types of applications they run. Resources that are defined
                  on a region's startup list are loaded during the startup routine, making them available for as long as the region is running.
                  
                  		
               
 
               		
               CICS Web services use the underlying resources provided by the standard 
                  		  Enterprise Server CICS Web interface (CWI) and CICS Web Services (CWS) support. However, the CICSWebServicesProjectTemplate used to create
                  the CWSREST region does not include these resources on the startup list; therefore, you need to add them manually. The CWI
                  resources reside in a predefined resource group named DFHWEB. The CWS resources are in the predefined DFHPIPE group. 
                  		
               
 
               		
               In addition, you need to create and a resource group to contain the resources required by the 
                  		  BookREST program, and also add the new group to the startup list. 
                  		
               
 
               		
                
                  		   
                  			 
                  - Start 
                     				Enterprise Server Administration 
                     			 
                  
-  
                     				
                      
                        				  
                        - From Server Explorer, right-click 
                           					 Micro Focus Servers; then select 
                           					 Administration. This starts 
                           					 Enterprise Server Administration. 
                           					 
                           Note: If this is the first time you have started the server you see a sign-on dialog box. If 
                                 			 Server is secured is checked, uncheck it; then click 
                                 			 OK. Unchecking 
                                 			 Server is secured prevents this dialog box from showing when you subsequently start the region. If 
                                 			 Server is secured is not checked, simply click 
                                 			 OK to clear the dialog box. If a Secure Storage prompt appears, click 
                              						No. 
                              					 
                            On the Home page, you should see the 
                              						CWSREST 
                                 						enterprise server region listed. 
                              					 
                            
- Back on the Server Explorer, right-click 
                           					 CWSREST; then select 
                           					 Start. 
                           					 
                           As the region is starting, the 
                              						Enterprise Server Administration Home page should show log information in the region's 
                              						Status Log column. When the region is fully started, this is indicated in the region's 
                              						Status column. 
                              					 
                            
 
- Start ES Monitor and Control (ESMAC) 
                     			 
                  
-  
                     				
                      
                        				  
                        - After CWSREST has started, on the Administration Home page, click the 
                           					 Details button located in the 
                           					 Status column for the 
                           					 CWSREST region. 
                           				  
                        
- On the 
                           					 Server > Control page, click 
                           					 ES Monitor & Control. This starts the ESMAC utility where you can edit the startup list. 
                           				  
                        
 
- Open the DEMOSTRT startup list 
                     			 
                  
-  
                     				
                      
                        				  
                        - On the ESMAC menu, click the drop-down list located under 
                           					 Resources; then select 
                           					 by Group. 
                           				  
                        
- Click 
                           					 Startup. This invokes a list of 
                           					 CICS Startup Lists in the right pane. 
                           					 
                           The CWSREST region uses the default startup list, named DEMOSTRT. 
                              					 
                            
- Click the 
                           					 Details button that corresponds to 
                           					 DEMOSTRT. This takes you to the CICS STARTUP - DEMOSTRT page. 
                           				  
                        
 
- Add resource groups 
                     			 
                  
- Here, you add the DFHWEB and DFHPIPE resource groups to the startup list, and add the CWSRESTP resource group name to the
                     startup list. At this point, you have you have neither created nor defined the CWSRESTP group and its respective resources.
                     Those tasks are completed in the next few sections of this tutorial. 
                     				
                      
                        				  
                        - On the CICS STARTUP - DEMOSTRT page, scroll down to the end of the list and type 
                           					 DFHWEB into the empty field at the bottom; then click 
                           					 Apply. ESMAC adds the DFHWEB group, and adds another empty field at the end of the list. 
                           				  
                        
- In the new empty field, type 
                           					 DFHPIPE; then click 
                           					 Apply. 
                           				  
                        
- In the new empty field, type 
                           					 CWSRESTP; then click 
                           					 Apply. 
                           				  
                        
 
- Create the CWSRESTP resource group 
                     			 
                  
-  
                     				
                      
                        				  
                        - On the ESMAC menu, click the 
                           					 Groups button located under 
                           					 Resources. 
                           				  
                        
- On the CICS Resource Groups page, click 
                           					 New. 
                           				  
                        
- In the 
                           					 Name field, type 
                           					 CWSRESTP. 
                           				  
                        
- In the 
                           					 Description field, type 
                           					 CICS Web Services JSON Provider Resources; then click 
                           					 Add. This invokes the CICS Group CWSRESTP page where you can create and define resources for the group. 
                           				  
                        
 
- Define CWSRESTP resources 
                     			 
                  
- The BookREST program requires a resource for TCP/IP service, and a resource to support a pipeline. 
                     				
                      
                        				  
                        - On the CICS Group CWSRESTP page, click 
                           					 TCPIPSv. 
                           				  
                        
- Complete these fields: 
                           					 
                           
                               
                                 						  
                                  
                                    							 
                                     
                                       								
                                       | Name | RSTTCPIP |   
                                       								
                                       | Description | My TCP/IP Service |   
                                       								
                                       | Port No | 5639 |  
 
 
- Click 
                           					 Add. 
                           					 Enterprise Server returns 
                           					 Add successful. 
                           				  
                        
- Click 
                           					 Apply. 
                           					 Enterprise Server returns 
                           					 Update successful. 
                           				  
                        
- Click 
                           					 Group List to return to the CICS Group CWSRESTP page. 
                           				  
                        
- Click 
                           					 Pipeline. 
                           				  
                        
- Complete these fields: 
                           					 
                           
                               
                                 						  
                                  
                                    							 
                                     
                                       								
                                       | Name | RESTPIPE |  |   
                                       								
                                       | Description | My CICS Provider Pipeline |  |   
                                       								
                                       | Resp Wait | DEFT | This is the number of seconds that an application waits for a response from the service. DEFT indicates the default value,
                                          which is 10 seconds for HTTP and 60 seconds for MQ. |   
                                       								
                                       | Config file | $IDE_XML_LOC\jsonjavaprovider.xml | The IDE_XML_LOC environment variable in CWSREST points to the 
                                          								  xml project folder.1 |   
                                       								
                                       | WebSvc Dir | $IDE_LOADLIB\ | The IDE_LOADLIB environment variable points to the 
                                          								  loadlib project folder.1 |   
                                       								
                                       | 1 To see a list of environment variables defined for CWSREST, from the ESMAC menu, click 
                                             									 Env.Vars.. 
                                             								  
                                           |  
 
 
- Click 
                           					 Add. 
                           					 Enterprise Server returns 
                           					 Add successful. 
                           				  
                        
- Click 
                           					 Apply. 
                           					 Enterprise Server returns 
                           					 Update successful. 
                           				  
                        
- Click 
                           					 Home to return to the Administration Home page. 
                           					 
                           You can install the new resources by stopping and starting the region. 
                              					 
                            
- From the 
                           					 Enterprise Developer Server Explorer, right-click 
                           					 CWSREST; then select 
                           					 Restart. This stops and then starts the CWSREST 
                           					 enterprise server region, automatically installing and loading the newly added resources on the startup list. 
                           				  
                        
 
  
            	 
            
               Verify Resources
 
               		 
               		
               After CWSREST is started, you can verify that the resources you have defined are installed and active. 
                  		
               
 
               		
                
                  		  
                  - In 
                     			 Enterprise Server, start ESMAC for the CWSREST region. 
                     		  
                  
- On the ESMAC menu, select 
                     			 Active from the drop-down list located under 
                     			 Resources. 
                     		  
                  
- On the ESMAC menu, click the 
                     			 WebSvc button. You should see the 
                     			 BookREST Web service listed and marked as 
                     			 INSERVICE. 
                     		  
                  
- On the ESMAC menu, click 
                     			 Pipeline; then click the 
                     			 Details button that corresponds to 
                     			 RESTPIPE. The Pipeline resource sets the response wait period, identifies the JSON configuration file, and the Web Service directory.
                     
                     		  
                  
- On the ESMAC menu, click 
                     			 URIMAP; then click the 
                     			 Details button that corresponds to 
                     			 PIPELINE and 
                     			 /cics/services/BookREST/*. 
                     			 
                     Enterprise Server generates URIMAPs to provide CICS with the information it needs to process requests. The name of each generated URIMAP begins
                        with a pounds sterling symbol (£). 
                        			 
                      To run your RESTful CICS Web service, you can either send an HTTP GET request to retrieve an existing 
                        				Book record or an HTTP PUT request to create a new 
                        				Book record. The request is sent to an endpoint URL that routes the request to your 
                        				enterprise server region. The endpoint URL contains a URI value. The incoming request reads the installed URIMAPs to identify the map whose 
                        				Path value matches the 
                        				URI value of the endpoint URL. When the correct URIMAP is identified, CICS uses the data defined in the URIMAP, such as the name
                        of the 
                        				Web Service and its associated 
                        				Pipeline, to process the request. 
                        			 
                      
  
            	 
            
               Test the 
                  		  Book Web service provider 
               
 
               		 
               		
               Now that you have your Web service provider running with all of its resources active, you are ready to send a 
                  		  GET request to run the Web service. You can do this using any JSON requester tool. 
                  		
               
 
               		
                
                  		  
                  - Create a JSON request with the following endpoint URL: 
                     			 http://localhost:5639/cics/services/BookREST/1111 
- Set the Method to GET. 
                     			 
                     You should receive the following JSON response: 
                        			 
                      {"book": {"lnk_b_details": {
   "lnk_b_text_details":    {
      "lnk_b_title": "LORD OF THE RINGS",
      "lnk_b_type": "FANTASY",
      "lnk_b_author": "TOLKIEN"
   },
   "lnk_b_stockno": "1111",
   "lnk_b_retail": 15,
   "lnk_b_onhand": 4000,
   "lnk_b_sold": 3444
}}}
-  Set the Method to PUT and remove the last five characters from the endpoint URL, so that it now reads: 
                     			 http://localhost:5639/cics/services/BookREST 
-  Enter the following JSON request and send it to create a new Book record: 
                     			 {"book": {"lnk_b_details": {
   "lnk_b_text_details":    {
      "lnk_b_title": "HARRY POTTER",
      "lnk_b_type": "FANTASY",
      "lnk_b_author": "ROWLING"
   },
   "lnk_b_stockno": "5555",
   "lnk_b_retail": 20,
   "lnk_b_onhand": 6000,
   "lnk_b_sold": 4555
}}}You should receive a response of 
                        				00 to show that the record has been added successfully. 
                        			 
                      
-  Set the Method to GET again and add 
                     			 /5555 to the endpoint URL. 
                     			 
                      You should receive a response that matches the JSON you sent in the PUT request.