Java web service server-side implementation of business processing method

By using Java reflection and Java annotations to build an HTTP request mapping table, the business processing flow of Java Web servers is simplified, the problem of complex framework configuration is solved, and it is suitable for beginners and small project development.

CN115185707BActive Publication Date: 2026-04-24YUNNAN NORMAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
YUNNAN NORMAL UNIV
Filing Date
2022-05-20
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing Java Web server frameworks are complex to configure and difficult to learn for beginners, and they are also cumbersome and difficult to master for small project development.

Method used

By employing Java reflection and Java annotations, the system automatically scans the server environment to build an HTTP request mapping table, simplifying configuration steps. Through the mapping of HTTP request routing information and business processing modules, it achieves automatic parsing and injection of business processing flows.

Benefits of technology

It reduces the learning difficulty for beginners, simplifies the development process of small web projects, and improves development efficiency and simplicity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115185707B_ABST
    Figure CN115185707B_ABST
Patent Text Reader

Abstract

The application provides a method for realizing business processing by Java Web service end, comprising the following steps: writing HTTP request mapping table in Java annotation; when the Web service end is started, automatically scanning the Java annotation of the service end environment by using Java reflection mechanism, and obtaining the HTTP request mapping table by analyzing the Java annotation; and parsing, encapsulating and taking the client-side business data as the entrance parameter, and injecting into the business processing interface. The application has the following advantages: by encapsulating various business processing flows of the Web service end, the complicated configuration steps are abandoned, beginners can easily understand and master the working principle and coding method of the Web application, and the development difficulty of small Web projects can be significantly reduced, and the development progress can be accelerated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of application development technology, specifically relating to a method for implementing business processing in a Java Web server. Background Technology

[0002] Java Web application development technology is one of the mainstream technologies for developing B / S architecture systems. The working principle of a B / S architecture system (Web application) is as follows: 1) The client enters a URL in the client's address bar and requests a page from the Web server; 2) The browser describes the request using the HTTP protocol and packages the address using TCP / IP, sending an HTTP request to the Web server; 3) The Web server receives and analyzes the HTTP request, processes it, generates a return page, and packages the result into an HTTP response; 4) The browser executes all client-side scripts and displays the HTTP response on the screen.

[0003] In the above process, web servers are commonly implemented using technologies such as ASP, ASP.NET, PHP, Node.js, and Java Web. Among them, Java Web technology is favored by programmers in the industry due to its excellent architecture. Web server technology occupies a pivotal position in the entire B / S architecture system, connecting the client and the database system. Due to the complexity of communication between the client and the web server, as well as the intricate design of its own business logic, learning and writing this part of the code is extremely difficult for beginners.

[0004] Web server-side frameworks (also known as "web application frameworks") provide tools and libraries to implement common development tasks, typically including routing, database interaction, session support, user authentication, and formatted output. Currently available Java-based web server-side frameworks include Struts, Spring MVC, and Spring Boot. While these frameworks are feature-rich, their architectures are large and configurations complex, requiring users to have a certain understanding of design patterns and related concepts. For beginners, they are extremely difficult to learn and master. Furthermore, for typical small-scale project development, these web server-side frameworks appear very bloated. Summary of the Invention

[0005] To address the shortcomings of existing technologies, this invention provides a method for implementing business processing in a Java Web server, which can effectively solve the aforementioned problems.

[0006] The technical solution adopted in this invention is as follows:

[0007] This invention provides a method for implementing business processing in a Java Web server, comprising the following steps:

[0008] Step 1: Write the HTTP request mapping table in the Java annotation; the HTTP request mapping table is a mapping table between HTTP request route registration information and user-defined business processing modules; wherein, the business processing module stores the mapping between business processing classes and business processing interfaces; the HTTP request mapping table is updated in real time according to changes in HTTP request route registration information and business processing modules;

[0009] Step 2: When the Web server starts, it automatically scans the Java annotations in the server environment using Java reflection and parses the HTTP request mapping table from the Java annotations.

[0010] Step 3: When the Web server listens to the HTTP request sent by the client, it parses the HTTP request data packet of the HTTP request to extract the HTTP request routing information and the client's upstream business data.

