I am porting application that uses Jetty as a HTTP server from Jetty 11 to Jetty 12. I use my own handler that extends ResourceHandler and changes request. I need to change request because for some requests there is session identificator in URL, and I need to remove it from URL. I also map WOPI requests (LibreOffice) and I have to change the same query with GET method to "view document", and with POST method "save document" with proper QueryString.
In Jetty 12 I changed many things like request.getRemoteAddr() -> Request.getRemoteAddr(request) but request is immutable, so I have problems with methods:
request.setQueryParameters()
request.setMethod()
request.setHttpURI()
request.setContext()
My code that works in Jetty 11:
class my_jetty_handler extends ResourceHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
StringBuilder fileURL = new StringBuilder(target);
...
// remove session from URL and put it on env
ProcesURLSubst(fileURL, env);
...
// map WOPI query to new query with changed QueryString
WOPIRedirectURL(baseRequest, fileURL, qs, session);
if (qs.size() > 0)
baseRequest.setQueryParameters(qs);
...
// handle static file
String new_path = sFileURL.toString();
baseRequest.setMethod("GET");
baseRequest.setHttpURI(HttpURI.build(new_path));
baseRequest.setContext(baseRequest.getContext(), new_path);
super.handle(new_path, baseRequest, request, response);
...
} // handle
Do you have any idea how to make changed request in Jetty 12?
You use a
Request.Wrapperto make a new Request object with the appropriate changes for the next call tosuper.handle(request, response, callback);Example:
Note: the Request does not have the Context. Only the
ContextHandlerhas that (even nestedContextHandleris supported in Jetty 12) You can access the current context viaContextHandler.getCurrentContext()Also, don't forget to look at the Jetty 11 to Jetty 12 porting guide.
https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-migration-11-to-12