How a Spring web service works , the inner workings using DispatcherServlet
Lets create a simple web-service in Spring, and observe how does Spring web service really works.
Lets go through step by step on how it works.
Step 1:
When the server recieves a request it calls the org.springframework.web.servlet.FrameworkServlet’s service() method to process it. If its a GET request doGet() delegates the GET request to processRequest().
Step 2:
processRequest() processes this request publishing an event regardless of the outcome using publishRequestEventHandler().
Step 3:
org.springframework.web.servlet.DispatcherServlet is the central dispatcher for HTTP request handlers/controllers, the doService() method handles the published event,and delegates to doDispatch() for the actual dispatching. doDispatch() processes the actual dispatching to the handler. The handler will be obtained by applying the servlet’s HandlerMappings in order.The HandlerAdapter will be obtained by querying the servlet’s installed HandlerAdapters to find the first that supports the handler class.
Step 4:
Appropriate handler is invoked by org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter’s handleInternal() with resquest, response and handler method using @RequestMapping and invokeHandleMethod().
Step 5:
invokeAndHandle() of ServletInvocableHandlerMethod() which invokes the method and handles the return value through a registered HandlerMethodReturnValueHandler.
Step 6:
org.springframework.web.method.support.InvocableHandlerMethod ‘s invokeForRequest() is called to invoke the method after resolving its argument values in the context of the given request. Then doInvoke() invokes the handler method with the given argument values.
Thats how you are served a response .




Comments
Post a Comment