Method and device for converting calling interface
By obtaining and mapping the interface identifier of the service framework, using Java reflection technology to realize direct calls between service frameworks of different program languages, solving the problem of cross-language calls and access restrictions, and achieving flexible and widespread applications.
Patent Information
- Application Number
- CN201810743642.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-07-09
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2038-07-09
AI Technical Summary
The prior art cannot realize direct calls between service frameworks in different program languages, and HTTP calls cannot be supported in a timely manner without a client or after the service framework is upgraded. The access of the registry center is limited to the LAN and requires a specific request address format. This leads to application limitations.
By obtaining the interface identifier of the target interface, generating interface information and establishing a mapping between the interface information and the request path, using Java reflection technology to convert the call to the target interface when calling, supporting direct calls between service frameworks in different programming languages without the need to do a service framework Perform source code extension or provide client.
It implements direct calls between service frameworks of different programming languages, overcomes cross-language call restrictions, supports widespread applications, avoids the limitations provided by source code extensions and client, and improves application flexibility and scalability.
Smart Images

Figure CN110704200B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for converting a calling interface. Background Art
[0002] At present, there are many types of service frameworks. Different service frameworks may use different programming languages. Most service frameworks are based on object notation (JSON, a lightweight data exchange format), extensible markup language (XML) or binary objects. For example, the RPC service framework, RPC is an inter-process communication method that allows remote services to be called like local services. The RPC service framework includes the RPC service interface, registration center and RPC client. The main goal of the RPC service framework is to make remote service calls simpler and more transparent. The RPC service framework can shield the underlying transmission method, serialization method and communication details. That is, when using it, developers only need to understand who provides what kind of RPC service interface and where, and do not need to care about the underlying communication details and calling process.
[0003] The service framework can be used to establish an independent order system, payment system, commodity system or user system, etc. At present, service frameworks using different programming languages cannot directly call service interfaces. Therefore, there are two main methods for interaction between service frameworks (i.e., calling service interfaces). One is to call through the client. The service framework provides the corresponding client to call the service interface. If the corresponding client is not used, it is necessary to call the service interface through a disguised HTTP call, that is, to expand the source code of the service framework to add the calling function; the other is to call through the registration center, using a specific request address format to send a request to the registration center to call the service interface.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0005] 1. Unable to call service interface across programming languages;
[0006] 2. If there is no client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after upgrading;
[0007] 3. The registration center cannot provide external access and can only be accessed within the local area network. A specific request address format is required, and its application is limited. Summary of the invention
[0008] In view of this, an embodiment of the present invention provides a method and device for converting calling interfaces, which can support direct calling of target interfaces between service frameworks in different programming languages; there is no need to expand the source code of the service framework or provide a client corresponding to the service framework; and it is widely used.
[0009] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for converting a calling interface is provided.
[0010] A method for converting a calling interface according to an embodiment of the present invention includes: obtaining an interface identifier of a target interface; wherein the interface identifier carries a request path of the target interface; generating interface information of the target interface according to the interface identifier, and establishing a mapping between the interface information and the request path; when calling the original interface through a calling request, calling the target interface based on the mapping conversion; wherein the calling request carries the request path.
[0011] Optionally, the interface identifier includes a request address annotation and a method parameter annotation; before obtaining the interface identifier of the target interface, the method further includes: adding the request address annotation and the method parameter annotation to the target interface.
[0012] Optionally, generating the interface information of the target interface according to the interface identifier includes: obtaining the interface implementation class and abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining the method parameter array of the abstract method according to the method parameter annotation of the target interface; and generating the interface information based on the interface implementation class, the abstract method and the method parameter array.
[0013] Optionally, the method parameter array includes the parameter name of the abstract method and the verification rules indicating whether the parameters of the abstract method are required; calling the target interface based on the mapping conversion includes: obtaining the request path from the call request; obtaining the interface implementation class, the abstract method and the method parameter array from the mapping based on the request path; checking the abstract method according to the method parameter array; when the abstract method passes the test, using Java reflection technology to call the target interface according to the interface implementation class conversion.
[0014] Optionally, establishing a mapping between the interface information and the request path includes: obtaining the request path of the target interface according to the request address annotation of the target interface; and establishing a mapping between the interface information of the target interface and the request path of the target interface.
[0015] Optionally, the method further includes: converting the return value of calling the target interface into a preset format and returning it.
[0016] Optionally, the target interface is an RPC service interface, and the original interface is an HTTP interface.
[0017] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for converting a calling interface is provided.
[0018] A device for converting a calling interface according to an embodiment of the present invention comprises: an acquisition module for acquiring an interface identifier of a target interface; wherein the interface identifier carries a request path of the target interface; a generation module for generating interface information of the target interface according to the interface identifier, and establishing a mapping between the interface information and the request path; a conversion calling module for calling the target interface based on the mapping conversion when calling the original interface through a calling request; wherein the calling request carries the request path.
[0019] Optionally, the interface identifier includes a request address annotation and a method parameter annotation; and the device further includes: an adding module, configured to add the request address annotation and the method parameter annotation to the target interface.
[0020] Optionally, the generation module is also used to: obtain the interface implementation class and abstract method of the target interface according to the request address annotation and the method parameter annotation; obtain the method parameter array of the abstract method according to the method parameter annotation of the target interface; and generate the interface information based on the interface implementation class, the abstract method and the method parameter array.
[0021] Optionally, the method parameter array includes the parameter name of the abstract method and the verification rules indicating whether the parameters of the abstract method are required; and the conversion call module is also used to: obtain the request path from the call request; obtain the interface implementation class, the abstract method and the method parameter array from the mapping based on the request path; check the abstract method according to the method parameter array; when the abstract method passes the test, use Java reflection technology to convert and call the target interface according to the interface implementation class.
[0022] Optionally, the generation module is further used to: obtain the request path of the target interface according to the request address annotation of the target interface; and establish a mapping between the interface information of the target interface and the request path of the target interface.
[0023] Optionally, the device further comprises: a conversion module, configured to convert the return value of calling the target interface into a preset format and return the result.
[0024] Optionally, the target interface is an RPC service interface, and the original interface is an HTTP interface.
[0025] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device for converting a calling interface is provided.
[0026] An electronic device for converting a calling interface according to an embodiment of the present invention comprises: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement a method for converting a calling interface according to an embodiment of the present invention.
[0027] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided.
[0028] A computer-readable storage medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a method for converting a calling interface according to an embodiment of the present invention is implemented.
[0029] An embodiment of the above invention has the following advantages or beneficial effects: because the interface identifier of the target interface is obtained; the interface information of the target interface is generated according to the interface identifier, and a mapping between the interface information and the request path is established; when the original interface is called through a call request, the technical means of calling the target interface based on the mapping conversion is used to realize the conversion of calling the target interface when calling the original interface through the interface identifier, so the inability to call the service interface across programming languages is overcome; if there is no client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after the upgrade; the registration center cannot provide external access and can only be accessed within the local area network, and a specific request address format needs to be used, and the application of limited technical problems is solved, thereby achieving support for directly calling the target interface between service frameworks in different programming languages; there is no need to expand the source code of the service framework, or provide a client corresponding to the service framework; the technical effect of wide application.
[0030] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0032] Figure 1 is a schematic diagram of the main steps of a method for converting a calling interface according to an embodiment of the present invention;
[0033] Figure 2 is a schematic diagram of the implementation flow of the method for converting the calling interface according to an embodiment of the present invention;
[0034] Figure 3 is a schematic diagram of main modules of a device for converting a calling interface according to an embodiment of the present invention;
[0035] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0036] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0037] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0038] It should be pointed out that the embodiments of the present invention and the technical features therein may be combined with each other without conflict.
[0039] Figure 1 It is a schematic diagram of main steps of a method for converting a calling interface according to an embodiment of the present invention.
[0040] like Figure 1 As shown, the method for converting the calling interface in the embodiment of the present invention mainly includes the following steps:
[0041] Step S101: Obtain the interface identifier of the target interface.
[0042] Since different service frameworks may use different programming languages, service interfaces between service frameworks can be called through common interfaces (i.e., original interfaces), but original interfaces may be subject to certain requirements or format requirements, and transmission efficiency or security is not as good as directly calling service interfaces. For example, the Hypertext Transfer Protocol (HTTP) interface, since the HTTP interface is limited by the Hypertext Transfer Protocol, the HTTP request header needs to be carried when calling the HTTP interface.
[0043] In addition, calling service interfaces between service frameworks can also be achieved through clients or registration centers. However, when calling service interfaces through clients, the service framework needs to provide the corresponding client. If the service framework does not provide a client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after upgrading; and the registration center cannot provide external access, can only be accessed within the local area network, and requires a specific request address format, which is limited in application.
[0044] The method for converting the calling interface proposed in the embodiment of the present invention can realize the conversion of calling the service interface (i.e., the target interface) when calling the original interface through the interface identifier, and supports calling the target interface between service frameworks of different programming languages, without the need to expand the source code of the service framework or provide a client corresponding to the service framework, and can be widely used. The interface identifier of the target interface carries the request path of the target interface, so the interface identifier of the target interface can be obtained before calling the target interface.
[0045] The interface identifier may include a request address annotation and a method parameter annotation, wherein the request address annotation is an annotation that indicates the request path of the target interface, and the value of the request address annotation is the request path.
[0046] In an embodiment of the present invention, before obtaining the interface identifier of the target interface, a request address annotation and a method parameter annotation may be added to the target interface. The request address annotation may be added to the interface implementation class and abstract method of the target interface. The method parameter annotation may be added to the abstract method of the target interface.
[0047] Step S102: Generate interface information of the target interface according to the interface identifier, and establish a mapping between the interface information and the request path.
[0048] After obtaining the interface identifier of the target interface, relevant information of the target interface is obtained according to the interface identifier, and interface information is generated. The interface identifier carries the request path of the target interface, so the mapping between the interface information and the request path can be directly established.
[0049] In an embodiment of the present invention, generating interface information of the target interface can be achieved in the following ways: obtaining the interface implementation class and abstract method of the target interface based on the request address annotation and method parameter annotation; obtaining the method parameter array of the abstract method based on the method parameter annotation of the target interface; generating interface information based on the interface implementation class, abstract method and method parameter array.
[0050] Since the request address annotation is added to the interface implementation class and abstract method of the target interface, and the method parameter annotation is added to the abstract method of the target interface, the interface implementation class and abstract method, as well as the method parameter array of the abstract method, can be obtained based on the request address annotation and method parameter annotation, thereby generating interface information.
[0051] In an embodiment of the present invention, mapping of interface information and request path can be achieved by: obtaining the request path of the target interface according to the request address annotation of the target interface; mapping of interface information of the target interface and the request path of the target interface is established.
[0052] The request address annotation is added to the interface implementation class and abstract method of the target interface, that is, the annotation value of the interface implementation class and the annotation value of the abstract method are the complete request path of the target interface. After obtaining the request path through the request address annotation, the mapping between the interface information and the request path can be established.
[0053] The method parameter array can indicate which parameters of the abstract method are required. The method parameter array includes the parameter names of the abstract method and the validation rules that indicate whether the parameters of the abstract method are required.
[0054] Step S103: when the original interface is called through the call request, the target interface is called based on the mapping conversion.
[0055] The call request for calling the original interface carries a request path, and the corresponding target interface can be obtained from the mapping based on the request path, thereby converting the call target interface.
[0056] In an embodiment of the present invention, step S103 can be implemented in the following manner: obtaining a request path from a call request; obtaining an interface implementation class, an abstract method, and a method parameter array from a mapping based on the request path; testing the abstract method according to the method parameter array; when the abstract method passes the test, using Java reflection technology to convert the call to the target interface according to the interface implementation class.
[0057] Mapping is the correspondence between interface information and request path. Through the mapping and the request path carried in the call request, the interface information of the target interface can be obtained, thereby obtaining the interface implementation class, abstract method and method parameter array of the target interface. According to the method parameter array, the parameters of the abstract method can be checked. If the required parameters of the abstract method meet the requirements and the parameters are correct, the abstract method is confirmed to have passed the inspection. At this time, JAVA (an object-oriented programming language) reflection technology can be used to convert the call to the target interface according to the interface implementation class.
[0058] JAVA reflection technology means that in the running state, for any class, all the properties and methods of this class can be known; for any object, any method and property of it can be called. That is, through JAVA reflection technology, all the properties and abstract methods of the interface implementation class can be known, so that the target interface can be called.
[0059] In the embodiment of the present invention, the return value of the target interface can be converted into a preset format and returned. Since the original interface is based on a text protocol, the interaction adopts a text format, and the service framework returns an object, when the service interface (i.e., the target interface) of the service framework is called through the original interface conversion, the return value of the target interface should be converted into a common preset format and returned to the caller, such as JSON or XML.
[0060] In the embodiment of the present invention, the target interface is the RPC service interface, and the original interface is the HTTP interface. Currently, there are many types of service frameworks, which can be used to establish independent order systems, payment systems, commodity systems or user systems, such as the RPC service framework.
[0061] It can be seen from the method for converting the calling interface according to the embodiment of the present invention that the interface identifier of the target interface is obtained; the interface information of the target interface is generated according to the interface identifier, and a mapping between the interface information and the request path is established; when the original interface is called through the calling request, the technical means of calling the target interface based on the mapping conversion is used, and the conversion of calling the target interface when calling the original interface is realized through the interface identifier, so the inability to call the service interface across programming languages is overcome; if there is no client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after upgrading; the registration center cannot provide external access and can only be accessed within the local area network, and a specific request address format needs to be used, and the application of limited technical problems, thereby achieving support for directly calling the target interface between service frameworks in different programming languages; there is no need to expand the source code of the service framework or provide a client corresponding to the service framework; the technical effect of wide application.
[0062] Figure 2 The present invention is a flowchart of a method for converting a calling interface according to an embodiment of the present invention.
[0063] like Figure 2 As shown, the method for converting the calling interface of the embodiment of the present invention can use a proxy server to convert the service interface of the calling service framework through the original interface. Now, taking the conversion of the RPC service interface to the HTTP interface as an example, the method for converting the calling interface is described, and the annotation is selected as the interface identifier. The specific implementation process includes:
[0064] First, define annotations, which are divided into two categories:
[0065] The request address annotation (APIUrl) is an annotation that indicates the request path of the target interface. It can be added to the interface implementation class and abstract method of the target interface. APIUrl has an attribute value (value), which is a part of the request path. The full path of the target interface is the annotation value of the interface implementation class and the annotation value of the abstract method. For example, if the annotation of the interface implementation class is @APIUrl(" / order") and the annotation of the abstract method is @APIUrl("get"), then the full request path of the target interface is " / order / get";
[0066] The method parameter annotation (MethodParam) is an annotation that marks the method parameter array of an abstract method. The method parameter array includes the parameter name of the abstract method and the verification rules that indicate whether the parameters of the abstract method are required. The value of the annotation attribute "name" is the name of the parameter, and the value of the annotation attribute "must" is the verification rule that indicates whether the parameter is required.
[0067] Then, create the mapping in the proxy server:
[0068] After adding annotations to the RPC service interface, a proxy server is required as a proxy. The role of the proxy server is to accept HTTP requests, convert and call the RPC service interface, and return data. Before the proxy server provides conversion calls, it is necessary to obtain the annotations of all RPC service interfaces first. The annotations can be obtained by scanning all RPC service interfaces, and the interface information of the RPC service interface is generated based on the annotations, and the mapping of the interface information and the request path is established. When applying the method of converting and calling interfaces in the embodiment of the present invention, an initialization class can be built, and the initialization starts when the proxy server is started. It is specifically divided into three steps: the first step is to obtain all interface implementation classes and abstract methods with added request address annotations, as well as the request path; the second step is to obtain the method parameter array of the abstract method according to the method parameter annotation of the abstract method; the third step is to encapsulate the interface implementation class, the abstract method and the method parameter array into a method details object (RpcApiInfo), that is, the interface information of the RPC service interface is generated; the fourth step is to use the request path as the key (key) and the interface information as the value (value) to establish the mapping of the interface information and the request path for saving.
[0069] Finally, the proxy calls the request:
[0070] After completing the above preparations, you can process the caller's call request for calling the HTTP interface. Specifically: Step 1: Get the call request for calling the HTTP interface. You can add an interceptor in the proxy server to intercept all user call requests; Step 2: Query the interface information of the corresponding RPC message interface in the mapping according to the request path in the call request, so as to obtain the interface implementation class, abstract method and method parameter array of the RPC message interface; Step 3: Check the abstract method according to the method parameter array; After the abstract method passes the test, use Java reflection technology to call the RPC message interface, and convert the return value of the RPC message interface into a preset format and return it to the caller.
[0071] Figure 3 4 is a schematic diagram of main modules of an apparatus for converting a calling interface according to an embodiment of the present invention.
[0072] like Figure 3As shown, the device 300 for converting and calling an interface according to an embodiment of the present invention includes: an acquisition module 301 , a generation module 302 and a conversion and calling module 303 .
[0073] in,
[0074] The acquisition module 301 is used to acquire the interface identifier of the target interface; wherein the interface identifier carries the request path of the target interface;
[0075] A generating module 302, configured to generate interface information of the target interface according to the interface identifier, and establish a mapping between the interface information and the request path;
[0076] The conversion calling module 303 is used to call the target interface based on the mapping conversion when calling the original interface through a calling request; wherein the calling request carries the request path.
[0077] In the embodiment of the present invention, the interface identifier includes a request address annotation and a method parameter annotation; and the device further includes: an adding module, which is used to add the request address annotation and the method parameter annotation to the target interface.
[0078] In an embodiment of the present invention, the generation module 302 is also used to: obtain the interface implementation class and the abstract method of the target interface according to the request address annotation and the method parameter annotation; obtain the method parameter array of the abstract method according to the method parameter annotation of the target interface; and generate the interface information based on the interface implementation class, the abstract method and the method parameter array.
[0079] In an embodiment of the present invention, the method parameter array includes the parameter name of the abstract method and the verification rules indicating whether the parameters of the abstract method are required; and the conversion call module 303 is also used to: obtain the request path from the call request; obtain the interface implementation class, the abstract method and the method parameter array from the mapping based on the request path; check the abstract method according to the method parameter array; when the abstract method passes the test, use Java reflection technology to convert and call the target interface according to the interface implementation class.
[0080] In the embodiment of the present invention, the generation module 302 is further used to: obtain the request path of the target interface according to the request address annotation of the target interface; and establish a mapping between the interface information of the target interface and the request path of the target interface.
[0081] In the embodiment of the present invention, the device further comprises: a conversion module, configured to convert the return value of calling the target interface into a preset format and return the converted value.
[0082] Furthermore, the target interface is an RPC service interface.
[0083] It can be seen from the device for converting the calling interface according to the embodiment of the present invention that the interface identifier of the target interface is obtained; the interface information of the target interface is generated according to the interface identifier, and a mapping between the interface information and the request path is established; when the original interface is called through the calling request, the technical means of calling the target interface based on the mapping conversion is used, and the conversion of calling the target interface when calling the original interface is realized through the interface identifier, so the inability to call the service interface across programming languages is overcome; if there is no client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after upgrading; the registration center cannot provide external access and can only be accessed within the local area network, and a specific request address format needs to be used, and the application of limited technical problems is solved, thereby achieving support for directly calling the target interface between service frameworks in different programming languages; there is no need to expand the source code of the service framework or provide a client corresponding to the service framework; the technical effect of wide application.
[0084] Figure 4 An exemplary system architecture 400 is shown to which the method for converting a calling interface or the apparatus for converting a calling interface according to an embodiment of the present invention can be applied.
[0085] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0086] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0087] The terminal devices 401 , 402 , and 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0088] Server 405 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using terminal devices 401, 402, and 403. The backend management server may analyze and process received data such as product information query requests, and feed back processing results (such as target push information and product information) to the terminal device.
[0089] It should be noted that the method for converting the calling interface provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the device for converting the calling interface is generally set in the server 405 .
[0090] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0091] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0092] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0093] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0094] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0095] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0096] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0097] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be arranged in a processor, for example, they may be described as: a processor includes an acquisition module, a generation module and a conversion call module. The names of these modules do not constitute a limitation on the modules themselves in certain cases, for example, the acquisition module may also be described as a "module for acquiring an interface identifier of a target interface".
[0098] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: step S101: obtaining an interface identifier of a target interface; step S102: generating interface information of the target interface according to the interface identifier, and establishing a mapping between the interface information and the request path; step S103: when calling the original interface through a call request, calling the target interface based on the mapping conversion.
[0099] According to the technical solution of the embodiment of the present invention, the interface identifier of the target interface is obtained; the interface information of the target interface is generated according to the interface identifier, and a mapping between the interface information and the request path is established; when the original interface is called through a call request, the technical means of calling the target interface based on the mapping conversion is used to realize the conversion of calling the target interface when calling the original interface through the interface identifier, so as to overcome the problem of being unable to call the service interface across programming languages; if there is no client, the service interface cannot be called directly, or the service framework cannot support disguised HTTP calls in time after upgrading; the registration center cannot provide external access and can only be accessed within the local area network, and a specific request address format needs to be adopted, and the application of limited technical problems, thereby achieving support for directly calling the target interface between service frameworks in different programming languages; there is no need to expand the source code of the service framework, or provide a client corresponding to the service framework; and the technical effect of wide application.
[0100] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for converting a calling interface, It is characterized in that include: Obtain the interface identifier of the target interface; wherein the interface identifier carries the request path of the target interface; the interface identifier includes a request address annotation and a method parameter annotation, the request address annotation is added to the interface implementation class and abstract method of the target interface, and the method parameter annotation is added to the abstract method of the target interface; Generate the interface information of the target interface according to the interface identifier, including: obtaining the interface implementation class and the abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining the method parameter array of the abstract method according to the method parameter annotation of the target interface; generating the interface information based on the interface implementation class, the abstract method and the method parameter array; wherein the method parameter array includes the parameter name of the abstract method and the verification rule for marking the parameter of the abstract method; and establishing a mapping between the interface information and the request path; When the original interface is called through a call request, the target interface is called based on the mapping conversion; wherein the call request carries the request path.
2. The method according to claim 1, It is characterized in that Before obtaining the interface identifier of the target interface, the following steps are also included: The request address annotation and the method parameter annotation are added to the target interface.
3. The method according to claim 2, It is characterized in that The method parameter array includes the parameter names of the abstract method and the verification rules indicating whether the parameters of the abstract method are required; Calling the target interface based on the mapping conversion includes: Obtaining the request path from the calling request; Obtaining the interface implementation class, the abstract method, and the method parameter array from the mapping based on the request path; Testing the abstract method according to the method parameter array; When the abstract method passes the inspection, the target interface is called according to the interface implementation class conversion using Java reflection technology.
4. The method according to claim 2, It is characterized in that Establishing the mapping between the interface information and the request path includes: Obtaining the request path of the target interface according to the request address annotation of the target interface; A mapping between the interface information of the target interface and a request path of the target interface is established.
5. The method according to claim 1, It is characterized in that The method further comprises: The return value of calling the target interface is converted into a preset format and returned.
6. The method according to claim 1, It is characterized in that The target interface is an RPC service interface, and the original interface is an HTTP interface.
7. A device for converting a calling interface, It is characterized in that include: An acquisition module, used to acquire the interface identifier of the target interface; wherein the interface identifier carries the request path of the target interface; the interface identifier includes a request address annotation and a method parameter annotation, the request address annotation is added to the interface implementation class and abstract method of the target interface, and the method parameter annotation is added to the abstract method of the target interface; A generation module, used to generate the interface information of the target interface according to the interface identifier, including: obtaining the interface implementation class and the abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining the method parameter array of the abstract method according to the method parameter annotation of the target interface; generating the interface information based on the interface implementation class, the abstract method and the method parameter array; and establishing a mapping between the interface information and the request path; wherein the method parameter array includes the parameter name of the abstract method and the verification rule for marking the parameter of the abstract method; The conversion calling module is used to call the target interface based on the mapping conversion when calling the original interface through a calling request; wherein the calling request carries the request path.
8. The device according to claim 7, It is characterized in that The device also includes: An adding module is used to add the request address annotation and the method parameter annotation to the target interface.
9. The device according to claim 8, It is characterized in that The method parameter array includes the parameter name of the abstract method and the verification rule indicating whether the parameter of the abstract method is required; and The conversion calling module is also used for: Obtaining the request path from the calling request; Obtaining the interface implementation class, the abstract method, and the method parameter array from the mapping based on the request path; Testing the abstract method according to the method parameter array; When the abstract method passes the inspection, the target interface is called according to the interface implementation class conversion using Java reflection technology.
10. The device according to claim 8, It is characterized in that The generating module is further used for: Obtaining the request path of the target interface according to the request address annotation of the target interface; A mapping between the interface information of the target interface and a request path of the target interface is established.
11. The device according to claim 7, It is characterized in that The device also includes: The conversion module is used to convert the return value of calling the target interface into a preset format and return it.
12. The device according to claim 7, It is characterized in that The target interface is an RPC service interface, and the original interface is an HTTP interface.
13. An electronic device for converting a calling interface, It is characterized in that include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
14. A computer readable medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
