1+ package sample ;
2+
3+ import java .io .IOException ;
4+
5+ import javax .servlet .ServletException ;
6+ import javax .servlet .annotation .WebServlet ;
7+ import javax .servlet .http .HttpServlet ;
8+ import javax .servlet .http .HttpServletRequest ;
9+ import javax .servlet .http .HttpServletResponse ;
10+
11+ import com .ibm .cics .jcicsx .CHARContainer ;
12+ import com .ibm .cics .jcicsx .CICSConditionException ;
13+ import com .ibm .cics .jcicsx .CICSContext ;
14+
15+ /**
16+ * Servlet implementation class SimpleServlet
17+ */
18+ @ WebServlet ("/SampleServlet" )
19+ public class SampleServlet extends HttpServlet {
20+
21+ private static final long serialVersionUID = 1L ;
22+
23+ private static final String CHANNEL_NAME = "charchan" ;
24+
25+ private static final String CONTAINER_NAME = "charcont" ;
26+
27+ /**
28+ * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
29+ */
30+ @ Override
31+ protected void doGet (HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException {
32+ response .setContentType ("text/html" );
33+
34+ response .getWriter ().print ("Hello world!" );
35+
36+ // Gets the current CICS Context for the environment we're running in
37+ CICSContext task = CICSContext .getCICSContext ();
38+
39+ try {
40+ // Create a new channel called "charchan", with a CHAR container called "charcont"
41+ // Add the text to the CHAR container
42+ CHARContainer charContainer = task .getChannel (CHANNEL_NAME )
43+ .getCHARContainer (CONTAINER_NAME )
44+ .put ("I'm running under task " );
45+
46+ // Get the current task number that this unit of work is running under
47+ Integer taskNumber = task .getTaskNumber ();
48+
49+ // Add the task number to the enf of the CHAR container
50+ charContainer = charContainer .append (taskNumber .toString ());
51+
52+ // Get the full contents of the container, and print this
53+ String combinedString = charContainer .get ();
54+ response .getWriter ().println (combinedString );
55+
56+ } catch (CICSConditionException e ) {
57+ System .out .println ("An exception has occured with" +
58+ " RESP: " + e .getResp2 () +
59+ " RESP2: " + e .getResp2 () +
60+ " Message: " + e .getMessage ());
61+ }
62+ }
63+
64+ }
0 commit comments