IBM Tivoli Composite Application Manager for Application Diagnostics, Version 7.1.0.1

Sample Request Mapper - mapRequest

public MappedRequest mapRequest(    java.lang.String servletClassName,                
javax.servlet.http.HttpServletRequest request)

This stateless method translates a servlet classname and a URL into a MappedRequest object. Any RequestMapper class should attempt to execute this method as quickly as possible, due to the fact that it lies directly in the path of the application server thread execution.


Request Mapper Example (1):

package com.cyanea.mapper;
public class MappedRequestExample implements MappedRequest {
    private String CRS;
    private String DRS;
    /** Creates a new instance of MappedRequestExample */
    public MappedRequestExample(String myCRS,String myDRS) {
        CRS = myCRS;
        DRS = myDRS;
    }
    public String getCRS() {
        return CRS;
    }
    public String getDRS() {
        return DRS;
    }
}


Request Mapper Example (2):

package com.cyanea.mapper;
import javax.servlet.http.HttpServletRequest;
public class RequestMapperExample implements RequestMapper {    
    /** static MappedRequest instance for welcome page requests      */    
    private static final MappedRequest welcomeRequest;
    /** static MappedRequest instance for quote page requests      */    
    private static final MappedRequest quoteRequest;
    /** static MappedRequest instance for buy page requests      */    
    private static final MappedRequest buyRequest;
    /** static MappedRequest instance for sell page requests      */    
    private static final MappedRequest sellRequest;
    /** static MappedRequest instance for portfolio page requests      */    
    private static final MappedRequest portfolioRequest;
    /** static MappedRequest instance for account page requests      */    
    private static final MappedRequest accountRequest;
    /** static MappedRequest instance for update page requests      */    
    private static final MappedRequest updateRequest;
    /**
     * Static class variables are used to avoid continuous object creation
     * of redundant information on a per-client-request basis. An 
     * unsynchronized, read-only HashMap can also be used for looking up 
     * MappedRequest instances to gain a performance increase.
     **/
    static {
welcomeRequest   = new MappedRequestExample("Welcome Page","welcome");
quoteRequest     = new MappedRequestExample("quote","quote");
buyRequest       = new MappedRequestExample("trade","buy");
sellRequest      = new MappedRequestExample("trade","sell");
portfolioRequest = new MappedRequestExample("overview","portfolio");
accountRequest   = new MappedRequestExample("account","account");
updateRequest      = new MappedRequestExample("account","updateAccount");               
    }
    /** Creates a new instance of RequestMapperExample */
    public RequestMapperExample() {
    }        
    /** 
     * This example checks the HttpServletRequest object for the GET or POST 
     * parameter "map".  If the parameter "map" is not found, "action" is 
     * used. This "action" string, is then used to look up the corresponding 
     * MappedRequest object. If no MappedRequest object is found, a new 
     * object is created and returned.  This should be avoided, as it can be 
     * an expensive operation.
     */    
    public MappedRequest mapRequest(String servletClassName, 
HttpServletRequest request) {
        String action = request.getParameter("map");
            if ( action == null) {
                action = request.getParameter("action");
            if ( action == null )
                return welcomeRequest;
        }
        /* A HashMap lookup could also be performed here instead of iterating
         * a list of string comparisons.  If a list of strings comparison are
         * used, it is desirable to list the most common action first.
         */

        if ( "quote".equals(action) )
            return quoteRequest;
        else if ( "buy".equals(action) )
            return buyRequest;
        else if( "sell".equals(action) )
            return sellRequest;
        else if( "portfolio".equals(action) )
            return portfolioRequest;
        else if( "account".equals(action) )
            return accountRequest;
        else if( "updateAccount".equals(action) )
            return updateRequest;
        else 
            return new MappedRequestExample(action,action);
    }
    }


Parent topic:

Configure a Request Mapper

+

Search Tips   |   Advanced Search