Skip to content

Commit 5e8e142

Browse files
committed
Link program for bit data
1 parent fc8546c commit 5e8e142

File tree

8 files changed

+325
-0
lines changed

8 files changed

+325
-0
lines changed

bit-link-program-sample/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Bit Link to Program Sample
2+
3+
This sample shows how you can use the JCICSX API to LINK to a CICS Program, passing through a CHAR container, and returning BIT data as the output of the Program.

bit-link-program-sample/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<groupId>com.ibm.cics</groupId>
5+
<artifactId>bit-link-program-sample</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
9+
<dependencies>
10+
<dependency>
11+
<groupId>javax.servlet</groupId>
12+
<artifactId>javax.servlet-api</artifactId>
13+
<version>3.1.0</version>
14+
<scope>provided</scope>
15+
</dependency>
16+
<dependency>
17+
<groupId>javax.annotation</groupId>
18+
<artifactId>jsr250-api</artifactId>
19+
<version>1.0</version>
20+
<scope>provided</scope>
21+
</dependency>
22+
<dependency>
23+
<!-- <groupId>com.ibm.cics</groupId>
24+
<artifactId>com.ibm.cics.jcicsx</artifactId> -->
25+
<groupId>com.ibm.cics.exec-cics-http</groupId>
26+
<artifactId>jcicsx-http-client</artifactId>
27+
<version>0.0.8-SNAPSHOT</version>
28+
</dependency>
29+
</dependencies>
30+
31+
<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>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<configuration>
46+
<source>1.8</source>
47+
<target>1.8</target>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</pluginManagement>
52+
</build>
53+
54+
55+
</project>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package sample;
2+
3+
import java.io.IOException;
4+
import java.text.MessageFormat;
5+
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
import com.ibm.cics.jcicsx.CICSConditionException;
13+
import com.ibm.cics.jcicsx.CICSContext;
14+
15+
/**
16+
* A sample servlet to demonstrate how to use JCICSX to LINK to a CICS Program, passing through CHAR data and receiving BIT data
17+
*/
18+
@WebServlet("/SampleServlet")
19+
public class SampleServlet extends HttpServlet {
20+
21+
private static final long serialVersionUID = 1L;
22+
23+
/**
24+
* Name of the program to invoke.
25+
*/
26+
private static final String PROG_NAME = "PROG";
27+
28+
/**
29+
* Name of the channel to use.
30+
*/
31+
private static final String CHANNEL = "CHAN";
32+
33+
/**
34+
* Name of the container used to send data to the target program.
35+
*/
36+
private static final String INPUT_CONTAINER = "INPUTDATA";
37+
38+
/**
39+
* Name of the container which will contain the response from the target program.
40+
*/
41+
private static final String OUTPUT_CONTAINER = "OUTPUTCONT";
42+
43+
/**
44+
* Data to place in the container to be sent to the target program.
45+
*/
46+
private static final String INPUTSTRING = "Hello from Java";
47+
48+
/**
49+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
50+
*/
51+
@Override
52+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
53+
response.setContentType("text/html");
54+
55+
response.getWriter().print("Hello world!");
56+
57+
// Message to emit as the response
58+
byte[] resultStr = null;
59+
60+
// Gets the current CICS Context for the environment we're running in
61+
CICSContext task = CICSContext.getCICSContext();
62+
63+
try {
64+
// Create a reference to the Program we will invoke and specify the channel
65+
// Don't syncpoint between remote links, this is the default
66+
// 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 byte array
68+
69+
resultStr = task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL)
70+
.setSyncOnReturn(false)
71+
.setStringInput(INPUT_CONTAINER, INPUTSTRING)
72+
.link()
73+
.getBytesOutput(OUTPUT_CONTAINER);
74+
75+
String msg;
76+
if (resultStr != null) {
77+
// Format the final message
78+
msg = MessageFormat.format("Returned from link to {0} with response data {1}",
79+
PROG_NAME, resultStr);
80+
}
81+
else {
82+
// Missing response container
83+
msg = MessageFormat.format("Returned from link to {0} with no data", PROG_NAME);
84+
}
85+
86+
// Print the final message
87+
response.getWriter().println(msg);
88+
89+
} catch (CICSConditionException e) {
90+
response.getWriter().println("An exception has occured" +
91+
"\nRESP: " + e.getResp2() +
92+
"\nRESP2: " + e.getResp2() +
93+
"\nMessage: " + e.getMessage());
94+
}
95+
}
96+
97+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
3+
<login-config>
4+
<auth-method>CLIENT-CERT</auth-method>
5+
</login-config>
6+
</web-app>
42.7 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Java Web Starter Application</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<link rel="stylesheet" href="style.css" />
7+
</head>
8+
<body>
9+
<table>
10+
<tr>
11+
<td style='width: 30%;'>
12+
<img class = "newappIcon" src='images/cics.png'>
13+
</td>
14+
<td>
15+
<!-- The message comes from /SampleServlet -->
16+
<h1 id = "message"></h1>
17+
18+
<p class='description'></p> Thanks for creating a <span class="blue">Liberty for Java Starter Application</span>.
19+
</td>
20+
</tr>
21+
</table>
22+
<!-- Call SampleServlet to get the message -->
23+
<script type="text/javascript" src="index.js"></script>
24+
</body>
25+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// index.js
2+
3+
// request message on server
4+
//Calls SampleServlet to get the message
5+
xhrGet("SampleServlet", function(responseText){
6+
// add to document
7+
var mytitle = document.getElementById('message');
8+
mytitle.innerHTML = responseText;
9+
10+
}, function(err){
11+
console.log(err);
12+
});
13+
14+
//utilities
15+
function createXHR(){
16+
if(typeof XMLHttpRequest != 'undefined'){
17+
return new XMLHttpRequest();
18+
}else{
19+
try{
20+
return new ActiveXObject('Msxml2.XMLHTTP');
21+
}catch(e){
22+
try{
23+
return new ActiveXObject('Microsoft.XMLHTTP');
24+
}catch(e){}
25+
}
26+
}
27+
return null;
28+
}
29+
function xhrGet(url, callback, errback){
30+
var xhr = new createXHR();
31+
xhr.open("GET", url, true);
32+
xhr.onreadystatechange = function(){
33+
if(xhr.readyState == 4){
34+
if(xhr.status == 200){
35+
callback(xhr.responseText);
36+
}else{
37+
errback('service not available');
38+
}
39+
}
40+
};
41+
xhr.timeout = 3000;
42+
xhr.ontimeout = errback;
43+
xhr.send();
44+
}
45+
function parseJson(str){
46+
return window.JSON ? JSON.parse(str) : eval('(' + str + ')');
47+
}
48+
function prettyJson(str){
49+
// If browser does not have JSON utilities, just print the raw string value.
50+
return window.JSON ? JSON.stringify(JSON.parse(str), null, ' ') : str;
51+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* style.css
2+
* This file provides css styles.
3+
*/
4+
5+
body,html {
6+
background-color: #3b4b54; width : 100%;
7+
height: 100%;
8+
margin: 0 auto;
9+
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
10+
color: #ffffff;
11+
}
12+
13+
a {
14+
text-decoration: none;
15+
color: #00aed1;
16+
}
17+
18+
a:hover {
19+
text-decoration: underline;
20+
}
21+
22+
.newappIcon {
23+
padding-top: 10%;
24+
display: block;
25+
margin: 0 auto;
26+
padding-bottom: 2em;
27+
max-width:200px;
28+
}
29+
30+
h1 {
31+
font-weight: bold;
32+
font-size: 2em;
33+
}
34+
35+
.leftHalf {
36+
float: left;
37+
background-color: #26343f;
38+
width: 45%;
39+
height: 100%;
40+
}
41+
42+
.rightHalf {
43+
float: right;
44+
width: 55%;
45+
background-color: #313f4a;
46+
height: 100%;
47+
overflow:auto;
48+
}
49+
50+
.description {
51+
padding-left: 50px;
52+
padding-right: 50px;
53+
text-align: center;
54+
font-size: 1.2em;
55+
}
56+
57+
.blue {
58+
color: #00aed1;
59+
}
60+
61+
62+
table {
63+
table-layout: fixed;
64+
width: 800px;
65+
margin: 0 auto;
66+
word-wrap: break-word;
67+
padding-top:10%;
68+
}
69+
70+
th {
71+
border-bottom: 1px solid #000;
72+
}
73+
74+
th, td {
75+
text-align: left;
76+
padding: 2px 20px;
77+
}
78+
79+
.env-var {
80+
text-align: right;
81+
border-right: 1px solid #000;
82+
width: 30%;
83+
}
84+
85+
pre {
86+
padding: 0;
87+
margin: 0;
88+
}

0 commit comments

Comments
 (0)