You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Boehler, Tim" <Ti...@eberspaecher.com> on 2013/10/11 15:37:01 UTC
ActivationRequestParameter and URLEncoder
Hi,
I have set up a ServiceOverride for the URLEncoder.class as I want to use standard % encoding. I am now using code from org.springframework.web.util.UriUtils in the decode and encode methods of my URLEncoderOverrideImpl.class. This all seems to work very well, except for a searchpage where I have a form input and an ActivationRequestParameter:
@Property
@Persist
@ActivationRequestParameter(value = "s")
private String searchQuery;
When I call http://example.com/search and then submit a querystring like %query, I receive the following exception: Invalid encoded sequence "%query" from my decode method.
I pointed the debugger to org.apache.tapestry5.internal.transform.ActivationRequestParameterWorker, after submitting the form it calls
1. setValueFromInitializeEventHandler() -> clientValue is null, since there is no parameter s yet
2. decorateLinks() -> value is now "%query" -> clientValue gets encoded to "%25query"
3. setValueFromInitializeEventHandler() -> clientValue is again "%query", which then leads to the exception when trying to decode it
Why is the clientValue in 3. "%query" and not "%25query"? When I switch back to the original URLEncoder the clientValue in 3. is always encoded "$0025query"
This is my Encoder Class:
import java.io.UnsupportedEncodingException;
import org.apache.tapestry5.services.URLEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.web.util.UriUtils;
public class URLEncoderOverrideImpl implements URLEncoder
{
private final static Logger LOG = LoggerFactory.getLogger(URLEncoder.class);
@Override
public String encode(String input)
{
String output;
try
{
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(input).build();
output = uriComponents.encode().toUriString();
}
catch (IllegalArgumentException e)
{
// input is not a valid http url
LOG.info("[" + input + "] is not a valid HTTP URL");
try
{
output = UriUtils.encodeQuery(input, "UTF-8");
}
catch (UnsupportedEncodingException e1)
{
throw new AssertionError("UTF-8 not supported");
}
}
return output;
}
@Override
public String decode(String input)
{
try
{
return UriUtils.decode(input, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
throw new AssertionError("UTF-8 not supported");
}
}
}
Thank you
Tim
Re: ActivationRequestParameter and URLEncoder
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 11 Oct 2013 10:37:01 -0300, Boehler, Tim
<Ti...@eberspaecher.com> wrote:
> Hi,
Hi!
As a workaround, you can @Inject Request and use its getParameter() method
directly.
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org