[0011] Step 4: The web server searches the HTTP request mapping table based on the parsed HTTP request routing information to determine whether the parsed HTTP request routing information is located in the HTTP request mapping table. If the result is no, the current HTTP request is intercepted and the process ends. If the result is yes, the business processing module corresponding to the parsed HTTP request routing information is found in the HTTP request mapping table.

[0012] From the identified business processing modules, the business processing class and business processing interface are parsed out; the parsed business processing class is represented as: Business Processing Class C0; the parsed business processing interface is represented as: Business Processing Interface P0;

[0013] Step 5: The web server instantiates the business processing class C0 into a business processing object B0 and dispatches the HTTP request to the business processing object B0.

[0014] The business processing object B0 sends the received HTTP request to the business processing interface P0, which then processes the HTTP request.

[0015] Step 6: The web server determines the data type of the client's upstream business data obtained in Step 3. If it is a character stream, proceed to Step 7; if it is a binary data stream, proceed to Step 8.

[0016] Step 7, the processing method for character stream types is as follows:

[0017] Step 7.1: The business processing interface P0 contains business processing interface annotation information; the business processing interface annotation information includes declaration information and interface parameter information; wherein, the declaration information includes a standard format;

[0018] Step 7.2: The Web server encapsulates the client's uplink business data into a standard format according to the standard format defined in the declaration information, and injects the client's uplink business data in the standard format as an entry parameter into the business processing interface P0;

[0019] Step 7.3: The business processing interface P0 executes the injected entry parameters, obtains the client's upstream business processing result, returns it to the client as an HTTP response, and ends the process;

[0020] Step 8, the binary data stream is processed as follows:

[0021] Step 8.1: The Web server writes the binary data stream to the Web server's file system to obtain the storage path of the binary data stream in the file system.

[0022] Step 8.2: Integrate the attribute information of the save path and binary data stream into file information;

[0023] Step 8.3: The Web server encapsulates the file information into a standard object and injects the standard object as an input parameter into the business processing interface P0.

[0024] Step 8.4: The business processing interface P0 executes the injected entry parameters, obtains the upstream business processing result from the client, returns it to the client as an HTTP response, and ends the process.

[0025] Preferably, step 7.3 specifically includes:

[0026] The standard format client-side uplink business data includes: operation type and operation object; the operation type includes write operation, read operation, delete operation and update operation;

[0027] When the operation type is a delete operation, the operation object is the object information to be deleted; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables and deletes the queried operation objects; if the deletion is successful, the client's upstream business processing result is a deletion success response; if the deletion fails, the client's upstream business processing result is a deletion failure response.

[0028] When the operation type is a write operation, the operation objects are the object information to be written and the write position information; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables, determines the write position, and writes the operation object to the corresponding position; then, the result of successful or unsuccessful writing is used as the business processing result of the client.

[0029] When the operation type is a read operation, the operation object is the object information to be read; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the object information to be read as the query keyword to query the bound data tables, obtains the query results, and uses the query results as the business processing results of the client.

[0030] When the operation type is an update operation, the operation objects are the old object and the new object to be updated. The business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the old object to be updated as the query keyword to query the bound data tables, obtains the old object, and updates the old object to the new object; then, the result of successful or failed update is used as the business processing result on the client.

[0031] Preferably, step 8.4 specifically includes:

[0032] The business processing interface P0 obtains the save path based on the injected entry parameters; then, based on the save path, it reads the binary data stream from the file system.

[0033] Based on the operation type in the business data on the client, perform corresponding operations on the read binary data stream and obtain the operation result.

[0034] The method for implementing business processing in a Java Web server provided by this invention has the following advantages:

[0035] By encapsulating various business processes on the web server and eliminating cumbersome configuration steps, beginners can easily understand and master the working principles and coding methods of web applications. This can also significantly reduce the development difficulty and accelerate the development process for small web projects. Attached Figure Description

[0036] Figure 1 This is a flowchart illustrating the method for implementing business processing in a Java Web server provided by the present invention. Detailed Implementation

[0037] To make the technical problems solved, the technical solutions, and the beneficial effects of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the invention.

[0038] To address the problems existing in the prior art, this invention provides a method for implementing business processing on a Java Web server. By encapsulating various business processing flows of the Web server and eliminating complicated configuration steps, it enables beginners to easily understand and master the working principles and coding methods of Web applications. It can also significantly reduce the development difficulty and accelerate the development progress for small Web projects.

