craigmcc 01/05/02 20:29:39
Modified: src/share/org/apache/struts/taglib/bean IncludeTag.java
LocalStrings.properties
src/share/org/apache/struts/taglib/html LinkTag.java
LocalStrings.properties
src/share/org/apache/struts/taglib/logic
LocalStrings.properties RedirectTag.java
src/share/org/apache/struts/util RequestUtils.java
Log:
Modify RequestUtils.absoluteURL() to throw a MalformedURLException if one is
encountered while trying to reconstruct a URL from the specified page context
and context-relative path. This will cause tags like <html:link>,
<bean:include>, and <logic:redirect> to throw an exception instead of create
null URLs. In addition, these three tags will log the exception to the servlet
context's log to facilitate further analysis.
These changes are in direct response to Bugzilla #1586, where the main page
of the example application creates bogus hyperlinks that look like this:
<a>Log on to the MailReader Demonstration Application</a>
I suspect that this is due to misconfiguration of the servlet container
being used (WebSphere in the case of the bug report). Throwing the exception,
and logging the details, will prove it one way or the other.
Revision Changes Path
1.11 +41 -4
jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTag.java
Index: IncludeTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/IncludeTag.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- IncludeTag.java 2001/02/12 01:26:57 1.10
+++ IncludeTag.java 2001/05/03 03:29:36 1.11
@@ -1,5 +1,5 @@
/*
- * $Id: IncludeTag.java,v 1.10 2001/02/12 01:26:57 craigmcc Exp $
+ * $Id: IncludeTag.java,v 1.11 2001/05/03 03:29:36 craigmcc Exp $
* ====================================================================
*
* The Apache Software License, Version 1.1
@@ -66,6 +66,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
@@ -89,7 +90,7 @@
* wrapped response passed to RequestDispatcher.include().
*
* @author Craig R. McClanahan
- * @version $Revision: 1.10 $ $Date: 2001/02/12 01:26:57 $
+ * @version $Revision: 1.11 $ $Date: 2001/05/03 03:29:36 $
*/
public class IncludeTag extends TagSupport {
@@ -301,14 +302,50 @@
}
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, forward.getPath());
+ try {
+ href = RequestUtils.absoluteURL(request, forward.getPath());
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("include.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("include.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()));
+ throw e;
+ }
} else if (this.href != null) {
href = this.href;
includeSession = false;
} else /* if (this.page != null) */ {
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, this.page);
+ try {
+ href = RequestUtils.absoluteURL(request, this.page);
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("include.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ this.page),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("include.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ this.page));
+ throw e;
+ }
}
// Append the session identifier if appropriate
1.11 +1 -0
jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/bean/LocalStrings.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- LocalStrings.properties 2001/02/13 01:56:06 1.10
+++ LocalStrings.properties 2001/05/03 03:29:36 1.11
@@ -6,6 +6,7 @@
include.malformed=Cannot create URL for {0}
include.open=Exception opening resource {0}: {1}
include.read=Exception reading resource {0}: {1}
+include.url=Cannot create URL with scheme={0} server={1} port={2} path={3}
message.message=Missing message for key {0}
message.resources=Missing resources attribute {0}
page.selector=Invalid page context selector {0}
1.12 +44 -6
jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java
Index: LinkTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- LinkTag.java 2001/05/03 01:13:54 1.11
+++ LinkTag.java 2001/05/03 03:29:36 1.12
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v 1.11
2001/05/03 01:13:54 craigmcc Exp $
- * $Revision: 1.11 $
- * $Date: 2001/05/03 01:13:54 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LinkTag.java,v 1.12
2001/05/03 03:29:36 craigmcc Exp $
+ * $Revision: 1.12 $
+ * $Date: 2001/05/03 03:29:36 $
*
* ====================================================================
*
@@ -65,9 +65,11 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -86,7 +88,7 @@
* Generate a URL-encoded hyperlink to the specified URI.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.11 $ $Date: 2001/05/03 01:13:54 $
+ * @version $Revision: 1.12 $ $Date: 2001/05/03 03:29:36 $
*/
public class LinkTag extends BaseHandlerTag {
@@ -477,7 +479,25 @@
}
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, forward.getPath());
+ try {
+ href = RequestUtils.absoluteURL(request, forward.getPath());
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("linkTag.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("linkTag.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()));
+ throw e;
+ }
}
// If "linkName" was specified, return null (not making an href)
@@ -489,7 +509,25 @@
else if (page != null) {
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, page);
+ try {
+ href = RequestUtils.absoluteURL(request, page);
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("linkTag.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ page),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("linkTag.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ page));
+ throw e;
+ }
}
// Save any currently specified anchor string
1.8 +1 -0
jakarta-struts/src/share/org/apache/struts/taglib/html/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/LocalStrings.properties,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- LocalStrings.properties 2001/02/20 05:20:09 1.7
+++ LocalStrings.properties 2001/05/03 03:29:37 1.8
@@ -27,6 +27,7 @@
linkTag.forwards=Cannot locate forwards mapping table
linkTag.type=Object must be of type Map
linkTag.type1=Object must be of type Dictionary
+linkTag.url=Cannot create URL with scheme={0} server={1} port={2} path={3}
messageTag.message=Missing message for key {0}
messageTag.resources=Missing resources attribute {0}
multiboxTag.value=You must specify the value attribute or nested tag content
1.5 +1 -0
jakarta-struts/src/share/org/apache/struts/taglib/logic/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/LocalStrings.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LocalStrings.properties 2001/02/12 21:49:57 1.4
+++ LocalStrings.properties 2001/05/03 03:29:37 1.5
@@ -11,3 +11,4 @@
redirect.forward=Missing ActionForward for {0}
redirect.forwards=Missing ActionForwards collection
redirect.map=Property {0} of bean {1} is not a Map
+redirect.url=Cannot create URL with scheme={0} server={1} port={2} path={3}
1.8 +44 -6
jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java
Index: RedirectTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- RedirectTag.java 2001/04/03 18:06:23 1.7
+++ RedirectTag.java 2001/05/03 03:29:38 1.8
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v
1.7 2001/04/03 18:06:23 craigmcc Exp $
- * $Revision: 1.7 $
- * $Date: 2001/04/03 18:06:23 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/RedirectTag.java,v
1.8 2001/05/03 03:29:38 craigmcc Exp $
+ * $Revision: 1.8 $
+ * $Date: 2001/05/03 03:29:38 $
*
* ====================================================================
*
@@ -64,9 +64,11 @@
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
+import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
@@ -86,7 +88,7 @@
* Generate a URL-encoded redirect to the specified URI.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.7 $ $Date: 2001/04/03 18:06:23 $
+ * @version $Revision: 1.8 $ $Date: 2001/05/03 03:29:38 $
*/
public class RedirectTag extends TagSupport {
@@ -358,14 +360,50 @@
}
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, forward.getPath());
+ try {
+ href = RequestUtils.absoluteURL(request, forward.getPath());
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("redirect.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("redirect.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ forward.getPath()));
+ throw e;
+ }
}
// If "page" was specified, compute the "href" to forward to
else if (page != null) {
HttpServletRequest request =
(HttpServletRequest) pageContext.getRequest();
- href = RequestUtils.absoluteURL(request, page);
+ try {
+ href = RequestUtils.absoluteURL(request, page);
+ } catch (MalformedURLException mue) {
+ RequestUtils.saveException(pageContext, mue);
+ ServletContext sc = pageContext.getServletContext();
+ sc.log(messages.getMessage("redirect.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ page),
+ mue);
+ JspException e = new JspException
+ (messages.getMessage("redirect.url",
+ request.getScheme(),
+ request.getServerName(),
+ "" + request.getServerPort(),
+ page));
+ throw e;
+ }
}
// Append a single-parameter name and value, if requested
1.10 +15 -16
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- RequestUtils.java 2001/04/18 23:32:35 1.9
+++ RequestUtils.java 2001/05/03 03:29:38 1.10
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.9
2001/04/18 23:32:35 craigmcc Exp $
- * $Revision: 1.9 $
- * $Date: 2001/04/18 23:32:35 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.10
2001/05/03 03:29:38 craigmcc Exp $
+ * $Revision: 1.10 $
+ * $Date: 2001/05/03 03:29:38 $
*
* ====================================================================
*
@@ -89,7 +89,7 @@
* in the Struts controller framework.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.9 $ $Date: 2001/04/18 23:32:35 $
+ * @version $Revision: 1.10 $ $Date: 2001/05/03 03:29:38 $
*/
public class RequestUtils {
@@ -123,25 +123,24 @@
*
* @param request The servlet request we are processing
* @param path The context-relative path (must start with '/')
+ *
+ * @exception MalformedURLException if we cannot create an absolute URL
*/
- public static String absoluteURL(HttpServletRequest request, String path) {
+ public static String absoluteURL(HttpServletRequest request, String path)
+ throws MalformedURLException {
URL url = null;
int port = request.getServerPort();
String scheme = request.getScheme();
String serverName = request.getServerName();
String uri = request.getContextPath() + path;
- try {
- if ("http".equals(scheme) && (80 == port))
- url = new URL(scheme, serverName, uri);
- else if ("https".equals(scheme) && (443 == port))
- url = new URL(scheme, serverName, uri);
- else
- url = new URL(scheme, serverName, port, uri);
- return (url.toString());
- } catch (MalformedURLException e) {
- return (null);
- }
+ if ("http".equals(scheme) && (80 == port))
+ url = new URL(scheme, serverName, uri);
+ else if ("https".equals(scheme) && (443 == port))
+ url = new URL(scheme, serverName, uri);
+ else
+ url = new URL(scheme, serverName, port, uri);
+ return (url.toString());
}