CN110704200A - Method and device for converting call interface - Google Patents

Method and device for converting call interface Download PDF

Info

Publication number
CN110704200A
CN110704200A CN201810743642.9A CN201810743642A CN110704200A CN 110704200 A CN110704200 A CN 110704200A CN 201810743642 A CN201810743642 A CN 201810743642A CN 110704200 A CN110704200 A CN 110704200A
Authority
CN
China
Prior art keywords
interface
request
target interface
target
calling
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.)
Pending
Application number
CN201810743642.9A
Other languages
Chinese (zh)
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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810743642.9A priority Critical patent/CN110704200A/en
Publication of CN110704200A publication Critical patent/CN110704200A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The invention discloses a method and a device for converting a calling interface, and relates to the technical field of computers. One embodiment of the method comprises: acquiring an interface identifier of a target interface; the interface identification carries a request path of a target interface; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; when the original interface is called through the calling request, a target interface is called based on mapping conversion; the call request carries a request path. The implementation mode can support direct calling of the target interface between service frameworks of different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the application is wide.

Description

Method and device for converting call interface
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for converting a calling interface.
Background
Currently, there are many types of service frameworks, different service frameworks may use different programming languages, and most of them are based on object notation (JSON, a lightweight data exchange format), extensible markup language (XML), or binary objects. For example, the RPC service framework is an interprocess communication mode, which allows remote services to be called as local services, and includes an RPC service interface, a registration center and an RPC client, the RPC service framework mainly aims to make remote service calls simpler and transparent, and the RPC service framework can shield the transmission mode, the serialization mode and the communication details of the bottom layer, i.e., when a developer is using, the developer only needs to know who provides the RPC service interface at what position, and does not need to care about the communication details and the calling process of the bottom layer.
The service framework may be used to establish a separate order system, payment system, merchandise system, or user system, etc. At present, service interfaces cannot be directly called between service frameworks using different programming languages, so that two methods for interaction (namely calling the service interfaces) among the service frameworks are mainly used, one method is calling through a client, the service frameworks provide corresponding clients to call the service interfaces, and for the condition that the corresponding clients are not used, the service interfaces need to be called through phase-change HTTP calling, namely, source codes of the service frameworks are expanded to increase calling functions; the other is through registry calls, sending requests to the registry in a specific request address format to invoke the service interface.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1. a service interface cannot be called across program languages;
2. if no client exists, the service interface can not be directly called, or the phase-change HTTP calling can not be supported in time after the service framework is upgraded;
3. the registration center can not provide access to the outside, can only access in the local area network, and needs to adopt a specific request address format, so that the application is limited.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for converting a call interface, which can support direct call of a target interface between service frameworks in different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the application is wide.
To achieve the above object, according to an aspect of an embodiment of the present invention, a method of converting a call interface is provided.
The method for converting the call interface comprises the following steps: acquiring an interface identifier of a target interface; 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 mapping between the interface information and the request path; when the original interface is called through a calling request, the target interface is called based on the mapping conversion; and the call request carries the request path.
Optionally, the interface identifier comprises a request address annotation and a method parameter annotation; before obtaining the interface identifier of the target interface, the method further comprises: and adding the request address annotation and the method parameter annotation to the target interface.
Optionally, generating the interface information of the target interface according to the interface identifier includes: obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining a 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.
Optionally, the method parameter array includes a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method must be filled; invoking the target interface based on the mapping transformation comprises: acquiring the request path from the calling request; acquiring 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 number group; and when the abstract method passes the inspection, calling the target interface by utilizing Java reflection technology to realize class conversion according to the interface.
Optionally, the establishing of 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; establishing a mapping of the interface information of the target interface and a request path of the target interface.
Optionally, the method further comprises: and converting the return value for calling the target interface into a preset format and returning.
Optionally, the target interface is an RPC service interface, and the original interface is an HTTP interface.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided an apparatus for converting a call interface.
The device for converting the call interface of the embodiment of the invention comprises: the acquisition module is used for acquiring the interface identifier of the target interface; the interface identifier carries a request path of the target interface; the generating module is used for generating interface information of the target interface according to the interface identifier and establishing mapping between the interface information and the request path; the conversion calling module is used for calling the target interface based on the mapping conversion when the original interface is called through a calling request; and the call request carries the request path.
Optionally, the interface identifier comprises a request address annotation and a method parameter annotation; and the apparatus further comprises: and the adding module is used for adding the request address annotation and the method parameter annotation for the target interface.
Optionally, the generating module is further configured to: obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining a 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.
Optionally, the method parameter array includes a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method must be filled; and the conversion calling module is also used for: acquiring the request path from the calling request; acquiring 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 number group; and when the abstract method passes the inspection, calling the target interface by utilizing Java reflection technology to realize class conversion according to the interface.
Optionally, the generating module is further configured to: obtaining the request path of the target interface according to the request address annotation of the target interface; establishing a mapping of the interface information of the target interface and a request path of the target interface.
Optionally, the apparatus further comprises: and the conversion module is used for converting the return value for calling the target interface into a preset format and returning the return value.
Optionally, the target interface is an RPC service interface, and the original interface is an HTTP interface.
To achieve the above object, according to still another aspect of the embodiments of the present invention, there is provided an electronic device for converting a call interface.
The electronic equipment for converting the calling interface of the embodiment of the invention comprises: one or more processors; a storage device, configured to store one or more programs that, when executed by the one or more processors, cause the one or more processors to implement a method for converting a call interface according to an embodiment of the present invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable storage medium.
A computer-readable storage medium of an embodiment of the present invention stores thereon a computer program that, when executed by a processor, implements a method of converting a call interface of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the interface identification of the target interface is acquired; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; when the original interface is called through the calling request, the target interface is converted and called through the interface identifier based on the technical means of mapping conversion calling the target interface, so that the problem that a service interface cannot be called across program languages is solved; if no client exists, the service interface can not be directly called, or the phase-change HTTP calling can not be supported in time after the service framework is upgraded; the registry can not provide access to the outside, can only access in a local area network, and needs to adopt a specific request address format and has limited application, thereby achieving the aim of supporting direct calling of target interfaces between service frameworks of different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the technical effect of wide application.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of a method of converting a calling interface according to an embodiment of the invention;
FIG. 2 is a flow chart illustrating an implementation of a method for converting a call interface according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main modules of a device for translating a call interface according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It should be noted that the embodiments of the present invention and the technical features of the embodiments may be combined with each other without conflict.
Fig. 1 is a schematic diagram of main steps of a method of converting a call interface according to an embodiment of the present invention.
As shown in fig. 1, the method for converting a call interface according to the embodiment of the present invention mainly includes the following steps:
step S101: and acquiring the interface identification of the target interface.
Since different service frameworks may use different programming languages, the calling of the service interface between the service frameworks may be performed through a general-purpose interface (i.e., an original interface), but the original interface may be limited by some requirements or format requirements, and the transmission efficiency or security is not as good as that of directly calling the service interface. For example, a hypertext transfer protocol (HTTP) interface is limited to the HTTP, and an HTTP request header needs to be carried when the HTTP interface is called.
In addition, the calling service interface between the service frameworks can also be realized through a client or a registry. However, when the service interface is called by the client, the service framework is required to provide the corresponding client, if the service framework does not provide the client, the service interface cannot be directly called, or the phase-change HTTP calling cannot be supported in time after the service framework is upgraded; the registration center can not provide access to the outside, can only access in the local area network, and needs to adopt a specific request address format, so that the application is limited.
The method for converting the call interface provided by the embodiment of the invention can realize conversion and call of the service interface (namely the target interface) when calling the original interface through the interface identifier, supports calling of the target interface between service frameworks of different programming languages, does not need to expand the source code of the service framework or provide a client corresponding to the service framework, and can be widely applied. The interface identifier of the target interface carries the request path of the target interface, so that the interface identifier of the target interface can be obtained before the target interface is called.
The interface identification may include request address annotation and method parameter annotation. The request address annotation is an annotation for marking a request path of the target interface, and the value of the request address annotation is the request path.
In the embodiment of the invention, before the interface identifier of the target interface is acquired, request address annotation and method parameter annotation can be added to the target interface. Wherein, the request address annotation can be added on the interface implementation class and abstract method of the target interface. Method parameter annotations may be added to the abstract methods of the target interface.
Step S102: and generating interface information of the target interface according to the interface identifier, and establishing mapping between the interface information and the request path.
And after the interface identifier of the target interface is obtained, obtaining the related information of the target interface according to the interface identifier and generating interface information. And the interface identifier carries the request path of the target interface, so that the mapping between the interface information and the request path can be directly established.
In the embodiment of the present invention, generating the interface information of the target interface may be implemented by: obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining a method parameter array of the abstract method according to the method parameter annotation of the target interface; interface information is generated based on the interface implementation class, the abstract method and the method parameter array.
Because the request address annotation is added to the interface implementation class and the 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, the abstract method and the method parameter array of the abstract method can be obtained according to the request address annotation and the method parameter annotation, and interface information is further generated.
In the embodiment of the present invention, the mapping between the interface information and the request path may be implemented as follows: obtaining a request path of the target interface according to the request address annotation of the target interface; and establishing mapping between the interface information of the target interface and the request path of the target interface.
The request address annotation is added to the interface implementation class and the abstract method of the target interface, namely 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 the request path is obtained through the request address annotation, mapping between the interface information and the request path can be established.
The method parameter array can indicate which parameters of the abstract method are mandatory. The method parameter array comprises the parameter name of the abstract method, a check rule for indicating whether the parameter of the abstract method needs to be filled or not, and the like.
Step S103: when the original interface is called through the calling request, the target interface is called based on mapping conversion.
The calling request for calling the original interface carries a request path, and a corresponding target interface can be obtained from the mapping based on the request path, so that the calling target interface is converted.
In the embodiment of the present invention, step S103 may be implemented by: acquiring a request path from the calling request; acquiring an interface implementation class, an abstract method and a method parameter array from mapping based on a request path; checking the abstract method according to the method parameter array; and when the abstract method passes the inspection, the class conversion and calling of the target interface are realized according to the interface by using a Java reflection technology.
The mapping is a corresponding relation between the interface information and the request path, and the interface information of the target interface can be acquired through the mapping and the request path carried in the calling request, so that an interface implementation class, an abstract method and a method parameter array of the target interface are acquired. The parameter array of the abstract method can be checked according to the method, if the mandatory parameter of the abstract method meets the requirement and the parameter is correct, the abstract method is confirmed to pass the check, and at the moment, the class conversion calling target interface can be realized according to the interface by using JAVA (one-door object-oriented programming language) reflection technology.
The JAVA reflection technique refers to: in the running state, for any one class, all the properties and methods of the class can be known; any method and property can be called for any object. That is, all the attributes and abstract methods of the interface implementation class can be known by JAVA reflection technology, so that the target interface can be called.
In the embodiment of the invention, the return value of the calling target interface can be converted into the preset format and returned. Because 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 (namely the target interface) of the calling service framework is converted through the original interface, the return value of the calling target interface is converted into a universal preset format and then returned to the calling party, for example, JSON or XML and other formats.
In the embodiment of the invention, the target interface is an RPC service interface, and the original interface is an HTTP interface. Currently, there are many types of service frameworks that can be used to build a separate order system, payment system, merchandise system, or user system, etc., such as an RPC service framework.
According to the method for converting the call interface, the interface identification of the target interface is obtained; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; when the original interface is called through the calling request, the target interface is converted and called through the interface identifier based on the technical means of mapping conversion calling the target interface, so that the problem that a service interface cannot be called across program languages is solved; if no client exists, the service interface can not be directly called, or the phase-change HTTP calling can not be supported in time after the service framework is upgraded; the registry can not provide access to the outside, can only access in a local area network, and needs to adopt a specific request address format and has limited application, thereby achieving the aim of supporting direct calling of target interfaces between service frameworks of different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the technical effect of wide application.
Fig. 2 is a schematic flow chart illustrating an implementation flow of the method for converting a call interface according to an embodiment of the present invention.
As shown in fig. 2, the method for converting a call interface according to the embodiment of the present invention may use a proxy server to convert a service interface of a call service framework through an original interface. Now, taking an example of converting an RPC service interface to an HTTP interface, a method for converting a call interface is described, and an annotation is selected as an interface identifier, and a specific implementation flow includes:
first, annotations are defined, which fall into two categories:
the request address annotation (apilrl) is an annotation indicating a request path of the target interface, and may be added to an interface implementation class and an abstract method of the target interface, where apilrl has an attribute value (value), the value is a part of the request path, and a full path of the target interface is an annotation value of the interface implementation class and an annotation value of the abstract method, for example, an annotation of the interface implementation class is @ apilrl ("/order"), an annotation of the abstract method is @ apilrl ("get"), and then a full request path of the target interface is "/order/get";
the method parameter annotation (MethodParam) is an annotation indicating a method parameter array of the abstract method, the method parameter array includes a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method needs to be filled, etc., the value of the annotation attribute "name" is the name of the parameter, and the value of the annotation attribute "must" is the check rule whether the parameter needs to be filled.
Then, a mapping is established in the proxy server:
after adding annotations to the RPC service interface, a proxy server is required as a proxy, and the role of the proxy server is to accept HTTP requests, convert calls to the RPC service interface, and return data. Before the proxy server provides the conversion call, the annotations of all RPC service interfaces need to be acquired, the annotations can be acquired by scanning all the RPC service interfaces, the interface information of the RPC service interfaces is generated based on the annotations, and the mapping between the interface information and the request path is established. When the method for converting the call interface of the embodiment of the invention is applied, an initialization class can be established, and initialization is started when the proxy server is started, which is specifically divided into three steps: the method comprises the steps of firstly, acquiring all interface implementation classes and abstract methods added with request address annotations and request paths; the second step is that: acquiring a method parameter array of the abstract method according to the method parameter annotation of the abstract method; the third step: packaging the interface implementation class, the abstract method and the method parameter array into a method detail object (RpcApipinfo), namely generating interface information of an RPC service interface; the fourth step: and establishing a mapping between the interface information and the request path by taking the request path as a key (key) and the interface information as a value (value) and storing the mapping.
Finally, the proxy invokes the request:
after the preparation work is completed, a call request of a caller for calling the HTTP interface may be processed, specifically: the first step is as follows: acquiring a call request for calling an HTTP interface, and adding an interceptor into a proxy server to intercept all call requests of a user; the second step is that: inquiring interface information of a corresponding RPC report interface in a mapping according to a request path in the calling request so as to obtain an interface implementation class, an abstract method and a method parameter array of the RPC report interface; the third step: checking the abstract method according to the method parameter array; after the abstract method passes the inspection, the RPC transaction interface is called by using Java reflection technology, and the return value of the RPC transaction interface is converted into a preset format and returned to the caller.
Fig. 3 is a schematic diagram of main blocks of a device for converting a call interface according to an embodiment of the present invention.
As shown in fig. 3, an apparatus 300 for converting a call interface according to an embodiment of the present invention includes: an acquisition module 301, a generation module 302 and a conversion calling module 303.
Wherein the content of the first and second substances,
an obtaining module 301, configured to obtain an interface identifier of a target interface; the interface identifier carries a request path of the target interface;
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;
a conversion calling module 303, configured to call the target interface based on the mapping conversion when the original interface is called by a calling request; and the call request carries the request path.
In the embodiment of the invention, the interface identifier comprises request address annotation and method parameter annotation; and the apparatus further comprises: and the adding module is used for adding the request address annotation and the method parameter annotation for the target interface.
In this embodiment of the present invention, the generating module 302 is further configured to: obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation; obtaining a 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.
In the embodiment of the present invention, the method parameter array includes a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method must be filled; and the conversion calling module 303 is further configured to: acquiring the request path from the calling request; acquiring 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 number group; and when the abstract method passes the inspection, calling the target interface by utilizing Java reflection technology to realize class conversion according to the interface.
In this embodiment of the present invention, the generating module 302 is further configured to: obtaining the request path of the target interface according to the request address annotation of the target interface; establishing a mapping of the interface information of the target interface and a request path of the target interface.
In an embodiment of the present invention, the apparatus further includes: and the conversion module is used for converting the return value for calling the target interface into a preset format and returning the return value.
Further, the target interface is an RPC service interface.
According to the device for converting the call interface, the interface identification of the target interface is acquired; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; when the original interface is called through the calling request, the target interface is converted and called through the interface identifier based on the technical means of mapping conversion calling the target interface, so that the problem that a service interface cannot be called across program languages is solved; if no client exists, the service interface can not be directly called, or the phase-change HTTP calling can not be supported in time after the service framework is upgraded; the registry can not provide access to the outside, can only access in a local area network, and needs to adopt a specific request address format and has limited application, thereby achieving the aim of supporting direct calling of target interfaces between service frameworks of different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the technical effect of wide application.
Fig. 4 illustrates an exemplary system architecture 400 to which the method of converting a calling interface or the apparatus for converting a calling interface of an embodiment of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various communication client applications installed thereon, such as shopping applications, web browser applications, search applications, instant messaging tools, mailbox clients, social platform software, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server that provides various services, such as a background management server that supports shopping websites browsed by users using the terminal devices 401, 402, and 403. The background management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (e.g., target push information and product information) to the terminal device.
It should be noted that the method for converting the call interface provided by the embodiment of the present invention is generally executed by the server 405, and accordingly, the apparatus for converting the call interface is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that 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 section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, 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 disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an acquisition module, a generation module, and a translation invocation module. The names of these modules do not in some cases constitute a limitation on the module itself, and for example, the acquiring module may also be described as a "module that acquires an interface identifier of a target interface".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: step S101: acquiring an interface identifier of a target interface; step S102: generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; step S103: when the original interface is called through the calling request, the target interface is called based on mapping conversion.
According to the technical scheme of the embodiment of the invention, the interface identification of the target interface is acquired; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and the request path; when the original interface is called through the calling request, the target interface is converted and called through the interface identifier based on the technical means of mapping conversion calling the target interface, so that the problem that a service interface cannot be called across program languages is solved; if no client exists, the service interface can not be directly called, or the phase-change HTTP calling can not be supported in time after the service framework is upgraded; the registry can not provide access to the outside, can only access in a local area network, and needs to adopt a specific request address format and has limited application, thereby achieving the aim of supporting direct calling of target interfaces between service frameworks of different programming languages; the source code of the service framework does not need to be expanded or a client corresponding to the service framework is provided; the technical effect of wide application.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (16)

