Skip to content

Commit 7b0c53d

Browse files
committed
Add cics-java-liberty-restapp sample
1 parent bc3c74d commit 7b0c53d

File tree

14 files changed

+910
-0
lines changed

14 files changed

+910
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Java Liberty Restapp Sample
2+
3+
This sample is the same as the existing JCICS [cics-java-liberty-restapp sample](https://github.com/cicsdev/cics-java-liberty-restapp/blob/master/src/Java/com/ibm/cicsdev/restapp/InfoResource.java), but updated to use JCICSX instead of JCICS to show the similarities and differences.
4+
5+
6+
Sample RESTful web application for deployment to a Liberty JVM server in CICS. The application is supplied with two resources:
7+
8+
1. `InfoResource` - This queries the JVM server environment using system properties and uses JAXB beans to return a JSON response detailing the CICS environment.
9+
1. `ReverseResource` - This is similar to `InfoResource`, but uses the JCICSX API to link to the COBOL program `EDUCHAN` using channels and containers. An input string is passed to `EDUCHAN`, which is then reversed and returned, along with the time from CICS.
10+
11+
The following Java source components are supplied in the [`src/Java`](src/Java) directory in this repository.
12+
13+
## Java package com.ibm.cicsdev.restapp
14+
* [`CICSApplication`](src/main/java/com/ibm/cicsdev/restapp/CICSApplication.java) - Sets the `ApplicationPath` for resources in this application
15+
* [`InfoResource`](src/main/java/com/ibm/cicsdev/restapp/InfoResource.java) - Returns JSON structure using `CICSInformation` bean
16+
* [`ReverseResource`](src/main/java/com/ibm/cicsdev/restapp/ReverseResource.java) - Returns JSON structure using `ReverseResult` bean
17+
18+
19+
## Java package com.ibm.cicsdev.restapp.bean
20+
* [`CICSEnvironment`](src/main/java/com/ibm/cicsdev/restapp/bean/CICSEnvironment.java) - JAXB bean returning JSON structure containing information about CICS product and version
21+
* [`CICSInformation`](src/main/java/com/ibm/cicsdev/restapp/bean/CICSInformation.java) - JAXB bean returning JSON structure containing CICS applid, time and JVM server name and instance of `CICSEnvironment`
22+
* [`ReverseResult`](src/main/java/com/ibm/cicsdev/restapp/bean/ReverseResult.java) - JAXB bean returning JSON structure containg input and output containers sent to `EDUCHAN` COBOL program
23+
24+
25+
## Supporting files
26+
* [`EDUCHAN.cbl`](src/main/cobol/EDUCHAN.cbl) - A sample CICS COBOL that returns the date and time and reversed input using channels and containers.
27+
Download and compile the supplied COBOL program EDUCHAN and deploy into CICS.
28+
29+
30+
## Pre-reqs
31+
32+
* CICS TS V5.1 or later, due to the usage of the `getString()` methods.
33+
* Java SE 1.7 or later on the z/OS system
34+
* Java SE 1.7 or later on the workstation
35+
36+
37+
## Setup
38+
39+
This application links to the COBOL program EDUCHAN, which can be found in `src/main/cobol`.
40+
Download and compile the supplied COBOL program EDUCHAN and deploy into CICS.
41+
42+
This sample is a Maven project, which uses the [CICS Bundle Maven plugin](https://github.com/IBM/cics-bundle-maven) to package the web application in a CICS bundle and deploy this to CICS. This requires the CICS bundle deployment API to be enabled in CICS as a [prerequisite](https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.6.0/configuring/cmci/config-bundle-api.html). Alternatively, if you aren't using Maven, you could take the source from this project and use one of the other methods of deploying the application to CICS such as creating a CICS bundle project in CICS Explorer and adding the source as a dynamic web project include.
43+
44+
To run the sample as-is, fill out values in the configuration block in pom.xml
45+
```xml
46+
<configuration>
47+
<defaultjvmserver>DFHWLP</defaultjvmserver>
48+
<url>http://yourcicsurl.com:9080</url>
49+
<username>${cics-user-id}</username>
50+
<password>${cics-password}</password>
51+
<bunddef>DEMOBUNDLE</bunddef>
52+
<csdgroup>BAR</csdgroup>
53+
<cicsplex>CICSEX56</cicsplex>
54+
<region>IYCWEMW2</region>
55+
</configuration>
56+
```
57+
Running `mvn clean install` will package the web application into a CICS Bundle and install and enable it.
58+
You can then view the web server `http://yourcicsurl.com:9080/cics-java-liberty-restapp-0.0.1-SNAPSHOT/`
59+
60+
#### Using a web browser you can issue the following HTTP GET requests
61+
62+
* http://yourcicsurl.com:9080/cics-java-liberty-restapp-0.0.1-SNAPSHOT/cicsinfo
63+
64+
This will invoke the `InfoResource` class and return the following JSON response with information about the target CICS system:
65+
66+
`{"applid":"IYK2Z32E","jvmServer":"DFHWLP","time":"2016-09-09T16:19:55.384Z","cicsEnvironment":{"cicsProduct":"CICS Transaction Server for z/OS","cicsVersion":"5.3.0"}}`
67+
68+
69+
* http://yourcicsurl.com:9080/cics-java-liberty-restapp-0.0.1-SNAPSHOT/
70+
71+
This will invoke the `ReverseResource` class which links to the CICS COBOL program and reverses the default string "Hello from Java" returning the following JSON response:
72+
73+
`{"time":"2016-09-09T16:15:52.756Z","original":"Hello from Java","reverse":"avaJ morf olleH","truncated":false}`
74+
75+
76+
* http://yourcicsurl.com:9080/cics-java-liberty-restapp-0.0.1-SNAPSHOT/ilovecics
77+
78+
This will invoke the `ReverseResource` class which links to the CICS COBOL program reversing the input string "ilovecics" as follows:
79+
80+
`{"time":"2016-09-09T16:15:32.466Z","original":"ilovecics","reverse":"scicevoli","truncated":false}`

cics-java-liberty-restapp/pom.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.ibm.cics</groupId>
8+
<artifactId>cics-java-liberty-restapp</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>javax.servlet</groupId>
15+
<artifactId>javax.servlet-api</artifactId>
16+
<version>3.1.0</version>
17+
<scope>provided</scope>
18+
</dependency>
19+
<dependency>
20+
<groupId>javax.annotation</groupId>
21+
<artifactId>jsr250-api</artifactId>
22+
<version>1.0</version>
23+
<scope>provided</scope>
24+
</dependency>
25+
26+
<!-- JCICSX dependency, used in ReverseResource.java -->
27+
<dependency>
28+
<!-- <groupId>com.ibm.cics</groupId>
29+
<artifactId>com.ibm.cics.jcicsx</artifactId> -->
30+
<groupId>com.ibm.cics.exec-cics-http</groupId>
31+
<artifactId>jcicsx-http-client</artifactId>
32+
<version>0.0.8-SNAPSHOT</version>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>3.8.1</version>
42+
<configuration>
43+
<source>1.8</source>
44+
<target>1.8</target>
45+
</configuration>
46+
</plugin>
47+
48+
<!-- The below bundles the application as a WAR in a CICS bundle and deploys this to CICS using the CICS bundle deployment API.
49+
This is optional and can be removed if you don't wish to deploy the application this way -->
50+
<plugin>
51+
<groupId>com.ibm.cics</groupId>
52+
<artifactId>cics-bundle-maven-plugin</artifactId>
53+
<version>1.0.0</version>
54+
<executions>
55+
<execution>
56+
57+
<!-- These goals will firstly run the war packaging on the project, and then will run the deploy goal, which will happen during the verify phase of the lifecycle by default-->
58+
<goals>
59+
<goal>bundle-war</goal>
60+
<goal>deploy</goal>
61+
</goals>
62+
63+
<configuration>
64+
<!-- The bundle classifier indicates that the war should be packaged into a CICS bundle -->
65+
<classifier>cics-bundle</classifier>
66+
67+
<!-- Update the default JVM server that the application will be installed into by default, This is used when creating the bundle, and goes into the CICS bundle's manifest -->
68+
<jvmserver>DFHWLP</jvmserver>
69+
70+
<!-- Set the URL of the deploy target -->
71+
<url>http://yourcicsurl.com:9080</url>
72+
73+
<!-- We'd recommend that you use Maven's password encryption, or supply your credentials using environment variables or properties, as shown here. -->
74+
<username>${cics-user-id}</username>
75+
<password>${cics-password}</password>
76+
77+
<!-- Identify which bundle definition you're going to use from the CSD and which region and CICSPlex you want to deploy to -->
78+
<bunddef>DEMOBUNDLE</bunddef>
79+
<csdgroup>BAR</csdgroup>
80+
<cicsplex>CICSEX56</cicsplex>
81+
<region>IYCWEMW2</region>
82+
</configuration>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
</plugins>
87+
</build>
88+
</project>
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
*----------------------------------------------------------------*
2+
* Licensed Materials - Property of IBM *
3+
* SAMPLE *
4+
* (c) Copyright IBM Corp. 2016 All Rights Reserved *
5+
* US Government Users Restricted Rights - Use, duplication or *
6+
* disclosure restricted by GSA ADP Schedule Contract with *
7+
* IBM Corp *
8+
*----------------------------------------------------------------*
9+
10+
******************************************************************
11+
* *
12+
* Module Name EDUCHAN.CBL *
13+
* Version 1.0 *
14+
* Date 22/10/2016 *
15+
* *
16+
* CICS back-end channel/container sample *
17+
* *
18+
* This program expects to be invoked with a CHAR container named *
19+
* INPUTDATA and returns the following containers: *
20+
* A CHAR container containing the reversed input string *
21+
* A CHAR container containing the time *
22+
* A BIT container containing the CICS return code from reading *
23+
* the input container *
24+
******************************************************************
25+
26+
IDENTIFICATION DIVISION.
27+
PROGRAM-ID. EDUCHAN.
28+
29+
ENVIRONMENT DIVISION.
30+
CONFIGURATION SECTION.
31+
DATA DIVISION.
32+
WORKING-STORAGE SECTION.
33+
34+
* Container name declarations
35+
* Channel and container names are case sensitive
36+
01 DATE-CONT PIC X(16) VALUE 'CICSTIME'.
37+
01 INPUT-CONT PIC X(16) VALUE 'INPUTDATA'.
38+
01 OUTPUT-CONT PIC X(16) VALUE 'OUTPUTDATA'.
39+
01 LENGTH-CONT PIC X(16) VALUE 'INPUTDATALENGTH'.
40+
01 ERROR-CONT PIC X(16) VALUE 'ERRORDATA'.
41+
01 RESP-CONT PIC X(16) VALUE 'CICSRC'.
42+
43+
44+
* Data fields used by the program
45+
01 INPUTLENGTH PIC S9(8) COMP-4.
46+
01 DATALENGTH PIC S9(8) COMP-4.
47+
01 CURRENTTIME PIC S9(15) COMP-3.
48+
01 ABENDCODE PIC X(4) VALUE SPACES.
49+
01 CHANNELNAME PIC X(16) VALUE SPACES.
50+
01 INPUTSTRING PIC X(72) VALUE SPACES.
51+
01 OUTPUTSTRING PIC X(72) VALUE SPACES.
52+
01 RESPCODE PIC S9(8) COMP-4 VALUE 0.
53+
01 RESPCODE2 PIC S9(8) COMP-4 VALUE 0.
54+
01 DATE-TIME.
55+
03 DATESTRING PIC X(10) VALUE SPACES.
56+
03 TIME-SEP PIC X(1) VALUE SPACES.
57+
03 TIMESTRING PIC X(8) VALUE SPACES.
58+
01 RC-RECORD PIC S9(8) COMP-4 VALUE 0.
59+
01 ERR-RECORD.
60+
03 ERRORCMD PIC X(16) VALUE SPACES.
61+
03 ERRORSTRING PIC X(32) VALUE SPACES.
62+
63+
64+
PROCEDURE DIVISION.
65+
* -----------------------------------------------------------
66+
MAIN-PROCESSING SECTION.
67+
* -----------------------------------------------------------
68+
69+
* Get name of channel
70+
EXEC CICS ASSIGN CHANNEL(CHANNELNAME)
71+
END-EXEC.
72+
73+
* If no channel passed in, terminate with abend code NOCH
74+
IF CHANNELNAME = SPACES THEN
75+
MOVE 'NOCH' TO ABENDCODE
76+
PERFORM ABEND-ROUTINE
77+
END-IF.
78+
79+
80+
* Read content and length of input container
81+
MOVE LENGTH OF INPUTSTRING TO INPUTLENGTH.
82+
EXEC CICS GET CONTAINER(INPUT-CONT)
83+
CHANNEL(CHANNELNAME)
84+
FLENGTH(INPUTLENGTH)
85+
INTO(INPUTSTRING)
86+
RESP(RESPCODE)
87+
RESP2(RESPCODE2)
88+
END-EXEC.
89+
90+
* Place RC in binary container for return to caller
91+
MOVE RESPCODE TO RC-RECORD.
92+
EXEC CICS PUT CONTAINER(RESP-CONT)
93+
FROM(RC-RECORD)
94+
FLENGTH(LENGTH OF RC-RECORD)
95+
BIT
96+
RESP(RESPCODE)
97+
END-EXEC.
98+
99+
IF RESPCODE NOT = DFHRESP(NORMAL)
100+
PERFORM RESP-ERROR
101+
END-IF.
102+
103+
* Place reversed string in output container
104+
MOVE FUNCTION REVERSE(INPUTSTRING) TO OUTPUTSTRING.
105+
106+
EXEC CICS PUT CONTAINER(OUTPUT-CONT)
107+
FROM(OUTPUTSTRING)
108+
FLENGTH(LENGTH OF OUTPUTSTRING)
109+
CHAR
110+
RESP(RESPCODE)
111+
END-EXEC.
112+
113+
IF RESPCODE NOT = DFHRESP(NORMAL)
114+
PERFORM RESP-ERROR
115+
END-IF.
116+
117+
* Get the current time
118+
EXEC CICS ASKTIME ABSTIME(CURRENTTIME)
119+
END-EXEC.
120+
121+
* Format date and time
122+
EXEC CICS FORMATTIME
123+
ABSTIME(CURRENTTIME)
124+
DDMMYYYY(DATESTRING)
125+
DATESEP('/')
126+
TIME(TIMESTRING)
127+
TIMESEP(':')
128+
RESP(RESPCODE)
129+
END-EXEC.
130+
131+
* Check return code
132+
IF RESPCODE NOT = DFHRESP(NORMAL)
133+
STRING 'Failed' DELIMITED BY SIZE
134+
INTO DATESTRING END-STRING
135+
END-IF.
136+
137+
* Place current date in container CICSTIME
138+
EXEC CICS PUT CONTAINER(DATE-CONT)
139+
FROM(DATE-TIME)
140+
FLENGTH(LENGTH OF DATE-TIME)
141+
CHAR
142+
RESP(RESPCODE)
143+
END-EXEC.
144+
* Check return code
145+
IF RESPCODE NOT = DFHRESP(NORMAL)
146+
PERFORM RESP-ERROR
147+
END-IF.
148+
149+
150+
151+
* Return back to caller
152+
PERFORM END-PGM.
153+
154+
* -----------------------------------------------------------
155+
RESP-ERROR.
156+
MOVE 'EDUC' TO ABENDCODE
157+
PERFORM ABEND-ROUTINE.
158+
159+
PERFORM END-PGM.
160+
161+
* -----------------------------------------------------------
162+
* Abnormal end
163+
* -----------------------------------------------------------
164+
ABEND-ROUTINE.
165+
EXEC CICS ABEND ABCODE(ABENDCODE) END-EXEC.
166+
167+
* -----------------------------------------------------------
168+
* Finish
169+
* -----------------------------------------------------------
170+
END-PGM.
171+
EXEC CICS RETURN END-EXEC.
172+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Licensed Materials - Property of IBM */
2+
/* */
3+
/* SAMPLE */
4+
/* */
5+
/* (c) Copyright IBM Corp. 2016 All Rights Reserved */
6+
/* */
7+
/* US Government Users Restricted Rights - Use, duplication or disclosure */
8+
/* restricted by GSA ADP Schedule Contract with IBM Corp */
9+
/* */
10+
11+
package com.ibm.cicsdev.restapp;
12+
13+
import javax.ws.rs.ApplicationPath;
14+
import javax.ws.rs.core.Application;
15+
16+
@ApplicationPath("/")
17+
public class CICSApplication extends Application {
18+
19+
}

0 commit comments

Comments
 (0)