Embodiment
In order to make object of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
Unless context separately has the description of specific distinct, the element in the present invention and assembly, the form that quantity both can be single exists, and form that also can be multiple exists, and the present invention does not limit this.Although the step in the present invention arranges with label, and be not used in and limit the precedence of step, the order of step or the execution of certain step need based on other steps unless expressly stated, otherwise the relative rank of step is adjustable.Be appreciated that term "and/or" used herein relates to and contains the one or more any and all possible combination in the Listed Items be associated.
In one embodiment, as shown in Figure 1, a kind of processing method of web access requests, the method can be dependent on computer program, can run in the computer system based on Feng Luoyiman system.This computer system can be web application server, such as nginx application server.
In the present embodiment, the method comprises:
Step S102, obtains the web access requests uploaded, and extracts the required parameter information submitted in web access requests.
Web access requests and user by browser address bar input web page address or on webpage clickthrough and button and the access request initiated to web application server.Then comprise required parameter (at least one in such as header information, method information, url information and host information) by the required parameter information extracted in web access requests or submit data (form data that such as user submits in POST mode fill in list on webpage after) to.
Web application server is usually packaged into request object according to the required parameter information extracted after receiving web access requests.Such as, in nginx framework, web access requests is packaged into request object; In j2ee framework, web access requests is then encapsulated as in httpRequest object.
In the present embodiment, the step extracting the required parameter information submitted in web access requests comprises: the request type obtaining web access requests, judge whether request type is POST, if, then call POST event call-back function, extracted the required parameter information submitted in web access requests by POST event call-back function.
Such as, in nginx framework, namely web application server can trigger POST event after receiving the web access requests of POST type (the method property value namely in http header information is POST), namely can call corresponding POST event call-back function after this POST event is triggered.The code extracting required parameter information can be defined in advance in POST event call-back function.When POST event triggers, then can automatically perform the code that defines in this POST event call-back function to extract the required parameter information submitted in web access requests.
Step S104, obtains the list of preliminary treatment service server, and therefrom chooses preliminary treatment service server.
Preliminary treatment business is carries out the needs relevant to the operation maintenance that web applies to the business of asking to process in advance to web access requests.Such as, can be whether Hole Detection (comprises aggressive script or code detects in request, for subsequent treatment provides safety assurance), data encryption (is decrypted enciphered data, facilitate subsequent treatment), code conversion (coded format of data in request is changed in advance, facilitates subsequent treatment), log statistic and analysis (statistic record and analysis are carried out in daily record web application being received to request) and compressed and decompressed (compression and decompression are carried out to the data of the gzip type comprised in request) etc.
Preliminary treatment service server is the computer equipment processing corresponding preliminary treatment service logic.As shown in Figure 2, web application server 10 can be connected with multiple preliminary treatment service server.Such as, in the application scenarios that Fig. 2 is corresponding, preliminary treatment service server can comprise the Hole Detection server 20, data encryption services device 30 and the code conversion server 40 that are connected with web application server.
Wherein, preliminary treatment service identification is comprised in the list of preliminary treatment service server, the corresponding preliminary treatment service server of described preliminary treatment service identification, the preliminary treatment service server that often kind of service identification is corresponding also can have multiple, such as, multiple service identification can be had, respectively corresponding log statistic and analysis, Hole Detection, the concrete preliminary treatment business such as compressed and decompressed.And Hole Detection server 20 also can have multiple, web application server is being selected according to the list of preliminary treatment service server to choose Hole Detection server under the prerequisite in load balancing in Hole Detection server 20.In other application scenarioss, the service identification of preliminary treatment business is also not limited to above-mentioned Hole Detection, data encryption, code conversion, log statistic and analysis and compressed and decompressed, and web application server 10 also can be connected with the preliminary treatment service server of other types.
In the present embodiment, the step choosing preliminary treatment service server from the list of preliminary treatment service server can be specially:
The preliminary treatment service identification comprised in the list of traversal preliminary treatment service server, chooses in the preliminary treatment service server corresponding with the preliminary treatment service identification traversed.
That is, if developer configures N kind preliminary treatment business of knowing clearly in advance in preprocessing server list, and one or more preliminary treatment service server corresponding that has been often kind of preliminary treatment service deployment, then when receiving web access requests, one or more preliminary treatment service server can be selected to carry out preliminary treatment to this web access requests in often kind of preliminary treatment business according to preprocessing server list.
Step S106, is sent to the preliminary treatment service server chosen by required parameter information, and receives its result returned.
In the present embodiment, the required parameter information of aforementioned extraction can be sent to the aforementioned preliminary treatment service server chosen in the mode of UDP.It should be noted that, the order and synchronous/asynchronous mode that send request parameter information in the list of preliminary treatment service server, can be defined.As in precedent, in the business procession of certain web access requests, the result of Hole Detection is the precondition performing data encryption and code conversion, then can define the preliminary treatment service server sending order corresponding with the url of this web access requests in the list of preliminary treatment service server is: Hole Detection server priority, and is synchronized transmission (namely only just can continue to send request parameter information to other preliminary treatment service servers after receiving the result returned); Follow-up for data encryption services device and code conversion server and be asynchronous transmission (parameter information can be sent request when not receiving result to other preliminary treatment service servers).
In the present embodiment, also comprise before receiving the step of the result that preliminary treatment service server returns: obtain the request object that web access requests is corresponding, request object is locked, and the context of its correspondence of buffer memory, and be that request object location registration process result receives event.
Such as, in nginx framework, can, by request object locking, then by its context data buffer memory corresponding in internal memory, then be that request object location registration process result receives event.Result receives event and is web application server when receiving the result that preliminary treatment service server returns, the system event of triggering.Result receive event can when registering and corresponding request object set up mapping relations (identification information by request object set up and mapped, such as, the identification information of request object can be comprised in the required parameter information sent, also comprise this identification information in the corresponding result returned, then also comprise this identification information in the result reception event triggered).
In nginx framework, if certain request object is locked, and after its context is buffered, then its treatment progress then switches to other request objects and processes.That is, web application server is after sending request parameter information to preliminary treatment service server, the web access requests that process is corresponding with this required parameter information can be suspended, and switch to the state of other web access requests of process, thus achieve the multiple web access requests of concurrent processing.
Such as, if nginx application server receives 3 web access requests, then can these 3 web access requests of asynchronous process, namely processor can be each web access requests distributes calculation resources.If certain web access requests is in processing procedure, required parameter information is have sent in a synchronous manner to preliminary treatment service server, enter the blocked state of the result that wait-receiving mode returns, then request object corresponding for this web access requests can be locked, and by the context cache of this request object, namely processor stops the web access requests corresponding to this request object to process, and computational resource is switched to other 2 web access requests of process.The processor resource of web application server is made to obtain maximum using and be unlikely to cause the waste of computational resource.
Step S108, judges that whether the result returned is abnormal, if so, then performs step S110: jump to the wrong page.
The mistake page can be 501 pages (in http agreements the page of numbering 501 mistake, identification server internal error), also can be the page comprising result.Such as, if the suspicious character string that SQL attacks if comprise in aforesaid Hole Detection server detects in web access requests submission data, then the wrong page comprising warning message and articles of law can jumped to.If the account initiating web access requests is Admin Account, then can jumps to the wrong page comprising log information, facilitate keeper to test.
In the present embodiment, if the result returned is without exception, then perform step S112: obtain the result corresponding with result and receive request object corresponding to event, unlocked by request object, and from buffer memory, extract the context of its correspondence.
As in precedent, based on the web application server of nginx framework when receiving the result that preliminary treatment service server returns, result can be triggered and receive event, the callback events process function of its correspondence can be defined when this result of aforementioned registration receives event, then this event handling function is called when triggering result and receiving event, in this event handling function, obtain result receive request object corresponding to event, request object is unlocked.In the present embodiment, result can be obtained according to the identification information of request object and receive request object corresponding to event, the context data of its correspondence after being unlocked, can be extracted in the buffer.After request object is unlocked, the request object that web application server can unlock to this carries out follow-up process.
It should be noted that, when this web application server carries out follow-up process to this request object, can continue to send request parameter information to other preliminary treatment service servers, and then this request object is locked; Also predefined Business Processing function (namely with the mode embedded and the Business Processing function bound of web application framework, that is, can in conventional art the processing method of web access requests be combined) can directly be called.
In one embodiment, also comprise after contextual step corresponding for cache request object: whether the request object detecting web access requests corresponding is recovered cancellation, the result corresponding with request object if so, removing registration receives event.
In nginx framework, the context of the request object of buffer memory has life cycle usually, even receive the overlong time of the result wait returned, then it can not forever be buffered in the internal memory of web application server, may be reclaimed cancellation fall by the Garbage Collection Mechanism of web application server.The result corresponding with described request object that can remove registration in the call back function of the Logout Events of request object receives event.After removing this result reception event, if web application server is when the subsequently received result corresponding with this request object (such as comprising the result of the identification information of this request object), corresponding result can not be triggered and receive event, namely not have the follow-up further process to request object.
In the present embodiment, also predeterminable timeout threshold, if after sending request parameter information to preliminary treatment service server, do not receive the result returned within the time of timeout threshold, then can jump to the wrong page.
In an application scenarios, the operation of the method can based on blocker object.Such as, the method can be run in the blocker object of web application.At web access requests before passing to controller object, first by blocker object, preliminary treatment is carried out to it, perform above-mentioned steps, if result is without exception, then can terminate the operation of blocker object, and web access requests be transferred to blocker object and process.
The method is run in the mode of blocker object, fixing business processing logic can be defined in the controller object of web application framework, and the required parameter information extracted in web access requests, selection preliminary treatment service server and execution are sent request the task definitions such as parameter information in blocker object to preliminary treatment service server, and can according to the difference of business demand, pre-defined polytype blocker object.If developer wishes switch the type of the required parameter information extracted or switch the load-balancing algorithm of selection preliminary treatment service server, then can run the method and realizing fast by switching blocker object, and when running into abnormal, also changeable time former blocker object, thus the degree of coupling reduced between code, convenient deployment and maintenance.
In one embodiment, as shown in Figure 3, a kind of processing unit of web access requests, comprises parameter extraction module 102, business chooses module 104, result receiver module 106, result analysis module 108 and wrong page reminding module 110, wherein:
A processing unit for web access requests, is characterized in that, comprising:
Parameter extraction module 102, for obtaining the web access requests uploaded, extracts the required parameter information submitted in web access requests.
Business chooses module 104, for obtaining the list of preliminary treatment service server, and therefrom chooses preliminary treatment service server.
Result receiver module 106, for required parameter information being sent to the preliminary treatment service server chosen, and receives its result returned.
Result analysis module 108, whether abnormal for judging the result returned.
Mistake page reminding module 110, for jumping to the wrong page when result is abnormal.
In the present embodiment, parameter extraction module 102, also for obtaining the request type of web access requests, judges whether request type is POST, if, then call POST event call-back function, extracted the required parameter information submitted in web access requests by POST event call-back function.
In the present embodiment, result receiver module 106 also for obtaining request object corresponding to web access requests, locks to request object, and the context of its correspondence of buffer memory, and be that described request object registration result receives event.
In the present embodiment, as shown in Figure 4, the processing unit of web access requests also comprises task recovery module 112, request object corresponding to event is received for obtaining the result corresponding with result when result is without exception, request object is unlocked, and from buffer memory, extracts the context of its correspondence.
In the present embodiment, as shown in Figure 4, the processing unit of web access requests also comprises task recycling module 114, whether is recovered cancellation for detecting request object corresponding to web access requests, if so, the result corresponding with request object removing registration receives event.
In the present embodiment, in the list of preliminary treatment service server, comprise preliminary treatment service identification, the corresponding preliminary treatment service server of described preliminary treatment service identification.
Business chooses module 104 also for traveling through the preliminary treatment service identification comprised in the list of preliminary treatment service server, chooses in the preliminary treatment service server corresponding with the preliminary treatment service identification traversed.
In the processing method of above-mentioned web access requests and device, execute the task that be placed on can with on web application server independently preliminary treatment service server by what specifically process the Business Processing algorithm of service logic, if Business Processing algorithm upgrades, do not need to redeploy web application server, web application server can process the web access requests of user constantly when not delaying machine.Preliminary treatment service server, when performing Business Processing algorithm, if there is fatal exception, also can not cause the collapse of web application server, thus improve reliability.
Simultaneously, the execution of Business Processing algorithm is positioned over independently on preliminary treatment service server, calculation task can be performed on multiple stage preliminary treatment service server, avoid the problem that when web application server performs Business Processing algorithm under high concurrent environment, calculation task is overweight, improve the response speed of web application server.
In one embodiment, as shown in Figure 5, provide a kind of server architecture schematic diagram running the processing method of aforementioned web access requests, this server architecture can be applicable on the web application server 10 in Fig. 2.This server 500 can produce larger difference because of configuration or performance difference, one or more central processing units (central processing units can be comprised, CPU) 522(such as, one or more processors) and memory 532, one or more store storage medium 530(such as one or more mass memory units of application program 542 or data 544).Wherein, memory 532 and storage medium 530 can be of short duration storages or store lastingly.The program being stored in storage medium 530 can comprise one or more modules (parameter extraction module 102 as the aforementioned, business choose module 104, result receiver module 106, result analysis module 108 and wrong page reminding module 110), and each module can comprise a series of command operatings in server.Further, central processing unit 522 can be set to communicate with storage medium 530, and server 500 performs a series of command operatings in storage medium 530.Server 500 can also comprise one or more power supplys 526, one or more wired or wireless network interfaces 550, one or more input/output interfaces 558, and/or, one or more operating systems 541, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM etc.
Above-mentioned embodiment illustrated in fig. 1 described in the step performed by server can based on the server architecture shown in this Fig. 5.One of ordinary skill in the art will appreciate that all or part of flow process realized in above-described embodiment method, that the hardware that can carry out instruction relevant by computer program has come, described program can be stored in a computer read/write memory medium, this program, when performing, can comprise the flow process of the embodiment as above-mentioned each side method.Wherein, described storage medium can be magnetic disc, CD, read-only store-memory body (Read-OnlyMemory, ROM) or random store-memory body (Random Access Memory, RAM) etc.
Above embodiment only have expressed several execution mode of the present invention, and it describes comparatively concrete and detailed, but therefore can not be interpreted as the restriction to the scope of the claims of the present invention.It should be pointed out that for the person of ordinary skill of the art, without departing from the inventive concept of the premise, can also make some distortion and improvement, these all belong to protection scope of the present invention.Therefore, the protection range of patent of the present invention should be as the criterion with claims.