javajettyjetty-9

How to handle http params in jetty?


I'm trying to handle requests like this ...

"http://someINSANEdomainFORsite.coolsuffix/" + Some text

For example:

I don't know how to do this I think there is some way to handle this, becouse its extremely common situation. Maybe there is some ContextHandler to do this or there isnt.

I tried to search some examples


Solution

  • Those examples are just paths in a request, not http params, nor http parameters, nor query strings, nor form details.

    If using Jetty 12, and a Jetty Handler, it would look like this ...

    public class GetPathHandler extends Handler.Abstract
    {
        @Override
        public boolean handle(Request request, Response response, Callback callback) throws Exception
        {
            String path = request.getHttpURI().getPath();
            String canonicalPath = request.getHttpURI().getCanonicalPath();
            String decodedPath = request.getHttpURI().getDecodedPath();
    
            String utf8Text = "path = " + path +
                "\ncanonicalPath = " + canonicalPath +
                "\ndecodedPath = " + decodedPath;
    
            response.getHeaders().put(HttpHeader.CONTENT_TYPE, "text/plain; charset=utf-8");
            Content.Sink.write(response, true, utf8Text, callback);
            return true;
        }
    }
    

    The differences between those paths are ...