Hi Oliver,
IMO you don't need to do any custom transformation. By default UTF-8
is used to decode the requestURI.
Here is small sample:
final GrizzlyWebServer w = new GrizzlyWebServer(8888, "~/
Downloads/", false);
GrizzlyAdapter ga = new GrizzlyAdapter() {
public void service(final GrizzlyRequest grizzlyRequest,
final GrizzlyResponse grizzlyResponse) {
try {
grizzlyResponse.setContentType("text/
plain;charset=\"UTF-8\"");
grizzlyResponse.getOutputStream().write("hello".getBytes());
grizzlyResponse.getOutputStream().flush();
} catch (Exception e) {
}
}
};
w.addGrizzlyAdapter(ga, new String[]{"/hello"});
GrizzlyAdapter ga2 = new GrizzlyAdapter() {
public void service(final GrizzlyRequest grizzlyRequest,
final GrizzlyResponse grizzlyResponse) {
try {
grizzlyResponse.setContentType("text/
plain;charset=\"UTF-8\"");
grizzlyResponse
.getOutputStream().write("Привет!".getBytes("UTF-8"));
grizzlyResponse.getOutputStream().flush();
} catch (Exception e) {
}
}
};
w.addGrizzlyAdapter(ga2, new String[]{"/привет"});
So, when in browser you'll request "
http://localhost:8888/hello" -
you'll see result "hello", if you'll type "
http://localhost:8888/
привет" - you'll get "привет" response.
Hope this will help.
WBR,
Alexey.
On Mar 25, 2010, at 17:25 , Oliver Schrenk wrote:
> Hi,
>
> I'm using grizzly-http-webserver-1.9.18-k to serve static files, but
> also need support for URL-encoded requests (in UTF-8). Is it
> possible to forward the request, response to the default Adapter?
> Something like:
>
> GrizzlyAdapter ga = new GrizzlyAdapter(rootDirectory.toString()) {
>
> @Override
> public void service(GrizzlyRequest request, GrizzlyResponse
> response) {
> String uri = "";
> try {
> uri = URLDecoder.decode(request.getDecodedRequestURI(), "UTF-8");
> } catch (UnsupportedEncodingException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> request.setDecodedRequestURI(uri);
> dispatch(request, response);
> }
> };
> ws.addGrizzlyAdapter(ga, new String[] { "/*" });
>
> Or is there another (better) way?
>
> Best regards
> Oliver
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>