KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > appclient > jws > JWSAdHocServletRequestWrapper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.appclient.jws;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
28
29 /**
30  *Wrapper around HttpServletRequest used for forwarding requests for the
31  *initial JNLP document for an app client - which arrives at the ad hoc
32  *servlet - off to the system servlet for processing.
33  *
34  * @author tjquinn
35  */

36 public class JWSAdHocServletRequestWrapper extends HttpServletRequestWrapper JavaDoc {
37     
38     private String JavaDoc adjustedPathInfo;
39     
40     /** Creates a new instance of AdHocServletRequestWrapper */
41     public JWSAdHocServletRequestWrapper(HttpServletRequest JavaDoc request, String JavaDoc contextRoot, String JavaDoc category) {
42         super(request);
43         setUserInfo(contextRoot, category);
44     }
45     
46     private void setUserInfo(String JavaDoc contextRoot, String JavaDoc category) {
47
48         adjustedPathInfo = "/" + removeLeadingSlash(category) + "/" + removeLeadingSlash(contextRoot);
49     }
50     
51     /**
52      *Returns the adjusted path information for use in the system web app.
53      *@return path info reflecting the request category (appclient or application)
54      *and the context root indicating which app client is of interest
55      */

56     public String JavaDoc getPathInfo() {
57         return adjustedPathInfo;
58     }
59     
60     /**
61      *Removes any leading slash from the path segment.
62      *@param path the path from which to remove any leading slash
63      *@return the path with any leading slash removed
64      */

65     private String JavaDoc removeLeadingSlash(String JavaDoc path) {
66         String JavaDoc result = null;
67         /*
68          *Exclude a slash at the beginning of the context root.
69          */

70         int slash = path.indexOf("/");
71         if (slash == 0 && path.length() > 1) {
72             result = path.substring(1);
73         } else {
74             result = path;
75         }
76         return result;
77     }
78 }
79
Popular Tags