org.utgenome.gwt.utgb.server
Class RequestDispatcher

java.lang.Object
  extended by org.utgenome.gwt.utgb.server.RequestDispatcher
All Implemented Interfaces:
javax.servlet.Filter

public class RequestDispatcher
extends Object
implements javax.servlet.Filter

RequestDispatcher dispatches HTTP GET/POST request to appropriate action handlers. see also http://trac.utgenome.org/project/UTGB/wiki/UTGBCore/RequestDispatcher

UTGB Request Dispatcher Mechanism

web.xml setting

Add the following description into your web.xml.
  • The lines param-name=base-package, param-value=(application base) specifies the location (base package name) where the RequestDispatcher? searches recursively for RequestHandler? implementations.
  • With the following setting, an HTTP request, e.g., http://localhost:8989/hello.action, is mapped to the request handler org.utgenome.gwt.utgb.server.app.Hello class. The upper letters are converted into the lower letters when mapping the request, e.g., Hello action can be accecced via hello.action URL.
  • Another example using hierarchies of actions: http://localhost:8989/admin/login.action is mapped to org.utgenome.gwt.utgb.server.Login class.
      <servlet>
      <servlet-name>dispatcher</servlet-name>
      <servlet-class>org.utgenome.gwt.utgb.server.RequestDispatcher</servlet-class>
      <init-param>
      <param-name>base-package</param-name>
      <param-value>(your web application request handler base package. e.g. org.utgenome.gwt.utgb.server.app)</param-value>
      </init-param>
      </servlet>
     
      <servlet-mapping>
      <servlet-name>dispatcher</servlet-name>
      <url-pattern>*.action</url-pattern>
      </servlet-mapping>
     

    Automatic Data Binding to Request Handler

    Hello.java class has serveral parameter values name and year:
     public class Hello implements RequestHandler {
            private String name = "";
            private int year = 2000;
     
            public void handle(HttpServletRequest request, HttpServletResponse response) {
                    PrintWriter out = response.getWriter().println("Hello " + name + "(" + year + ")");
            }
     
            public void setName(String name) {
                    this.name = name;
            }
     
            public void setYear(int year) {
                    this.year = year;
            }
     }
     
    Our RequestDispatcher automatically set these parameter values from a given HTTP request. For example, an HTTP request http://localhost:8989/hello.action?name=leo&year=2007 will invoke setName("leo") and setYear(2007) methods. Note that, although the query string in the HTTP request consists of string values, our BeanUtil library detects the data type to which the string should be translated by analysing the class definition. In this example, the string value "2007" is translated into an integer, 2007. The web page result of the avobe request looks like as this:
      Hello leo(2007)
     
    Alternate access method: http://localhost:8989/dispathcer?actionClass=org.utgenome .gwt.utgb.server.app.hello&

    Author:
    leo

    Constructor Summary
    RequestDispatcher()
               
     
    Method Summary
     void addRequestMap(RequestMap map)
               
     void destroy()
               
     void dispatchRequest(RequestURI requestURI, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, javax.servlet.FilterChain filterChain)
               
     void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain)
               
    static String getExtension(String path)
               
     void init(javax.servlet.FilterConfig config)
               
     void initRequestMap()
               
    static boolean isGWTHostedMode()
               
    static String removeGWTModuleNamePart(String requestURI)
               
    static void setRequestParametersToHandler(RequestHandler handler, javax.servlet.http.HttpServletRequest req)
               
    static String toInternetDateFormat(long time)
              Converts a file-style date/time into a string form that is compatible with HTTP.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    RequestDispatcher

    public RequestDispatcher()
    Method Detail

    removeGWTModuleNamePart

    public static String removeGWTModuleNamePart(String requestURI)

    setRequestParametersToHandler

    public static void setRequestParametersToHandler(RequestHandler handler,
                                                     javax.servlet.http.HttpServletRequest req)

    destroy

    public void destroy()
    Specified by:
    destroy in interface javax.servlet.Filter

    getExtension

    public static String getExtension(String path)

    doFilter

    public void doFilter(javax.servlet.ServletRequest request,
                         javax.servlet.ServletResponse response,
                         javax.servlet.FilterChain filterChain)
                  throws IOException,
                         javax.servlet.ServletException
    Specified by:
    doFilter in interface javax.servlet.Filter
    Throws:
    IOException
    javax.servlet.ServletException

    dispatchRequest

    public void dispatchRequest(RequestURI requestURI,
                                javax.servlet.http.HttpServletRequest req,
                                javax.servlet.http.HttpServletResponse resp,
                                javax.servlet.FilterChain filterChain)
                         throws IOException,
                                javax.servlet.ServletException
    Throws:
    IOException
    javax.servlet.ServletException

    toInternetDateFormat

    public static String toInternetDateFormat(long time)
    Converts a file-style date/time into a string form that is compatible with HTTP.


    isGWTHostedMode

    public static boolean isGWTHostedMode()

    init

    public void init(javax.servlet.FilterConfig config)
              throws javax.servlet.ServletException
    Specified by:
    init in interface javax.servlet.Filter
    Throws:
    javax.servlet.ServletException

    initRequestMap

    public void initRequestMap()

    addRequestMap

    public void addRequestMap(RequestMap map)


    Copyright © 2007-2012 utgenome.org. All Rights Reserved.