Skip to content

Commit fc8546c

Browse files
committed
Link program sample for char data
1 parent f9796c8 commit fc8546c

File tree

11 files changed

+332
-12
lines changed

11 files changed

+332
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ buildNumber.properties
1515
.settings
1616
.project
1717
.classpath
18-
.metadata
18+
.metadata
19+
/.recommenders/

append-char-container-sample/src/main/java/sample/SampleServlet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.ibm.cics.jcicsx.CICSContext;
1414

1515
/**
16-
* Servlet implementation class SimpleServlet
16+
* A sample servlet to demonstrate how to use JCICSX to create CHAR containers and append data to them
1717
*/
1818
@WebServlet("/SampleServlet")
1919
public class SampleServlet extends HttpServlet {
@@ -54,10 +54,10 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
5454
response.getWriter().println(combinedString);
5555

5656
} catch (CICSConditionException e) {
57-
System.out.println("An exception has occured with" +
58-
" RESP: " + e.getResp2() +
59-
" RESP2: " + e.getResp2() +
60-
" Message: " + e.getMessage());
57+
response.getWriter().println("An exception has occured" +
58+
"\nRESP: " + e.getResp2() +
59+
"\nRESP2: " + e.getResp2() +
60+
"\nMessage: " + e.getMessage());
6161
}
6262
}
6363

char-link-program-sample/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CHAR 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 CHAR data as the output of the Program.

char-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>char-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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 with CHAR 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+
String 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 string
68+
69+
resultStr = task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL)
70+
.setSyncOnReturn(false)
71+
.setStringInput(INPUT_CONTAINER, INPUTSTRING)
72+
.link()
73+
.getStringOutput(OUTPUT_CONTAINER);
74+
75+
if (resultStr == null) {
76+
// Missing response container
77+
resultStr = "<missing>";
78+
}
79+
80+
// 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);
83+
response.getWriter().println(msg);
84+
85+
} catch (CICSConditionException e) {
86+
response.getWriter().println("An exception has occured" +
87+
"\nRESP: " + e.getResp2() +
88+
"\nRESP2: " + e.getResp2() +
89+
"\nMessage: " + e.getMessage());
90+
}
91+
}
92+
93+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
5+
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
6+
version="3.1">
7+
<login-config>
8+
<auth-method>CLIENT-CERT</auth-method>
9+
</login-config>
10+
</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)