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().
Web Service Request
Web Service Request
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.
Dispatcher Servlet in web.xml
Dispatcher Servlet in web.xml
WebService Dispatcher
Dispatcher Servlet
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.
RequestMapping
RequestMapping
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 .


Response from Server
Response from Server

Comments

Popular posts from this blog

Java Interview : Threads

Spring Framework Interview Notes : Part Two Wiring

Card Dealer In Java in Less than 5 minutes