Web hosting rating - 362 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER
362 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN The configuration of the SearchBuilderclass is relatively simple. The initmethod is over ridden, and the configuration values are retrieved from the configuration file associated with the web application. In the Architecture section of this chapter, the asynchronous interface implements the Persistent Communications pattern, and implements the HTTP GET and HTTP POST, which in Java Servletspeak means to implement the doPost and doGet methods. Following is the imple mentation of the doPost method: protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { HttpSession session = request.getSession( true); AsynchronousParent parent = null; if( session.isNew()) { parent = new AsynchronousParent(); session.setAttribute( “parent”, parent); } else { parent = (AsynchronousParent)session.getAttribute( “parent”); } String value = request.getParameter( “query”); String queryIdentifier = request.getHeader( “X-query-identifier”); if( value != null && value.length() > 0) { synchronized( parent) { SearchBuilder.buildCommands( parent); parent.processRequest( new SearchRequest(queryIdentifier, value)); } response.setContentType( “text/xml”); PrintWriter out = response.getWriter(); out.println( “
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.