Spring was born in 2003 when Elder Brother, a veteran, started his postgraduate internship in ZTE. The 1.0 version was released in March 2004, which has been more than 15 years now. From single layered architecture to cloud native microservices architecture, it has remained at the top of the JAVA application framework and has never been challenged. It has brought us great value, not only reducing the difficulty of development, but also improving the efficiency of development. But time has not only changed veteran brother, but also Spring, and we have become stronger and stronger.

By the time Spring Boot/Spring Cloud came out, it had evolved through five major releases and countless smaller ones, becoming increasingly feature-rich and ecologically rich. However, for those who are new to Spring, this is not fair. Unlike the veteran brother who can grow up with it slowly, the technology stack is now very large. Is there a shortcut to understand the giant in a short time? Have, like the DOS operating system one floppy disk to hold, a total of only a few MB, now ready to dozens of hundreds of GB, but the operating system kernel is small, the principle of the mechanism is the textbook, two, two three, everything in life, only to master these stable “123”, namely the core principle of the mechanism (such as: IOC, AOP, ORM, etc.), then our learning can achieve twice the result with half the effort.

Just like we bought the blank room, must be decorated before moving in, which water, electricity, gas, network and other pipeline wiring must go first, different pipelines have different way, some go to the floor, some go to the wall, and so on the pipeline are laid properly to pave tiles, hanging ceiling, brush stickers and so on. As a property owner, if you do not know the routing of these pipes, you do not know how to analyze, locate and repair when there is power failure, disconnection or leakage. In the company veteran brother often received questions for help, because the partner did not know these principles and mechanisms, quite simple problem analysis and positioning for a few days still do not have a clue. If we follow the principles, then we can do it with ease.

In fact, these underlying principles and mechanisms are not complicated, but we do not know, or lack of good information, veteran brother is going to analyze these principles and mechanisms to the big guys through the way of diagrams. This series of articles will focus on the whole process of Spring processing HTTP requests, to help you understand and master the pipeline and wiring inside the skyscraper of Spring, so that learning becomes twice the result with half the effort, so that using it becomes easy and easy. The specific contents will include the following aspects, welcome to subscribe as soon as possible, so as to publish online as soon as possible, thank you!

  1. The whole process of HTTP request processing, including browser, Web server, application Spring, etc.
  2. The interaction interface, cooperation mechanism and configuration rules between Web server and Application Spring;
  3. Spring process HTTP request mechanism, including Dispatcher, Controller, View, Model, Service, DAO, etc.
  4. The sub-process of HTTP request processing under different application architecture scenarios, including JSP, front and back end separation, etc.
  5. Configuration files related to HTTP request processing, including Web, Bootstrap, Spring MVC, Application Context, etc.
  6. Frequently asked Questions about HTTP request processing.

For readers: development, testing, architecture, etc

1. HTTP request processing process overview

The cyberspace constructed by computers is a virtual world, an extension of our human brain power. Although virtual worlds are abstract and illusory, they are ultimately constructed from our experience of building physical worlds. I’ve been in IT for a long time, and I’ve found a way to understand the virtual world, which is to find prototypes in the real world. Prototypes are more vivid and familiar to us, and through prototypes we can more accurately understand the mechanism behind computer technology. What real-world archetypes can we use for clients (or browsers), Web containers, Web applications, The Spring framework, etc., that process HTTP requests? We can compare it to the process of sending documents and packages by logistics.

Computer networks are like real-world transportation networks, where the main function of the network is to carry goods. In the OSI 7-layer or TCP/IP 4-layer network protocol model, Hyper Text Transfer Protocol (HTTP) and File Transfer Protocol (FTP), Simple Mail Transfer Protocol (SMTP), and Post Office (POP3) Protocol 3, Internet Mail Access Protocol (IMAP4) and other protocols belong to application layer protocols. These protocols are just like logistics and express companies that transport different types of goods. The FTP system is dedicated to transporting files. SMTP, POP3, and IMAP4 are dedicated to mail delivery, while the HTTP protocol was originally used for hypertext. However, with the vigorous development of the World Wide Web (WWW), HTTP protocol system has been the most extensive development, its design is very good, brings flexibility, scalability and ease of use, can bear the transmission of various types of information, just like the Internet logistics company is getting bigger, can cover more and more business.

An HTTP request or reply is like a packet, which is divided into a header and a message, in which the message is the payload of information to be carried, and the message header is like a waybill filled in when we mail something, including the address of the sender, the service level requirements, and the description of the item to be mailed, etc. For the purpose of this article, we will focus only on the recipient address. An HTTP URL for a RESTful service interface API looks like this:

http:// {ip} : {port} / {context-path} / {service-name} / {method-name}

For a specific example, let’s say we want to send a file to the following address to complete user registration:

http://201.187.10.21:8080/spring-demo/user/register

The above format is for us to read. Finally, the information should be filled into the HTTP packet. The real effect is as follows:

Accept: application/json accept-language: zh-cn user-agent: Mozilla/5.0 Host: 201.187.10.21:8080 Content-Length: 112 Connection: keep-alive cache-control: no-cache Cookie: JSESSIONID=12DII6898EFY998APBE17B

name=itlaobingge&password=123456&sex=male&age=30

Let’s parse the HTTP URL piece by piece to see what each piece of information means:

  • IP: IP address information used to address different computers on a specific network.
  • Port: Port information for addressing different Web containers on the same computer. A computer can run multiple Instances of Web containers.
  • Context-path: context path used to address different applications in the same Web container. Multiple applications can be deployed in one Web container instance.
  • Service-name: specifies the service name, which is used to address different services in the same application. Multiple services may exist in an application.
  • Method-name: specifies the method name used to address different methods within the same service. A service usually contains multiple methods.

The recipient address is filled in by the client (or browser). The HTTP transport system will deliver the packet according to the recipient address information, find a specific computer based on the IP address or domain name information, and the computer will deliver the packet to a specific Web container instance according to the port information. Next, the Web container takes over the parcel delivery task, and it finds the specific application based on the context path. If the current application is built with the Spring framework, Spring will take over the parcel delivery task, and it will find the service method that can actually handle the payload information in the parcel based on the service name and method name. The service method will process the information in the packet in time, and then put the result information into a new packet and send it back to the client (or browser). As shown below, this is a schematic of how HTTP requests traverse the network, computer, Web container, Web application, and Spring framework.

Today first share here, if you feel valuable, please move your finger to forward to other partners in need. In addition, I will share my experience in career planning, job interviews, skills improvement and influence building in the future. Please pay attention to this column or “IT veteran brother”!

Other articles in this series are indexed below:

  • Spring: HTTP Request Processing and mechanism [2]
  • Spring: HTTP Request Processing and mechanism [3]
  • Spring: HTTP Request Processing flow and mechanism [4]
  • Spring: HTTP Request Processing flow and mechanism [5]