1. A method of converting a calling interface, comprising:
acquiring an interface identifier of a target interface; 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 mapping between the interface information and the request path;
when the original interface is called through a calling request, the target interface is called based on the mapping conversion; and the call request carries the request path.
2. The method of claim 1, wherein the interface identification includes a request address annotation and a method parameter annotation; before obtaining the interface identifier of the target interface, the method further comprises:
and adding the request address annotation and the method parameter annotation to the target interface.
3. The method of claim 2, wherein generating interface information for the target interface according to the interface identifier comprises:
obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation;
obtaining a 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.
4. The method of claim 3, wherein the method parameter array comprises a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method must be filled; invoking the target interface based on the mapping transformation comprises:
acquiring the request path from the calling request;
acquiring 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 number group;
and when the abstract method passes the inspection, calling the target interface by utilizing Java reflection technology to realize class conversion according to the interface.
5. The method of claim 2, wherein establishing the mapping of the interface information and request path comprises:
obtaining the request path of the target interface according to the request address annotation of the target interface;
establishing a mapping of the interface information of the target interface and a request path of the target interface.
6. The method of claim 1, further comprising:
and converting the return value for calling the target interface into a preset format and returning.
7. The method of claim 1, wherein the target interface is an RPC service interface and the source interface is an HTTP interface.
8. An apparatus for converting a calling interface, comprising:
the acquisition module is used for acquiring the interface identifier of the target interface; the interface identifier carries a request path of the target interface;
the generating module is used for generating interface information of the target interface according to the interface identifier and establishing mapping between the interface information and the request path;
the conversion calling module is used for calling the target interface based on the mapping conversion when the original interface is called through a calling request; and the call request carries the request path.
9. The apparatus of claim 8, wherein the interface identification comprises a request address annotation and a method parameter annotation; and
the device further comprises:
and the adding module is used for adding the request address annotation and the method parameter annotation for the target interface.
10. The apparatus of claim 9, wherein the generating module is further configured to:
obtaining an interface implementation class and an abstract method of the target interface according to the request address annotation and the method parameter annotation;
obtaining a 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.
11. The apparatus of claim 10, wherein the method parameter array comprises a parameter name of the abstract method and a check rule indicating whether the parameter of the abstract method must be filled; and
the conversion calling module is further configured to:
acquiring the request path from the calling request;
acquiring 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 number group;
and when the abstract method passes the inspection, calling the target interface by utilizing Java reflection technology to realize class conversion according to the interface.
12. The apparatus of claim 9, wherein the generating module is further configured to:
obtaining the request path of the target interface according to the request address annotation of the target interface;
establishing a mapping of the interface information of the target interface and a request path of the target interface.
13. The apparatus of claim 8, further comprising:
and the conversion module is used for converting the return value for calling the target interface into a preset format and returning the return value.
14. The apparatus of claim 8, wherein the target interface is an RPC service interface and the source interface is an HTTP interface.
15. An electronic device for converting a calling interface, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
16. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN201810743642.9A 2018-07-09 2018-07-09 Method and device for converting call interface Pending CN110704200A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810743642.9A CN110704200A (en) 2018-07-09 2018-07-09 Method and device for converting call interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810743642.9A CN110704200A (en) 2018-07-09 2018-07-09 Method and device for converting call interface

