Skip to content

Commit ca09d62

Browse files
sophiegreenGitHub Enterprise
authored andcommitted
Merge pull request #4 from CICS/jaxrs
Add jax-rs-2.0 dependency to bit-link sample, Tidy up
2 parents 245f459 + 1d6cd1e commit ca09d62

File tree

14 files changed

+428
-425
lines changed

14 files changed

+428
-425
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ buildNumber.properties
99
.mvn/timing.properties
1010

1111
.apt_generated
12+
.apt_generated_tests
1213
.factorypath
1314

1415
# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)

append-char-container-sample/src/main/java/sample/SampleServlet.java renamed to append-char-container-sample/src/main/java/sample/AppendCharServlet.java

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,53 @@
2323
import com.ibm.cics.jcicsx.CICSContext;
2424

2525
/**
26-
* A sample servlet to demonstrate how to use JCICSX to create CHAR containers and append data to them
26+
* A sample servlet to demonstrate how to use JCICSX to create CHAR containers
27+
* and append data to them
2728
*/
2829
@WebServlet("/SampleServlet")
29-
public class SampleServlet extends HttpServlet {
30-
31-
private static final long serialVersionUID = 1L;
32-
33-
private static final String CHANNEL_NAME = "charchan";
34-
35-
private static final String CONTAINER_NAME = "charcont";
36-
37-
/**
38-
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
39-
*/
40-
@Override
41-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30+
public class AppendCharServlet extends HttpServlet {
31+
32+
private static final long serialVersionUID = 1L;
33+
34+
private static final String CHANNEL_NAME = "charchan";
35+
36+
private static final String CONTAINER_NAME = "charcont";
37+
38+
/**
39+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
40+
* response)
41+
*/
42+
@Override
43+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
44+
throws ServletException, IOException {
4245
response.setContentType("text/html");
43-
46+
4447
response.getWriter().print("Hello world!");
45-
48+
4649
// Gets the current CICS Context for the environment we're running in
4750
CICSContext task = CICSContext.getCICSContext();
48-
51+
4952
try {
50-
// Create a new channel called "charchan", with a CHAR container called "charcont"
53+
// Create a new channel called "charchan", with a CHAR container called
54+
// "charcont"
5155
// Add the text to the CHAR container
52-
CHARContainer charContainer = task.getChannel(CHANNEL_NAME)
53-
.getCHARContainer(CONTAINER_NAME)
56+
CHARContainer charContainer = task.getChannel(CHANNEL_NAME).getCHARContainer(CONTAINER_NAME)
5457
.put("I'm running under task ");
55-
58+
5659
// Get the current task number that this unit of work is running under
5760
Integer taskNumber = task.getTaskNumber();
58-
61+
5962
// Add the task number to the end of the CHAR container
6063
charContainer = charContainer.append(taskNumber.toString());
61-
64+
6265
// Get the full contents of the container, and print this
6366
String combinedString = charContainer.get();
6467
response.getWriter().println(combinedString);
65-
68+
6669
} catch (CICSConditionException e) {
67-
response.getWriter().println("An exception has occured" +
68-
"\nRESP: " + e.getResp2() +
69-
"\nRESP2: " + e.getResp2() +
70-
"\nMessage: " + e.getMessage());
70+
response.getWriter().println("An exception has occured" + "\nRESP: " + e.getResp2() + "\nRESP2: "
71+
+ e.getResp2() + "\nMessage: " + e.getMessage());
7172
}
72-
}
73+
}
7374

7475
}

bit-link-program-sample/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
<version>1.0</version>
2323
<scope>provided</scope>
2424
</dependency>
25+
<dependency>
26+
<groupId>javax.ws.rs</groupId>
27+
<artifactId>javax.ws.rs-api</artifactId>
28+
<version>2.0.1</version>
29+
</dependency>
2530

26-
<!-- JCICSX dependency, used in ReverseResource.java -->
31+
<!-- JCICSX dependency -->
2732
<dependency>
2833
<!--
2934
<groupId>com.ibm.cics</groupId>

bit-link-program-sample/src/main/java/sample/SampleServlet.java renamed to bit-link-program-sample/src/main/java/sample/BitLinkServlet.java

Lines changed: 70 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -27,99 +27,98 @@
2727
import com.ibm.cics.jcicsx.CICSContext;
2828

2929
/**
30-
* A sample servlet to demonstrate how to use JCICSX to LINK to a CICS Program with BIT data
30+
* A sample servlet to demonstrate how to use JCICSX to LINK to a CICS Program
31+
* with BIT data
3132
*/
3233
@Path("/")
3334
@Produces(MediaType.APPLICATION_JSON)
34-
public class SampleServlet {
35-
36-
/**
37-
* Name of the program to invoke.
38-
*/
39-
private static final String PROG_NAME = "CONVERT";
40-
41-
/**
42-
* Name of the channel to use.
43-
*/
44-
private static final String CHANNEL = "MYCHANNEL";
45-
46-
/**
47-
* Name of the container used to send data to the target program.
48-
*/
49-
private static final String INPUT_CONTAINER = "INPUTDATA";
50-
51-
/**
52-
* Name of the container which will contain the response from the target program.
53-
*/
54-
private static final String OUTPUT_CONTAINER = "OUTPUTDATA";
55-
56-
/**
57-
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
58-
*/
59-
@GET
60-
@Path("/{text}")
61-
public String convertCelciusToFahrenheit(@PathParam("text") String temperatureString) {
62-
63-
Integer temperature = null;
64-
65-
try {
66-
temperature = Integer.valueOf(temperatureString);
35+
public class BitLinkServlet {
36+
37+
/**
38+
* Name of the program to invoke.
39+
*/
40+
private static final String PROG_NAME = "CONVERT";
41+
42+
/**
43+
* Name of the channel to use.
44+
*/
45+
private static final String CHANNEL = "MYCHANNEL";
46+
47+
/**
48+
* Name of the container used to send data to the target program.
49+
*/
50+
private static final String INPUT_CONTAINER = "INPUTDATA";
51+
52+
/**
53+
* Name of the container which will contain the response from the target
54+
* program.
55+
*/
56+
private static final String OUTPUT_CONTAINER = "OUTPUTDATA";
57+
58+
/**
59+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
60+
* response)
61+
*/
62+
@GET
63+
@Path("/{text}")
64+
public String convertCelciusToFahrenheit(@PathParam("text") String temperatureString) {
65+
66+
Integer temperature = null;
67+
68+
try {
69+
temperature = Integer.valueOf(temperatureString);
6770
} catch (NumberFormatException e) {
6871
Response.serverError().entity("Input is not a valid number").build();
6972
}
70-
71-
// Message to emit as the response
72-
String convertedTemperature = null;
73-
74-
// Gets the current CICS Context for the environment we're running in
75-
CICSContext task = CICSContext.getCICSContext();
76-
77-
// Allocate a byte buffer of 4 bytes for our integer
78-
ByteBuffer bytebuffer = ByteBuffer.allocate(4);
79-
80-
//Data to place in the container to be sent to the target program.
81-
byte[] inputData = bytebuffer.putInt(temperature).array();
82-
bytebuffer.rewind();
83-
84-
73+
74+
// Message to emit as the response
75+
String convertedTemperature = null;
76+
77+
// Gets the current CICS Context for the environment we're running in
78+
CICSContext task = CICSContext.getCICSContext();
79+
80+
// Allocate a byte buffer of 4 bytes for our integer
81+
ByteBuffer bytebuffer = ByteBuffer.allocate(4);
82+
83+
// Data to place in the container to be sent to the target program.
84+
byte[] inputData = bytebuffer.putInt(temperature).array();
85+
bytebuffer.rewind();
86+
8587
try {
8688
// Create a reference to the Program we will invoke and specify the channel
87-
// Don't syncpoint between remote links, this is the default
89+
// Don't syncpoint between remote links, this is the default
8890
// Link to the program with an input container, containing the input data
89-
task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL)
90-
.setSyncOnReturn(false)
91-
.setBytesInput(INPUT_CONTAINER, inputData)
92-
.link();
93-
91+
task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL).setSyncOnReturn(false)
92+
.setBytesInput(INPUT_CONTAINER, inputData).link();
93+
9494
// Get the data from the output container as a byte array
95-
// 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
96-
byte[] returnedData = task.getChannel(CHANNEL)
97-
.getBITContainer(OUTPUT_CONTAINER)
98-
.get();
99-
95+
// You could remove task.getChannel(CHANNEL) and do this as one chained command
96+
// above, but this demonstrates how you could call this part later on in your
97+
// program
98+
byte[] returnedData = task.getChannel(CHANNEL).getBITContainer(OUTPUT_CONTAINER).get();
99+
100100
bytebuffer.put(returnedData);
101101
bytebuffer.rewind();
102102
convertedTemperature = String.valueOf(bytebuffer.getInt());
103-
103+
104104
if (convertedTemperature == null) {
105105
// Missing response container
106106
convertedTemperature = "<missing>";
107107
}
108-
108+
109109
// Format the final message and print it
110-
return "Returned from link to \'" + PROG_NAME + "\'. " + temperature + " degrees celcius = " + convertedTemperature + " degrees fahrenheit";
111-
110+
return "Returned from link to \'" + PROG_NAME + "\'. " + temperature + " degrees celcius = "
111+
+ convertedTemperature + " degrees fahrenheit";
112+
112113
} catch (CICSConditionException e) {
113-
String msg = "An exception has occured" +
114-
"\nRESP: " + e.getRespCode() +
115-
"\nRESP2: " + e.getResp2() +
116-
"\nMessage: " + e.getMessage();
117-
114+
String msg = "An exception has occured" + "\nRESP: " + e.getRespCode() + "\nRESP2: " + e.getResp2()
115+
+ "\nMessage: " + e.getMessage();
116+
118117
Response r = Response.serverError().entity(msg).build();
119-
118+
120119
// Pass the error back up the handler chain
121120
throw new WebApplicationException(e, r);
122121
}
123-
}
122+
}
124123

125124
}

