The Application Tier
Multitier application interactions usually consist of an HTTP-based request passed from a client to an HTTP server that executes business-domain logic. The server formats the response from the business-logic object into some type of markup language (HTML, WML, XML, etc.) and passes that back to the client. The model-view-controller (MVC) pattern often embodies the interaction.
Using the MVC pattern to encapsulate client/server interactions helps to illustrate software-pattern roles as well as developer roles by separating object, components, and services into tiers with well-defined boundaries. Other benefits derived from this pattern include the ability to easily maintain, manage, and extend the system; more easily support multiple client devices; simplify testing procedures; and reduce code duplication.
The Client Tier
At this point, you can assume that the client tier handles only standard HTTP requests from a Web browser. Therefore, the FrontController class handles each request/response in a simple model-view-controller manner. However, the framework will eventually be modified to support a push-styled, event-driven model, which will make the framework more responsive and dynamic.
The FrontController class is defined as follows:
public class FrontController extends HttpServlet
{
public void init(ServletConfig servletConfig)
throws ServletException
{
super.init(servletConfig);
}
protected void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
doGet(req, res);
}
protected void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
try
{
Model model = RequestProcessor.getInstance().
processRequest(req);
// view type should be matched to request
// type using config file
String formatted =
XSLViewFactory.getView(View.DEFAULT_VIEW).
format(model.toXML());
PrintWriter out = res.getWriter();
out.println(formatted);
out.flush();
out.close();
}
catch (RequestException e)
{
PrintWriter out = res.getWriter();
out.println(
"<H2>Error: " + e.toString() + "</H2>");
out.flush();
out.close();
}
}
}
This article is the first of a two-part series discussing how to refactor a mainframe application using service-oriented techniques into deployable Web services within a standard Java servlet framework. This first part discussed how to apply SOA to a mainframe-dependent system. The second part discusses how to enable the framework to use XMLHttpRequest background requests from a browser to invoke the Web services and provide data directly to the client application rather than screen-scraping and reformatting to provide data to a desktop application.