Summary of the invention
Technical problems to be solved in this application are to provide a kind of code data disposal route and device, in order to solve in prior art when generating the code of REST interface, need developer to each interface carry out a large amount of repeat write code operation, not only easily make mistakes, reduce the accuracy rate of code, and increase the rise time of code, reduce the technical matters of code building efficiency.
This application provides a kind of code data disposal route, be applied to electronic equipment, the expandable mark language XML description document of declarative state transfer REST interface is stored in described electronic equipment, described XML description document comprises the multinomial attribute information of described REST interface, and described method comprises:
Read the XML description document in described electronic equipment;
According to the description rule of described XML description document, every attribute information of REST interface described in described XML description document is encoded, obtains the code data of described REST interface.
Said method, preferably, the XML description document in the described electronic equipment of described reading comprises:
Determine the described memory location of XML description document in described electronic equipment;
The XML description document in described electronic equipment is read according to described memory location.
Said method, preferably, the described description rule according to described XML description document, every attribute information of REST interface described in described XML description document is encoded, obtains the code data of described REST interface, comprising:
According to the data structure of described XML description document, in described XML description document, parse the attribute information of every described RESE interface of described XML description document;
According to the data layout of described REST interface, code is carried out to the attribute information of RESE interface every described and writes, generate the code data of described REST interface.
Said method, preferably, after the code data obtaining described REST interface, described method also comprises:
The code data of described REST interface is preserved according to the store path preset.
Said method, preferably, after the code data obtaining described REST interface, described method also comprises:
Receive the interface interchange instruction of described REST interface, described interface interchange instruction is corresponding with the interface identifier of described REST interface;
Object switching motion data are extracted in the code data of described REST interface;
According to described object switching motion data, java object data in described code data is converted to json data or xml data;
According to the http communication operation data in described code data, in the network being provided with resource node, run described json data or xml data, to realize the access to resource node corresponding to described REST interface.
Present invention also provides a kind of code data treating apparatus, be applied to electronic equipment, store the XML description document of RSET interface in described electronic equipment, described XML description document comprises the multinomial attribute information of described REST interface, and described device comprises:
Document reading unit, for reading the XML description document in described electronic equipment;
The various attribute informations of REST interface described in described XML description document, for the description rule according to described XML description document, are encoded, are obtained the code data of described REST interface by information coding unit.
Said apparatus, preferably, described document reading unit comprises:
Subelement is determined in position, for determining the described memory location of XML description document in described electronic equipment;
File reads subelement, for reading the XML description document in described electronic equipment according to described memory location.
Said apparatus, preferably, described information coding unit comprises:
Information analysis subelement, for the data structure according to described XML description document, goes out the attribute information of every described REST interface of described XML description document in described XML description document according to Ei system;
Code building subelement, for the data layout according to described REST interface, carries out code to the attribute information of REST interface every described and writes, generate the code data of described REST interface.
Said apparatus, preferably, also comprises:
Code storage unit, for obtain described REST interface at described information coding unit code data after, the code data of described REST interface is preserved according to the store path preset.
Said apparatus, preferably, also comprises:
Instruction reception unit, for receiving the interface interchange instruction of described REST interface, described interface interchange instruction is corresponding with the interface identifier of described REST interface;
Data extracting unit, for extracting object switching motion data in the code data of described REST interface;
Date Conversion Unit, for according to described object switching motion data, is converted to json data or xml data by java object data in described code data;
Data run unit, for according to the http communication operation data in described code data, runs described json data or xml data in the network being provided with resource node, to realize the access to resource node corresponding to described REST interface.
From such scheme, a kind of code data disposal route that the application provides and device, be applied in the electronic equipment of the XML description document storing REST interface, this XML description document comprises the multinomial attribute information of REST interface, the application is by reading the XML description document that these have the attribute information of REST interface, and then the description rule of foundation XML description document, the REST interface attributes information in XML description document is encoded, to obtain the code data of REST interface.Pass through the application, hand-coding is carried out without the need to the code data of developer to each REST interface, only need write XML description document, and XML description document is because of its specific data structure, make developer only need be filled in XML description document by the attribute information of concrete REST interface, and then follow-up this XML description document to be encoded by the application, its code generation process is not only not easily made mistakes, improve the accuracy rate of code building, and its process operation flow process is less and operate simple and easy, reduce the rise time of code, improve the formation efficiency of code.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present application, be clearly and completely described the technical scheme in the embodiment of the present application, obviously, described embodiment is only some embodiments of the present application, instead of whole embodiments.Based on the embodiment in the application, those of ordinary skill in the art are not making the every other embodiment obtained under creative work prerequisite, all belong to the scope of the application's protection.
With reference to figure 1, for the process flow diagram of a kind of code data disposal route embodiment one that the application provides, wherein, described method is applied to electronic equipment, described electronic equipment can be to run by run time version, and with the resource node in network, there is the device end etc. of data cube computation, the XML description document of REST interface is stored in described electronic equipment, described XML description document comprises the multinomial attribute information of described REST interface, as httpMethod and httpHeader design parameter, data layout is (as json, xml), rreturn value, the information such as authentication mode (as httpBasicAuth), the method of the embodiment of the present application can comprise the following steps:
Step 101: read the XML description document in described electronic equipment.
Wherein, described step 101 refers to, obtains the XML description document of the REST interface stored in described electronic equipment.
It should be noted that, described XML description document has its specific data structure, such as, is below that the several main node in XML description document illustrate:
The website of Domain: this api, i.e. reference address, support to define with variable format;
Auth: at present only support httpBasic certification, in node can the username and password of input authentication, supports to define with variable format;
Resource a: resource node of concrete REST;
Uri: the uri of resource node, domain+uri form the actual url of this REST;
Action: some operations that this resource points is carried out, such as Gains resources information, or more new resources;
Cookies: need the cookie key added in access process;
Headers: need the header key added in access process;
RequestBody: the body content of http request in access process, supports json or xml format conversion;
ResponseBody: the body content of http response in access process, supports json or xml format conversion;
Some attributes in Property:Body data structure, correspond to a specific object inside java object, itself also can be list, or another nested data structure;
Etc..
In the embodiment of the present application, the information that in described XML description document, each node stores is every attribute information of described REST interface, that is, before method is in the embodiment of the present application run, every attribute information of REST interface is filled in the corresponding node of XML by developer, to obtain the XML description document of this REST interface.
Step 102: according to the description rule of described XML description document, encodes every attribute information of REST interface described in described XML description document, obtains the code data of described REST interface.
Wherein, the description rule of described XML description document can be understood as: in XML description document, the optimum configurations of each node, langue such as to arrange at the rule, be in described step 102: every attribute information of REST interface described in described XML description document is encoded according to this description rule, to obtain the code data of described REST interface.
From such scheme, a kind of code data disposal route embodiment one that the application provides, be applied in the electronic equipment of the XML description document storing REST interface, this XML description document comprises the multinomial attribute information of REST interface, the embodiment of the present application is by reading the XML description document that these have the attribute information of REST interface, and then the description rule of foundation XML description document, REST interface attributes information in XML description document is encoded, to obtain the code data of REST interface.Pass through the embodiment of the present application, hand-coding is carried out without the need to the code data of developer to each REST interface, only need write XML description document, and XML description document is because of its specific data structure, make developer only need be filled in XML description document by the attribute information of concrete REST interface, and then follow-up this XML description document to be encoded by the embodiment of the present application, its code generation process is not only not easily made mistakes, improve the accuracy rate of code building, and its process operation flow process is less and operate simple and easy, reduce the rise time of code, improve the formation efficiency of code.
With reference to figure 2, be the process flow diagram of step 101 described in a kind of code data disposal route embodiment two that the application provides, wherein, described step 101 can comprise the following steps realization:
Step 111: determine the described memory location of XML description document in described electronic equipment.
Wherein, described memory location can be the store path information of described XML description document in described electronic equipment: relative path is as .. * * description document .xml or absolute path etc.
It should be noted that, the memory location of described XML description document can for pre-setting, and that is, is developed after personnel have filled in the XML description document of described REST interface, this XML description document is stored in electronic equipment, setting is carried out in its memory location simultaneously and fill in.
Step 112: read the XML description document in described electronic equipment according to described memory location.
Wherein, file reading manner in described step 112 can be different according to the character of this memory location, that is, when in described memory location being the relative path information of current location, in described step 112, read XML description document corresponding to its relative path information by described current location; When described memory location is absolute path information, in described step 112, directly read the XML description document under this absolute path.
With reference to figure 3, be the process flow diagram of step 102 described in a kind of code data disposal route embodiment three that the application provides, wherein, described step 102 can be realized by each step following:
Step 121: according to the data structure of described XML description document, parses the attribute information of every described REST interface of described XML description document in described XML description document.
Wherein, the data structure of described XML description document can with reference to the content above described in middle the embodiment of the present application one, in described step 121, according to the data structure of described XML description document, in described XML description document, resolve every the attribute information extracting described REST interface.
Step 122: according to the data layout of described REST interface, carries out code to the attribute information of REST interface every described and writes, generate the code data of described REST interface.
Wherein, the data layout of described REST interface refers to the data layout that described REST interface object data present, in described step 122, according to described data layout, carry out code to attribute information every described to write, to obtain the code data of described REST interface, the data layout of described code data is consistent with the data layout of described REST interface.
With reference to figure 4, be the process flow diagram of a kind of code data disposal route embodiment four that the application provides, wherein, after described step 102, described method can also comprise the following steps:
Step 103: the code data of described REST interface is preserved according to the store path preset.
Wherein, described store path can be the relative path of current location, also can be absolute path.And described store path can be arranged in advance by developer.After described step 103, developer can pass through multiple exercise the application embodiment of the method, realizes the repeatedly generation of the code data of described REST interface and repeatedly applies.
With reference to figure 5, be the process flow diagram of a kind of code data disposal route embodiment five that the application provides, wherein, after described step 102, described method can also comprise the following steps:
Step 104: the interface interchange instruction receiving described REST interface, described interface interchange instruction is corresponding with the interface identifier of described REST interface.
Wherein, described interface interchange instruction can need to carry out operation when code data generation or interface accessing by developer and generate, the interface identifier of REST interface needing to carry out code building or conduct interviews can be carried, to make described interface interchange instruction corresponding with the interface identifier of described REST interface in described interface interchange instruction.
Step 105: extract object switching motion data in the code data of described REST interface.
Wherein, described object switching motion data, refer to the rotational action data of java object to json data or xml data.
Step 106: according to described object switching motion data, java object data in described code data is converted to json data or xml data.
Wherein, in described code data, described REST interface exists with the data mode of java object, therefore, in order to REST interface described in protocol identification in network can be made, in described step 106, the json data or xml data that network can identify are converted to the java object data in described code data.
Step 107: according to the http communication operation data in described code data, run described json data or xml data in the network being provided with resource node, to realize the access to resource node corresponding to described REST interface.
Wherein, http communication activities data are packaged with in described code data, thus, when passing through this REST interface orientation REST client as resource node in the external world, can according to these http communication activities data as http agreement, in the network being provided with resource node (rest client), run described json data or xml data, realize the access to resource node corresponding to described REST interface thus.
With reference to figure 6, for the structural representation of a kind of code data treating apparatus embodiment six that the application provides, wherein, described application of installation is in electronic equipment, described electronic equipment can be to run by run time version, and with the resource node in network, there is the device end etc. of data cube computation, the XML description document of RSET interface is stored in described electronic equipment, described XML description document comprises the multinomial attribute information of described REST interface, as httpMethod and httpHeader design parameter, data layout is (as json, xml), rreturn value, the information such as authentication mode (as httpBasicAuth), device in the embodiment of the present application can comprise following structure:
Document reading unit 601, for reading the XML description document in described electronic equipment.
Wherein, described document reading unit 601 refers to, obtains the XML description document of the REST interface stored in described electronic equipment.
It should be noted that, described XML description document has its specific data structure, can data structure show to XML description document in REFERENCE TO RELATED embodiment of the method.
In the embodiment of the present application, the information that in described XML description document, each node stores is every attribute information of described REST interface, that is, before method is in the embodiment of the present application run, every attribute information of REST interface is filled in the corresponding node of XML by developer, to obtain the XML description document of this REST interface.
The various attribute informations of REST interface described in described XML description document, for the description rule according to described XML description document, are encoded, are obtained the code data of described REST interface by information coding unit 602.
Wherein, the description rule of described XML description document can be understood as: in XML description document, the optimum configurations of each node, langue such as to arrange at the rule, be in described information coding unit 602: every attribute information of REST interface described in described XML description document is encoded according to this description rule, to obtain the code data of described REST interface.
From such scheme, a kind of code data treating apparatus embodiment six that the application provides, be applied in the electronic equipment of the XML description document storing REST interface, this XML description document comprises the multinomial attribute information of REST interface, the embodiment of the present application is by reading the XML description document that these have the attribute information of REST interface, and then the description rule of foundation XML description document, REST interface attributes information in XML description document is encoded, to obtain the code data of REST interface.Pass through the embodiment of the present application, hand-coding is carried out without the need to the code data of developer to each REST interface, only need write XML description document, and XML description document is because of its specific data structure, make developer only need be filled in XML description document by the attribute information of concrete REST interface, and then follow-up this XML description document to be encoded by the embodiment of the present application, its code generation process is not only not easily made mistakes, improve the accuracy rate of code building, and its process operation flow process is less and operate simple and easy, reduce the rise time of code, improve the formation efficiency of code.
With reference to figure 7, be the structural representation of document reading unit 601 described in a kind of code data treating apparatus embodiment seven that the application provides, wherein, described document reading unit 601 can comprise following structure:
Subelement 611 is determined in position, for determining the described memory location of XML description document in described electronic equipment.
Wherein, described memory location can be the store path information of described XML description document in described electronic equipment: relative path is as .. * * description document .xml or absolute path etc.
It should be noted that, the memory location of described XML description document can for pre-setting, and that is, is developed after personnel have filled in the XML description document of described REST interface, this XML description document is stored in electronic equipment, setting is carried out in its memory location simultaneously and fill in.
File reads subelement 612, for reading the XML description document in described electronic equipment according to described memory location.
Wherein, the file reading manner that described file reads in subelement 612 can be different according to the character of this memory location, that is, when in described memory location being the relative path information of current location, described file reads subelement 612 can read XML description document corresponding to its relative path information by described current location; When described memory location is absolute path information, described file reading subelement 612 directly can read the XML description document under this absolute path.
With reference to figure 8, be the structural representation of information coding unit 602 described in a kind of code data treating apparatus embodiment eight that the application provides, wherein, described information coding unit 602 can comprise following structure:
Information analysis subelement 621, for the data structure according to described XML description document, goes out the attribute information of every described REST interface of described XML description document in described XML description document according to Ei system.
Wherein, the data structure of described XML description document can with reference to the content above described in middle the embodiment of the present application one, in described information analysis subelement 621, according to the data structure of described XML description document, in described XML description document, resolve every the attribute information extracting described REST interface.
Code building subelement 622, for the data layout according to described REST interface, carries out code to the attribute information of REST interface every described and writes, generate the code data of described REST interface.
Wherein, the data layout of described REST interface refers to the data layout that described REST interface object data present, in described code building subelement 622, according to described data layout, carry out code to attribute information every described to write, to obtain the code data of described REST interface, the data layout of described code data is consistent with the data layout of described REST interface.
With reference to figure 9, be the structural representation of a kind of code data treating apparatus embodiment nine that the application provides, wherein, described device can also comprise following structure:
Code storage unit 603, after obtaining the code data of described REST interface at described information coding unit 602, preserves the code data of described REST interface according to the store path preset.
Wherein, described store path can be the relative path of current location, also can be absolute path.And described store path can be arranged in advance by developer.After the code data of described REST interface is preserved according to the store path preset by described code storage unit 603, developer can pass through multiple exercise the application embodiment of the method, realizes the repeatedly generation of the code data of described REST interface and repeatedly applies.
With reference to Figure 10, be the structural representation of a kind of code data treating apparatus embodiment ten that the application provides, wherein, described device can also comprise following structure:
Instruction reception unit 604, for receiving the interface interchange instruction of described REST interface, described interface interchange instruction is corresponding with the interface identifier of described REST interface.
Wherein, described interface interchange instruction can need to carry out operation when code data generation or interface accessing by developer and generate, the interface identifier of REST interface needing to carry out code building or conduct interviews can be carried, to make described interface interchange instruction corresponding with the interface identifier of described REST interface in described interface interchange instruction.
Data extracting unit 605, for extracting object switching motion data in the code data of described REST interface.
Wherein, described object switching motion data, refer to the rotational action data of java object to json data or xml data.
Date Conversion Unit 606, for according to described object switching motion data, is converted to json data or xml data by java object data in described code data.
Wherein, in described code data, described REST interface exists with the data mode of java object, therefore, in order to REST interface described in protocol identification in network can be made, in described Date Conversion Unit 606, the json data or xml data that network can identify are converted to the java object data in described code data.
Data run unit 607, for according to the http communication operation data in described code data, runs described json data or xml data in the network being provided with resource node, to realize the access to resource node corresponding to described REST interface.
Wherein, http communication activities data are packaged with in described code data, thus, when passing through this REST interface orientation REST client as resource node in the external world, can according to these http communication activities data as http agreement, in the network being provided with resource node (rest client), run described json data or xml data, realize the access to resource node corresponding to described REST interface thus.
By the description of above embodiment, those skilled in the art can be well understood to the mode that the application can add necessary common hardware by software and realize, and can certainly pass through hardware, but in a lot of situation, the former is more real-time mode.Based on such understanding, the technical scheme of the application can embody with the form of software product the part that prior art contributes in essence in other words, this computer software product is stored in the storage medium that can read, as the floppy disk of computing machine, hard disk or CD etc., comprise some instructions and perform technical scheme described in each embodiment of the application in order to make a computer equipment (can be personal computer, server or the network equipment etc.).
It should be noted that, each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is the difference with other embodiments, between each embodiment identical similar part mutually see.
A kind of code data disposal route provided the application above and device are described in detail, apply specific case herein to set forth the principle of the application and embodiment, the explanation of above embodiment is just for helping method and the core concept thereof of understanding the application; Meanwhile, for one of ordinary skill in the art, according to the thought of the application, all will change in specific embodiments and applications, in sum, this description should not be construed as the restriction to the application.