char-link-program-sample/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
<scope>provided</scope>
2424
</dependency>
2525

26-
<!-- JCICSX dependency, used in SampleServlet.java -->
26+
<!-- JCICSX dependency, used in CharLinkServlet.java -->
2727
<dependency>
28-
<!--
28+
<!--
2929
<groupId>com.ibm.cics</groupId>
3030
<artifactId>com.ibm.cics.jcicsx</artifactId>
3131
-->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package sample;
2+
3+
/* Licensed Materials - Property of IBM */
4+
/* */
5+
/* SAMPLE */
6+
/* */
7+
/* (c) Copyright IBM Corp. 2020 All Rights Reserved */
8+
/* */
9+
/* US Government Users Restricted Rights - Use, duplication or disclosure */
10+
/* restricted by GSA ADP Schedule Contract with IBM Corp */
11+
/* */
12+
13+
import java.io.IOException;
14+
15+
import javax.servlet.ServletException;
16+
import javax.servlet.annotation.WebServlet;
17+
import javax.servlet.http.HttpServlet;
18+
import javax.servlet.http.HttpServletRequest;
19+
import javax.servlet.http.HttpServletResponse;
20+
21+
import com.ibm.cics.jcicsx.CICSConditionException;
22+
import com.ibm.cics.jcicsx.CICSContext;
23+
24+
/**
25+
* A sample servlet to demonstrate how to use JCICSX to LINK to a CICS Program
26+
* with CHAR data
27+
*/
28+
@WebServlet("/SampleServlet")
29+
public class CharLinkServlet extends HttpServlet {
30+
31+
private static final long serialVersionUID = 1L;
32+
33+
/**
34+
* Name of the program to invoke.
35+
*/
36+
private static final String PROG_NAME = "EDUCHAN";
37+
38+
/**
39+
* Name of the channel to use.
40+
*/
41+
private static final String CHANNEL = "MYCHANNEL";
42+
43+
/**
44+
* Name of the container used to send data to the target program.
45+
*/
46+
private static final String INPUT_CONTAINER = "INPUTDATA";
47+
48+
/**
49+
* Name of the container which will contain the response from the target
50+
* program.
51+
*/
52+
private static final String OUTPUT_CONTAINER = "OUTPUTDATA";
53+
54+
/**
55+
* Data to place in the container to be sent to the target program.
56+
*/
57+
private static final String INPUTSTRING = "Hello from Java";
58+
59+
/**
60+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
61+
* response)
62+
*/
63+
@Override
64+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
65+
throws ServletException, IOException {
66+
response.setContentType("text/html");
67+
68+
response.getWriter().print("Hello world! ");
69+
70+
// Message to emit as the response
71+
String resultStr = null;
72+
73+
// Gets the current CICS Context for the environment we're running in
74+
CICSContext task = CICSContext.getCICSContext();
75+
76+
try {
77+
// Create a reference to the Program we will invoke and specify the channel
78+
// Don't syncpoint between remote links, this is the default
79+
// Link to the program with an input container, containing the input string of
80+
// "Hello from Java"
81+
task.createProgramLinkerWithChannel(PROG_NAME, CHANNEL).setSyncOnReturn(false)
82+
.setStringInput(INPUT_CONTAINER, INPUTSTRING).link();
83+
84+
// Get the data from the output container as a string
85+
// You could remove task.getChannel(CHANNEL) and do this as one chained command
86+
// above, but this demonstrates how you could call this part later on in your
87+
// program
88+
resultStr = task.getChannel(CHANNEL).getCHARContainer(OUTPUT_CONTAINER).get();
89+
90+
if (resultStr == null) {
91+
// Missing response container
92+
resultStr = "<missing>";
93+
}
94+
95+
// Format the final message and print it
96+
String msg = "Returned from link to \'" + PROG_NAME + "\' with a text response of \'" + resultStr + "\'";
97+
response.getWriter().println(msg);
98+
99+
} catch (CICSConditionException e) {
100+
response.getWriter().println("An exception has occured" + "\nRESP: " + e.getRespCode() + "\nRESP2: "
101+
+ e.getResp2() + "\nMessage: " + e.getMessage());
102+
}
103+
}
104+
105+
}

0 commit comments

Comments
 (0)