Embodiment
In order to make the purpose , technical scheme and advantage of the present invention be clearer, it is right below in conjunction with drawings and Examples
The present invention is further elaborated.It should be appreciated that the specific embodiments described herein are merely illustrative of the present invention, and
It is not used in the restriction present invention.
Element and component in the description of specific distinct unless the context otherwise, the present invention, quantity both can be with single shape
Formula is present, and form that can also be multiple is present, and the present invention is defined not to this.Although the step in the present invention is entered with label
Arrangement is gone, but is not used to limit the precedence of step, unless expressly stated the order of step or holding for certain step
Row is needed based on other steps, and otherwise the relative rank of step is adjustable.It is appreciated that used herein
Term "and/or" is related to and covers one of associated Listed Items or one or more of any and all possible group
Close.
In one embodiment, as shown in figure 1, a kind of processing method of web access requests, this method can be dependent on meter
Calculation machine program, can run in the computer system based on Von Neumann system.The computer system can be web application clothes
Business device, such as nginx application servers.
In the present embodiment, this method includes:
Step S102, obtains the web access requests uploaded, extracts the required parameter information submitted in web access requests.
Web access requests be user by input web page address in browser address bar or on webpage clickthrough and
Button and to web application servers initiate access request.The required parameter information extracted in web access requests then includes
Required parameter(Such as at least one of header information, method information, url information and host information)Or submit data
(For example user fills in the form data submitted after list in POST modes on webpage).
Web application servers are encapsulated after web access requests are received generally according to the required parameter information of extraction
Into request object.For example, in nginx frameworks, web access requests are packaged into request objects;In j2ee frameworks, net
Access to web page request is then encapsulated as in httpRequest objects.
In the present embodiment, the step of extracting the required parameter information submitted in web access requests includes:Obtain webpage
The request type of access request, whether be POST, if so, then calling POST event call-back functions, pass through if judging request type
POST event call-backs function extracts the required parameter information submitted in web access requests.
For example, in nginx frameworks, web application servers are receiving the web access requests of POST types(That is http
Method property values in header information are POST)POST events can be triggered afterwards, the POST events can be called after being triggered
Corresponding POST event call-back functions.The code of required parameter information can be extracted defined in POST event call-back functions in advance.
When POST events are triggered, then it can perform the code defined in the POST event call-back functions automatically to extract web access requests
The required parameter information of middle submission.
Step S104, obtains pretreatment service server list, and therefrom chooses pretreatment service server.
Pretreatment business be to web access requests carry out with web apply operation maintenance it is related the need for request it is pre-
The business first handled.For example, it may be Hole Detection(To whether being examined in request comprising aggressive script or code
Survey, safety assurance is provided for subsequent treatment), data encryption(Encryption data is decrypted, facilitates subsequent treatment), code conversion
(Coded format to the data in request is changed in advance, facilitates subsequent treatment), log statistic and analysis(Web is applied
The daily record for receiving request carries out statistic record and analysis)And it is compressed and decompressed(To the data of the gzip types included in request
It is compressed and decompresses)Deng.
Pretreatment service server is the computer equipment of the corresponding pretreatment service logic of processing.As shown in Fig. 2
Web application servers 10 can be connected with a variety of pretreatment service servers.For example, in the corresponding application scenarios of Fig. 2, pre-processing industry
Business server may include that the Hole Detection server 20, data encryption services device 30 and coding that are connected with web application servers turn
Change server 40.
Wherein, pretreatment service identification, the pretreatment service identification correspondence are included in pretreatment service server list
Service server is pre-processed, the corresponding service server that pre-processes of every kind of service identification can also have multiple, for example, can have many
Individual service identification, corresponds to log statistic and analysis, Hole Detection, compressed and decompressed etc. specifically pretreatment business respectively.And leak
Hole detection service device 20 can also have multiple, and web application servers are according to pretreatment service server list selection leak inspection
Hole Detection server can be chosen on the premise of load balancing by surveying in server 20.In other application scene, industry is pre-processed
The service identification of business is also not necessarily limited to above-mentioned Hole Detection, data encryption, code conversion, log statistic and analysis and compression solution
Compression, web application servers 10 can be also connected with other kinds of pretreatment service server.
In the present embodiment, the step of pretreatment service server is chosen from pretreatment service server list can be specific
For:
The pretreatment service identification included in traversal pretreatment service server list, in the pretreatment business with traversing
Chosen in the corresponding pretreatment service server of mark.
The N kinds pretreatment business that is, if developer's configuration in preprocessing server list in advance is known clearly, and be
It is every kind of to pre-process one or more corresponding pretreatment service server of service deployment, then receiving web access requests
When, can according to preprocessing server list be every kind of pretreatment business in select one or more pre-process service server come pair
The web access requests are pre-processed.
Step S106, required parameter information is sent to the pretreatment service server of selection, and receives the place of its return
Manage result.
In the present embodiment, the required parameter information of foregoing extraction can be sent to pre- to foregoing selection in the way of UDP
Processing business server.Required parameter information is sent it should be noted that can be defined in pretreatment service server list
Order and synchronous/asynchronous mode.In such as precedent, in the business procession of some web access requests, the knot of Hole Detection
Fruit is the precondition for performing data encryption and code conversion, then can defined in pretreatment service server list with the webpage
The corresponding pretreatment service server transmission order of the url of access request is:Hole Detection server priority, and be synchronized transmission
(It only just may proceed to send required parameter letter to other pretreatment service servers after the result of return is received
Breath);It is follow-up to be data encryption services device and code conversion server and be asynchronous transmission(Result can not received
In the case of to other pretreatment service servers send required parameter information).
In the present embodiment, also include before the step of receiving the result of pretreatment service server return:Obtain
The corresponding request object of web access requests, to request object locking, and caches its corresponding context, and be request object note
Volume result receives event.
For example, in nginx frameworks, can by request object lockings, then by it in internal memory corresponding context number
According to caching, then event is received for request object registration result.It is that web application servers exist that result, which receives event,
When receiving the result that pretreatment service server is returned, the system event of triggering.Result receives event can be in note
During volume mapping relations are set up with corresponding request object(It can be mapped by asking the identification information of object to be set up, for example, can be in hair
Include in the identification information of request object, the result accordingly returned and also believe comprising the mark in the required parameter information sent
Also the identification information is included in breath, then the result reception event triggered).
In nginx frameworks, if after some request object is locked, and its context is buffered, then its treatment progress
Other request objects are then switched to be handled.That is, web application servers are sent out to pretreatment service server
Send after required parameter information, processing web access requests corresponding with the required parameter information can be suspended, and switch to processing
The state of other web access requests, it is achieved thereby that the multiple web access requests of concurrent processing.
If, can asynchronous process 3 web page access for example, nginx application servers receive 3 web access requests
Request, i.e. processor can distribute computing resource for each web access requests.If some web access requests is in processing procedure,
In a synchronous manner to pretreatment service server have sent required parameter information, into etc. return to be received result
Blocked state, then can by the corresponding request object locking of the web access requests, and by the context cache of the request object,
I.e. processor stops handling the corresponding web access requests of request object, and computing resource is switched to and handles other
2 web access requests.So that the processor resource of web application servers is maximally utilized and is unlikely to cause to calculate to provide
The waste in source.
Step S108, judges whether the result returned is abnormal, if so, then performing step S110:Jump to faulty page
Face.
The mistake page can be 501 pages(It is wrong inside the page of the mistake of numbering 501, identification server in http agreements
By mistake)Or the page comprising result.If if for example, foregoing Hole Detection server detect web page access please
The suspicious character string attacked in the submission data asked comprising SQL, then can jump to comprising warning message and articles of law
The mistake page.If the account for initiating web access requests is Admin Account, the faulty page comprising log information can be jumped to
Face, facilitates keeper to test.
In the present embodiment, if the result returned is without exception, step S112 is performed:Obtain corresponding with result
Result receive the corresponding request object of event, will request object unblock, and extract from caching its corresponding context.
As in precedent, the web application servers based on nginx frameworks are receiving the place that pretreatment service server is returned
When managing result, result can be triggered and receive event, its can be defined when foregoing registration result receives event corresponding
Callback events handle function, then the event handling function are called when triggering result reception event, in the event handling
Result is obtained in function and receives the corresponding request object of event, by request object unblock.In the present embodiment, can according to please
Ask the identification information of object to obtain result and receive the corresponding request object of event, can be extracted in the buffer after being unlocked
Its corresponding context data.After request object is unlocked, the request object that web application servers can have been unlocked to this enters
The follow-up processing of row.
It should be noted that when the web application servers carry out follow-up processing to the request object, can continue to other
Pre-process service server and send required parameter information, then again by the request object locking;Also it can directly invoke pre-defined
Business processing function(The business processing function bound with embedded mode and web application frameworks, that is to say, that can be with biography
The processing method of web access requests is combined in system technology).
In one embodiment, also include after the step of context that cache request object is corresponding:Detect that webpage is visited
Ask whether the corresponding request object of request is recovered cancellation, if so, the result corresponding with request object for removing registration connects
Receipts event.
In nginx frameworks, the context of the request objects of caching generally has life cycle, even receives and returns
Result wait overlong time, then its will not forever be buffered in the internal memory of web application servers, may be by web
The Garbage Collection Mechanism of application server reclaims cancellation and fallen.It can be removed in the call back function of the Logout Events of request objects
The result corresponding with the request object of registration receives event.Remove after the result reception event, if web is applied
Server is in subsequently received result corresponding with the request object(The place of identification information for example comprising the request object
Manage result)When, corresponding result will not be triggered and receive event, i.e., do not have the follow-up further place to request objects
Reason.
In the present embodiment, also predeterminable timeout threshold, if being sent to pretreatment service server after required parameter information,
Do not receive the result of return within the time of timeout threshold, then can jump to the wrong page.
In an application scenarios, the operation of this method can be based on blocker object.For example, the interception that can be applied in web
This method is run in device object.In web access requests before controller object is passed to, first it is entered by blocker object
Row pretreatment, performs above-mentioned steps, if result is without exception, can terminate the operation of blocker object, and by web page access
Request is transferred blocker object to and handled.
This method is run in the way of blocker object, fixed business processing logic web application frameworks can be defined on
Controller object in, and the required parameter information extracted in web access requests, selection pretreatment and are held service server
Row sends the task definitions such as required parameter information in blocker object to pretreatment service server, and can be according to business demand
Difference, pre-define polytype blocker object.If developer wishes the class for the required parameter information that switching is extracted
The load-balancing algorithm of type or switching selection pretreatment service server, then can run the party by switching blocker object
Method is quickly realized, and when running into abnormal, also may switch back to former blocker object, so that the coupling between reducing code
Degree, convenient deployment and maintenance.
In one embodiment, as shown in figure 3, a kind of processing unit of web access requests, including parameter extraction module
102nd, business chooses module 104, result receiving module 106, result analysis module 108 and wrong page reminding module
110, wherein:
A kind of processing unit of web access requests, it is characterised in that including:
Parameter extraction module 102, what is submitted for obtaining in the web access requests uploaded, extraction web access requests please
Seek parameter information.
Business chooses module 104, for obtaining pretreatment service server list, and therefrom chooses pretreatment business service
Device.
Result receiving module 106, for required parameter information to be sent to the pretreatment service server of selection, and
Receive the result of its return.
Whether result analysis module 108, the result for judging to return is abnormal.
Mistake page reminding module 110, for jumping to the wrong page when result is abnormal.
In the present embodiment, parameter extraction module 102 is additionally operable to obtain the request type of web access requests, judges request
Whether type is POST, if so, then calling POST event call-back functions, extracting web page access by POST event call-backs function please
Seek the required parameter information of middle submission.
In the present embodiment, result receiving module 106 is additionally operable to obtain the corresponding request object of web access requests,
To request object locking, and its corresponding context is cached, and event is received for the request object registration result.
In the present embodiment, as shown in figure 4, the processing unit of web access requests also includes task recovery module 112, use
The corresponding request object of event is received in obtaining result corresponding with result when result is without exception, will be asked
Object is unlocked, and extracts from caching its corresponding context.
In the present embodiment, as shown in figure 4, the processing unit of web access requests also includes task recycling module 114, use
Cancellation whether is recovered in the corresponding request object of detection web access requests, if so, removing the corresponding with request object of registration
Result receive event.
In the present embodiment, pretreatment service identification, the pretreatment business are included in pretreatment service server list
Mark correspondence pretreatment service server.
Business chooses the pretreatment service identification that module 104 is additionally operable to include in traversal pretreatment service server list,
The pretreatment service identification with traversing it is corresponding pretreatment service server in chosen.
In the processing method and processing device of above-mentioned web access requests, by the business processing algorithm of specific processing business logic
Execution task be placed on can with the pretreatment service server of web application server independences, if business processing algorithm carry out more
Newly, and web application servers need not be redeployed, web application servers can constantly processing be used in the case of machine of not delaying
The web access requests at family.Service server is pre-processed when performing business processing algorithm, if there is fatal exception, will not also be led
The collapse of web application servers is caused, so as to improve reliability.
Meanwhile, the execution of business processing algorithm is positioned on independent pretreatment service server so that calculating task
It can pre-process on service servers and perform at many, it is to avoid web application servers under high concurrent environment perform business processing
The problem of calculating task is overweight during algorithm, improves the response speed of web application servers.
In one embodiment, there is provided a kind of processing method for running foregoing web access requests as shown in Figure 5
Server architecture schematic diagram, the server architecture can be applied on the web application servers 10 in Fig. 2.The server 500 can
Produced because of configuration or performance difference than larger difference, one or more central processing units can be included(central
Processing units, CPU)522(For example, one or more processors)With memory 532, one or more
Store the storage medium 530 of application program 542 or data 544(Such as one or more mass memory units).Wherein, deposit
Reservoir 532 and storage medium 530 can be of short duration storage or persistently storage.Being stored in the program of storage medium 530 can include
One or more modules(Parameter extraction module 102 as the aforementioned, business choose module 104, result receiving module
106th, result analysis module 108 and wrong page reminding module 110), each module can be including to one in server
Series of instructions is operated.Further, central processing unit 522 could be arranged to communicate with storage medium 530, in server 500
The upper series of instructions operation performed in storage medium 530.Server 500 can also include 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 than one operating system 541, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM,
FreeBSDTM etc..
Described in above-mentioned embodiment illustrated in fig. 1 can be based on the service shown in the Fig. 5 as the step performed by server
Device structure.One of ordinary skill in the art will appreciate that realize all or part of flow in above-described embodiment method, being can be with
The hardware of correlation is instructed to complete by computer program, described program can be stored in a computer read/write memory medium
In, the program is upon execution, it may include such as the flow of the embodiment of above-mentioned each method.Wherein, described storage medium can be magnetic
Dish, CD, read-only memory(Read-Only Memory, ROM)Or random access memory(Random Access
Memory, RAM)Deng.
Above example only expresses the several embodiments of the present invention, and it describes more specific and detailed, but can not
Therefore it is interpreted as the limitation 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, various modifications and improvements can be made, these belong to the protection model of the present invention
Enclose.Therefore, the protection domain of patent of the present invention should be determined by the appended claims.