Restore former behavior of URL encoding [WAS: Re: new URLEncoder Service]

2008-11-07 Thread Martin Grotzke
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


Re: new URLEncoder Service

2008-10-29 Thread Thiago H. de Paula Figueiredo

Em Tue, 28 Oct 2008 19:54:21 -0300, Fernando Padilla [EMAIL PROTECTED]
escreveu:

Just wondering if Tapestry-IOC will ever support something like  
override of services ( like alias )?


It already does! The documentaton in T5's site is a little scarce and can
be found here: http://tapestry.apache.org/tapestry5/guide/alias.html.

One example, taken from Ulrich Stärk from this JIRA:  
https://issues.apache.org/jira/browse/TAP5-211?focusedCommentId=12643440#action_12643440


public static void  
contributeAliasOverrides(ConfigurationAliasContribution configuration,

@InjectService(LocalizedTranslatorSource)
LocalizedTranslatorSource localizedTranslatorSource)
{
configuration.add(AliasContribution.create(
TranslatorSource.class,
localizedTranslatorSource));
}

--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: new URLEncoder Service

2008-10-29 Thread Thiago H. de Paula Figueiredo

Em Wed, 29 Oct 2008 10:08:36 -0300, Thiago H. de Paula Figueiredo
[EMAIL PROTECTED] escreveu:


It already does! The documentaton in T5's site is a little scarce and can
be found here: http://tapestry.apache.org/tapestry5/guide/alias.html.


Well, not quite. Alias and AliasContribution are part of tapestry-core,
not tapestry-ioc. Howard, is there a reason the service alias and override
support is not in Tapestry-IoC?

--
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: new URLEncoder Service

2008-10-29 Thread Fernando Padilla

that's what I was talking about :)

And I was just wondering because we already have a mechanism to decorate 
a service (decorateService), and adding an overrideService syntax 
might be something to play with..


though as we've seen tapestry ioc contributions/configurations don't 
support overriding at all either, which is sad..


Thiago H. de Paula Figueiredo wrote:

Em Wed, 29 Oct 2008 10:08:36 -0300, Thiago H. de Paula Figueiredo
[EMAIL PROTECTED] escreveu:


It already does! The documentaton in T5's site is a little scarce and can
be found here: http://tapestry.apache.org/tapestry5/guide/alias.html.


Well, not quite. Alias and AliasContribution are part of tapestry-core,
not tapestry-ioc. Howard, is there a reason the service alias and override
support is not in Tapestry-IoC?



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



new URLEncoder Service

2008-10-28 Thread jthompson209

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]



Re: new URLEncoder Service

2008-10-28 Thread Howard Lewis Ship
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]





-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: new URLEncoder Service

2008-10-28 Thread jthompson209

yes thanks for the response,

the problem i am having is, i wrote some code to do a zone update from a
text field 'onKeyup' event using the T5-Components mixin OnEvent

and in the javascript they use to make the ajax call they are not encoding
the context data, so when the URLEncoder goes to decode it breaks on strings
with any character that isnt in the SAFE character array defined in
URLEncoderImpl

hope this description helps
-jeff



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]


 
 
 
 -- 
 Howard M. Lewis Ship
 
 Creator Apache Tapestry and Apache HiveMind
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://n2.nabble.com/new-URLEncoder-Service-tp1389907p1391065.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]



Re: new URLEncoder Service

2008-10-28 Thread Fernando Padilla
Just wondering if Tapestry-IOC will ever support something like 
override of services ( like alias )?



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]








-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]