Publications (1)

Publication Number Publication Date
CN110704200A true CN110704200A (en) 2020-01-17

Family

ID=69192689

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810743642.9A Pending CN110704200A (en) 2018-07-09 2018-07-09 Method and device for converting call interface

Country Status (1)

Country Link
CN (1) CN110704200A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258786A (en) * 2020-01-20 2020-06-09 北京无限光场科技有限公司 Decoupling method and device in layered architecture, terminal and storage medium
CN111782420A (en) * 2020-06-24 2020-10-16 中国工商银行股份有限公司 Information processing method, device, equipment and medium based on Java Web framework
CN113391860A (en) * 2020-03-11 2021-09-14 北京字节跳动网络技术有限公司 Service request processing method and device, electronic equipment and computer storage medium
CN113407367A (en) * 2021-08-18 2021-09-17 万商云集(成都)科技股份有限公司 Interface configuration method and system
CN115225624A (en) * 2022-07-22 2022-10-21 济南浪潮数据技术有限公司 Network control method, system, equipment and storage medium based on cloud platform

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049271A (en) * 2012-12-27 2013-04-17 微梦创科网络科技(中国)有限公司 Method and device for automatically generating description document of API (application program interface)
CN106354481A (en) * 2015-07-13 2017-01-25 阿里巴巴集团控股有限公司 Method and equipment for uniform mapping of HTTP requests
CN107360261A (en) * 2017-09-07 2017-11-17 北京奇艺世纪科技有限公司 A kind of HTTP request processing method, device and electronic equipment
CN107832045A (en) * 2017-10-16 2018-03-23 北京京东尚科信息技术有限公司 Across the method and apparatus of programming language interface conversion
WO2018116933A1 (en) * 2016-12-22 2018-06-28 日本電信電話株式会社 Rpc conversion process system and rpc conversion method
CN108255513A (en) * 2017-12-28 2018-07-06 平安科技(深圳)有限公司 Electronic device, the data-interface based on springmvc and its illustrate automatic generation method and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103049271A (en) * 2012-12-27 2013-04-17 微梦创科网络科技(中国)有限公司 Method and device for automatically generating description document of API (application program interface)
CN106354481A (en) * 2015-07-13 2017-01-25 阿里巴巴集团控股有限公司 Method and equipment for uniform mapping of HTTP requests
WO2018116933A1 (en) * 2016-12-22 2018-06-28 日本電信電話株式会社 Rpc conversion process system and rpc conversion method
CN107360261A (en) * 2017-09-07 2017-11-17 北京奇艺世纪科技有限公司 A kind of HTTP request processing method, device and electronic equipment
CN107832045A (en) * 2017-10-16 2018-03-23 北京京东尚科信息技术有限公司 Across the method and apparatus of programming language interface conversion
CN108255513A (en) * 2017-12-28 2018-07-06 平安科技(深圳)有限公司 Electronic device, the data-interface based on springmvc and its illustrate automatic generation method and storage medium

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258786A (en) * 2020-01-20 2020-06-09 北京无限光场科技有限公司 Decoupling method and device in layered architecture, terminal and storage medium
CN111258786B (en) * 2020-01-20 2023-09-05 北京有竹居网络技术有限公司 Decoupling method, device, terminal and storage medium in layered architecture
CN113391860A (en) * 2020-03-11 2021-09-14 北京字节跳动网络技术有限公司 Service request processing method and device, electronic equipment and computer storage medium
CN113391860B (en) * 2020-03-11 2024-01-30 抖音视界有限公司 Service request processing method and device, electronic equipment and computer storage medium
CN111782420A (en) * 2020-06-24 2020-10-16 中国工商银行股份有限公司 Information processing method, device, equipment and medium based on Java Web framework
CN111782420B (en) * 2020-06-24 2023-09-05 中国工商银行股份有限公司 Information processing method, device, equipment and medium based on Java Web framework
CN113407367A (en) * 2021-08-18 2021-09-17 万商云集(成都)科技股份有限公司 Interface configuration method and system
CN115225624A (en) * 2022-07-22 2022-10-21 济南浪潮数据技术有限公司 Network control method, system, equipment and storage medium based on cloud platform

Similar Documents

Publication Publication Date Title
CN107622135B (en) Method and apparatus for displaying information
CN110704200A (en) Method and device for converting call interface
CN108574604B (en) Test method and device
CN110471848B (en) Method and device for dynamically returning message
US11368447B2 (en) Oauth2 SAML token service
CN112507005B (en) Method and device for processing message
CN111045833B (en) Interface calling method and device
US20060179125A1 (en) System and method for exposing a J2EE application server as a web service transaction participant
GB2520246A (en) Method for accessing business object resources and machine-to-machine communication environment
CN111443909B (en) Method and device for generating page
CN113076153B (en) Interface calling method and device
CN109343975B (en) Method and apparatus for inter-page asynchronous communication
CN112202744B (en) Multi-system data communication method and device
CN113076294A (en) Information sharing method and device
CN114979295A (en) Gateway management method and device
CN109981546B (en) Method and device for acquiring remote call relation between application modules
CN112015383A (en) Login method and device
CN116561013B (en) Testing method and device based on target service framework, electronic equipment and medium
CN110764769B (en) Method and device for processing user request
US7685258B2 (en) Disconnectible applications
CN111614762A (en) Electronic data exchange system and apparatus comprising an electronic data exchange system
WO2019122011A1 (en) Computer system and method for extracting dynamic content from websites
CN110909269B (en) Log reporting method and device
CN113992641A (en) Data processing method, device, equipment and storage medium
CN112905273A (en) Service calling method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination