Skip to content

Commit 496c63d

Browse files
committed
- Fixed bug processing redirects. Problem was in the request.getRequestURL() method when an app is hosted as the web root. Added new method to the Utils class to return the proper URL.
- Added exceptions to the Documentation class in case the caller requests a class that does not exist. git-svn-id: svn://192.168.0.80/JavaXT/javaxt-portal@193 2c7b0aa6-e0b2-3c4e-bb4a-8b65b6c465ff
1 parent 17f9369 commit 496c63d

File tree

3 files changed

+69
-11
lines changed

3 files changed

+69
-11
lines changed

src/javaxt/portal/Documentation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Documentation(String jar, javaxt.io.Directory dir, javax.servlet.http.Htt
6464
/** Used to construct an html fragment with a index of all the classes found
6565
* in the jar file.
6666
*/
67-
public String getIndex(String title){
67+
public String getIndex(String title) throws Exception {
6868

6969
StringBuffer str = new StringBuffer();
7070
boolean showIndex = true;
@@ -135,7 +135,7 @@ public String getIndex(String title){
135135
* <li> package: The name of the package (e.g. javaxt.io) </li>
136136
* <ul>
137137
*/
138-
public String getClassInfo(){
138+
public String getClassInfo() throws Exception {
139139

140140
//Parse QueryString Parameters
141141
String jarFile = request.getParameter("jar");
@@ -154,9 +154,10 @@ public String getClassInfo(){
154154
* @param className The name of the class (e.g. File)
155155
* @param packageName The name of the package (e.g. javaxt.io)
156156
*/
157-
public String getClassInfo(String className, String packageName){
157+
public String getClassInfo(String className, String packageName) throws Exception{
158158

159159
//Get class info
160+
160161
com.jeldoclet.Class theClass = parser.getPackage(packageName).getClass(className);
161162
com.jeldoclet.Method[] methods = theClass.getMethods();
162163
com.jeldoclet.Method[] constructors = theClass.getConstructors();

src/javaxt/portal/Redirects.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ private void parseRedirects(){
5252
}
5353

5454
public String getRedirect(javax.servlet.http.HttpServletRequest request){
55-
javaxt.utils.URL url = new javaxt.utils.URL(request.getRequestURL().toString());
56-
url.setQueryString(request.getQueryString());
57-
return getRedirect(url.toString());
55+
return getRedirect(Utils.getURL(request));
5856
}
5957

6058
public String getRedirect(javaxt.utils.URL url){

src/javaxt/portal/Utils.java

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ public class Utils {
1212

1313

1414
//**************************************************************************
15-
//** Constructor
15+
//** Private Constructor
1616
//**************************************************************************
17-
/** Creates a new instance of Utils. */
17+
/** Prevent users from instantiating this class. */
1818

19-
private Utils() {
20-
21-
}
19+
private Utils() {}
2220

2321

22+
//**************************************************************************
23+
//** getPath
24+
//**************************************************************************
25+
/** Returns the path to the app root.
26+
*/
2427
public static String getPath(javax.servlet.http.HttpServletRequest request){
2528

2629
String Path = request.getContextPath();
@@ -46,4 +49,60 @@ public static String getPath(javax.servlet.http.HttpServletRequest request){
4649

4750
}
4851

52+
53+
//**************************************************************************
54+
//** getURL
55+
//**************************************************************************
56+
/** Returns the url associated with a given request. Note that the standard
57+
* request.getRequestURL() method returns the ContextPath even when the
58+
* app is deployed as the default web application. For example, the "JavaXT"
59+
* web app is deployed as the default web app. When clients request
60+
* "http://www.javaxt.com" the request.getRequestURL() returns
61+
* "http://www.javaxt.com/JavaXT". This method will return the correct url,
62+
* namely "http://www.javaxt.com".
63+
*/
64+
public static javaxt.utils.URL getURL(javax.servlet.http.HttpServletRequest request){
65+
66+
67+
String protocol = request.getProtocol();
68+
if (protocol==null) protocol = "http";
69+
else{
70+
if (protocol.contains("/")) protocol = protocol.substring(0, protocol.indexOf("/"));
71+
protocol = protocol.toLowerCase();
72+
}
73+
74+
//Get Host
75+
String host = request.getServerName();
76+
77+
Integer port = request.getServerPort();
78+
if (port!=null && port>0 && port!=80) host += ":" + port;
79+
80+
//Get Path
81+
String path = request.getRequestURI();
82+
if (path==null) path = "";
83+
84+
//Update Path: Special case when app is deployed as root
85+
if (path.length()>0){
86+
if (Utils.getPath(request).equals("/")){
87+
String contextPath = request.getContextPath();
88+
if (path.startsWith(contextPath)){
89+
path = path.substring(contextPath.length());
90+
}
91+
}
92+
}
93+
94+
95+
96+
//Get Query String
97+
String query = request.getQueryString();
98+
if (query==null) query = "";
99+
if (query.length()>0) query = "?" + query;
100+
101+
102+
//Assemble URL
103+
String url = protocol + "://" + host + path + query;
104+
//System.out.println("\r\nURL: " + url + "\r\nPath: " + Utils.getPath(request));
105+
return new javaxt.utils.URL(url);
106+
}
107+
49108
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy