Hi, I also want to keep the former behavior of URL encoding but have issues with form submissions.
For keeping the former behavior I added a custom URLEncoder service
which does mostly what was before done in TapestryInternalUtils (see the
code at the end of the post).
However, when I do a form submission containing special chars (like
german umlauts), they are decoded wrong. We're using UTF-8, and have
configured UTF-8 support in our AppModule (Utf8Filter).
AFAICS RequestImpl.getParameter already returns the wrong parameter
value when the form input fields are processed.
Can anybody help with this issue?
Thx && cheers,
Martin
public class UrlEncoderImpl implements URLEncoder {
private final static URLCodec CODEC = new URLCodec();
private static final String PERCENT = "%";
private static final Pattern PERCENT_PATTERN = Pattern.compile(PERCENT);
private static final String ENCODED_PERCENT = "%25";
private static final Pattern ENCODED_PERCENT_PATTERN =
Pattern.compile(ENCODED_PERCENT);
private static final String SLASH = "/";
private static final Pattern SLASH_PATTERN = Pattern.compile(SLASH);
// just a special char that denotes the slash, to circumvent issues with
mod_jk
private static final String ENCODED_SLASH = "172";
private static final Pattern ENCODED_SLASH_PATTERN =
Pattern.compile(ENCODED_SLASH, Pattern.CASE_INSENSITIVE);
/* (non-Javadoc)
* @see org.apache.tapestry5.services.URLEncoder#decode(java.lang.String)
*/
public String decode( String input ) {
return unescapePercentAndSlash( input );
}
/* (non-Javadoc)
* @see org.apache.tapestry5.services.URLEncoder#encode(java.lang.String)
*/
public String encode( String input ) {
try {
return CODEC.encode( escapePercentAndSlash(input) );
} catch ( EncoderException e ) {
throw new RuntimeException( e );
}
}
/**
* Encodes percent and slash characters in the string for later decoding
via [EMAIL PROTECTED]
* #unescapePercentAndSlash(String)}.
*
* @param input string to encode
* @return modified string
*/
public static String escapePercentAndSlash(String input) {
return replace(replace(input, PERCENT_PATTERN, ENCODED_PERCENT),
SLASH_PATTERN, ENCODED_SLASH);
}
/**
* Used to decode certain escaped characters that are replaced when using
[EMAIL PROTECTED] #encodeContext(String)}}.
*
* @param input a previously encoded string
* @return the string with slash and percent characters restored
*/
public static String unescapePercentAndSlash(String input) {
return replace( replace( input, ENCODED_SLASH_PATTERN, SLASH ),
ENCODED_PERCENT_PATTERN, PERCENT );
}
private static String replace( String input, Pattern pattern, String
replacement ) {
return pattern.matcher(input).replaceAll(replacement);
}
public static void main( String[] args ) {
print( "foo/bar test" );
print( "tästumlaut" );
}
private static void print( final String uri ) {
System.out.println( "encoded: " + new UrlEncoderImpl().encode( uri ) );
System.out.println( "decoded: " + new UrlEncoderImpl().decode( new
UrlEncoderImpl().encode( uri ) ) );
}
}
On Tue, 2008-10-28 at 15:39 -0700, Howard Lewis Ship wrote:
> Contribute a new implementation of URLEncoder to the Alias service
> configuration and Tapestry will use the contributed one instead of the
> default URLEncoder service.
>
> Alternately, you can decorate the URLEncoder service with an
> alternative implementation, or a filter depending on how much of the
> existing URLEncoder service implementation you want to keep.
>
> Could you provide some more context as to why URLEncoder is a problem?
>
> On Tue, Oct 28, 2008 at 11:39 AM, jthompson209 <[EMAIL PROTECTED]> wrote:
> >
> > Hello I am in need of either turning off this new service or overriding it
> > and having it do nothing, it is currently breaking some code that I have,
> > what would be the best way of doing that, also if overriding it is the
> > answer how would i go about doing it.
> >
> > thanks so much
> > -jeff
> > --
> > View this message in context:
> > http://n2.nabble.com/new-URLEncoder-Service-tp1389907p1389907.html
> > Sent from the Tapestry Users mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
signature.asc
Description: This is a digitally signed message part
