Skip to content

Commit bc3c74d

Browse files
committed
Update char link sample to work with a EDUCHAN
1 parent 1401438 commit bc3c74d

File tree

4 files changed

+264
-31
lines changed

4 files changed

+264
-31
lines changed

char-link-program-sample/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1-
CHAR Link to Program Sample
1+
# CHAR Link to Program Sample
22

33
This sample shows how you can use the JCICSX API to LINK to a CICS Program, passing through a CHAR container, and returning CHAR data as the output of the Program.
4+
5+
This web application takes the string "Hello from Java" and links to the EDUCHAN program with the channel `MYCHANNEL` and an input container called `INPUTDATA`. The EDUCHAN program reads the data from the input container and reverses the string. The output string is placed in the output container `OUTPUTDATA`, read in by the servlet and displayed on the web page.
6+
7+
## Setup
8+
9+
This application links to the COBOL program EDUCHAN, which can be found in `src/main/cobol`.
10+
Download and compile the supplied COBOL program EDUCHAN and deploy into CICS.
11+
12+
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.
13+
14+
To run the sample as-is, fill out values in the configuration block in pom.xml
15+
```xml
16+
<configuration>
17+
<defaultjvmserver>DFHWLP</defaultjvmserver>
18+
<url>http://yourcicsurl.com:9080</url>
19+
<username>${cics-user-id}</username>
20+
<password>${cics-password}</password>
21+
<bunddef>DEMOBUNDLE</bunddef>
22+
<csdgroup>BAR</csdgroup>
23+
<cicsplex>CICSEX56</cicsplex>
24+
<region>IYCWEMW2</region>
25+
</configuration>
26+
```
27+
Running `mvn clean install` will package the web application into a CICS Bundle and install and enable it.
28+
You can then view the web server `http://yourcicsurl.com:9080/char-link-program-sample-0.0.1-SNAPSHOT/`
29+
You should see the message `Hello world! Returned from link to 'EDUCHAN' with a text response of ' avaJ morf olleH'`

char-link-program-sample/pom.xml

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
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">
25
<modelVersion>4.0.0</modelVersion>
3-
6+
47
<groupId>com.ibm.cics</groupId>
58
<artifactId>char-link-program-sample</artifactId>
69
<version>0.0.1-SNAPSHOT</version>
710
<packaging>war</packaging>
8-
11+
912
<dependencies>
1013
<dependency>
1114
<groupId>javax.servlet</groupId>
@@ -19,6 +22,8 @@
1922
<version>1.0</version>
2023
<scope>provided</scope>
2124
</dependency>
25+
26+
<!-- JCICSX dependency, used in SampleServlet.java -->
2227
<dependency>
2328
<!-- <groupId>com.ibm.cics</groupId>
2429
<artifactId>com.ibm.cics.jcicsx</artifactId> -->
@@ -29,27 +34,55 @@
2934
</dependencies>
3035

3136
<build>
32-
<pluginManagement>
33-
<plugins>
34-
<plugin>
35-
<groupId>org.apache.maven.plugins</groupId>
36-
<artifactId>maven-war-plugin</artifactId>
37-
<version>3.2.2</version>
38-
<configuration>
39-
<failOnMissingWebXml>false</failOnMissingWebXml>
40-
</configuration>
41-
</plugin>
37+
<plugins>
4238
<plugin>
4339
<groupId>org.apache.maven.plugins</groupId>
4440
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>3.8.1</version>
4542
<configuration>
4643
<source>1.8</source>
4744
<target>1.8</target>
4845
</configuration>
4946
</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>
5086
</plugins>
51-
</pluginManagement>
5287
</build>
53-
54-
55-
</project>
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+

char-link-program-sample/src/main/java/sample/SampleServlet.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package sample;
22

33
import java.io.IOException;
4-
import java.text.MessageFormat;
54

65
import javax.servlet.ServletException;
76
import javax.servlet.annotation.WebServlet;
@@ -23,12 +22,12 @@ public class SampleServlet extends HttpServlet {
2322
/**
2423
* Name of the program to invoke.
2524
*/
26-
private static final String PROG_NAME = "PROG";
25+
private static final String PROG_NAME = "EDUCHAN";
2726

2827
/**
2928
* Name of the channel to use.
3029
*/
31-
private static final String CHANNEL = "CHAN";
30+
private static final String CHANNEL = "MYCHANNEL";
3231

3332
/**
3433
* Name of the container used to send data to the target program.
@@ -38,7 +37,7 @@ public class SampleServlet extends HttpServlet {
3837
/**
3938
* Name of the container which will contain the response from the target program.
4039
*/
41-
private static final String OUTPUT_CONTAINER = "OUTPUTCONT";
40+
private static final String OUTPUT_CONTAINER = "OUTPUTDATA";
4241

4342
/**
4443
* Data to place in the container to be sent to the target program.
@@ -52,7 +51,7 @@ public class SampleServlet extends HttpServlet {
5251
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
5352
response.setContentType("text/html");
5453

55-
response.getWriter().print("Hello world!");
54+
response.getWriter().print("Hello world! ");
5655

5756
// Message to emit as the response
5857
String resultStr = null;
@@ -64,27 +63,30 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
6463
// Create a reference to the Program we will invoke and specify the channel
6564
// Don't syncpoint between remote links, this is the default
6665
// Link to the program with an input container, containing the input string of "Hello from Java"
67-
// Get the output from the Program as a string
68-
69-
resultStr = task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL)
66+
task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL)
7067
.setSyncOnReturn(false)
7168
.setStringInput(INPUT_CONTAINER, INPUTSTRING)
72-
.link()
73-
.getStringOutput(OUTPUT_CONTAINER);
69+
.link();
70+
71+
72+
// Get the data from the output container as a string
73+
// You could remove task.getChannel(CHANNEL) and do this as one chained command above, but this demonstrates how you could call this part later on in your program
74+
resultStr = task.getChannel(CHANNEL)
75+
.getCHARContainer(OUTPUT_CONTAINER)
76+
.get();
7477

7578
if (resultStr == null) {
7679
// Missing response container
7780
resultStr = "<missing>";
7881
}
7982

8083
// Format the final message and print it
81-
String msg = MessageFormat.format("Returned from link to {0} with a text response of \'{1}\'",
82-
PROG_NAME, resultStr);
84+
String msg = "Returned from link to \'" + PROG_NAME + "\' with a text response of \'" + resultStr + "\'";
8385
response.getWriter().println(msg);
8486

8587
} catch (CICSConditionException e) {
8688
response.getWriter().println("An exception has occured" +
87-
"\nRESP: " + e.getResp2() +
89+
"\nRESP: " + e.getRespCode() +
8890
"\nRESP2: " + e.getResp2() +
8991
"\nMessage: " + e.getMessage());
9092
}

0 commit comments

Comments
 (0)