CN109324958A - A kind of REST unifies method of calibration, device, equipment and readable storage medium storing program for executing - Google Patents
A kind of REST unifies method of calibration, device, equipment and readable storage medium storing program for executing Download PDFInfo
- Publication number
- CN109324958A CN109324958A CN201810677117.1A CN201810677117A CN109324958A CN 109324958 A CN109324958 A CN 109324958A CN 201810677117 A CN201810677117 A CN 201810677117A CN 109324958 A CN109324958 A CN 109324958A
- Authority
- CN
- China
- Prior art keywords
- rest
- verification
- format
- parameter
- request
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3604—Software analysis for verifying properties of programs
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a kind of REST to unify method of calibration, method includes the following steps: receiving REST request;Judge in preset format tree with the presence or absence of object format object corresponding with REST request;Wherein, in preset format tree, node corresponding with each REST interface respectively corresponds a format object, and format object includes the corresponding checking parameter of each verification project;If it is, obtaining object format object;REST request is verified using each verification project corresponding checking parameter of object format object.It can smoothly complete and the parameter of various REST request is verified when receiving REST request, that is, realize the unified verification of RSET, simplify development process, reduce the calling of function or method, can effectively promote the accuracy rate of REST check results.The invention also discloses a kind of REST to unify calibration equipment, equipment and readable storage medium storing program for executing, has corresponding technical effect.
Description
Technical field
The present invention relates to software technology field, unify method of calibration, device, equipment and readable more particularly to a kind of REST
Storage medium.
Background technique
REST (Representational State Transfer, declarative state transfer) is born in interconnection net height
Developing period, with stateless, easy extension, more adapt to current internet multisystem, multi rack structure the features such as be widely used.
Particularly, in fields such as cloud service, storage systems using more.
After REST service termination receives REST request, needs to verify REST request correctness, then execute request.However,
Since REST interface is varied, also cause REST parameter varied, is difficult to find a kind of unified verification mode.At present
REST parameter verification is usually to provide different parameter verifications according to different REST interfaces.But sometimes due to value difference
Different methods of calibration is developed, very time-consuming and laborious, development amount is big and cumbersome.And when different methods of calibration is by more people
When exploitation, it is easy to cause code to repeat, more cumbersome to the verification of parameter especially when there are many interface, it is even more impossible to guarantee
The accuracy of check results.
In conclusion the problems such as how efficiently solving simplified REST development process, is that current those skilled in the art are anxious
Technical problem to be solved.
Summary of the invention
The object of the present invention is to provide a kind of REST to unify method of calibration, device, equipment and readable storage medium storing program for executing, with simplification
Development process improves development efficiency.
In order to solve the above technical problems, the invention provides the following technical scheme:
A kind of REST unifies method of calibration, comprising:
Receive REST request;
Judge in preset format tree with the presence or absence of object format object corresponding with REST request;Wherein, described
In preset format tree, node corresponding with each REST interface respectively corresponds a format object, and the format object includes each
The corresponding checking parameter of a verification project;
If it is, obtaining the object format object;
Using the object format object the corresponding checking parameter of each verification project to the REST request into
Row verification.
Preferably, further includes:
Formatted file is respectively created for each REST interface;Wherein, the file path of the formatted file and REST interface
URI it is consistent, the formatted file includes relying between mutex relation, parameter between the mandatory parameter of corresponding REST interface, parameter
Relationship, range of parameter values;
Each formatted file is loaded onto memory, and utilizes the corresponding file road of each formatted file
Diameter creates format tree;
Each formatted file is resolved into the corresponding format object of current development language, and is stored in the format tree
In.
Preferably, it whether there is object format object corresponding with REST request in the judgement preset format tree,
Include:
The target URI requested using the REST is searched and is judged that the format tree whether there is and requested with the REST
Corresponding destination node;
If it is not, then directly determining, there is no object format objects corresponding with REST request;
If it is, judging the destination node with the presence or absence of the corresponding object format object.
Preferably, using the corresponding checking parameter of each verification project of the object format object to the REST
Request is verified, comprising:
Using the corresponding checking parameter of each verification project of the object format object in REST request
Parameter verified;Wherein, the verification project includes parameter value verification, dependence verification, alternative verification and essential ginseng
Number verification;
In to each verification project checking procedure, when there is any one verification project failure, stop school
Test simultaneously output verification failure result;
When each verification project passes through, output verification successful result.
Preferably, mandatory parameter verifies, comprising:
Judge whether there is the mandatory parameter in the REST request;
It is verified if it is, directly determining by the mandatory parameter;
If it is not, then further determining whether there is the target component that there is mutex relation with the mandatory parameter;
If there is the target component, it is determined that verified by the mandatory parameter.
Preferably, the reception REST request, comprising:
The REST with TOKEN is received to request.
Preferably, in the corresponding checking parameter of each verification project using the object format object to described
Before REST request is verified, further includes:
TOKEN in REST request is verified;
If verification failure, stops verification and output verification failure result.
A kind of REST unifies calibration equipment, comprising:
REST request receiving module, for receiving REST request;
Object format object judgment module, for judging in preset format tree with the presence or absence of corresponding with REST request
Object format object;Wherein, in the preset format tree, node corresponding with each REST interface respectively corresponds a format
Object, the format object include the corresponding checking parameter of each verification project;
Object format object acquisition module, for obtaining the object format object when there are the object format objects;
REST requests correction verification module, for the corresponding verification of each verification project using the object format object
Parameter verifies REST request.
A kind of REST unifies calibration equipment, comprising:
Memory, for storing computer program;
Processor realizes the step of above-mentioned REST unifies method of calibration when for executing the computer program.
A kind of readable storage medium storing program for executing is stored with computer program, the computer program quilt on the readable storage medium storing program for executing
Processor realizes the step of above-mentioned REST unifies method of calibration when executing.
It can be determined in preset format tree using method provided by the embodiment of the present invention when receiving REST request
And obtain out object format object corresponding with REST request.Wherein, in the preset format tree, with each REST interface pair
The node answered respectively corresponds a format object, and the format object includes the corresponding checking parameter of each verification project;
When not finding object format object in preset format tree, it is believed that the REST request being currently received is improper asks
Ask, can the direct prompt information of back-checking failure or request error, verification number is reduced with this, improves verification efficiency.So
It can be completed afterwards using the object format object and the parameter in REST request verified.As long as that is, developing
Cheng Zhong has created various REST and has requested corresponding format object.It is defined in the format object needed for corresponding REST request
The checking parameter of the verification project of verification and each verification item objects.That is, can be smoothly complete when receiving REST request
The parameter of various REST requests is verified in pairs, that is, realizes the unified verification of RSET.Because without being requested for each REST
Different methods of calibration is respectively set in (REST interface), simplifies development process.In addition, due to without being each REST interface
Individually creation method of calibration, in actual checking treatment logic, can also simplified code, reduce the tune between function or method
With, can effectively improve code accuracy rate, further promoted REST check results accuracy rate.
Correspondingly, the embodiment of the invention also provides unify the corresponding REST of method of calibration with above-mentioned REST to unify school
Experiment device, equipment and readable storage medium storing program for executing, have above-mentioned technique effect, and details are not described herein.
Detailed description of the invention
In order to more clearly explain the embodiment of the invention or the technical proposal in the existing technology, to embodiment or will show below
There is attached drawing needed in technical description to be briefly described, it should be apparent that, the accompanying drawings in the following description is only this
Some embodiments of invention for those of ordinary skill in the art without creative efforts, can be with
It obtains other drawings based on these drawings.
Fig. 1 unifies the implementation flow chart of method of calibration for REST a kind of in the embodiment of the present invention;
Fig. 2 is the formatted file content schematic diagram that is created when creating format object in development process;
Fig. 3 is the content schematic diagram of required parameter clipped " ... " in Fig. 2;
Fig. 4 is the constraint content schematic diagram of parameter value;
Fig. 5 unifies the specific implementation flow chart of method of calibration for REST a kind of in the embodiment of the present invention;
Fig. 6 unifies the structural schematic diagram of calibration equipment for REST a kind of in the embodiment of the present invention;
Fig. 7 unifies the structural schematic diagram of calibration equipment for REST a kind of in the embodiment of the present invention.
Specific embodiment
Core of the invention is to provide a kind of REST and unifies method of calibration, and this method is connect by presetting different REST
Mouthful, the format pair of REST interface and URI (Uniform Resource Identifier, uniform resource identifier) Corresponding matching
As.And the verification project and checking parameter of the parameter of corresponding REST interface are pre-defined in each format object.Cause
This, can carry out the parameter in REST request using format object in the REST request for receiving each REST interface
Verification, without the unused method of inspection is arranged for each interface.Method of calibration is only unified by a REST or is referred to as
A set of REST checking process can verify multiple and different REST interfaces, i.e. the unified verification of realization REST, simplification is opened
Hair process.
Another core of the invention, which is to provide, unifies the unified verification dress of the corresponding REST of method of calibration with above-mentioned REST
It sets, equipment and readable storage medium storing program for executing.
In order to enable those skilled in the art to better understand the solution of the present invention, with reference to the accompanying drawings and detailed description
The present invention is described in further detail.Obviously, described embodiments are only a part of the embodiments of the present invention, rather than
Whole embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art are not making creative work premise
Under every other embodiment obtained, shall fall within the protection scope of the present invention.
Embodiment one:
Referring to FIG. 1, Fig. 1 unifies the flow chart of method of calibration for REST a kind of in the embodiment of the present invention, this method includes
Following steps:
S101, REST request is received.
Technical solution provided by the embodiment of the present invention can be applied to use in the software systems of REST.Because REST is asked
The operation requests being adjusted to REST are sought, and REST is matched one by one with URI, thus REST request may be considered correspondence
The request that content in some URI is operated.
REST request can be increase, the modification, the request for adjusting or checking URL content that user sends in client.
It can be the request of certain browsing record of deletion, or check certain picture for example, can be the request of modification user name
Request.It should be noted that in this application, not done for the object of REST request operation, the particular content of REST request
It limits.That is, being different from an existing method of calibration only can determine that the method or mode of a kind of or one kind REST request
Difference, method provided by the embodiment of the present invention can request REST carry out unified verification, thus for REST request itself
It can be without being limited to the corresponding request of a certain specific REST interface.
S102, judge in preset format tree with the presence or absence of object format object corresponding with REST request.
Wherein, in the preset format tree, node corresponding with each REST interface respectively corresponds a format object,
The format object includes the corresponding checking parameter of each verification project.
In embodiments of the present invention, a format tree can be preset, and in format tree section corresponding with REST interface
Corresponding format object is established on point.For example, for example in the presence of the URI of two REST interfaces be respectively/rest/device and/
Rest/device/fan, then " device " node in format tree, there is the format object of "/rest/device " interface;" fan " section
Point is also with the format object of "/rest/device/fan " interface.It should be noted that created format object is asked with REST
It asks with corresponding relationship.Specifically, a format object can be created for each URI, it is arranged in the format object to this
The parameter for the REST request that content in URI is operated is defined.It can be between the classification of defined parameters, parameter value, parameter
All contents relevant to parameter such as dependence, mutex relation between parameter can be defined.
The label information relationship corresponding with each node of preset format tree that can be requested by REST, it is determined whether deposit
In object format object corresponding with REST request.For example, the label information can be the URI of the object of REST request operation.
If so, thening follow the steps S103;If it is not, then thinking that REST request is false request, direct output error
Prompt information.
S103, object format object is obtained.
After determining that REST request has corresponding object format object, target can be obtained by way of reading
Format object.Specifically, the label information such as name or number of object format object can be read, object format can also be read
The corresponding checking parameter of each verification project in object.
S104, REST request is verified using each verification project corresponding checking parameter.
When verifying to REST request, the corresponding checking parameter of each verification project is mainly utilized, judgement should
Parameter, parameter value in REST request request whether the parameter request of corresponding REST interface matches or algorithm meets with the REST
The requirement or definition of REST interface.Currently, before being verified to the parameter that REST is requested, can also identity to user into
Row verification, verifies user right.
Preferably, when the REST request received is the request with TOKEN.It can be in the ginseng in requesting REST
Before number is verified, TOKEN verification is first carried out.Specifically, TOKEN verification includes:
Step 1:
TOKEN in REST request is verified;
Step 2: if verification failure, stops verification and output verification failure result.
It is illustrated for ease of description, below combining above-mentioned steps one and step 2.
When REST client is interacted with server-side, by client, username and password is can be used to service in user
End request TOKEN.After requesting TOKEN, the REST sent using client requests TOKEN placing HTTP header, for clothes
The identity for end verifying client of being engaged in.Certainly, there are validity periods by TOKEN, and when TOKEN is expired, client should be re-requested
TOKEN.It verifies TOKEN validity, verifies and successfully go in next step, i.e. S104;Otherwise stop verification and output verification is unsuccessfully tied
Fruit.In this way, the legitimacy of REST request can be ensured, the malicious operation of illegal user is reduced.
Identity is verified, user right is verified, the verification sequence verified to TOKEN can sequentially be held
Row, can execute parallel.It should be noted that, once there is certain verification failure, can stop verifying and exporting in checking procedure
Failure result is verified, with this to reduce inessential verification, is promoted and verifies efficiency, reduction computer resource waste.
It can be determined in preset format tree using method provided by the embodiment of the present invention when receiving REST request
And obtain out object format object corresponding with REST request.Wherein, in the preset format tree, with each REST interface pair
The node answered respectively corresponds a format object, and the format object includes the corresponding checking parameter of each verification project;
When not finding object format object in preset format tree, it is believed that the REST request being currently received is improper asks
Ask, can the direct prompt information of back-checking failure or request error, verification number is reduced with this, improves verification efficiency.So
It can be completed afterwards using the object format object and the parameter in REST request verified.As long as that is, developing
Cheng Zhong has created various REST and has requested corresponding format object.It is defined in the format object needed for corresponding REST request
The checking parameter of the verification project of verification and each verification item objects.That is, can be smoothly complete when receiving REST request
The parameter of various REST requests is verified in pairs, that is, realizes the unified verification of RSET.Because without being requested for each REST
Different methods of calibration is respectively set in (REST interface), simplifies development process.In addition, due to without being each REST interface
Individually creation method of calibration, in actual checking treatment logic, can also simplified code, reduce the tune between function or method
With, can effectively improve code accuracy rate, further promoted REST check results accuracy rate.
It should be noted that based on the above embodiment one, for convenient for those skilled in the art understand that and realizing that the present invention is real
Technical solution provided by example is applied, the embodiment of the invention also provides be correspondingly improved scheme.Involved in the subsequent embodiment with
It can mutually be referred between same steps or corresponding steps in above-described embodiment one, corresponding beneficial effect can also be cross-referenced,
It is no longer repeated one by one in improvement embodiment hereafter.
Preferably, corresponding lattice can be established for each REST interface according to each REST interface as minimum unit
Formula object.Specifically includes the following steps:
Step 1: formatted file is respectively created for each REST interface.
Wherein, the file path of formatted file is consistent with the URI of REST interface, and formatted file includes corresponding REST interface
Mandatory parameter, dependence, range of parameter values between mutex relation, parameter between parameter.
A formatted file is created for each REST interface, which is that the corresponding parameter of REST interface is fixed
Justice, or it is known as the checking parameter when correctness progress items verification of verification RSET request corresponding with the REST interface.Tool
Body, JSON format can be used, is that the corresponding formatted file of each REST interface adds file content.Wherein, file content
The agreement supported including REST interface, the method for support, whether verify between Token, parameter, parameter between mutex relation, parameter according to
Dependence etc. between mutex relation, parameter value between the relationship of relying, parameter value, parameter value.
Step 2: each formatted file is loaded onto memory, and utilize the corresponding file road of each formatted file
Diameter creates format tree.
All formatted files are loaded onto memory, and create format tree, i.e. each format text using file path
The file path of part can uniquely determine out a corresponding node in format tree.
Step 3: each formatted file is resolved to the corresponding format object of current development language, and it is stored in format tree.
Formatted file is parsed, can parse as the identifiable format object of current development language, and be stored in format
In tree.Wherein, current development language can be common development language, such as: java language development is used, it can be by lattice
Formula document analysis is at java object;When using python language development, formatted file is parsed into python object, the present invention is real
Apply the unlimited settled preceding development language of example.
It should be noted that in this application, the corresponding formatted file of a REST interface, formatted file path with
The URI of REST interface is consistent.For example, the URI of REST interface is "/rest/security/usergrp ", then formatted file path
It is certainly herein relative directory for "/rest/security/user.fmt ".Since there may be variables in URI, such as inquire
User list under user group " usergrp1 ", URI may be "/rest/security/usergrp/usergrp1/user ",
" usergrp1 " herein is the name of certain user group, is variable.Present invention provide that " " is used to indicate the variable in URI, this
When this URI be "/rest/security/usergrp/./user ".
It, can be above-mentioned by executing after having created the corresponding format object of all or common REST interface
The unified verification of REST is realized in the operation of verification step described in embodiment one.
Preferably, when step S102 in embodiment one, may include:
Step 1: the target URI requested using REST, is searched and judges format tree with the presence or absence of corresponding with REST request
Destination node;
If not, executing step 2;If so, executing step 3.
Step 2: directly determining, there is no object format objects corresponding with REST request;
Step 3: judging destination node with the presence or absence of corresponding object format object.
It is illustrated for ease of description, below combining above three step.
Due to creation format object and REST interface have one-to-one relationship, and REST request target URI with
REST also has corresponding relationship.Therefore, REST request and format object also specific corresponding relationship.It can use the mesh of REST request
The corresponding relationship between URI and format object is marked, mesh corresponding with REST request can be first determined whether there is in format tree
Mark node.If there is no corresponding destination node, it may be considered that REST request is false request, directly stop verification,
And the prompt information of output verification failure result or REST request error.When there are corresponding destination node, it is determined that the mesh
Whether mark node has corresponding format object, requests corresponding object format pair if there is the format object is then determined as REST
As.If without corresponding format object the foundation of the format object of destination node may be missed in development process,
It can stop verifying, and output verification failure result or output format object do not have to existing prompt information and give development management people
Member, to be supplemented in time.
Preferably, after getting object format object, when testing to REST request, i.e., the step of above-mentioned example one
Rapid S104 may comprise steps of:
Step 1: using the corresponding checking parameter of each verification project of object format object in REST request
Parameter verified.
Wherein, verification project includes parameter value verification, dependence verification, alternative verification and mandatory parameter verification.
Step 2:, when there is any one verification project failure, stopping verification in each verification project checking procedure
And output verification failure result.
Step 3: when each verification project passes through, output verification successful result.
It is illustrated for ease of description, below combining above three step.
In the corresponding checking parameter of each verification project using object format object to the parameter in REST request
When being verified, parameter value verification, dependence verification, alternative verification and essential ginseng mainly are carried out to the parameter in REST request
Number verification.
Wherein, parameter value verifies, and mainly judges whether the numerical value of the parameter in REST request meets corresponding REST interface
Parameter value and parameters value between dependence and mutex relation.
Dependence verification mainly judges between the parameter in REST request with the presence or absence of missing.That is, being deposited between certain parameters
In complementary relationship, such as parameter value a and parameter value b is appearance in pairs, and only includes parameter value in some REST request
A can assert that REST request is unsatisfactory for the dependence between parameter, i.e. dependence verification failure without parameter value b at this time.
Alternative verification mainly judges the parameter in REST request with the presence or absence of mutually exclusive, conflicting situation.Example
Such as, when there is parameter a, project c is created, when there is parameter b, deleting project c, parameter a and parameter b, there are mutex relations;When
There is a REST request, existing parameter a has parameter b again in the request, has mutex relation based on a and b, that is, can determine whether this
REST request is false request, and verification does not pass through.
Mandatory parameter verification, mainly judges whether certain request is full request.For example, the URL of the request is the finger of webpage
When determining picture, corresponding operation is only when checking, deleting, that is to say, that the parameter in the REST request of the corresponding URL should correspond to
One of them, if a REST request occur is that can be considered invalidation request or mistake also without the parameter of deletion without the parameter checked
Accidentally request.
Preferably due to certain parameters are there are alternative, thus, although there is no mandatory parameter can also be effective in request
Request can also be verified by mandatory parameter.In order to avoid the generation of this kind of situation is judged by accident, optional parameters judgement includes:
Step 1: judging whether there is mandatory parameter in REST request.
If so, executing step 2;If not, executing, step 3 is further to be judged.
It is verified Step 2: directly determining by mandatory parameter.
Step 3: judging whether there is the target component that there is mutex relation with mandatory parameter.
If there is target component, it is determined that verified by mandatory parameter;If it does not exist, then directly determining mandatory parameter
Verification failure.
It should be noted that when there is any one verification failure, then stopping when being verified to the parameter that REST is requested
It only verifies, and output verification failure result;Only when all verifications pass through, output verification successful result, to execute
REST request.It verifies in addition, the embodiment of the present invention is signified by referring to that current corresponding REST interface correspondence needs to verify
Verification project by being to pass through, and the corresponding verification project of non-present REST interface is then not required to by or without carrying out school
It tests, can directly skip.
Embodiment two:
For just those skilled in the art, technical solution provided by the embodiment of the present invention is understood, below specifically to apply
Example, and be provided for the embodiments of the invention technical solution in conjunction with design parameter and be described in detail.
Referring to FIG. 2, Fig. 2 is the formatted file content schematic diagram created when creating format object in development process,
In:
1) " protocol ": indicate support agreement, support value HTTP, HTTPS, BOTH, BOTH wherein,
Protocol, default value (in not specified situation) are BOTH;
2) " method ": indicating the HTTP method set supported, array value not subregion capital and small letter, and array element value can be with
For get, put, post, patch, delete etc., default supports all methods;
3) " check_token ": representing whether verification TOKEN, can value: yes or no, default value yes;
4) it " privilege ": when indicating the permission, only check_token value yes that request REST needs, just verifies
This constraint;
5) " privilege.get ": indicating the authority set needed when requesting method is get, meets one of set power
Limit;Privilege.put, privilege.patch, privilege.post, privilege.delete are similarly;
6) " params ": the restriction on the parameters supported is indicated;
7) " params.get ": restriction on the parameters when requesting method is get is indicated;Params.put requesting method is
Restriction on the parameters when " put ";Params.patch, params.post, params.delete are similarly;Omission in these constraints
Number " ... " indicate content omit, hereafter explain.
In two kinds of situation, a kind of in request body, another kind is after requesting URI for HTTP/HTTPS required parameter.Such as
" http:182.16.3.32:8080/rest/security/usergrp? type=root&name=grp1 ", wherein parameter
When after URI, " type ", " name " are parameter, and the value of these parameters is simple data type (number, character string) cannot
It is array or object.When parameter is in body, content of parameter of the present invention can be JSON object, and only comprising letter in JSON object
The attribute (not including object or array) of forms data type, this is just similar with the parameter after URI, and the parameter of another kind of form is united
One gets up.
Next Fig. 3 is introduced, Fig. 3 is the content schematic diagram of required parameter clipped " ... " in Fig. 2." ... " is array
Content, each element of array are an object, the constraint of a corresponding parameter, as shown in Figure 2.
1) " name ": expression parameter name;
2) " required ": expression parameter whether be it is essential, can value: yes or no, default value no;
3) " dependent ": the dependence of expression parameter;
4) " dependent [i] ": one of Dependency Set of expression parameter, parameter meet one of dependent
The constraint of [i];
5) " dependent [i] [j] ": for dependent [i], parameter must satisfy all dependent
[i] [j] (j=0,1 ...) when, just think that parameter meets dependent [i] constraint.
6) it " dependent [i] [j] .option ": indicates to rely on the parameter name of parameter;
7) it " dependent [i] [j] .values ": indicates to rely on the parameter value of parameter, meets one of value, such as
This field of fruit is not present, but option field exists, and indicates to rely on entire parameter;
8) " mutex ": the mutual exclusion number set of expression parameter, the parameter there are identical mutual exclusion number is mutual exclusion;
9) " value ": the constraint of expression parameter value.There is no when this attribute, indicating this parameter printenv value, in this attribute
Hold and omits, it is hereinafter described.
As shown in figure 4, Fig. 4 is the constraint content schematic diagram of parameter value:
1) whether " allowList ": allowing multiple parameter values, and multiple parameter values are divided with English colon, can value: yes
Or no, default value no;
2) " is_number ": whether Parameter Value Type is number, can value: yes or no, default value no;
3) " allowed_values ": can value set, there are when this attribute, parameter value can only be taken during this gathers
Value;
4) " rang ": when parameter value is number, the value range of expression parameter value;When parameter value is character string, word is indicated
Accord with the value range of string length;
5) " rang.max ": maximum value;
6) " rang.min ": minimum value;
7) " rang.step ": value step-length;
8) " regular ": the regular expression that parameter value need meet, it is only effective to the parameter value of character string type;
9) it " regular_dependent ": indicates to rely on other parameters to the canonical verification of parameter value, only to character string class
The parameter value of type is effective;
10) it " regular_dependent [i] .option_name ": indicates to rely on the parameter name of parameter;
11) it " regular_dependent [i] .option_value ": indicates to rely on the parameter value of parameter;
12) " regular_dependent [i] .regular ": when meeting this dependence, canonical table that parameter value need meet
Up to formula;
13) " relation ": dependence and the mutual exclusion constraint of parameter value;
14) " relation [i] .value ": this parameter needs to meet this constraint when taking this value;
15) " relation [i] .dependent ": the dependence constraint of parameter value, the dependent constraint of similar parameters,
Except that one be to parameter dependence constraint, one be to parameter value dependence constraint;
16) " relation [i] .mutex ": the mutual exclusion number set of parameter value, parameter value or ginseng with identical mutual exclusion number
Mutual exclusion between number.
In above-mentioned constraint, the pact of allowed_values, rang, regular, regular_dependent to parameter value
There are contradictions for beam, this four constraint priorities are (from high to low) in example thus, it may be assumed that
1) when there is " allowed_values ", then it need not meet other three constraints;
2) when satisfaction " regular_dependent " meets, it is not necessary to meet " rang ", " regular ";
3) when meeting " regular ", it is not necessary to meet " rang ".
It should be noted that all bind fields can be not present in formatted file, in the absence of by constraint default
Value verification REST request, if not carrying out the verification of this constraint to REST request without default value.
In practical applications, when starting such as program, the formatted file of all REST interfaces is loaded into memory by parsing module
In, and it is parsed into the object (this object is known as format object in the embodiment of the present invention) that development language is identified, according to format
Format object is put into tree structure (this tree is known as format tree by the embodiment of the present invention) by file path, and format object is in lattice
Position in formula tree is (consistent with format file path) determining by the URI of REST interface.For example, the URI of certain REST interface be "/
Rest/security/usergrp ", then position of the format object of this interface in format tree are as follows:
" node rest " -> " node security " -> " node usergrp "
That is, the formatted file of this REST interface is placed in " the node usergrp " of tree structure.
When REST client is interacted with server-side in the present invention, " user name " and " password " is can be used to service in client
TOKEN can be placed the head HTTP by end request TOKEN, the REST that client is sent later, for the body of server-side verifying client
Part.Certainly, there are validity periods by TOKEN, and when TOKEN is expired, client should re-request TOKEN.
As Fig. 5 illustrate receive REST request after, to REST request checking process, it is specific as follows:
S1: according to request URI, the corresponding format object of this URI is searched in format tree, if it is found, then carrying out next
Step, otherwise goes to S91;
S2: it according to format object, is gone to when " check_token " value is " yes " in next step;Otherwise S5 is gone to;
S3: verification TOKEN validity is verified and is successfully gone in next step;Otherwise S91 is gone to;
S4: obtaining the permission of corresponding user according to TOKEN, and whether verification, which meets in format object " privilege ", is wanted
It asks, if it is satisfied, then going in next step;Otherwise S91 is gone to;
S5: according to format object content, whether checking parameter value is met the requirements, if it is satisfied, then going in next step;Otherwise
Go to S91;
S6: according to format object content, verify all mandatory parameters whether input (if parameter a, b is mandatory parameter,
Then a, b think that mandatory parameter has inputted there are one), if it is satisfied, then going in next step;Otherwise S91 is gone to;
S7: according to format object content, the dependence of checking parameter and parameter value, if it is satisfied, then going in next step;It is no
Then go to S91;
S8: according to format object content, the alternative of checking parameter and parameter value;
S91: back-checking failure result, verification terminate.
S92: back-checking successful result, verification terminate.
To sum up, by introduce REST request and format object (by formatted file parse come), in conjunction with above-mentioned checking process,
It forms a kind of REST and unifies method of calibration.This method, on the one hand when developing REST interface, it is only necessary to which definition is simple
Formatted file does not need especially when there are many REST interface, to significantly improve for each REST request individually verification again
Development efficiency.On the other hand, verification is extracted into separate modular, embodies modularization programming.
Corresponding to above method embodiment, the embodiment of the invention also provides a kind of storage system configuration devices, hereafter
The storage system configuration device of description can correspond to each other reference with above-described storage system configuration method.
Show referring to Fig. 6, which comprises the following modules:
REST request receiving module 101, for receiving REST request;
Object format object judgment module 102 whether there is and REST request pair for judging in preset format tree
The object format object answered;Wherein, in the preset format tree, node corresponding with each REST interface respectively corresponds one
A format object, the format object include the corresponding checking parameter of each verification project;
Object format object acquisition module 103 obtains the object format pair for working as there are the object format object
As;
REST requests correction verification module 104, for corresponding using each verification project of the object format object
Checking parameter verifies REST request.
It can be determined in preset format tree using device provided by the embodiment of the present invention when receiving REST request
And obtain out object format object corresponding with REST request.Wherein, corresponding with each REST interface in preset format tree
Node respectively corresponds a format object, and format object includes the corresponding checking parameter of each verification project;When default
When object format object is not found in format tree, it is believed that the REST request being currently received is abnormal request, can be direct
The prompt information of back-checking failure or request error reduces verification number with this, improves verification efficiency.Then the mesh is utilized
Mark format object, which can be completed, verifies the parameter in REST request.As long as that is, in the process of development, creating
Various REST request corresponding format objects.The check item verified needed for corresponding REST request is defined in the format object
The checking parameter of mesh and each verification item objects.That is, can smoothly complete when receiving REST request to various REST
The parameter of request is verified, that is, realizes the unified verification of RSET.Because without requesting (REST interface) respectively for each REST
Different methods of calibration is set, development process is simplified.In addition, due to without the independent creation verification side for each REST interface
Method, in actual checking treatment logic, can also simplified code, reduce the calling between function or method, can be effective
Code accuracy rate is improved, the accuracy rate of REST check results is further promoted.
In a kind of specific embodiment of the invention, further includes:
Formula Object Creation module, for formatted file to be respectively created for each REST interface;Wherein, the file of formatted file
Path is consistent with the URI of REST interface, formatted file include mutex relation between the mandatory parameter of corresponding REST interface, parameter,
Dependence, range of parameter values between parameter;Each formatted file is loaded onto memory, and right respectively using each formatted file
The file path creation format tree answered;Each formatted file is resolved into the corresponding format object of current development language, and is stored in
In format tree.
In a kind of specific embodiment of the invention, object format object judgment module 102 is specifically used for utilizing REST
The target URI of request is searched and is judged format tree with the presence or absence of destination node corresponding with REST request;If it is not, then directly
It determines and object format object corresponding with REST request is not present;If it is, judging destination node with the presence or absence of corresponding mesh
Mark format object.
In a kind of specific embodiment of the invention, REST requests correction verification module 104, comprising:
Parameter verification unit, for the corresponding checking parameter pair of each verification project using object format object
Parameter in REST request is verified;Wherein, verification project include parameter value verification, dependence verification, alternative verification and
Mandatory parameter verification;
Failure result output unit is verified, for there is any one verification in each verification project checking procedure
When project failure, stop verification and output verification failure result;
Verify successful result output unit, for when each verification project passes through, output verification successful result.
In a kind of specific embodiment of the invention, parameter verification unit is specifically used for sentencing in mandatory parameter verification
Whether there is mandatory parameter in disconnected REST request;It is verified if it is, directly determining by mandatory parameter;If it is not, then into one
Step judges whether there is the target component for having mutex relation with mandatory parameter;If there is target component, it is determined that by must
Select parameter verification.
In a kind of specific embodiment of the invention, REST request receiving module 101 has specifically for receiving
The REST of TOKEN is requested.
In a kind of specific embodiment of the invention, further includes:
TOKEN correction verification module, in the corresponding checking parameter of each verification project using object format object
Before being verified to REST request, the TOKEN in REST request is verified;If verification failure, stops verification simultaneously
Output verification failure result.
Corresponding to above method embodiment, the embodiment of the invention also provides a kind of REST to unify calibration equipment, hereafter
A kind of REST of description unifies calibration equipment and unifies method of calibration with a kind of above-described REST that reference can be corresponded to each other.
Shown in Figure 7, which unifies calibration equipment and includes:
Memory D1, for storing computer program;
Processor D2 realizes that the REST of above method embodiment unifies the step of method of calibration when for executing computer program
Suddenly.
Corresponding to above method embodiment, the embodiment of the invention also provides a kind of readable storage medium storing program for executing, are described below
A kind of readable storage medium storing program for executing unify method of calibration with a kind of above-described REST and can correspond to each other reference.
A kind of readable storage medium storing program for executing is stored with computer program on readable storage medium storing program for executing, and computer program is held by processor
The step of REST of above method embodiment unifies method of calibration is realized when row.
The readable storage medium storing program for executing be specifically as follows USB flash disk, mobile hard disk, read-only memory (Read-Only Memory,
ROM), the various program storage generations such as random access memory (Random Access Memory, RAM), magnetic or disk
The readable storage medium storing program for executing of code.
Each embodiment in this specification is described in a progressive manner, the highlights of each of the examples are with it is other
The difference of embodiment, same or similar part may refer to each other between each embodiment.For being filled disclosed in embodiment
For setting, since it is corresponded to the methods disclosed in the examples, so being described relatively simple, related place is referring to method part
Explanation.
Professional further appreciates that, unit described in conjunction with the examples disclosed in the embodiments of the present disclosure
And algorithm steps, can be realized with electronic hardware, computer software, or a combination of the two, in order to clearly demonstrate hardware and
The interchangeability of software generally describes each exemplary composition and step according to function in the above description.These
Function is implemented in hardware or software actually, the specific application and design constraint depending on technical solution.Profession
Technical staff can use different methods to achieve the described function each specific application, but this realization is not answered
Think beyond the scope of this invention.
The step of method described in conjunction with the examples disclosed in this document or algorithm, can directly be held with hardware, processor
The combination of capable software module or the two is implemented.Software module can be placed in random access memory (RAM), memory, read-only deposit
Reservoir (ROM), electrically programmable ROM, electrically erasable ROM, register, hard disk, moveable magnetic disc, CD-ROM or technology
In any other form of storage medium well known in field.
Used herein a specific example illustrates the principle and implementation of the invention, and above embodiments are said
It is bright to be merely used to help understand technical solution of the present invention and its core concept.It should be pointed out that for the common of the art
, without departing from the principle of the present invention, can be with several improvements and modifications are made to the present invention for technical staff, these
Improvement and modification are also fallen within the protection scope of the claims of the present invention.
Claims (10)
1. a kind of REST unifies method of calibration characterized by comprising
Receive REST request;
Judge in preset format tree with the presence or absence of object format object corresponding with REST request;Wherein, described default
In format tree, node corresponding with each REST interface respectively corresponds a format object, and the format object includes each school
Test the corresponding checking parameter of project;
If it is, obtaining the object format object;
School is carried out to REST request using each verification project corresponding checking parameter of the object format object
It tests.
2. REST according to claim 1 unifies method of calibration, which is characterized in that further include:
Formatted file is respectively created for each REST interface;Wherein, the URI of the file path of the formatted file and REST interface
Unanimously, the formatted file include dependence between mutex relation, parameter between the mandatory parameter of corresponding REST interface, parameter,
Range of parameter values;
Each formatted file is loaded onto memory, and the corresponding file path of each formatted file is utilized to create
Build format tree;
Each formatted file is resolved into the corresponding format object of current development language, and is stored in the format tree.
3. REST according to claim 2 unifies method of calibration, which is characterized in that it is described judge in preset format tree whether
In the presence of object format object corresponding with REST request, comprising:
The target URI requested using the REST is searched and is judged the format tree with the presence or absence of corresponding with REST request
Destination node;
If it is not, then directly determining, there is no object format objects corresponding with REST request;
If it is, judging the destination node with the presence or absence of the corresponding object format object.
4. REST according to claim 2 unifies method of calibration, which is characterized in that utilize each of the object format object
The corresponding checking parameter of a verification project verifies REST request, comprising:
Using the corresponding checking parameter of each verification project of the object format object to the ginseng in REST request
Number is verified;Wherein, the verification project includes parameter value verification, dependence verification, alternative verification and mandatory parameter school
It tests;
In to each verification project checking procedure, when there is any one verification project failure, stop verification simultaneously
Output verification failure result;
When each verification project passes through, output verification successful result.
5. REST according to claim 4 unifies method of calibration, which is characterized in that mandatory parameter verification, comprising:
Judge whether there is the mandatory parameter in the REST request;
It is verified if it is, directly determining by the mandatory parameter;
If it is not, then further determining whether there is the target component that there is mutex relation with the mandatory parameter;
If there is the target component, it is determined that verified by the mandatory parameter.
6. REST according to claim 1 unifies method of calibration, which is characterized in that the reception REST request, comprising:
The REST with TOKEN is received to request.
7. REST according to claim 6 unifies method of calibration, which is characterized in that utilizing the object format object
Before the corresponding checking parameter of each verification project verifies REST request, further includes:
TOKEN in REST request is verified;
If verification failure, stops verification and output verification failure result.
8. a kind of REST unifies calibration equipment characterized by comprising
REST request receiving module, for receiving REST request;
Object format object judgment module, for judging in preset format tree with the presence or absence of target corresponding with REST request
Format object;Wherein, in the preset format tree, node corresponding with each REST interface respectively corresponds a format pair
As the format object includes the corresponding checking parameter of each verification project;
Object format object acquisition module, for obtaining the object format object when there are the object format objects;
REST requests correction verification module, for the corresponding checking parameter of each verification project using the object format object
REST request is verified.
9. a kind of REST unifies calibration equipment characterized by comprising
Memory, for storing computer program;
Processor realizes the unified verification side the REST as described in any one of claim 1 to 7 when for executing the computer program
The step of method.
10. a kind of readable storage medium storing program for executing, which is characterized in that be stored with computer program, the meter on the readable storage medium storing program for executing
The step of REST as described in any one of claim 1 to 7 unifies method of calibration is realized when calculation machine program is executed by processor.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810677117.1A CN109324958B (en) | 2018-06-27 | 2018-06-27 | REST unified verification method, device, equipment and readable storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810677117.1A CN109324958B (en) | 2018-06-27 | 2018-06-27 | REST unified verification method, device, equipment and readable storage medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109324958A true CN109324958A (en) | 2019-02-12 |
CN109324958B CN109324958B (en) | 2021-10-29 |
Family
ID=65263117
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810677117.1A Active CN109324958B (en) | 2018-06-27 | 2018-06-27 | REST unified verification method, device, equipment and readable storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109324958B (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110188038A (en) * | 2019-05-13 | 2019-08-30 | 青岛海尔科技有限公司 | A kind of parameter verification method and device, verification framework |
CN111835710A (en) * | 2020-05-29 | 2020-10-27 | 中国平安财产保险股份有限公司 | Method and device for checking request body, computer equipment and storage medium |
CN112148540A (en) * | 2020-08-27 | 2020-12-29 | 云账户技术(天津)有限公司 | Interface parameter checking method and device, electronic equipment and readable storage medium |
CN112261075A (en) * | 2020-09-07 | 2021-01-22 | 上海泛微软件有限公司 | Network request processing method, device, equipment and computer readable storage medium |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS56164468A (en) * | 1980-05-23 | 1981-12-17 | Fujitsu Ltd | Program forming and registrating system for checking of slip format |
CN102129469A (en) * | 2011-03-23 | 2011-07-20 | 华中科技大学 | Virtual experiment-oriented unstructured data accessing method |
CN106775937A (en) * | 2016-12-02 | 2017-05-31 | 郑州云海信息技术有限公司 | A kind of order line method of calibration and device |
CN107222363A (en) * | 2017-05-26 | 2017-09-29 | 郑州云海信息技术有限公司 | One kind storage protocol conformance test method and system |
CN107908485A (en) * | 2017-10-26 | 2018-04-13 | 中国平安人寿保险股份有限公司 | Interface parameters transmission method, device, equipment and computer-readable recording medium |
-
2018
- 2018-06-27 CN CN201810677117.1A patent/CN109324958B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JPS56164468A (en) * | 1980-05-23 | 1981-12-17 | Fujitsu Ltd | Program forming and registrating system for checking of slip format |
CN102129469A (en) * | 2011-03-23 | 2011-07-20 | 华中科技大学 | Virtual experiment-oriented unstructured data accessing method |
CN106775937A (en) * | 2016-12-02 | 2017-05-31 | 郑州云海信息技术有限公司 | A kind of order line method of calibration and device |
CN107222363A (en) * | 2017-05-26 | 2017-09-29 | 郑州云海信息技术有限公司 | One kind storage protocol conformance test method and system |
CN107908485A (en) * | 2017-10-26 | 2018-04-13 | 中国平安人寿保险股份有限公司 | Interface parameters transmission method, device, equipment and computer-readable recording medium |
Non-Patent Citations (1)
Title |
---|
赵启升等: "一种基于REST架构的高校移动教务数据开放平台设计方法", 《江苏科技大学学报(自然科学版)》 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110188038A (en) * | 2019-05-13 | 2019-08-30 | 青岛海尔科技有限公司 | A kind of parameter verification method and device, verification framework |
CN111835710A (en) * | 2020-05-29 | 2020-10-27 | 中国平安财产保险股份有限公司 | Method and device for checking request body, computer equipment and storage medium |
CN111835710B (en) * | 2020-05-29 | 2023-08-15 | 中国平安财产保险股份有限公司 | Method, device, computer equipment and storage medium for verifying request body |
CN112148540A (en) * | 2020-08-27 | 2020-12-29 | 云账户技术(天津)有限公司 | Interface parameter checking method and device, electronic equipment and readable storage medium |
CN112261075A (en) * | 2020-09-07 | 2021-01-22 | 上海泛微软件有限公司 | Network request processing method, device, equipment and computer readable storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN109324958B (en) | 2021-10-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109324958A (en) | A kind of REST unifies method of calibration, device, equipment and readable storage medium storing program for executing | |
CN105099811B (en) | Interface testing method and device | |
CN108628748B (en) | Automatic test management method and automatic test management system | |
CN104360920A (en) | Automatic testing method and device for interface | |
CN109308285A (en) | Database script management method, device, computer equipment and storage medium | |
CN109960653A (en) | Regression testing method, device, equipment and storage medium | |
CN110309125A (en) | Data verification method, electronic device and storage medium | |
CN110532168A (en) | Full LI(link interface) pressure surveys method, apparatus, computer equipment and storage medium | |
US9654580B2 (en) | Proxy-based web application monitoring through script instrumentation | |
Bertolino et al. | Automatic test data generation for XML schema-based partition testing | |
CN110543427B (en) | Test case storage method and device, electronic equipment and storage medium | |
CN112905437B (en) | Method, device and storage medium for testing cases | |
CN103246606A (en) | Method and system for testing performances of ESB (enterprises service bus) platform | |
CN108460068A (en) | Method, apparatus, storage medium and the terminal that report imports and exports | |
CN114398293A (en) | Interface test case generation method, electronic device and storage medium | |
CN103777092A (en) | Cloud technology based relay protection test system and method | |
CN105184559B (en) | A kind of payment system and method | |
CN114742630A (en) | Method for processing business documents and corresponding system, equipment and medium | |
CN112559525B (en) | Data checking system, method, device and server | |
CN109726313A (en) | The method and device of operating database | |
CN112235124B (en) | Method and device for configuring pico-cell, storage medium and electronic device | |
CN106919374A (en) | A kind of scenario generation method and device | |
CN108595656A (en) | A kind of processing method and system of data | |
CN112181599A (en) | Model training method, device and storage medium | |
CN113868219A (en) | Method and device for migrating account set data, electronic equipment and computer storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |