364 CHAPTER 11 (Cheapest web hosting) REST-BASED MODEL VIEW CONTROLLER

364 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN out.println( “” + result.getURL() + ““); out.println( “” + result.getTitle() + ““); out.println( ““); out.println( ““); } } return; } In the implementation of doGet, the first step is to retrieve the session by using getSession, which is then used to retrieve the AsynchronousParent instance by using getAttribute. The return value of getAttribute is assigned to an Object type because if the value of objis null and a typecast is attempted, an exception will arise. If the value of obj is not null, it is possible to perform a typecast to AsynchronousParent. The cast value is assigned to parent, which retrieves a value by using the method getResult. If there is a result, the retrieved value will be non-null, allowing the appropriate XML content to be generated. Notice how the query identifier is assigned to an HTTP header, which the client will need to process. Based on the query identifier, the client would know whether the result is stale or to which query the result belongs. If the result is valid, it can be manipulated by the client and transformed to HTML or parsed to fill some HTML. Handling a Synchronous Search The other way of calling the REST-Based Model View Controller pattern implementation is to use the synchronous interface. A web browser, HTTP client, or even another REST-Based Model View Controller pattern implementation can call the synchronous interface. As the synchronous interface is a standard HTTP GET, the Permutations pattern is applicable. Implementing the Servlet-Based Permutations Pattern In the Permutations pattern, the example illustrated how to implement the pattern by using an HTTP filter or module. The Permutations pattern is implemented in the Java servlet or ASP.NET handler to reduce the number of redirections. However, when a Java servlet or ASP.NET handler implements the Permutations pattern, an object redirection (instead of a URL redirection or rewriting) occurs. The object redirection is illustrated in Figure 11-9. In Figure 11-9, the Handler class receives an HTTP request. In the implementation of the method doGet, the Permutations pattern is implemented. The URL along with the HTTP headers would be read in the doGet method. Like the original Permutations pattern, the acceptable types would be iterated for which a new URL could be rewritten or redirected to. In this imple mentation of the Permutations pattern, the acceptable types would be iterated and matched to an object instance that could process the acceptable type. The object instances implement the Representation interface. For Handler, there are two appropriate Representations: XML and HTML. The cross-referencing of the acceptable type and object instance is based on the getType method that returns the MIME type that it can process. The idea of the outlined architecture is to mimic a redirection infrastructure of Java Servlet or ASP.NET handlers.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Leave a Reply