[0039] Specifically, this invention avoids using XML files for configuration (which is complex and unintuitive) as commonly used by other Java Web server frameworks. Instead, it uses Java reflection, along with necessary Java annotations, to directly read information from the declaration of user-defined business processing methods, thereby establishing an HTTP request mapping table and enabling the parsing and injection of HTTP request data.

[0040] refer to Figure 1 The method for implementing business processing in a Java Web server provided by this invention includes the following steps:

[0041] Step 1: Write the HTTP request mapping table in the Java annotation; the HTTP request mapping table is a mapping table between HTTP request route registration information and user-defined business processing modules; wherein, the business processing module stores the mapping between business processing classes and business processing interfaces; the HTTP request mapping table is updated in real time according to changes in HTTP request route registration information and business processing modules;

[0042] Step 2: When the Web server starts, it uses Java reflection to automatically scan the Java annotations in the server environment for initialization and parses the HTTP request mapping table from the Java annotations.

[0043] As a specific implementation method, when the web server starts, it uses Java reflection mechanism to automatically scan the server environment. The scanning program traverses all source code files in the project folder, retrieves all responsive HTTP request route registration information and user-defined business processing modules according to the agreed declaration mechanism, and builds an HTTP request mapping table.

[0044] This invention utilizes Java's annotation mechanism to read HTTP request route registration information from Java annotations and simultaneously parse user-defined business processing interface (Method) declarations to construct an "HTTP request mapping table." The aforementioned declaration mechanism completely abandons the traditional XML document configuration method, using Java annotations for configuration, which is relatively more intuitive and easier to use.

[0045] Step 3: When the Web server listens to the HTTP request sent by the client, it parses the HTTP request data packet of the HTTP request to extract the HTTP request routing information and the client's upstream business data.

[0046] Specifically, the HTTP request contains a URL. By querying the HTTP request mapping table based on the URL, the HTTP request routing information and the client's upstream business data can be obtained.

[0047] In this invention, the business data uploaded by the client can be in the following three parameter formats: NamedRouter Parameter, URL Query String, and Request Body Parameter.

[0048] The Request Body parameters support three formats: application / x-www-form-urlencoded, application / json, and multipart / form-data.

[0049] Step 4: The web server searches the HTTP request mapping table based on the parsed HTTP request routing information to determine whether the parsed HTTP request routing information is located in the HTTP request mapping table. If the result is no, the current HTTP request is intercepted and the process ends. If the result is yes, the business processing module corresponding to the parsed HTTP request routing information is found in the HTTP request mapping table.

[0050] From the identified business processing modules, the business processing class and business processing interface are parsed out; the parsed business processing class is represented as: Business Processing Class C0; the parsed business processing interface is represented as: Business Processing Interface P0;

[0051] Step 5: The web server instantiates the business processing class C0 into a business processing object B0 and dispatches the HTTP request to the business processing object B0.

[0052] The business processing object B0 sends the received HTTP request to the business processing interface P0, which then processes the HTTP request.

[0053] Step 6: The web server determines the data type of the client's upstream business data obtained in Step 3. If it is a character stream, proceed to Step 7; if it is a binary data stream, proceed to Step 8.

[0054] Step 7, the processing method for character stream types is as follows:

[0055] Step 7.1: The business processing interface P0 contains business processing interface annotation information; the business processing interface annotation information includes declaration information and interface parameter information; wherein, the declaration information includes a standard format;

[0056] Step 7.2: The Web server encapsulates the client's uplink business data into a standard format according to the standard format defined in the declaration information, and injects the client's uplink business data in the standard format as an entry parameter into the business processing interface P0;

[0057] Step 7.3: The business processing interface P0 executes the injected entry parameters, obtains the client's upstream business processing result, returns it to the client as an HTTP response, and ends the process;

[0058] Step 7.3 specifically involves:

[0059] The standard format client-side uplink business data includes: operation type and operation object; the operation type includes write operation, read operation, delete operation and update operation;

[0060] When the operation type is a delete operation, the operation object is the object information to be deleted; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables and deletes the queried operation objects; if the deletion is successful, the client's upstream business processing result is a deletion success response; if the deletion fails, the client's upstream business processing result is a deletion failure response.

[0061] When the operation type is a write operation, the operation objects are the object information to be written and the write position information; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables, determines the write position, and writes the operation object to the corresponding position; then, the result of successful or unsuccessful writing is used as the business processing result of the client.

[0062] When the operation type is a read operation, the operation object is the object information to be read; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the object information to be read as the query keyword to query the bound data tables, obtains the query results, and uses the query results as the business processing results of the client.

[0063] When the operation type is an update operation, the operation objects are the old object and the new object to be updated. The business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the old object to be updated as the query keyword to query the bound data tables, obtains the old object, and updates the old object to the new object; then, the result of successful or failed update is used as the business processing result on the client.

[0064] The implementation scheme of steps 1-8 of this invention is mainly as follows: First, determine the parameter format carried by the HTTP request based on the information in the Content-Type of the HTTP request data packet; then, parse the client uplink parameters according to the declaration information (acceptable data format) in the user's annotation of the business processing interface and the method interface parameter information, and encapsulate them into the target format; finally, call the user-defined business processing interface, and inject the parsed and encapsulated client uplink parameters as input parameters into the business processing interface, and use the user-defined business processing interface to process the client uplink parameters.

[0065] For general client-side uplink parameters, based on the declaration of the user-defined business processing interface, this solution supports encapsulating client-side uplink parameters into a single user-defined VO object (ValueObject) or a generic interface instance. If necessary, a user-defined Service class is also instantiated and injected as an entry parameter.

[0066] Step 8, the binary data stream is processed as follows:

[0067] Step 8.1: The Web server writes the binary data stream to the Web server's file system to obtain the storage path of the binary data stream in the file system.

[0068] The binary data stream can be of type multipart / form-data.

[0069] Step 8.2: Integrate the attribute information of the save path and binary data stream into file information; the attribute information includes file name and file size, etc.

[0070] Step 8.3: The web server encapsulates the file information into a java.io.File standard object and injects the standard object as an input parameter into the business processing interface P0;

[0071] Step 8.4: The business processing interface P0 executes the injected entry parameters, obtains the upstream business processing result from the client, returns it to the client as an HTTP response, and ends the process.

[0072] Step 8.4 specifically involves:

[0073] The business processing interface P0 obtains the save path based on the injected entry parameters; then, based on the save path, it reads the binary data stream from the file system.

[0074] Based on the operation type in the business data on the client, perform corresponding operations on the read binary data stream and obtain the operation result.

[0075] In steps 7 and 8, the processing result is encapsulated into standard JSON format response data and returned to the client, ultimately completing the server-side business processing. The response data packet format includes:

[0076] The code is the status code of the processing result. A non-negative number indicates success, while a negative number indicates an error.

[0077] The message contains descriptive text about the processing results;

[0078] result is the business processing result data;

[0079] When the data returned to the client is a collection of data, the total field represents the total number of records that meet the conditions, and is typically used to implement pagination functionality.

[0080] Depending on actual business needs, programmers can add request interceptors to custom business processing interfaces, or throw exception objects carrying error messages. Exception messages are also encapsulated as standard JSON format data packets (with negative codes) and returned to the client.

[0081] The method for implementing business processing in a Java Web server provided by this invention completes steps 1-8 of this invention by encapsulating a server-side environment initialization module, an HTTP request routing and distribution module, an HTTP request parameter parsing module, and an HTTP response encapsulation module in the Web server control layer logic. This invention enables developers to implement user business processing logic with minimal cost.

[0082] Other Java Web server frameworks, for architectural and complete reasons, often introduce more design patterns and higher-level business abstractions, requiring developers to have certain practical development experience, understand more design concepts, and fully grasp the framework's working principles. However, this is too demanding for beginners (such as students) and inconvenient for learning and use; for the development of typical small Web projects, such frameworks also appear bloated. This invention simplifies the level of abstraction as much as possible, while encapsulating necessary but complex common development tasks.

[0083] Compared to other existing Java Web server-side frameworks, this technical solution significantly simplifies the configuration and coding process, encapsulating complex and common development tasks and providing programmers with a concise interface, allowing them to focus more on implementing specific business logic. Relatively speaking, this solution is easier to learn, suitable for beginners to familiarize themselves with the working principles of web applications and build practice projects. Of course, its lightweight design is also suitable for building small web projects, resulting in lower development costs and higher development efficiency.

