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+ "\n RESP: " + e .getResp2 () +
88+ "\n RESP2: " + e .getResp2 () +
89+ "\n Message: " + e .getMessage ());
90+ }
91+ }
92+
93+ }
0 commit comments