CN103399734A - Method for generating REST service and achieving REST and corresponding equipment - Google Patents

Method for generating REST service and achieving REST and corresponding equipment Download PDF

Info

Publication number
CN103399734A
CN103399734A CN2013102889839A CN201310288983A CN103399734A CN 103399734 A CN103399734 A CN 103399734A CN 2013102889839 A CN2013102889839 A CN 2013102889839A CN 201310288983 A CN201310288983 A CN 201310288983A CN 103399734 A CN103399734 A CN 103399734A
Authority
CN
China
Prior art keywords
service
interface
rest
class
service interface
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
Application number
CN2013102889839A
Other languages
Chinese (zh)
Other versions
CN103399734B (en
Inventor
张晓辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
BEIJING HUIDIAN TECHNOLOGY Co Ltd
Original Assignee
BEIJING HUIDIAN TECHNOLOGY Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by BEIJING HUIDIAN TECHNOLOGY Co Ltd filed Critical BEIJING HUIDIAN TECHNOLOGY Co Ltd
Priority to CN201310288983.9A priority Critical patent/CN103399734B/en
Publication of CN103399734A publication Critical patent/CN103399734A/en
Application granted granted Critical
Publication of CN103399734B publication Critical patent/CN103399734B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention relates to the technical field of computers, in particular to a method for generating REST service and achieving REST and corresponding equipment. The method for generating the REST service and achieving the REST and the corresponding equipment are used for solving the problems that when an existing manual coding mode is used for generating the REST service and achieving the REST, efficiency is low, and the quality of codes is difficult to ensure. The method for generating the REST service comprises the steps that a server scans all service interfaces of an API of Java and obtains interface information of all the service interfaces; for each service interface, the server generates a corresponding class file of a REST service class according to the interface information corresponding to each service interface; for each REST service class, the server generates corresponding REST service. The method for generating the REST service and achieving the REST and the corresponding equipment have the advantages of being high in efficiency and accurate in code generation.

Description

Generate method and corresponding equipment that REST service and REST realize
Technical field
The present invention relates to field of computer technology, relate in particular to generation REST(Representational State Transfer, the migration of statement sexual state) service and the method for REST realization and the equipment of correspondence.
Background technology
In Web applied software development field, experiencing from traditional deployment way to the cloud service deployment and integrated change.Under such trend, increasing Web application has adopted the Web service mode that open web application DLL (dynamic link library) (Web Application Programming Interface externally is provided, Web API), provide the supports such as data integration and expansion for third party's application.
REST is a kind of with the abstract resource for URL(uniform resource locator) (Uniform Resource Locator, URL) sensing of Web service, and adopts the development scheme of HTML (Hypertext Markup Language) (Hyper Text Transfer Protocol, HTTP) protocol access.Because it is simple, easy-to-use, the compatible characteristics such as good of platform, adopted by increasing manufacturer.In the Java development field, with the Web service of REST development scheme exploitation, although can use some middlewares, but still exist that the exploitation amount is large, efficiency is low and the unsharp problem of licensing scheme.
As shown in Figure 1, (being the modules A in Fig. 1) realized in this locality of the Java API of server end, can only carry out this locality and call, if convert it into the REST service that can be called by across a network, REST that must development server side serves (being the module B in Fig. 1).
Wherein, the REST service of server end is used for providing the REST service based on the Java API of server end, complete REST services request that client sends to the scheduling of local Java API Calls and adaptive, obtain the method for the local Java API that the REST services request need to call, convert the parameter of REST services request to form that the method can be called.After local Java API was called, the REST service of server end was that the REST service response is issued client with invoked Java API method rreturn value according to the desired format conversion of REST service.
The REST of the Java API of client realizes (being the module C in Fig. 1), be used for the Java API Calls of client application (being the module D of Fig. 1) is converted to the REST services request, and the method rreturn value that the REST service response that server end is sent is converted to invoked Java API is issued client application.If client is wanted the REST service of the server end in across a network access Fig. 1, need to generate based on the Java API identical with server end the REST realization of the Java API of client, client uses the REST of this Java API to realize that the API that provides completes the indirect call to server end Java API.
Complex structure due to Java API, comprise a plurality of service interfaces, the definition of each service interface different (such as: the definition of method rreturn value, method parameter etc.), what be difficult to find a kind of unification generates the method for REST service code automatically based on each different service interface.In therefore existing scheme, all adopt artificial mode to write the code of the REST service of server end,, if need to use identical Java API to conduct interviews in client, based on the Java API identical with server end, manually develop the code of the Java API REST realization of client.And the manual type code exists efficiency low, and the code quality problem that is difficult to guarantee.
To sum up, also there is no a kind of method that can generate efficiently REST service and REST realization at present.
Summary of the invention
Method, a kind of server and a kind of client that the embodiment of the present invention provides a kind of method of the REST of generation service, a kind of REST that generates client Java API to realize, the mode that adopts the h coding in existing mode generates the REST service and REST realizes, the problem that efficiency is low and code quality is difficult to guarantee in order to solve.
The embodiment of the present invention provides a kind of method of the REST of generation service, comprising:
Each service interface of server scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
For each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface;
For each REST service class, be used for defining the note of REST service features in the interface message of server according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
The method of utilizing the embodiment of the present invention to provide, server scanning Java API, generate the class file of REST service class, finally generates the REST service, has that efficiency is high, a generating code advantage accurately.
Preferably, one or more service interfaces of described Java API are for establishing the service interface of authority;
Described for each described service interface, the class file that the interface message that server is corresponding according to this service interface generates REST service class corresponding to this service interface also comprises:
Established the service interface of authority for each, server is placed in this with this code that is used for control of authority of having established the rights service interface and has established the class file of REST service class corresponding to rights service interface;
Wherein, this code that is used for control of authority of having established the rights service interface is to be converted to by this note that is used for control of authority of having established interface message corresponding to the service interface of authority.
, by adding and explain on Java API Service interface definition or in the method definition, can control neatly the control of authority strategy of REST service access.Note on Service interface definition can be shared by a plurality of method of this service interface, and this makes code structure more clear succinct, has also improved the reusable degree of code logic.
Preferably, each service interface of described server scanning Java API, obtain interface message corresponding to each service interface, comprising:
Server is determined the service interface of root node service interface for scanning of described Java API;
Server scans the service interface that will scan, and obtains interface message corresponding to service interface;
If it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, server is determined the service interface that next will scan according to the rreturn value of the method, and returns to the step that the service interface that will scan is scanned; Otherwise end scanning process.
This scheme relatively and prior art, the structure of Java API has been carried out simplifying processed, utilize incidence relation between each service interface of Java API to realize the scanning of all service interfaces, overcome in the method for existing artificial generation REST service, due to the complex structure of Java API with can't find the unified problem of obtaining interface message method corresponding to each service interface.
Preferably, described server scans the service interface that will scan, and obtains interface message corresponding to service interface and comprises:
Server loads the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
Utilize the method for Java reflection class object, can obtain more simply, easily the interface message corresponding to service interface that will scan.
Preferably, described for each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface, comprising:
For each described service interface, server generates the source code of REST service class corresponding to this service interface according to the interface message of this service interface that obtains;
The source code of the REST service class that server is corresponding according to described this service interface, generate the class file of REST service class corresponding to this service interface.
Write code with existing manual type and compare, the interface message that in this programme, server is corresponding according to service interface generates the class file of REST service class corresponding to this service interface automatically, and efficiency is higher, and the code of generation is more accurate.
Preferably, described for each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface, comprising:
For each described service interface, the interface message that server is corresponding according to this service interface, utilize Java bytecode operative technique, generates the class file of REST service class corresponding to this service interface.
In this programme, adopt Java bytecode operative technique, need not to write source code, saved the time that code transforms, improved efficiency.
Preferably, described for a REST service class, be used for defining the note of REST service features in the interface message of server according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class, comprising:
Server is corresponding REST service class to the class file that Java Virtual Machine loads each REST service class that generates, and each REST service class that loading is obtained encapsulates in Wink Application object;
For each REST service class, server, by the Wink middleware, utilizes the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generates REST service corresponding to this REST service class.
In this programme, automatically generate the REST service by the Wink middleware, more accurate than existing manual method, efficiency is higher.
A kind of method that the embodiment of the present invention provides REST that generates client Java API to realize comprises:
Each service interface of client scan java application DLL (dynamic link library) API, obtain the interface message of each service interface, and wherein said Java API is identical with the Java API on REST service place server that this client will be called;
For each described service interface, client generates REST corresponding to this service interface according to the interface message of this service interface and realizes the class file of class, and class file comprises the code of the client-requested REST service related parameters of determining according to the note that is used for defining the REST service features in the interface message of this service interface;
Client loads each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
The method of utilizing the embodiment of the present invention to provide, client scan Java API, generate REST and realize the class file of class, and the REST of End-Customer end Java API realizes, has that efficiency is high, a generating code advantage accurately.
Preferably, each service interface of described client scan Java API, obtain interface message corresponding to each service interface and comprise:
Client is determined the service interface of root node service interface for scanning of described Java API;
Client scans the service interface that will scan, and obtains interface message corresponding to service interface;
If it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, client is determined the service interface that next will scan according to the rreturn value of the method, and returns to the step that the service interface that will scan is scanned; Otherwise end scanning process.
This scheme relatively and prior art, the structure of Java API has been carried out simplifying processed, utilize incidence relation between each service interface of Java API to realize the scanning of all service interfaces, overcome in the method that existing artificial generation REST realizes, due to the complex structure of Java API with can't find the unified problem of obtaining interface message method corresponding to each service interface.
Preferably, described client scans the service interface that will scan, and obtains interface message corresponding to service interface and comprises;
Client loads the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
This programme utilizes the method for Java reflection class object, can obtain more simply, easily the interface message corresponding to service interface that will scan.
Preferably, described for each described service interface, the client interface message corresponding according to this service interface generates REST corresponding to this service interface and realizes that the class file of class comprises:
For each described service interface, the interface message of this service interface that the client basis is obtained generates REST corresponding to this service interface and realizes the source code of class;
Realize the source code of class according to REST corresponding to described this service interface, client generates the REST corresponding with this service interface and realizes the class file of class.
Write code with existing manual type and compare, in this programme, the client interface message corresponding according to service interface generates the class file of REST service class corresponding to this service interface automatically, and efficiency is higher, and the code of generation is more accurate.
Described for each described service interface, the client interface message corresponding according to this service interface generates REST corresponding to this service interface and realizes that the class file of class comprises:
For each described service interface, the interface message that client is corresponding according to this service interface, utilize Java bytecode operative technique, generates the REST corresponding with this service interface and realize the class file of class.
In this programme, adopt Java bytecode operative technique, need not to write source code, saved the time that code transforms, improved efficiency.
The embodiment of the present invention provides a kind of server, and this server comprises:
Scan module, each service interface for scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
The class file generation module, be used for for each described service interface, and the interface message corresponding according to this service interface generates the class file of REST service class corresponding to this service interface;
REST service creation module, be used for for each REST service class, be used for defining the note of REST service features in interface message according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
In this programme, server scanning Java API, generate the class file of REST service class, finally generates the REST service, has that efficiency is high, a generating code advantage accurately.
Preferably, one or more service interfaces of described Java API are for establishing the service interface of authority;
Described class file generation module also is used for: established the service interface of authority for each, this code that is used for control of authority of having established the rights service interface has been placed in this has established the class file of REST service class corresponding to rights service interface;
Wherein, this code that is used for control of authority of having established the rights service interface is that the note that is used for control of authority that this that obtain by described scan module established interface message corresponding to the service interface of authority is converted to.
, by adding and explain on Java API Service interface definition or in the method definition, can control neatly the control of authority strategy of REST service access.Note on Service interface definition can be shared by a plurality of method of this service interface, and this makes code structure more clear succinct, has also improved the reusable degree of code logic.
Preferably, described scan module specifically is used for: the service interface of root node service interface for scanning of determining described Java API; The service interface that will scan is scanned, obtain interface message corresponding to service interface; , if it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, according to the rreturn value of the method, determines the service interface that next will scan, and return to the step that the service interface that will scan is scanned; Otherwise end scanning process.
This scheme relatively and prior art, the structure of Java API has been carried out simplifying processed, utilize incidence relation between each service interface of Java API to realize the scanning of all service interfaces, overcome in the method that existing artificial generation REST service and REST realize, due to the complex structure of Java API with can't find the unified problem of obtaining interface message method corresponding to each service interface.
Preferably, described the service interface that will scan is scanned, obtaining interface message corresponding to service interface comprises: load the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
Utilize the method for Java reflection class object, can obtain more simply, easily the interface message corresponding to service interface that will scan.
Preferably, described class file generation module specifically is used for:, for each described service interface, generate the source code of REST service class corresponding to this service interface according to the interface message of this service interface that obtains; The source code of the REST service class corresponding according to described this service interface, generate the class file of REST service class corresponding to this service interface.
Write code with existing manual type and compare, the interface message that in this programme, server is corresponding according to service interface generates the class file of REST service class corresponding to this service interface automatically, and efficiency is higher, and the code of generation is more accurate.
Preferably, described class file generation module specifically is used for: for each described service interface, the interface message corresponding according to this service interface, utilize Java bytecode operative technique, generates the class file of REST service class corresponding to this service interface.
In this programme, adopt Java bytecode operative technique, need not to write source code, saved the time that code transforms, improved efficiency.
Preferably, described REST service creation module specifically is used for: the class file that loads each REST service class that generates to Java Virtual Machine is corresponding REST service class, and each REST service class that loading is obtained encapsulates in Wink Application object; For each REST service class,, by the Wink middleware, utilize the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
In this programme, automatically generate the REST service by the Wink middleware, more accurate than existing manual method, efficiency is higher.
The embodiment of the present invention provides a kind of client, and this client comprises:
Scan module,, for each service interface of scanning java application DLL (dynamic link library) API, obtain the interface message of each service interface, and wherein said Java API is identical with the Java API that the REST that this client will be called serves on the server of place;
The class file generation module, be used for for each described service interface, generate REST corresponding to this service interface according to the interface message of this service interface and realize the class file of class, class file comprises the code of the client-requested REST service related parameters of determining according to the note that is used for defining the REST service features in the interface message of this service interface;
REST realizes generation module, is used for loading each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
In this programme, client scan Java API, generate REST and realize the class file of class, and the REST of End-Customer end Java API realizes, compared with prior art, has that efficiency is high, a generating code advantage accurately.
Preferably, described scan module specifically is used for: the service interface of root node service interface for scanning of determining described Java API; The service interface that will scan is scanned, obtain interface message corresponding to service interface; , if it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, according to the rreturn value of the method, determines the service interface that next will scan, and return to the step that the service interface that will scan is scanned; Otherwise end scanning process.
This scheme relatively and prior art, the structure of Java API has been carried out simplifying processed, utilize incidence relation between each service interface of Java API to realize the scanning of all service interfaces, overcome in the method that existing artificial generation REST realizes, due to the complex structure of Java API with can't find the unified problem of obtaining interface message method corresponding to each service interface.
Preferably, described the service interface that will scan is scanned, obtain interface message corresponding to service interface and comprise; Load the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
This programme utilizes the method for Java reflection class object, can obtain more simply, easily the interface message corresponding to service interface that will scan.
Preferably, described class file generation module specifically is used for:, for each described service interface, generate REST corresponding to this service interface according to the interface message of this service interface that obtains and realize the source code of class; Realize the source code of class according to REST corresponding to described this service interface, generate the REST corresponding with this service interface and realize the class file of class.
Write code with existing manual type and compare, in this programme, the client interface message corresponding according to service interface generates the class file of REST service class corresponding to this service interface automatically, and efficiency is higher, and the code of generation is more accurate.
Preferably, described class file generation module specifically is used for: for each described service interface, the interface message corresponding according to this service interface, utilize Java bytecode operative technique, generates the REST corresponding with this service interface and realize the class file of class.
In this programme, adopt Java bytecode operative technique, need not to write source code, saved the time that code transforms, improved efficiency.
Description of drawings
Fig. 1 is the server and client side's of employing REST development scheme software configuration and the schematic diagram of Java API Calls process;
The procedure schematic diagram that a kind of REST of generation that Fig. 2 provides for the embodiment of the present invention serves;
The procedure schematic diagram that the REST of the generation client Java API that Fig. 3 provides for the embodiment of the present invention realizes;
Fig. 4 is the structural representation that is scanned the Java API of service interface in example one;
Fig. 5 is each service interface of scanning Java API of example one, obtains the procedure schematic diagram of interface message corresponding to each service interface;
Fig. 6 is the procedure schematic diagram that the server of example two generates the class file of REST service class;
Fig. 7 is the procedure schematic diagram that the client generation REST of example three realizes the class file of class;
Fig. 8 is the structural representation of the server of the embodiment of the present invention;
Fig. 9 is the structural representation of the client of the embodiment of the present invention.
Embodiment
Method, a kind of server and a kind of client that the embodiment of the present invention provides a kind of method of the REST of generation service, a kind of REST that generates client Java API to realize, in the method that the embodiment of the present invention provides, server scanning Java API, generate the class file of REST service class, final generate the REST service, have that efficiency is high, a generating code advantage accurately.
Below, as follows to the several concept brief descriptions that relate in the embodiment of the present invention:
Service: in computer network, offered the interface that is used for data interaction of client by server.
The REST service: with the service that the REST development scheme provides, its service abstraction with server becomes resource, uses URL to identify and search, and by http protocol, conducts interviews.
Realize: in java applet, interface definition the behavior of class and method, but there is no the specific code of define method, the method that is embodied as in interface provides concrete code, with Interface realization, is class.In the embodiment of the present invention, the realization of the Java API of the realization of this locality of Java API and client is the difference realization of same Java API.
REST realizes: is used for initiating the REST services request to server, and the REST response of reception server, and this response is converted into method rreturn value type corresponding to Java API, return to client application.
Framework: the method that the embodiment of the present invention provides automatically performs when server or client terminal start-up,, for server, is used for generating the REST service; , for client, be used for generating the REST realization of client Java API.Needn't regenerate again REST service or REST realization when server or client operation.In embodiments of the present invention, framework is what move on server or client, based on Java API, and by implementing each step of the embodiment of the present invention, the program that the REST service of generation server or the REST of client realize.
For server, during startup of server, framework starts Apache Wink middleware (hereinafter to be referred as " Wink middleware ") automatically, call the get Application method of the Rest Servlet class of Wink middleware, ApplicationEx class after obtaining to expand, the object of establishment ApplicationEx class, trigger each service interface of carrying out scanning Java API, the process that generates class file, generation REST service according to the interface message of service interface.Wherein, the method of the get Classes of the object by calling this establishment ApplicationEx class, call the Generator class that framework provides in get Classes method, generate the object of Generator class, read the root node service interface (method for the root node service interface is set of perhaps calling the Generator class object arranges the root node service interface) of Java API from configuration file.Call the operation of the scan method of Generator class object and each service interface that the generate method scans respectively Java API and the class file that generates the REST service class, start to scan each service interface of whole Java API from Java API root node service interface, generate the class file of REST service class according to the interface message of obtaining service interface.In get Classes method, the class file that loads each REST service class that generates to Java Virtual Machine is corresponding REST service class and returns to the Wink middleware afterwards.For each REST service class, the Wink middleware utilizes the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generates REST service corresponding to this REST service class.
For server, framework has been expanded the Application class of Wink middleware, has rewritten the get Classes method of Application class, has obtained the ApplicationEX class after the expansion; Expand the Rest Servlet class of Wink middleware, rewritten its get Application method, obtained the ApplicationEX class after the expansion.
The example code of ApplicationEx class is as follows, has rewritten the get Classes method of Application class in this code, is used for loading the class file that generates; Use the java class loader, each REST service class is loaded as the Class object.
Figure BDA00003491420600131
Code snippet 1, ApplicationEx class
For client, during client terminal start-up, call the Generator class that framework provides, generate the object of Generator class, read Java API root node service interface (method for the root node service interface is set of perhaps calling the Generator class object arranges the root node service interface) from configuration file; The method that the generation client Java API REST that the start method of calling the generator class object is carried out the embodiment of the present invention to be provided realizes, start to scan each service interface of Java API from Java API root node service interface, generate REST according to the interface message of obtaining service interface and realize the class file of class, load each REST that generates and realize the REST realization of the class file generation client Java API of class.
As shown in Figure 1, the process of client-access Java API: when client application D module need to be accessed Java API, create the object of a Java API root node service interface, call the root node interface method (such as: get service1) obtain child node service interface service1, call again child node service interface service1 method (such as: getusername is used for obtaining user name).The C module is converted into the REST services request with the request of the access Java API of module D and issues server, and server returns to the REST response, and the method rreturn value that the C module is converted into the REST response getusername again returns to client application D module.
The procedure schematic diagram that the generation REST that Fig. 2 provides for the embodiment of the present invention serves, as shown in Figure 2, the method comprises the following steps:
S201: each service interface of server scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
S202: for each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface;
S203:, for each REST service class, be used for defining the note of REST service features in the interface message of server according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
In step S201, the interface message that the service interface that obtains is corresponding includes but not limited to: all methods of the interface name of service interface, the note on Service interface definition and service interface, and the parameter of each method of service interface, the rreturn value type of each method of service interface and the note on each method of service interface.
Wherein, note comprises be used to the note that defines the REST service features, such as, the JAX-RS(Java API for RESTful Web Services of standard, adopt the Java API of the web services of REST development scheme exploitation) to explain, it can be used for defining the REST service features.JAX-RS explains, and is the note that meets REST service note standard, and the JAX-RS of standard explains and comprises:
1) be used for arranging the note of HTTP access method;
2) be used for arranging the note of REST service request parameter;
3) be used for arranging the note etc. in the URL path of REST service.
JAX-RS note commonly used and uses thereof is as shown in table 1.
Figure BDA00003491420600141
Figure BDA00003491420600151
Table 1
Alternatively, one or more service interfaces of Java API are for establishing the service interface of authority;
Step S202, for each service interface, the class file that the interface message that server is corresponding according to this service interface generates REST service class corresponding to this service interface also comprises:
Established the service interface of authority for each, server is placed in this with this code that is used for control of authority of having established the rights service interface and has established the class file of REST service class corresponding to rights service interface;
Wherein, this code that is used for control of authority of having established the rights service interface is to be converted to by this note that is used for control of authority of having established interface message corresponding to the service interface of authority.Below the note that is used for control of authority is described.
, by adding and explain on Java API Service interface definition or in the method definition, can control neatly the control of authority strategy of REST service access.Explain class@REST Access Control(such as using " has Role (admin) "), just can allow admin user to have the authority of access REST service by parameter configuration.Note on Service interface definition can be shared by a plurality of method of this service interface, and this makes code structure more clear succinct, has also improved the reusable degree of code logic.
With establish the note that is used for control of authority in the rights service interface be converted into this example of having established the code that is used for control of authority of service class corresponding to rights service interface can be referring to example four.
In the embodiment of the present invention, the note that is used for control of authority can be added in Service interface definition, also can be added in the method definition of service interface.Be added in all methods that the note that is used for control of authority on Service interface definition is applicable to this service interface, the note that is added in the method definition of service interface is only applicable to corresponding method.If have simultaneously the note that is used for control of authority on Service interface definition and in certain method definition of this service interface, according to the note that is used for control of authority that is positioned in corresponding method definition, generate the code of the control of authority of corresponding method, and be placed in the method body of the method.
The embodiment of the present invention, the note that is used for control of authority identifies with "@Access Control ", when execution step S202 generates the code that is used for control of authority, when identifying "@Access Control ", be about to thereafter followed by bracket in note convert code for control of authority to.
In the method for existing artificial generation REST service,, if will carry out control of authority to the REST service of server, need in code corresponding to REST service, add dispersedly a large amount of codes that are used for control of authority.The method that adopts the embodiment of the present invention to provide, can generate the code for control of authority automatically, implements efficiency higher, and be difficult for makeing mistakes.And the final code that is used for control of authority is the method body that is added in each method, mixed in together with the code of additive method body, if existing employing manual type generates, be not easy identification and safeguard, and the automatic generation of adopting the embodiment of the present invention is used for the code of control of authority, need not to consider the unsharp problem of above-mentioned code structure of artificial generating code.
When a plurality of methods of a service interface have identical control of authority strategy, adopt the method for the embodiment of the present invention, can be by (namely explaining is to be added on Service interface definition adding the mode of explaining on service interface, outside the method body of service interface), a plurality of methods that namely can be this service interface arrange identical control of authority strategy.Then by the S202 step, automatically generate uniformly the identical code that is used for control of authority in each side's body of laws of class file corresponding to this service interface, avoided repeatedly writing same code by manual type in each method body, improved efficiency, and be not easy to make mistakes.So just realized same control of authority strategy, by a plurality of methods, reused.
Alternatively, step S203 comprises following two steps:
Server is corresponding REST service class to the class file that Java Virtual Machine loads each REST service class that generates, and each REST service class that loading is obtained encapsulates in Wink Application object;
For each REST service class, server, by the Wink middleware, utilizes the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generates REST service corresponding to this REST service class.
Apache Wink(is designated hereinafter simply as " Wink middleware ") be the middleware that is used for generating the REST service of increasing income.In step S202, generated the class file of the REST service class corresponding with service interface, the class file of each REST service class that server will generate is loaded in Java Virtual Machine, generate corresponding REST service class, and each REST service class that loading obtains is encapsulated in Wink Application object.Class file in the REST service class that generates comprises be used to the note that defines the REST service features, and the Wink middleware just can utilize these fixed generation REST that explain to serve like this.Realize repeating no more here described in the code such as code snippet 1 of above-mentioned steps.
The procedure schematic diagram that the REST of the generation client Java API that Fig. 3 provides for the embodiment of the present invention realizes, as shown in Figure 3, the method comprises the steps:
S301: each service interface of client scan java application DLL (dynamic link library) API, obtain the interface message of each service interface, wherein this Java API is identical with the Java API on REST service place server that this client will be called;
S302: for each described service interface, client generates REST corresponding to this service interface according to the interface message of this service interface and realizes the class file of class, and class file comprises the code of the client-requested REST service related parameters of determining according to the note that is used for defining the REST service features in the interface message of this service interface;
S303: client loads each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
In step S301, the Java API that why limits on the REST service place server that Java API and this client will call is identical, that client could be accessed the REST service of this server because only have the client and server end all based on identical Java API, to generate respectively Java API REST realization and the REST service of client.
Step S302 is used for defining the note of REST service features can be referring to table 1, and the method for the code of the client-requested REST service related parameters of determining according to the note that is used for defining the REST service features in the interface message of service interface is referring to example five.
Below, each service interface that scans Java API is described by example one, obtain the method for interface message corresponding to each service interface.
Each service interface of example one scan Java API, obtain interface message corresponding to each service interface
The method of example one is applicable to client and server simultaneously.For client, the executive agent of the method is client; For server, the executive agent of the method is server.Fig. 4 is the structural representation that is scanned the Java API of service interface in example one.For the process of each service interface of scanning Java API can simply clearly be described, Java API structure shown in Figure 4 structure for simplifying, often comprise tens service interfaces in actual Java API.The structure of Java API shown in Figure 4 is tree structure, and its root node service interface is Service Facede interface, its lower polymerization two service interfaces, be respectively Service1 interface and Service2 interface, method is separately arranged in each service interface.The structure of actual Java API is not limited to tree structure,, such as loop configuration etc.,, as long as have incidence relation between each service interface of Java API, can, by each service interface of scanning Java API, obtain interface message corresponding to each service interface.
In example one, from the root node service interface Service Facede interface of Java API, each service interface of scanning Java API, obtain interface message corresponding to each service interface.
The method of determining Java API root node service interface has a lot, such as, when server or client terminal start-up, by reading configuration file, determine Java API root node service interface.
Below,, take Java API shown in Figure 4 as example, illustrate the method for obtaining interface message corresponding to each service interface of Java API, as shown in Figure 5, the method comprises the steps:
S501, the service interface of root node service interface for scanning of determining described Java API;
S502, the service interface that will scan is scanned, obtain interface message corresponding to service interface;
If it is the method for interface that the interface message that the service interface that S503 obtains is corresponding comprises the rreturn value type, server determines according to the rreturn value of the method the service interface that the next one will scan, and returns to the step that the service interface that will scan is scanned; Otherwise end scanning process.
Alternatively, step S502 can utilize the Java reflex mechanism to realize.Utilize the Java reflex mechanism, Class class in the java.lang.reflect bag that use Java development kit (Java Development Kit, JDK) provides is obtained all methods of interface name, the note on Service interface definition and the service interface of service interface; Obtain note on the method name, method rreturn value type, method of service interface, method parameter type etc. with the Method class.
Specific practice is, load and obtain the java.lang.reflect.Class object from the java class loader, call this object method (as the method for table 2java.lang.reflect.Class), obtain all methods of interface name, the note on Service interface definition and the service interface of service interface.
Figure BDA00003491420600191
Table 2
All methods of traversal service interface, by the method (as the method for table 3java.lang.reflect.Method) of calling the java.lang.reflect.Method object, obtain the rreturn value type of each method of parameter of each method of this service interface, the note on each method.
Figure BDA00003491420600192
Table 3
Obtained each method of service interface by step S502., take the root node service interface Service Facede interface of the Java API in Fig. 4 as example, determine that by step S502 the rreturn value type of its method get Service1 is interface Service1; The rreturn value type of method get Service2 is Service2, and the service interface of so just having determined the Java API that next will scan is Service1 interface and Service2 interface., as long as the rreturn value type of certain method in service interface is interface, can determine the service interface that the next one will scan according to this rreturn value type.For two Service1 interfaces and Serivce2 interface, then each method by java.lang.reflect.Class object in table 2 obtains note, all methods of service interface on service interface title, Service interface definition respectively; Obtain note, parameter type on the method name, method rreturn value type, method of each method of service interface by each method of java.lang.reflect.Method object in table 3.
So circulation is gone down, until comprise that no longer the rreturn value type is the method (namely having obtained interface message corresponding to all service interfaces of Java API) of interface in interface message corresponding to the service interface that obtains.Need to prove, the structure of the structure of Java API in Fig. 4 for simplifying, may comprise tens service interfaces in actual Java API, as long as exist related between each service interface, so these service interfaces are carried out the iterative operation identical with top step,, until traveled through the service interface of all Java API, can obtain interface message corresponding to all service interfaces of this Java API.
In the embodiment of the present invention, the structure of Java API has been carried out simplifying processed, utilize incidence relation between each service interface of Java API realize the scanning of all service interfaces (such as, in example two, method rreturn value by service interface is determined the service interface that next will scan), overcome in the method that existing artificial generation REST service and REST realize, due to the complex structure of Java API with can't find the unified problem of obtaining interface message method corresponding to each service interface.
Below, by two pairs of embodiment of the present invention of example provide for each described service interface, the general approach that the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface is described; By three pairs of embodiment of the present invention of example provide for each described service interface, client generates REST corresponding to this service interface according to the interface message of this service interface and realizes that the general approach of the class file of class is described; By four pairs of embodiment of the present invention of example provide for a specific Java API service interface, server generates the method for the class file of REST service class corresponding to this service interface; By five pairs of embodiment of the present invention of example provide for a specific Java API service interface, client generates REST corresponding to this service interface and realizes the method for the class file of class.
Example two is for each described service interface, and the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface
Fig. 6 is the procedure schematic diagram of example two.As shown in Figure 6, the method comprises the steps:
S601, for each service interface, server generates the source code of REST service class corresponding to this service interface according to the interface message of this service interface of obtaining;
The source code of S602, REST service class that server is corresponding according to this service interface, generate the class file of REST service class corresponding to this service interface.
Alternatively, in step S602, the source code of REST service class that can service interface is corresponding compiles, and generates the class file of REST service class corresponding to this service interface.
Fig. 7 is the procedure schematic diagram of example three.As shown in Figure 7, the method comprises the steps:
S701, for each service interface, client generates REST corresponding to this service interface according to the interface message of this service interface of obtaining and realizes the source code of class;
S702, the REST corresponding according to this service interface realize the source code of class, and client generates the REST corresponding with this service interface and realizes the class file of class.
Alternatively, in step S702, the source code of REST service class that can service interface is corresponding compiles, and generates REST corresponding to this service interface and realizes the class file of class.
Below, illustrate respectively that by example four and example five server and client side generates the method for class file
Example four, server end generate class file
For purposes of simplicity of explanation, certain service interface in Java API is done following simplification.Interface is called Service1, and this service interface only has a method; @Path ,@Get, three notes of@Path Param are that JAX-RS explains ,@Access Control is for being used for the note of control of authority.The Service1 interface is defined as follows:
The Service1 interface code that code snippet 2. is simplified
Based on the interface message of obtaining to the Service1 interface scans, server generates the source code of the REST service class corresponding with the Service1 interface, and wherein the Service1Resource class is the REST service class corresponding with the Service1 interface; @Path ,@GET, three JAX-RS of@Path Param explain, and have been copied on the source code that generates; The note@Access Control that is used for control of authority, be converted into the anterior code that is used for control of authority of method body (get User Age).
The source code of the REST service class corresponding with the Serivce1 interface that generates comprises:
1) being used for is the code of method parameter type corresponding to local Java API with the type conversion of get User Age method parameter;
2) be used for interface message corresponding to the Service1 interface that obtains based on scanning before and generate the code that calls local Java API;
3) being used for is the code of the data type of REST service request with the type conversion of the execution result of local Java API method;
4) be used for returning the code of REST service response result;
5) be used for the code of control of authority.
The source code example of the REST service class corresponding with the Serivce1 interface that server generates is as follows, and wherein splicing resource in interface name back obtains the class title, and actual naming method is not limited to this, as long as different for class name corresponding to different interfaces.All classes are the public type; The note (such as JAX-RS explains) that is used for defining the REST service features is direct copying, Response.* refers to the rreturn value of method, the methodical rreturn value of institute is all with " Response. " beginning, and the method name is identical with the method name in the Service1 interface, and parameter is identical.
Figure BDA00003491420600231
The source code of the corresponding REST service class of code snippet 3.Service1 interface
Then, the compilation of source code of the REST service class of above-mentioned generation is become class file.
When server end generates the code of REST service class, directly copy for the note that generates the REST service, do not do other processing.Treat in step S203, recycle these and explain the feature of the REST service of definition generation.When the note that is used for generation REST service was JAX-RS note, available@PATH explained the HTTP path of the access of definition resource, available@Path Param, the parameter of@Query Param note definition REST services request etc., but detailed directions reference table 1.Need to prove, in this example, occurred@Path Param (" userId ") in code, is to explain with@Path Param a part that has defined URL, is the parameter value of method, and the source code that not generates the REST service class is necessary.
Example five, client generate class file
Still, take the Service1 service interface in example four as example, generate REST corresponding to Service1 interface and realize class, REST realizes that in the source code of class, the Service1ClientImpl class has realized the Service1 interface; The Service1ClientImpl.getUserAge method, calling of Java API converted to the REST services request of sending to server, and will be converted into from the REST service response of server the rreturn value of Service1ClientImpl.get User Age method, make like this client can call get User Age method, and need not be concerned about the REST service whether it has called server.
The REST corresponding with the Service1 service interface that generates realizes that the source code of class comprises:
1) be used for obtaining the code of server address, wherein server address can read from the client configuration file;
2) be used for the URL address of the REST service of generation server, and the code of the URL address access services device end service that utilize to generate (according to the note that is used for defining the REST service features on the get User Age method that scans before (such as: JAX-RS explains) generate), wherein, the user ID userId of client has been put into URL;
3) be used for that the parameter type of method get User Age is converted to the REST services request and require the code of type;
4) be used for initiating the REST services request to server, obtain the code of REST service response;
5) be used for REST service response parameter type is converted to the code of method get User Age rreturn value type;
6) be used for the code that the result after type conversion is returned as method get User Age rreturn value.
The REST corresponding with the Service1 service interface that generates realizes that the example code of class is as follows:
Figure BDA00003491420600251
Figure BDA00003491420600261
The REST that code snippet 4.Service1 interface is corresponding realizes the code of class
Generating during client REST realizes the process of category code, the note that is used for defining the REST service features in the interface message that scanning is obtained is processed.Take example five as example, when the note for generating the REST service is JAX-RS note, the ULR address String rest ServiceURL=server Host+ "/users " that the REST that utilizes@PATH to explain@Path ("/users ") generation server serves+userId+ "/age "; Using PathParam to explain certain part that has indicated the URL value is the value of parameter, and parameter value has been put into URL; The mode of using@GET to explain to determine to generate the REST request (GET POST PUT DELETE), when client call REST serves, if there is@GET to explain on the discovery corresponding method, just use HTTP GET request in generating code, just use the get method in code.In like manner, if@POST explains, just use the post method, by that analogy.Other are similar to the disposal route principle of explaining, and repeat no longer one by one here.
The method that generates class file in example two, example three, example four and example five is to generate source code by the mode that first adopts the character string splicing, then according to source code, generates corresponding class file.Wherein, the implication of " character string splicing " is explained as follows:
The character string splicing, be a plurality of character strings connected into a character string.Huang is total in the java applet design,, by creating character string buffer area (String Buffer) object code, then uses such as following code:
code.append(“public”)
code.append(“class”)
code.append(“Service1ClientImpl{”)
Take example four as example, all character strings of the Service1 interface code in the code snippet of example 43 sequentially are spliced in character string cache object code, finally obtain the code snippet 3 in example four.
In the Java language program development, the content of text (Java source code) when the .java file is exploitation, it after the compiler compiling, generates binary class file (being the .class file).The * .java file that class file is corresponding with it is equivalent, and different is, in class file, the code in the .java file has been carried out binary compiling.Simultaneously, class file can be directly performed by Java Virtual Machine, and all .java source codes all need to be compiled into class file and just can be performed.
Adopt Java bytecode operative technique, need not to write source code, generation source code in example four and example five and the step of compiling are united two into one, it adopts instruction and the rule of java virtual machine, mode by binary data generates the code identical with example five (client) with example four (server) (implication of " identical " refers to: the source code that generates in example four or example five is the binary class file that generates by Java bytecode operative technique after compiling) here, directly generates class file.Because the step 1 step that will generate source code and compiling completes, saved the time that code transforms, improved efficiency.In embodiments of the present invention, by character string, splice or Java bytecode operative technique, generate the class file of REST service class, solved the employing manual type and write code complexity, inefficient problem, and the code that generates is accurate.
Based on same inventive concept, a kind of server also is provided in the embodiment of the present invention, the principle of dealing with problems due to this server is similar to the method for the generation REST service that the embodiment of the present invention provides, therefore the enforcement of this server can, referring to the enforcement of the method that generates the REST service, repeat part and repeat no more.
The structural representation of the server that Fig. 8 provides for the embodiment of the present invention.As shown in Figure 8, this server specifically comprises:
Scan module 801, each service interface for scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
Class file generation module 802, be used for for each service interface, and the interface message corresponding according to this service interface generates the class file of REST service class corresponding to this service interface;
REST service creation module 803, be used for for each REST service class, be used for defining the note of REST service features in interface message according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
Alternatively, one or more service interfaces of Java API are for establishing the service interface of authority;
Class file generation module 802 also is used for: established the service interface of authority for each, this code that is used for control of authority of having established the rights service interface has been placed in this has established the class file of REST service class corresponding to rights service interface;
Wherein, this code that is used for control of authority of having established the rights service interface is that the note that is used for control of authority that this that obtain by described scan module established interface message corresponding to the service interface of authority is converted to.
Alternatively, scan module 801 specifically is used for: the service interface of root node service interface for scanning of determining Java API; The service interface that will scan is scanned, obtain interface message corresponding to service interface; , if it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, according to the rreturn value of the method, determines the service interface that next will scan, and return to the step that the service interface that will scan is scanned; Otherwise end scanning process.
Alternatively, the service interface that will scan is scanned, obtaining interface message corresponding to service interface comprises: load the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
Alternatively, class file generation module 802 specifically is used for:, for each described service interface, generate the source code of REST service class corresponding to this service interface according to the interface message of this service interface that obtains; The source code of the REST service class corresponding according to this service interface, generate the class file of REST service class corresponding to this service interface.
Alternatively, class file generation module 802 specifically is used for: for each described service interface, the interface message corresponding according to this service interface, utilize Java bytecode operative technique, generates the class file of REST service class corresponding to this service interface.
REST service creation module 803 specifically is used for: the class file that loads each REST service class that generates to Java Virtual Machine is corresponding REST service class, and each REST service class that loading is obtained encapsulates in Wink Application object; For each REST service class,, by the Wink middleware, utilize the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
Based on same inventive concept, a kind of client also is provided in the embodiment of the present invention, the principle of dealing with problems due to this client is similar to the method that the generation REST that the embodiment of the present invention provides realizes, therefore the enforcement of this client can, referring to the enforcement of the method that generates the REST realization, repeat part and repeat no more.
Fig. 9 is the structural representation of the client of the embodiment of the present invention.As shown in Figure 9, this client specifically comprises:
Scan module 901, be used for each service interface of scanning java application DLL (dynamic link library) API, obtains the interface message of each service interface, and wherein Java API is identical with the Java API that REST that this client will be called serves on the server of place;
Class file generation module 902, be used for for each service interface, generate REST corresponding to this service interface according to the interface message of this service interface and realize the class file of class, class file comprises the code of the client-requested REST service related parameters of determining according to the note that is used for defining the REST service features in the interface message of this service interface;
REST realizes generation module 903, is used for loading each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
Alternatively, scan module 901 specifically is used for: the service interface of root node service interface for scanning of determining Java API; The service interface that will scan is scanned, obtain interface message corresponding to service interface; , if it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, according to the rreturn value of the method, determines the service interface that next will scan, and return to the step that the service interface that will scan is scanned; Otherwise end scanning process.
Alternatively, the service interface that scan is scanned, obtain interface message corresponding to service interface and comprise; Load the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
Alternatively, class file generation module 902 specifically is used for:, for each described service interface, generate REST corresponding to this service interface according to the interface message of this service interface that obtains and realize the source code of class; Realize the source code of class according to REST corresponding to described this service interface, generate the REST corresponding with this service interface and realize the class file of class.
Alternatively, class file generation module concrete 902 is used for: for each described service interface, the interface message corresponding according to this service interface, utilize Java bytecode operative technique, generates the REST corresponding with this service interface and realize the class file of class.
Those skilled in the art should understand, embodiments of the invention can be provided as method, system or computer program.Therefore, the present invention can adopt complete hardware implementation example, implement software example or in conjunction with the form of the embodiment of software and hardware aspect fully.And the present invention can adopt the form that wherein includes the upper computer program of implementing of computer-usable storage medium (including but not limited to magnetic disk memory, CD-ROM, optical memory etc.) of computer usable program code one or more.
The present invention describes with reference to process flow diagram and/or the block scheme of method, equipment (system) and computer program according to the embodiment of the present invention.Should understand can be by the flow process in each flow process in computer program instructions realization flow figure and/or block scheme and/or square frame and process flow diagram and/or block scheme and/or the combination of square frame.Can provide these computer program instructions to the processor of multi-purpose computer, special purpose computer, Embedded Processor or other programmable data processing device to produce a machine, make the instruction of carrying out by the processor of computing machine or other programmable data processing device produce to be used for the device of realizing in the function of flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame appointments.
These computer program instructions also can be stored in energy vectoring computer or the computer-readable memory of other programmable data processing device with ad hoc fashion work, make the instruction that is stored in this computer-readable memory produce the manufacture that comprises command device, this command device is realized the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame.
These computer program instructions also can be loaded on computing machine or other programmable data processing device, make on computing machine or other programmable devices and to carry out the sequence of operations step to produce computer implemented processing, thereby be provided for realizing the step of the function of appointment in flow process of process flow diagram or a plurality of flow process and/or square frame of block scheme or a plurality of square frame in the instruction of carrying out on computing machine or other programmable devices.
Although described the preferred embodiments of the present invention, in a single day those skilled in the art obtain the basic creative concept of cicada, can make other change and modification to these embodiment.So claims are intended to all changes and the modification that are interpreted as comprising preferred embodiment and fall into the scope of the invention.
Obviously, those skilled in the art can carry out various changes and modification and not break away from the spirit and scope of the present invention the present invention.Like this, if within of the present invention these are revised and modification belongs to the scope of the claims in the present invention and equivalent technologies thereof, the present invention also is intended to comprise these changes and modification interior.

Claims (14)

1. a method that generates statement sexual state transfer REST service, is characterized in that, the method comprises:
Each service interface of server scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
For each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface;
For each REST service class, be used for defining the note of REST service features in the interface message of server according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
2. the method for claim 1, is characterized in that, one or more service interfaces of described Java API are for establishing the service interface of authority;
Described for each described service interface, the class file that the interface message that server is corresponding according to this service interface generates REST service class corresponding to this service interface also comprises:
Established the service interface of authority for each, server is placed in this with this code that is used for control of authority of having established the rights service interface and has established the class file of REST service class corresponding to rights service interface;
Wherein, this code that is used for control of authority of having established the rights service interface is to be converted to by this note that is used for control of authority of having established interface message corresponding to the service interface of authority.
3. method as claimed in claim 1 or 2, is characterized in that, each service interface of described server scanning Java API, obtain interface message corresponding to each service interface, comprising:
Server is determined the service interface of root node service interface for scanning of described Java API;
Server scans the service interface that will scan, and obtains interface message corresponding to service interface;
If it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, server is determined the service interface that next will scan according to the rreturn value of the method, and returns to the step that the service interface that will scan is scanned; Otherwise end scanning process.
4. method as claimed in claim 3, is characterized in that, described server scans the service interface that will scan, and obtains interface message corresponding to service interface and comprise:
Server loads the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
5. method as claimed in claim 1 or 2, is characterized in that, described for each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface, comprising:
For each described service interface, server generates the source code of REST service class corresponding to this service interface according to the interface message of this service interface that obtains;
The source code of the REST service class that server is corresponding according to described this service interface, generate the class file of REST service class corresponding to this service interface.
6. method as claimed in claim 1 or 2, is characterized in that, described for each described service interface, the interface message that server is corresponding according to this service interface generates the class file of REST service class corresponding to this service interface, comprising:
For each described service interface, the interface message that server is corresponding according to this service interface, utilize Java bytecode operative technique, generates the class file of REST service class corresponding to this service interface.
7. method as claimed in claim 1 or 2, it is characterized in that, described for a REST service class, the note that is used for defining the REST service features in the interface message of server according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class, comprising:
Server is corresponding REST service class to the class file that Java Virtual Machine loads each REST service class that generates, and each REST service class that loading is obtained encapsulates in Wink Application object;
For each REST service class, server, by the Wink middleware, utilizes the annotating information that is used for defining the REST service features in service interface corresponding to this REST service class, generates REST service corresponding to this REST service class.
8. a statement sexual state that generates client Java API shifts the method that REST realizes, it is characterized in that, the method comprises:
Each service interface of client scan java application DLL (dynamic link library) API, obtain the interface message of each service interface, and wherein said Java API is identical with the Java API on REST service place server that this client will be called;
For each described service interface, client generates REST corresponding to this service interface according to the interface message of this service interface and realizes the class file of class, class file comprises the code of client-requested REST service related parameters, and wherein said code is according to determining for the note that defines the REST service features in the interface message of this service interface;
Client loads each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
9. method as claimed in claim 8, is characterized in that, each service interface of described client scan Java API obtains interface message corresponding to each service interface and comprises:
Client is determined the service interface of root node service interface for scanning of described Java API;
Client scans the service interface that will scan, and obtains interface message corresponding to service interface;
If it is the method for interface that the interface message that the service interface that obtains is corresponding comprises the rreturn value type, client is determined the service interface that next will scan according to the rreturn value of the method, and returns to the step that the service interface that will scan is scanned; Otherwise end scanning process.
10. method as claimed in claim 9, is characterized in that, described client scans the service interface that will scan, and obtains interface message corresponding to service interface and comprise;
Client loads the object of Java reflection class from the java class loader, use the method for Java reflection class object to obtain the interface message corresponding to service interface that will scan.
11. method as claimed in claim 8, is characterized in that, and is described for each described service interface, the client interface message corresponding according to this service interface generates REST corresponding to this service interface and realizes that the class file of class comprises:
For each described service interface, the interface message of this service interface that the client basis is obtained generates REST corresponding to this service interface and realizes the source code of class;
Realize the source code of class according to REST corresponding to described this service interface, client generates the REST corresponding with this service interface and realizes the class file of class.
12. method as claimed in claim 8, is characterized in that, and is described for each described service interface, the client interface message corresponding according to this service interface generates REST corresponding to this service interface and realizes that the class file of class comprises:
For each described service interface, the interface message that client is corresponding according to this service interface, utilize Java bytecode operative technique, generates the REST corresponding with this service interface and realize the class file of class.
13. a server, is characterized in that, this server comprises:
Scan module, each service interface for scanning java application DLL (dynamic link library) API, obtain interface message corresponding to each service interface;
The class file generation module, be used for for each described service interface, and the interface message corresponding according to this service interface generates statement sexual state corresponding to this service interface and shift the class file of REST service class;
REST service creation module, be used for for each REST service class, be used for defining the note of REST service features in interface message according to the class file of this REST service class and service interface corresponding to this REST service class, generate REST service corresponding to this REST service class.
14. a client, is characterized in that, this client comprises:
Scan module, each service interface that is used for scanning java application DLL (dynamic link library) API, obtain the interface message of each service interface, wherein said Java API is identical with the Java API that the statement sexual state that this client will be called shifts on the server of REST service place;
The class file generation module, be used for for each described service interface, generate REST corresponding to this service interface according to the interface message of this service interface and realize the class file of class, class file comprises the code of client-requested REST service related parameters, and wherein said code is according to determining for the note that defines the REST service features in the interface message of this service interface;
REST realizes generation module, is used for loading each REST that generates and realizes the class file of class, and the REST that generates client Java API realizes.
CN201310288983.9A 2013-07-10 2013-07-10 Method for generating REST service and achieving REST and corresponding equipment Active CN103399734B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310288983.9A CN103399734B (en) 2013-07-10 2013-07-10 Method for generating REST service and achieving REST and corresponding equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310288983.9A CN103399734B (en) 2013-07-10 2013-07-10 Method for generating REST service and achieving REST and corresponding equipment

Publications (2)

Publication Number Publication Date
CN103399734A true CN103399734A (en) 2013-11-20
CN103399734B CN103399734B (en) 2017-02-08

Family

ID=49563368

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310288983.9A Active CN103399734B (en) 2013-07-10 2013-07-10 Method for generating REST service and achieving REST and corresponding equipment

Country Status (1)

Country Link
CN (1) CN103399734B (en)

Cited By (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN105955790A (en) * 2016-05-20 2016-09-21 广州华多网络科技有限公司 Data processing method and apparatus
CN106302442A (en) * 2016-08-12 2017-01-04 广州慧睿思通信息科技有限公司 A kind of network communication packet analytic method based on Java language
WO2017041657A1 (en) * 2015-09-09 2017-03-16 阿里巴巴集团控股有限公司 Application interface management method and device
CN106663002A (en) * 2014-06-25 2017-05-10 甲骨文国际公司 REST service source code generation
CN106664298A (en) * 2014-07-13 2017-05-10 思科技术公司 Representational state transfer operations using information centric networking
CN107038057A (en) * 2016-10-31 2017-08-11 东软集团股份有限公司 Create the method and device of class
CN107888673A (en) * 2017-11-03 2018-04-06 国云科技股份有限公司 A kind of unified management implementation method suitable for isomery cloud platform
CN108156022A (en) * 2017-12-04 2018-06-12 北京奇艺世纪科技有限公司 A kind of service calling method, device and electronic equipment
CN108446105A (en) * 2018-02-08 2018-08-24 广州亦云信息技术股份有限公司 A kind of Lightweight AP I Server Development Frameworks and development approach
CN108874833A (en) * 2017-05-15 2018-11-23 武汉斗鱼网络科技有限公司 A kind of method and device for realizing Etcd Java client
CN108885633A (en) * 2016-03-23 2018-11-23 交互智能集团有限公司 For finding and being connected to the technology of REST interface automatically
CN110191141A (en) * 2018-02-23 2019-08-30 阿里巴巴集团控股有限公司 Service invocation information processing method, device and computer system
CN110300082A (en) * 2018-03-21 2019-10-01 腾讯科技(深圳)有限公司 A kind of interface creation method, device and storage medium
CN110381135A (en) * 2019-07-18 2019-10-25 北京奇艺世纪科技有限公司 Interface creation method, service request method, device, computer equipment and medium
CN110381056A (en) * 2019-07-17 2019-10-25 钛马信息网络技术有限公司 Proprietary protocol decoding method and device based on Netty
CN110704828A (en) * 2019-09-06 2020-01-17 苏州浪潮智能科技有限公司 Verification method, device, equipment and computer readable storage medium
CN112612452A (en) * 2020-12-18 2021-04-06 华人运通(上海)云计算科技有限公司 API platform implementation method, device, equipment and storage medium
CN112711405A (en) * 2020-12-28 2021-04-27 山东浪潮通软信息科技有限公司 Method, equipment and storage medium for generating add-delete-modify-check application program interface
US11442765B1 (en) 2019-09-18 2022-09-13 Amazon Technologies, Inc. Identifying dependencies for processes for automated containerization
US11487878B1 (en) 2019-09-18 2022-11-01 Amazon Technologies, Inc. Identifying cooperating processes for automated containerization
US11650810B1 (en) * 2020-05-27 2023-05-16 Amazon Technologies, Inc. Annotation based automated containerization

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101478439A (en) * 2009-01-20 2009-07-08 中兴通讯股份有限公司 Uniform service management platform, interface machine, service processing system and process method
CN101840334A (en) * 2010-04-16 2010-09-22 中国电子科技集团公司第二十八研究所 Software component service packaging method
US20110041171A1 (en) * 2009-08-11 2011-02-17 Lloyd Leon Burch Techniques for virtual representational state transfer (rest) interfaces
CN103092982A (en) * 2013-02-01 2013-05-08 苏州鸿然信息科技有限公司 Information service system based on multiple-view business model

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101478439A (en) * 2009-01-20 2009-07-08 中兴通讯股份有限公司 Uniform service management platform, interface machine, service processing system and process method
US20110041171A1 (en) * 2009-08-11 2011-02-17 Lloyd Leon Burch Techniques for virtual representational state transfer (rest) interfaces
CN101840334A (en) * 2010-04-16 2010-09-22 中国电子科技集团公司第二十八研究所 Software component service packaging method
CN103092982A (en) * 2013-02-01 2013-05-08 苏州鸿然信息科技有限公司 Information service system based on multiple-view business model

Cited By (34)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106663002A (en) * 2014-06-25 2017-05-10 甲骨文国际公司 REST service source code generation
CN106663002B (en) * 2014-06-25 2020-11-10 甲骨文国际公司 REST service source code generation
CN106664298B (en) * 2014-07-13 2020-06-30 思科技术公司 Method and apparatus for representational state transfer operations
US10742552B2 (en) 2014-07-13 2020-08-11 Cisco Technology, Inc. Representational state transfer operations using information centric networking
CN106664298A (en) * 2014-07-13 2017-05-10 思科技术公司 Representational state transfer operations using information centric networking
WO2017041657A1 (en) * 2015-09-09 2017-03-16 阿里巴巴集团控股有限公司 Application interface management method and device
CN106528185A (en) * 2015-09-09 2017-03-22 阿里巴巴集团控股有限公司 Application interface management method and apparatus
CN105117233A (en) * 2015-09-14 2015-12-02 百度在线网络技术(北京)有限公司 API calling method and device
CN105117233B (en) * 2015-09-14 2019-05-28 百度在线网络技术(北京)有限公司 API Calls method and device
CN108885633B (en) * 2016-03-23 2022-04-19 交互智能集团有限公司 Techniques for auto-discovery and connection to REST interfaces
CN108885633A (en) * 2016-03-23 2018-11-23 交互智能集团有限公司 For finding and being connected to the technology of REST interface automatically
CN105955790B (en) * 2016-05-20 2019-05-14 广州华多网络科技有限公司 Data processing method and device
CN105955790A (en) * 2016-05-20 2016-09-21 广州华多网络科技有限公司 Data processing method and apparatus
CN106302442B (en) * 2016-08-12 2019-06-25 广州慧睿思通信息科技有限公司 A kind of network communication resolve packet method based on Java language
CN106302442A (en) * 2016-08-12 2017-01-04 广州慧睿思通信息科技有限公司 A kind of network communication packet analytic method based on Java language
CN107038057A (en) * 2016-10-31 2017-08-11 东软集团股份有限公司 Create the method and device of class
CN108874833A (en) * 2017-05-15 2018-11-23 武汉斗鱼网络科技有限公司 A kind of method and device for realizing Etcd Java client
CN107888673A (en) * 2017-11-03 2018-04-06 国云科技股份有限公司 A kind of unified management implementation method suitable for isomery cloud platform
CN108156022A (en) * 2017-12-04 2018-06-12 北京奇艺世纪科技有限公司 A kind of service calling method, device and electronic equipment
CN108446105A (en) * 2018-02-08 2018-08-24 广州亦云信息技术股份有限公司 A kind of Lightweight AP I Server Development Frameworks and development approach
CN108446105B (en) * 2018-02-08 2021-09-07 广州亦云信息技术股份有限公司 Lightweight API Server development framework and development method
CN110191141A (en) * 2018-02-23 2019-08-30 阿里巴巴集团控股有限公司 Service invocation information processing method, device and computer system
CN110300082A (en) * 2018-03-21 2019-10-01 腾讯科技(深圳)有限公司 A kind of interface creation method, device and storage medium
CN110381056A (en) * 2019-07-17 2019-10-25 钛马信息网络技术有限公司 Proprietary protocol decoding method and device based on Netty
CN110381056B (en) * 2019-07-17 2021-08-03 钛马信息网络技术有限公司 Netty-based private protocol coding and decoding method and apparatus
CN110381135A (en) * 2019-07-18 2019-10-25 北京奇艺世纪科技有限公司 Interface creation method, service request method, device, computer equipment and medium
CN110381135B (en) * 2019-07-18 2021-09-28 北京奇艺世纪科技有限公司 Interface creating method, service requesting method, device, computer device, and medium
CN110704828A (en) * 2019-09-06 2020-01-17 苏州浪潮智能科技有限公司 Verification method, device, equipment and computer readable storage medium
US11442765B1 (en) 2019-09-18 2022-09-13 Amazon Technologies, Inc. Identifying dependencies for processes for automated containerization
US11487878B1 (en) 2019-09-18 2022-11-01 Amazon Technologies, Inc. Identifying cooperating processes for automated containerization
US11650810B1 (en) * 2020-05-27 2023-05-16 Amazon Technologies, Inc. Annotation based automated containerization
CN112612452A (en) * 2020-12-18 2021-04-06 华人运通(上海)云计算科技有限公司 API platform implementation method, device, equipment and storage medium
CN112612452B (en) * 2020-12-18 2023-11-14 华人运通(上海)云计算科技有限公司 API platform realization method, device, equipment and storage medium
CN112711405A (en) * 2020-12-28 2021-04-27 山东浪潮通软信息科技有限公司 Method, equipment and storage medium for generating add-delete-modify-check application program interface

Also Published As

Publication number Publication date
CN103399734B (en) 2017-02-08

Similar Documents

Publication Publication Date Title
CN103399734A (en) Method for generating REST service and achieving REST and corresponding equipment
US8051405B2 (en) System and method for build script generation in a software development environment
US7895566B2 (en) System and method for building a deployable component based application
CN112748908B (en) Method and device for developing Restful service based on SSM framework
US9959160B2 (en) Fault handling in a distributed IT environment
US8615750B1 (en) Optimizing application compiling
EP2827244A1 (en) Extension mechanism for scripting language compiler
US20060206863A1 (en) System and method for designing component based applications
US10209968B2 (en) Application compiling
CN105022630A (en) Component management system and component management method
EP2479663A1 (en) Resource management method and system
KR20140089410A (en) Java applicaiton server and web service processing method
US20130117356A1 (en) Storage Device Including Software Development Kit that Includes Web Service Interface and Terminal Apparatus Including the Software Development Kit
CN105335132A (en) Method, apparatus and system for user-defined application function
CN110716720A (en) Method and device for realizing application hot deployment
CN110457013B (en) Program component configuration device and method
CN116466915A (en) MVP architecture-based iOS development framework construction method and device
CN113360156B (en) IOS compiling method and related equipment
CN113342399A (en) Application structure configuration method and device and readable storage medium
CN114115982A (en) Code issuing method, device, equipment and storage medium
Srinivasmurthy et al. Web2exchange: A model-based service transformation and integration environment
CN117311799B (en) Configuration method of software project page
JP2004246413A (en) Computer system
CN115480757A (en) iOS system engineering component generation method, device, equipment and storage medium
Bode et al. Puppet Types and Providers: Extending Puppet with Ruby

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 100192 Beijing city Haidian District West SIP No. 66 Dongsheng Technology Park. The Northern Territory C1-105

Applicant after: SMARTDOT TECHNOLOGIES CO., LTD.

Address before: 100192 Beijing city Haidian District West SIP No. 66 Dongsheng Technology Park. The Northern Territory C1-105

Applicant before: Beijing Huidian Technology Co., Ltd.

CB03 Change of inventor or designer information

Inventor after: Jiang Xiaodan

Inventor after: Lv Yi

Inventor after: Huang Haifeng

Inventor after: Han Guoquan

Inventor after: Du Sheng

Inventor after: Zhang Xiaohui

Inventor before: Zhang Xiaohui

COR Change of bibliographic data
C14 Grant of patent or utility model
GR01 Patent grant