[0084] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for implementing business processing in a Java Web server, characterized in that, Includes the following steps: Step 1: Write the HTTP request mapping table in the Java annotation; the HTTP request mapping table is a mapping table between HTTP request route registration information and user-defined business processing modules; wherein, the business processing module stores the mapping between business processing classes and business processing interfaces; the HTTP request mapping table is updated in real time according to changes in HTTP request route registration information and business processing modules; Step 2: When the Web server starts, it automatically scans the Java annotations in the server environment using Java reflection and parses the HTTP request mapping table from the Java annotations. Step 3: When the Web server listens to the HTTP request sent by the client, it parses the HTTP request data packet of the HTTP request to extract the HTTP request routing information and the client's upstream business data. Step 4: The web server searches the HTTP request mapping table based on the parsed HTTP request routing information to determine whether the parsed HTTP request routing information is located in the HTTP request mapping table. If the result is no, the current HTTP request is intercepted and the process ends. If the result is yes, the business processing module corresponding to the parsed HTTP request routing information is found in the HTTP request mapping table. From the identified business processing modules, the business processing class and business processing interface are parsed out; the parsed business processing class is represented as: Business Processing Class C0; the parsed business processing interface is represented as: Business Processing Interface P0; Step 5: The web server instantiates the business processing class C0 into a business processing object B0 and dispatches the HTTP request to the business processing object B0. The business processing object B0 sends the received HTTP request to the business processing interface P0, which then processes the HTTP request. Step 6: The web server determines the data type of the client's upstream business data obtained in Step 3. If it is a character stream, proceed to Step 7; if it is a binary data stream, proceed to Step 8. Step 7, the processing method for character stream types is as follows: Step 7.1: The business processing interface P0 contains business processing interface annotation information; the business processing interface annotation information includes declaration information and interface parameter information; wherein, the declaration information includes a standard format; Step 7.2: The Web server encapsulates the client's uplink business data into a standard format according to the standard format defined in the declaration information, and injects the client's uplink business data in the standard format as an input parameter into the business processing interface P0; Step 7.3: The business processing interface P0 executes the injected entry parameters, obtains the client's upstream business processing result, returns it to the client as an HTTP response, and ends the process; Step 8, the binary data stream is processed as follows: Step 8.1: The Web server writes the binary data stream to the Web server's file system to obtain the storage path of the binary data stream in the file system. Step 8.2: Integrate the attribute information of the save path and binary data stream into file information; Step 8.3: The Web server encapsulates the file information into a standard object and injects the standard object as an input parameter into the business processing interface P0. Step 8.4: The business processing interface P0 executes the injected entry parameters, obtains the upstream business processing result from the client, returns it to the client as an HTTP response, and ends the process.

2. The method for implementing business processing in a Java Web server according to claim 1, characterized in that, Step 7.3 specifically involves: The standard format client-side uplink business data includes: operation type and operation object; the operation type includes write operation, read operation, delete operation and update operation; When the operation type is a delete operation, the operation object is the object information to be deleted; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables and deletes the queried operation objects; if the deletion is successful, the client's upstream business processing result is a deletion success response; if the deletion fails, the client's upstream business processing result is a deletion failure response. When the operation type is a write operation, the operation objects are the object information to be written and the write position information; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 queries the bound data tables, determines the write position, and writes the operation object to the corresponding position; then, the result of successful or unsuccessful writing is used as the business processing result of the client. When the operation type is a read operation, the operation object is the object information to be read; its business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the object information to be read as the query keyword to query the bound data tables, obtains the query results, and uses the query results as the business processing results of the client. When the operation type is an update operation, the operation objects are the old object and the new object to be updated. The business processing logic is as follows: the business processing interface P0 is pre-bound to several data tables in the database system; the business processing interface P0 uses the old object to be updated as the query keyword to query the bound data tables, obtains the old object, and updates the old object to the new object; then, the result of successful or failed update is used as the business processing result on the client.

3. The method for implementing business processing in a Java Web server according to claim 1, characterized in that, Step 8.4 specifically involves: The business processing interface P0 obtains the save path based on the injected entry parameters; then, based on the save path, it reads the binary data stream from the file system. Based on the operation type in the business data on the client, perform corresponding operations on the read binary data stream and obtain the operation result.

Citation Information

Patent Citations

  • Platform system for quickly developing Java Web application and application thereof

    CN110069246A

  • Method and apparatus for supporting XML-based service consumption in a web presentation architecture

    US20050050456A1