01.01.2013 Views

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

CICS Transaction Gateway V5 The WebSphere ... - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>The</strong> next section of code deals with the results of the ECI request. If there have<br />

been no errors, then we convert the output COMMAREA into String objects,<br />

using both the default encoding and that specified in the form, and pass them to<br />

the JSP. We also convert the original byte data into a String hexadecimal<br />

representation, to help with data conversion debugging, and pass that to the JSP.<br />

If there has been an error, then we set jsp to forward to the name of the JSP that<br />

displays errors (error.jsp). In either case, we pass the ECI return codes and error<br />

strings to the JSP.<br />

<strong>The</strong> next section of code handles any exceptions that occur while building and<br />

sending the ECI request. To deal with an exception, we build a message<br />

consisting of a timestamp and the String representation of the exception that<br />

occurred. We then set a request attribute containing this String and specify we<br />

want to forward to the JSP that displays exceptions (exception.jsp).<br />

We then close the Java<strong>Gateway</strong> connection in a finally block, to ensure it is<br />

closed even if an exception occurs during the flow() method.<br />

<strong>The</strong> final section of code in the processRequest() method forwards to the<br />

appropriate JSP, set in the member variable jsp (Figure B-10).<br />

// route to jsp<br />

ServletContext servletContext = getServletContext();<br />

RequestDispatcher dispatcher =<br />

servletContext.getRequestDispatcher(jsp);<br />

try<br />

{<br />

dispatcher.forward(request, response);<br />

}<br />

catch(ServletException ex)<br />

{<br />

// log exception to servlet log<br />

servletContext.log("Exception routing to jsp: " + ex);<br />

}<br />

Figure B-10 Routing to a JSP<br />

We get the ServletContext object that represents the current request and<br />

response. We then get the RequestDispatcher object for the selected JSP from<br />

the ServletContext. <strong>The</strong> forward() method is called on the RequestDispatcher,<br />

passing in the HttpRequest and HttpResponse. This causes the request to be<br />

forwarded to the JSP, along with the objects representing the session. <strong>The</strong> JSP<br />

will then generate the response HTML.<br />

<strong>The</strong> other method in our servlet is byteArrayToHex(), which takes a byte array<br />

and converts it to a String showing the array data in a hexadecimal form.<br />

Appendix B. Sample applications 347

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!