JSON API spec. solves this problem by letting you send multiple operations for each request. There is even a fairly mature implementation that supports this feature called Elide . But I think that this may not fully meet your requirements.
Anyway, here is what you can do.
You should be aware that the DispatcherServlet contains a list of handlerMappings , which is used to find the appropriate request handler and handlerAdaptors . The selection strategy for both lists is customizable (see DispatcherServlet#initHandlerMappings and #initHandlerAdapters ).
You must decide how you prefer to receive these handlerMappings / initHandlerAdapters and stay in sync with the DispatcherServlet .
After that, you can implement your own HandlerMapping / HandlerAdaptor (or introduce the Controller method, as in your example), which would process the request to /encode path.
Btw, HandlerMapping , as javadoc says,
The interface that will be implemented by the objects that define the mapping between requests and handler objects
or just say if we take DefaultAnnotationHandlerMapping , which DefaultAnnotationHandlerMapping our HttpServletRequests to @Controller methods annotated using @RequestMapping . If this mapping, the HandlerAdapter prepares an incoming request to the consumption controller method, f.ex. retrieving the params , body request and using them to call the controller method.
After that, you can extract the URL from the main request , create a list of HttpRequests stubs containing the information necessary for further processing, and skip through them:
HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { for (HandlerMapping hm : this.handlerMappings) { if (logger.isTraceEnabled()) { logger.trace( "Testing handler map [" + hm + "] in DispatcherServlet with name '" + getServletName() + "'"); } HandlerExecutionChain handler = hm.getHandler(request); if (handler != null) { return handler; } } return null; }
having HandlerMapping , you call
HandlerAdapter getHandlerAdapter(Object handler) throws ServletException { for (HandlerAdapter ha : this.handlerAdapters) { if (logger.isTraceEnabled()) { logger.trace("Testing handler adapter [" + ha + "]"); } if (ha.supports(handler)) { return ha; } }
and then you can finally call
ha.handle(processedRequest, response, mappedHandler.getHandler());
which, in turn, will execute the controller method with parameters.
But with all this, I would not recommend following this approach, instead consider using the JSON API spec or whatever.