Hi Cliff,
the cause of your bad experience is described here:
http://www.restlet.org/documentation/1.1/api/org/restlet/service/TunnelService.html
The TunnelService which is attached to an application is able to
preprocess incoming requests, especially it allows to workaround some
browser's limitations (send PUT requests, update client preferences, etc).
By default this service is allowed to process the query parameters...
That is to say, if the query contains a "language" parameter, it's value
is automatically converted in a client preference (only if the value of
the parameter is known by the MetadataService of the Application, which
by default knows "en" and "fr"...).
In order to make your code run, you can:
- either turn the "query tunneling" feature off =>
application.getTunnelService().setQueryTunnel(false)
- let this feature, but change the value of the "language" parameter =>
application.getTunnelService().setLanguageParameter("<what you want,
_language for example>");
I would like to add that there should not be confusion between form
input and query parameters. Strictly speaking, the query is part of the
URI that is to say part of the unmutable identifier of a precise
resource. The form input (I mean web form) is a entity sent to a
resource via the POST method.
Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org <http://www.restlet.org/>
Noelios Technologies ~ Co-founder ~ http://www.noelios.com
<http://www.noelios.com/>
I believe there is something wrong, or at least unpleasant in the
Restlet Engine (V1.1 RC2).
I am using the "language" as a form input.
I have a simple test case (below) which mimics the form input.
Input of this:
http://localhost:8080/test?lang=all&language=all&xyz=all
<http://localhost:8080/xbrlet/test/test?lang=all&language=all&xyz=all>
Provides (expected):
Test Form Data:
lang = all
xyz = all
language = all
But, input of this:
http://localhost:8080/test?lang=fr&language=fr&xyz=fr
<http://localhost:8080/test?lang=fr&language=fr&xyz=fr>
Provides (unexpected):
Test Form Data:
lang = fr
xyz = fr
(note missing "language = fr "text).
Random sampling: It works for language="it", and "de", but not "en"
or "fr".
Is there something special about the language name? I can of course
use some other name, but I spent hours tracing this down. I have
tried it in Tomcat (my standard environment) and standalone.
Here's the quick test code, pasted basically into your
HelloWorldResource example:
@Override
public Representation represent(final Variant variant) {
final Form form = getRequest().getResourceRef().getQueryAsForm();
final StringBuffer formsb = new StringBuffer();
if (form != null) {
formsb.append("Form Data:\n");
for (String name : form.getNames()) {
final String value = form.getFirstValue(name);
formsb.append("\t");
formsb.append(name);
formsb.append(" = ");
formsb.append(value);
formsb.append("\n");
}
}
final Representation representation = new
StringRepresentation("Test " + formsb.toString(), MediaType.TEXT_PLAIN);
final Response response = getResponse();
response.setStatus(Status.SUCCESS_OK);
return representation;
}
Cliff Binstock
Coyote Reporting