Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/enhydra/httpServerTest/server/application/presentation/RequestDispatchForwardTest.java


1   /*
2    * Enhydra Java Application Server Project
3    * 
4    * The contents of this file are subject to the Enhydra Public License
5    * Version 1.1 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License on
7    * the Enhydra web site ( http://www.enhydra.org/ ).
8    * 
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
11   * the License for the specific terms governing rights and limitations
12   * under the License.
13   * 
14   * The Initial Developer of the Enhydra Application Server is Lutris
15   * Technologies, Inc. The Enhydra Application Server and portions created
16   * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17   * All Rights Reserved.
18   * 
19   * Contributor(s):
20   * 
21   * $Id: RequestDispatchForwardTest.java,v 1.1.2.1.2.1 2000/10/19 17:59:08 jasona Exp $
22   */
23  
24  package org.enhydra.httpServerTest.server.application.presentation;
25  
26  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
27  
28  import com.lutris.appserver.server.httpPresentation.HttpPresentation;
29  import com.lutris.appserver.server.httpPresentation.HttpPresentationRequest;
30  import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
31  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
32  
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  import javax.servlet.RequestDispatcher;
36  
37  /**
38   * This class is the generic server side test presentation object that client
39   * side test threads talk to.  The purpose of this presentation object is to 
40   * test the RequestDispatcher.  All this class does is to forward all requests
41   * to the BasicTest.po.  In doing so, the client will verify that no request
42   * information was lost.
43   *
44   * @see org.enhydra.httpServerTest.server.application.presentation.BasicTest
45   *
46   * @author Mike Ward
47   **/
48  public class RequestDispatchForwardTest
49      implements HttpPresentation {
50  
51      public static final String REDIRECT_TO_FILE = "BasicTest.po";
52      /**
53       * The run method for this presentation object.  This method grabs a 
54       * reference to the RequestDispatcher and forwards the current request onto
55       * BasicTest.po.
56       *
57       * @param comms
58       *        The comms objects for this request.  All request, response,
59       *        and session information are available from this object.
60       **/
61      public void run(HttpPresentationComms comms) 
62          throws HttpPresentationException {
63  
64    HttpServletRequest request = 
65        comms.request.getHttpServletRequest();
66    HttpServletResponse response = 
67        comms.response.getHttpServletResponse();
68    
69    //Grab any cgi parameters held in path info
70    String pathInfo = request.getPathInfo();
71    String redirectURL = REDIRECT_TO_FILE;
72    if (pathInfo != null) {
73        int cgiParamIndex = pathInfo.indexOf(';');
74        if (cgiParamIndex >= 0) {
75      redirectURL += pathInfo.substring(cgiParamIndex);
76        }
77    }     
78  
79    RequestDispatcher dispatcher = 
80        request.getRequestDispatcher(redirectURL);
81    
82    try {
83        dispatcher.forward(request, response);
84    } catch (Exception e) {
85        throw new HttpPresentationException("Failed to dispatch request.",
86              e);
87    }
88      }
89  }