Re: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
On Sat, 2 Mar 2003 [EMAIL PROTECTED] wrote: Date: 2 Mar 2003 00:22:40 - From: [EMAIL PROTECTED] Reply-To: Struts Developers List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: cvs commit: jakarta-struts/src/share/org/apache/struts/util RequestUtils.java dgraham 2003/03/01 16:22:40 Modified:src/share/org/apache/struts/util RequestUtils.java Log: Change encodeURL to not use reflection on every call. Note that this change imposes a 1.4 dependency to build Struts. That would be OK with *me* (since I use 1.4 all the time), but may not be OK with other folks. Craig Revision ChangesPath 1.91 +26 -15 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.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- RequestUtils.java 26 Feb 2003 04:48:56 - 1.90 +++ RequestUtils.java 2 Mar 2003 00:22:40 - 1.91 @@ -142,6 +142,24 @@ * The context attribute under which we store our prefixes list. */ private static final String PREFIXES_KEY = org.apache.struts.util.PREFIXES; + +/** + * Java 1.4 encode method to use instead of deprecated 1.3 version. + */ +private static Method encode = null; + +/** + * Initialize the encode variable with the 1.4 method if available + */ +static { +try { +// get version of encode method with two String args +Class[] args = new Class[] { String.class, String.class }; +encode = URLEncoder.class.getMethod(encode, args); +} catch (NoSuchMethodException e) { +log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); +} +} // - Public Methods @@ -1904,27 +1922,20 @@ * @return String - the encoded url. */ public static String encodeURL(String url) { -// default to old version -String encodedURL = URLEncoder.encode(url); -Class encoderClass = URLEncoder.class; - try { -// get version of encode method with two String args -Class[] args = new Class[] { String.class, String.class }; -Method encode = encoderClass.getMethod(encode, args); // encode url with new 1.4 method and UTF-8 encoding -encodedURL = (String) encode.invoke(null, new Object[] { url, UTF-8 }); +if (encode != null) { +return (String) encode.invoke(null, new Object[] { url, UTF-8 }); +} } catch (IllegalAccessException e) { log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); } catch (InvocationTargetException e) { log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); -} catch (NoSuchMethodException e) { -log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); } -return encodedURL; +return URLEncoder.encode(url); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
How is it any different than the way it was implemented before? If it doesn't find the 1.4 method it uses the 1.3 method. David From: Craig R. McClanahan [EMAIL PROTECTED] Reply-To: Struts Developers List [EMAIL PROTECTED] To: Struts Developers List [EMAIL PROTECTED] Subject: Re: cvs commit: jakarta-struts/src/share/org/apache/struts/util RequestUtils.java Date: Sat, 1 Mar 2003 16:42:21 -0800 (PST) On Sat, 2 Mar 2003 [EMAIL PROTECTED] wrote: Date: 2 Mar 2003 00:22:40 - From: [EMAIL PROTECTED] Reply-To: Struts Developers List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: cvs commit: jakarta-struts/src/share/org/apache/struts/util RequestUtils.java dgraham 2003/03/01 16:22:40 Modified:src/share/org/apache/struts/util RequestUtils.java Log: Change encodeURL to not use reflection on every call. Note that this change imposes a 1.4 dependency to build Struts. That would be OK with *me* (since I use 1.4 all the time), but may not be OK with other folks. Craig Revision ChangesPath 1.91 +26 -15 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.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- RequestUtils.java 26 Feb 2003 04:48:56 - 1.90 +++ RequestUtils.java 2 Mar 2003 00:22:40 - 1.91 @@ -142,6 +142,24 @@ * The context attribute under which we store our prefixes list. */ private static final String PREFIXES_KEY = org.apache.struts.util.PREFIXES; + +/** + * Java 1.4 encode method to use instead of deprecated 1.3 version. + */ +private static Method encode = null; + +/** + * Initialize the encode variable with the 1.4 method if available + */ +static { +try { +// get version of encode method with two String args +Class[] args = new Class[] { String.class, String.class }; +encode = URLEncoder.class.getMethod(encode, args); +} catch (NoSuchMethodException e) { +log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); +} +} // - Public Methods @@ -1904,27 +1922,20 @@ * @return String - the encoded url. */ public static String encodeURL(String url) { -// default to old version -String encodedURL = URLEncoder.encode(url); -Class encoderClass = URLEncoder.class; - try { -// get version of encode method with two String args -Class[] args = new Class[] { String.class, String.class }; -Method encode = encoderClass.getMethod(encode, args); // encode url with new 1.4 method and UTF-8 encoding -encodedURL = (String) encode.invoke(null, new Object[] { url, UTF-8 }); +if (encode != null) { +return (String) encode.invoke(null, new Object[] { url, UTF-8 }); +} } catch (IllegalAccessException e) { log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); } catch (InvocationTargetException e) { log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); -} catch (NoSuchMethodException e) { -log.debug(Could not find Java 1.4 encode method. Using deprecated version., e); } -return encodedURL; +return URLEncoder.encode(url); } } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
On Fri, 1 Jun 2001, Deadman, Hal wrote: Does this change mean that there will be a link generated that looks like this: some.jsp?test=1amp;test=2 instead of some.jsp?test=1test=2 Yes, in the generated HTML code of the page (i.e. when you do a view source). If so, I don't think that will work. It doesn't work on Weblogic 6.0. Calling getParameterValues() only sees the first value. In my tests, both Netscape and IE would both send this hyperlink back in with a '' instead, so multiple parameter values would still be recognized in the usual way. Are there clients that don't do this? Hal Craig -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, June 01, 2001 4:22 PM To: [EMAIL PROTECTED] Subject: cvs commit: jakarta-struts/src/share/org/apache/struts/util RequestUtils.java craigmcc01/06/01 13:21:41 Modified:src/share/org/apache/struts/util Tag: STRUTS_1_0_BRANCH RequestUtils.java Log: Generate amp; instead of in request URIs so that the output is still legal XML syntax in the value returned by computeURL(). PR: Bugzilla #1938 Submitted by : Alessandro Vernet [EMAIL PROTECTED] (also supplied the patch - thanks!) Revision ChangesPath No revision No revision 1.14.2.2 +7 -7 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/Requ estUtils.java,v retrieving revision 1.14.2.1 retrieving revision 1.14.2.2 diff -u -r1.14.2.1 -r1.14.2.2 --- RequestUtils.java 2001/06/01 18:45:03 1.14.2.1 +++ RequestUtils.java 2001/06/01 20:21:40 1.14.2.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/Requ estUtils.java,v 1.14.2.1 2001/06/01 18:45:03 craigmcc Exp $ - * $Revision: 1.14.2.1 $ - * $Date: 2001/06/01 18:45:03 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/Requ estUtils.java,v 1.14.2.2 2001/06/01 20:21:40 craigmcc Exp $ + * $Revision: 1.14.2.2 $ + * $Date: 2001/06/01 20:21:40 $ * * * @@ -95,7 +95,7 @@ * in the Struts controller framework. * * @author Craig R. McClanahan - * @version $Revision: 1.14.2.1 $ $Date: 2001/06/01 18:45:03 $ + * @version $Revision: 1.14.2.2 $ $Date: 2001/06/01 20:21:40 $ */ public class RequestUtils { @@ -364,7 +364,7 @@ url.append('?'); question = true; } else -url.append(''); +url.append(amp;); url.append(URLEncoder.encode(key)); url.append('='); // Interpret null as no value } else if (value instanceof String) { @@ -372,7 +372,7 @@ url.append('?'); question = true; } else -url.append(''); +url.append(amp;); url.append(URLEncoder.encode(key)); url.append('='); url.append(URLEncoder.encode((String) value)); @@ -383,7 +383,7 @@ url.append('?'); question = true; } else -url.append(''); +url.append(amp;); url.append(URLEncoder.encode(key)); url.append('='); url.append(URLEncoder.encode(values[i]));
Re: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
On 11 May 2001 [EMAIL PROTECTED] wrote: mschachter01/05/11 15:33:38 Modified:src/share/org/apache/struts/action Action.java ActionServlet.java src/share/org/apache/struts/upload DiskMultipartRequestHandler.java src/share/org/apache/struts/util RequestUtils.java Added: src/share/org/apache/struts/upload MultipartRequestWrapper.java Log: - Added the MultipartRequestWrapper class, which is a class that implements HttpServletRequest and wraps a normal request. All normal HttpServletRequest methods will be called to the underlying request, except for methods involving parameters, which were over-ridden to provide a transparent way of accessing multipart elements. The version of the HttpServletRequest is Servlet 2.2, however the new methods from Servlet 2.3 are also included in this class with empty implementations so that Struts will build against the servlet 2.2 and 2.3 jars One thing to remember in 2.2 is that you cannot pass your wrapped request object to a RequestDispatcher.forward() or RequestDispatcher.include() call. In Tomcat 3.x, for example, you'd get a ClassCastException error if you tried to use this in an RD call. Craig
Re: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
At 03:44 PM 5/11/01, Craig R. McClanahan wrote: On 11 May 2001 [EMAIL PROTECTED] wrote: mschachter01/05/11 15:33:38 Modified:src/share/org/apache/struts/action Action.java ActionServlet.java src/share/org/apache/struts/upload DiskMultipartRequestHandler.java src/share/org/apache/struts/util RequestUtils.java Added: src/share/org/apache/struts/upload MultipartRequestWrapper.java Log: - Added the MultipartRequestWrapper class, which is a class that implements HttpServletRequest and wraps a normal request. All normal HttpServletRequest methods will be called to the underlying request, except for methods involving parameters, which were over-ridden to provide a transparent way of accessing multipart elements. The version of the HttpServletRequest is Servlet 2.2, however the new methods from Servlet 2.3 are also included in this class with empty implementations so that Struts will build against the servlet 2.2 and 2.3 jars One thing to remember in 2.2 is that you cannot pass your wrapped request object to a RequestDispatcher.forward() or RequestDispatcher.include() call. In Tomcat 3.x, for example, you'd get a ClassCastException error if you tried to use this in an RD call. You mean if I have an Action that is invoked via POST with a file upload, and I try to forward from there using mapping.findForward(nextAction), where the forward has redirect=false, this will fail? This would be very bad - in every case where we have a file upload, we subsequently forward to another action. Craig -- Martin Cooper
Re: cvs commit: jakarta-struts/src/share/org/apache/struts/utilRequestUtils.java
On Fri, 11 May 2001, Martin Cooper wrote: At 03:44 PM 5/11/01, Craig R. McClanahan wrote: On 11 May 2001 [EMAIL PROTECTED] wrote: mschachter01/05/11 15:33:38 Modified:src/share/org/apache/struts/action Action.java ActionServlet.java src/share/org/apache/struts/upload DiskMultipartRequestHandler.java src/share/org/apache/struts/util RequestUtils.java Added: src/share/org/apache/struts/upload MultipartRequestWrapper.java Log: - Added the MultipartRequestWrapper class, which is a class that implements HttpServletRequest and wraps a normal request. All normal HttpServletRequest methods will be called to the underlying request, except for methods involving parameters, which were over-ridden to provide a transparent way of accessing multipart elements. The version of the HttpServletRequest is Servlet 2.2, however the new methods from Servlet 2.3 are also included in this class with empty implementations so that Struts will build against the servlet 2.2 and 2.3 jars One thing to remember in 2.2 is that you cannot pass your wrapped request object to a RequestDispatcher.forward() or RequestDispatcher.include() call. In Tomcat 3.x, for example, you'd get a ClassCastException error if you tried to use this in an RD call. You mean if I have an Action that is invoked via POST with a file upload, and I try to forward from there using mapping.findForward(nextAction), where the forward has redirect=false, this will fail? This would be very bad - in every case where we have a file upload, we subsequently forward to another action. As long as you forward the *original* request object (and not the wrapper), you're fine. I'm fighting some security fires on Tomcat so I haven't had time to look deeply into what Michael is changing, but wanted to raise the flag in case some assumptions about this were being made incorrectly. Craig -- Martin Cooper Craig