Detailed Description
The terminology used in the embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to any or all possible combinations including one or more of the associated listed items.
It should be understood that although the terms first, second, third, etc. may be used in embodiments of the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, a first message may also be referred to as a second message, and similarly, a second message may also be referred to as a first message, without departing from the scope of the present application. Depending on the context, furthermore, the word "if" used may be interpreted as "at … …" or "at … …" or "in response to a determination".
The embodiment of the application provides an operation request processing method, which can be applied to a system comprising an application server, middleware and a database, wherein the middleware is transfer equipment positioned between the application server and the database and can be called as middleware equipment, and the middleware can be respectively connected with the application server and the database. The application server may be a client for accessing a database, which may also be a database server.
In one example, the application server, middleware, and database may be deployed on the same device. In another example, the application server, middleware, and database may be deployed on different devices, such as on separate devices. Referring to fig. 1, for an application scenario schematic diagram of the embodiment of the present application, the number of application servers may be one or more, the number of middleware may be one or more, and the number of databases may be one or more, which is not limited.
In one example, the middleware may be a transit device located between the application server and the database, where the middleware encapsulates processing methods related to an operating system, a communication protocol, and the like of the application server, so that a unified interface may be provided for the database, so that the application server does not need to change program codes of the database after replacing an underlying configuration such as the operating system and the communication protocol, and portability of the database is enhanced.
The middleware can also manage the connection of the database, and the burden of the database is reduced. Specifically, if middleware is not used, an application server needs to establish a connection with the database every time the application server accesses the database, and when a large number of application servers access the database in parallel, a large number of connections need to be established with the database at the same time. The middleware can pre-establish a plurality of idle connections with the database, and maintain and manage the connections, when the application server requests to access the database through the middleware, the application server establishes the connection with the middleware, then the middleware selects the idle connection from the connections established with the database, distributes the idle connection to the application server for use, and after the application server finishes use, the middleware recovers the connection, thereby improving the access efficiency of the application server to the database.
Wherein the database includes, but is not limited to, mySQL (My Structured Query Language, relational database management system) database, and the connection between the middleware and the database may include, but is not limited to, JDBC (Java Database Connectivity, java database connection). Of course, mySQL and JDBC are just one example of the present application, and neither the database nor the connection is limited.
Based on the application scenario, in the conventional manner, after receiving the operation request, the middleware directly sends the operation request to the database, and the database executes the operation request, but the middleware does not analyze the operation request and cannot provide customized service for the application server. For the discovery, in the embodiment of the present application, in order to provide customized services for an application server and improve user experience, the following manner is adopted:
in the first mode, the SQL parser is configured in the middleware. After the middleware receives the operation request, the SQL parser can parse the operation request and provide customized service for the application server according to the parsing result. However, the SQL parser may not be able to correctly identify 100% of all operation requests, and the SQL parser needs to be additionally configured in the middleware, which results in waste of resources and increases the use cost.
The second mode is that after the middleware receives the operation request, the middleware generates a designated type message carrying the operation request and sends the designated type message to the analysis database, the analysis database can analyze the operation request after receiving the operation request and returns an analysis result to the middleware, and after receiving the analysis result, the middleware can provide customized service for the application server according to the analysis result. According to the method, the SQL parser does not need to be configured in the middleware, so that the problem of the first mode is solved, the middleware can analyze the operation request on the premise that the user behavior is not influenced, customized service is provided for the application server, and user experience is improved.
For the second mode, referring to fig. 2, a flowchart of the operation request processing method in the present embodiment is shown.
In step 201, the middleware generates a message of a specified type carrying the operation request according to the received operation request.
When the application server needs to operate on the data in the database, an operation request is sent to the middleware, and after the middleware receives the operation request, the middleware does not directly send the operation request to the database for executing the operation request, but generates a specified type message carrying the operation request.
In one example, the operation request may include, but is not limited to, an SQL statement. The SQL statement may be a data query language statement, a data manipulation language statement, a data definition language statement, a data control language statement, a transaction language statement, a pointer control language statement, or the like, which is not limited thereto.
In one example, after receiving the operation request, the middleware first determines whether the operation request carries an SQL sentence, if so, generates a specified type message carrying the operation request, and if not, directly sends the operation request to a database for executing the operation request.
Step 202, the middleware sends the specified type message to the parsing database, where the specified type message is used to instruct the parsing database to parse the operation request and return a parsing result. After receiving the message of the specified type, the parsing database parses the operation request carried by the message of the specified type and returns a parsing result for the operation request to the middleware, but the parsing database does not execute the operation request.
In one example, the parsing database is any database connected to the middleware, and may be a database for providing services to the application server (i.e., a database in a conventional manner), or may be a database that does not provide services to the application server (i.e., a new database provided in the present embodiment, and is only used to implement the parsing function of the operation request in the present embodiment), and the type of the database is not limited. For convenience of description, the middleware will take the parsing database as an example from the database 1, the database 2 and the database 3 in fig. 1.
When the middleware selects the analysis database, the middleware can select the same database or different databases for all operation requests. For example, for all operation requests, the middleware selects database 1 as the resolution database. For another example, the middleware may select database 1 as the resolution database when receiving the first operation request, select database 2 as the resolution database when receiving the second operation request, select database 3 as the resolution database when receiving the third operation request, select database 1 as the resolution database when receiving the fourth operation request, and so on.
In one example, the specified type of message is a message agreed by the middleware and the parsing database, and the format of the specified type of message is not limited. For example, the message type is carried in a specified type message and is a preset flag a, and this preset flag a indicates that the current message is a specified type message.
Based on this, when the middleware generates a specified type message carrying an operation request, the specified type message carries a message type, and the message type is a preset flag a. The middleware then sends the specified type of message to the resolution database. After receiving the message, the parsing database parses the message type from the message, and if the message type is found to be a preset mark A, the parsing database determines that the currently received message is a message of a specified type.
Further, after receiving the message of the specified type, the parsing database parses the operation request carried by the message of the specified type, and returns a parsing result for the operation request to the middleware, but the parsing database does not execute the operation request. For example, the operation request is used for writing the data a, the parsing database returns the parsing result for the operation request to the middleware, but the parsing database does not write the data a in the parsing database according to the operation request, i.e. the parsing database does not execute the operation request.
Step 203, the middleware receives the analysis result for the operation request returned by the analysis database.
And 204, the middleware processes the operation request according to the analysis result.
In one example, the middleware may also determine whether the middleware is to be used to provide a specified type of service before generating a specified type of message carrying an operation request. If it is used to provide a specified type of service, the middleware generates a specified type message carrying an operation request from the received operation request and performs steps 202-204. If not for providing the specified type of service, the middleware may directly send the operation request to a database for executing the operation request, which is executed by the database.
Wherein the specified type of service may include, but is not limited to, one or any combination of the following: read-write separation service, database and table separation service, injection analysis service (such as SQL injection analysis service), etc.
Wherein, for the process of judging whether the middleware is used for providing the specified type of service, the method can comprise the following steps: querying whether the middleware is configured to provide a specified type of service (e.g., the middleware is configured to provide a read-write separation service, and/or injection analysis service, etc.), if so, determining that the middleware is used to provide the specified type of service; if not, it may be determined that the middleware is not used to provide the specified type of service.
Wherein, when the middleware is used for providing the specified type of service, the process of processing the operation request according to the analysis result by the middleware can include: and the middleware processes the operation request corresponding to the specified type of service according to the analysis result. For example, the middleware performs processing corresponding to the read-write separation service on the operation request according to the analysis result; and/or processing the operation request corresponding to the database and table dividing service; and/or processing the operation request corresponding to the injection analysis service.
The specified type information can also carry information of the specified type service, and the specified type information is also used for indicating the analysis database to return an analysis result corresponding to the specified type service. Thus, for the process of "the middleware processes the operation request according to the analysis result", the middleware can process the operation request according to the analysis result corresponding to the specified type of service.
For example, the specified type message may also carry information of the read-write separation service (such as the identifier 1 for indicating the read-write separation service), and after the specified type message is received by the parsing database, the parsing result returned by the parsing database to the middleware may be a parsing result corresponding to the read-write separation service because the specified type message carries information of the read-write separation service. Further, the middleware may perform processing corresponding to the read-write separation service on the operation request according to the analysis result corresponding to the read-write separation service.
For another example, the specified type message may also carry information of the sub-library sub-table service (e.g. the identifier 2 for indicating the sub-library sub-table service), and after the parsing database receives the specified type message, since the specified type message carries information of the sub-library sub-table service, the parsing result returned by the parsing database to the middleware may be a parsing result corresponding to the sub-library sub-table service. Further, the middleware may perform processing corresponding to the sub-library sub-table service on the operation request according to the analysis result corresponding to the sub-library sub-table service.
For another example, the specified type message may also carry information of the injection analysis service (for example, the identifier 3 for indicating the injection analysis service), and after the specified type message is received by the analysis database, the analysis result returned by the analysis database to the middleware may be an analysis result corresponding to the injection analysis service because the specified type message carries information of the injection analysis service. Further, the middleware may perform processing corresponding to the injection analysis service on the operation request according to the analysis result corresponding to the injection analysis service.
Of course, the above-mentioned read-write separation service, the database-division table service, and the injection analysis service are only examples of the specified type service, and in practical application, other types of specified type services are also possible, which is not limited. For convenience of description, the following processes of "middleware processes the operation request according to the analysis result" are described in detail in combination with a read-write separation service, a database and table separation service, and an injection analysis service.
In the first case, when the specified type service includes a read-write separation service, the analysis result corresponding to the read-write separation service includes a read type or a write type. Further, when the analysis result is the read type, the middleware selects a database for processing the read service and sends an operation request to the selected database so that the database executes the operation request. When the analysis result is the writing type, the middleware selects a database for processing writing service and sends an operation request to the selected database so that the database executes the operation request.
After receiving the specified type message, the parsing database obtains a parsing result related to the operation type (read type or write type) when parsing the operation request, namely the parsing result comprises the read type or the write type, because the specified type message carries information of the read-write separation service.
For example, when the operation requests for writing data to the database, then the parsing result may be a write type; when the operation request is used for deleting the data in the database, the analysis result can be a writing type; when the operation request is used for modifying data in the database, the analysis result can be a writing type; when the operation request is for querying data in a database, then the parsing result may be of a read type. Of course, the above is only given as a few examples of parsing the operation request by the parsing database, and the parsing process is not limited.
In the read-write separation service, a database for processing the write service (hereinafter referred to as a write database) may be disposed in the database system, and a database for processing the read service (hereinafter referred to as a read database) may be disposed in the database system, the data in the write database being identical to the data in the read database.
Based on the above, after receiving the analysis result returned by the analysis database, if the analysis result is a read type, the middleware selects one read database for processing the read service from all the read databases, and sends the operation request to the selected read database, so that the read database executes the operation request. If the analysis result is the writing type, the middleware selects one writing database for processing the writing service from all writing databases, and sends the operation request to the selected writing database so that the writing database executes the operation request.
And in the second case, when the specified type service comprises a database and table dividing service, the analysis result corresponding to the database and table dividing service comprises the corresponding relation between the statement and the database table information. Further, the middleware stores the sentences in the operation request into the data table of the database corresponding to the database table information according to the corresponding relation between the sentences and the database table information.
After receiving the specified type of message, the parsing database obtains a parsing result related to the sub-library sub-table service when parsing the operation request, i.e. the parsing result may include a corresponding relationship between a statement and library table information, because the specified type of message carries information of the sub-library sub-table service.
For example, when the operation request includes the statement a, the statement B, and the statement C, if the statement a, the statement B, and the statement C are used to operate the data in the data table 1, in order to implement the database splitting service, the analysis database determines that the statement a, the statement B, and the statement C correspond to different databases, and therefore, the analysis database may determine that the database table information corresponding to the statement a is the database 1 and the data table 1, determine that the database table information corresponding to the statement B is the database 2 and the data table 1, and determine that the database table information corresponding to the statement C is the database 3 and the data table 1. In summary, the analysis result may include: the corresponding relation among the statement A, the database 1 and the data table 1; statement B, database 2, and table 1 correspondence; statement C, database 3, and table 1. Of course, the above is merely an example of resolving the operation request by the resolving database, and the resolving process is not limited.
Further, after receiving the analysis result returned by the analysis database, the middleware may store the statement in the operation request into the data table of the database corresponding to the database table information based on the corresponding relationship between the statement and the database table information. For example, based on the correspondence of statement a, database 1, and data table 1, the middleware may store statement a into data table 1 of database 1, and execute statement a from the data in data table 1 by database 1. Based on the correspondence of statement B, database 2, and data table 1, the middleware may store statement B into data table 1 of database 2, and execute statement B from the data in data table 1 by database 2. Based on the correspondence of statement C, database 3 and data table 1, the middleware may store statement C into data table 1 of database 3, and execute statement C from the data in data table 1 by database 3.
In the third case, when the specified type of service includes the injection analysis service, the analysis result corresponding to the injection analysis service includes an attack statement or no attack statement. Further, if the analysis result is that the attack statement exists, the middleware discards the operation request and refuses to send the operation request to the database; if the analysis result is that the attack statement does not exist, the middleware sends the operation request to a database for executing the operation request.
After receiving the specified type of message, the parsing database obtains a parsing result related to the injection parsing service when parsing the operation request, i.e. the parsing result may include an attack statement or no attack statement, because the specified type of message carries information of the injection parsing service. For example, the parsing database may parse the sentences included in the operation request, and parse whether the sentences have attack sentences, if so, the parsing result may be that the sentences have attack sentences, and if not, the parsing result may be that the sentences have no attack sentences. Of course, the above procedure is only given as an example of resolving the operation request by the resolving database, and the resolving procedure is not limited.
Further, after receiving the analysis result returned by the analysis database, if the analysis result is that the analysis result has an attack statement, the middleware discards the operation request and refuses to send the operation request to the database, so that the injection attack to the database can be prevented, and the safety of the database is ensured. If the analysis result is that the attack statement does not exist, the middleware sends the operation request to a database for executing the operation request.
In the above embodiment, after receiving the operation request, the database has two processing manners, where one processing manner is: the database analyzes the operation request and sends the analysis result to the middleware, and the processing manner is already described in the above process and will not be described herein. Another processing mode is as follows: the database executes the operation request, such as data writing operation, data modifying operation, data inquiring operation, data deleting operation, etc., and the process of executing the operation request will not be described in detail.
That is, after the specified type message is sent to the parsing database, the parsing database parses the operation request carried by the specified type message, returns a parsing result to the middleware, and refuses to execute the operation request. In addition, after sending the operation request to the selected database, the database executes the operation request.
Based on the above technical solution, in the embodiment of the present application, after receiving an operation request, the middleware does not directly send the operation request to the database, but generates a specified type message carrying the operation request, and sends the specified type message to the parsing database, where the parsing database may parse the operation request after receiving the operation request, and return a parsing result to the middleware, but the parsing database does not execute the operation request (i.e. does not perform an operation on data in the database according to the operation request). After receiving the analysis result, the middleware can process the operation request according to the analysis result. In summary, the middleware can analyze the operation request and provide customized services (such as read-write separation service, database and table separation service, injection analysis service, etc.) for the application server on the premise of not affecting the user behavior.
Based on the same application concept as the above method, the embodiment of the present application further provides an operation request processing apparatus, which may be applied to a middleware (also referred to as a middleware device), as shown in fig. 3, which is a structural diagram of the operation request processing apparatus, and includes:
a generating module 301, configured to generate a message of a specified type carrying the operation request according to the received operation request;
the sending module 302 is configured to send the specified type message to an parsing database, where the specified type message is used to instruct the parsing database to parse the operation request and return a parsing result;
the receiving module 303 is configured to receive an analysis result for the operation request returned by the analysis database;
and the processing module 304 is configured to process the operation request according to the analysis result.
In one example, the generating module 301 is specifically configured to, in a process of generating, according to the received operation request, a specific type message carrying the operation request, if the middleware is configured to provide a specific type service, generate, according to the received operation request, the specific type message carrying the operation request.
In an example, the processing module 304 is specifically configured to, in a process of processing the operation request according to the parsing result, if the middleware is configured to provide a specified type of service, perform a process corresponding to the specified type of service on the operation request according to the parsing result.
The specified type information is also used for indicating the analysis database to return an analysis result corresponding to the specified type service;
wherein the specified type of service includes one or any combination of the following: reading and writing separation service, library and table separation service and injection analysis service; the analysis result corresponding to the read-write separation service includes: a read type or a write type; the analysis results corresponding to the database and table separation service comprise: the corresponding relation between the sentences and the library table information; the parsing result corresponding to the injection parsing service includes: with or without attack statements.
In one example, the processing module 304 is specifically configured to, when the middleware provides a read-write separation service in a process of processing the operation request according to the analysis result, select a database for processing the read service if the analysis result is a read type, and send the operation request to the selected database, so that the database executes the operation request; if the analysis result is the writing type, selecting a database for processing writing service, and sending the operation request to the selected database so that the database executes the operation request; when the middleware provides the database and table dividing service, according to the corresponding relation between the sentences and the database table information, storing the sentences in the operation request into the data table of the database corresponding to the database table information; when the middleware provides injection analysis service, if the analysis result is that the analysis result has attack sentences, discarding the operation request, and refusing to send the operation request to a database; and if the analysis result is that the attack statement does not exist, the operation request is sent to a database for executing the operation request.
In one example, the operation request includes: structured query language SQL statements.
Based on the same application concept as the method, the embodiment of the application also provides a middleware device, which may include: a receiver, a processor, and a transmitter; the processor is used for generating a designated type message carrying the operation request according to the received operation request; the transmitter is used for transmitting the specified type information to an analysis database, and the specified type information is used for indicating the analysis database to analyze the operation request and returning an analysis result; the receiver is used for receiving an analysis result which is returned by the analysis database and is aimed at the operation request; and the processor is also used for processing the operation request according to the analysis result.
Based on the same application concept as the above method, there is further provided in an embodiment of the present application a machine-readable storage medium, where the machine-readable storage medium may be applied to a middleware device, and the machine-readable storage medium stores a number of computer instructions, where the computer instructions when executed perform the following processing:
generating a designated type message carrying the operation request according to the received operation request;
the appointed type information is sent to an analysis database, and the appointed type information is used for indicating the analysis database to analyze the operation request and returning an analysis result;
receiving an analysis result returned by the analysis database and aiming at the operation request;
and processing the operation request according to the analysis result.
Based on the same application concept as the above method, an operation request processing system is further provided in the embodiments of the present application, where the operation request processing system may include:
the middleware is used for generating a specified type message carrying the operation request according to the received operation request and sending the specified type message to the analysis database;
the analysis database is used for analyzing the operation request carried in the appointed type message to obtain an analysis result aiming at the operation request, and sending the analysis result to the middleware;
the middleware is further configured to receive an analysis result returned by the analysis database and directed against the operation request, and process the operation request according to the analysis result.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email device, game console, tablet computer, wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being functionally divided into various units, respectively. Of course, the functions of each element may be implemented in one or more software and/or hardware elements when implemented in the present application.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present application may take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
Moreover, these computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and changes may be made to the present application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. which are within the spirit and principles of the present application are intended to be included within the scope of the claims of the present application.