[go: up one dir, main page]

CN110704200B - Method and device for converting calling interface - Google Patents

Method and device for converting calling interface Download PDF

Info

Publication number
CN110704200B
CN110704200B CN201810743642.9A CN201810743642A CN110704200B CN 110704200 B CN110704200 B CN 110704200B CN 201810743642 A CN201810743642 A CN 201810743642A CN 110704200 B CN110704200 B CN 110704200B
Authority
CN
China
Prior art keywords
interface
target interface
request
target
annotation
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.)
Active
Application number
CN201810743642.9A
Other languages
Chinese (zh)
Other versions
CN110704200A (en
Inventor
时锐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing 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/CN110704200B/en
Publication of CN110704200A publication Critical patent/CN110704200A/en
Application granted granted Critical
Publication of CN110704200B publication Critical patent/CN110704200B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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)
  • Computer And Data Communications (AREA)

Abstract

本发明公开了一种转换调用接口的方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:获取目标接口的接口标识;其中,接口标识携带有目标接口的请求路径;根据接口标识生成目标接口的接口信息,并建立接口信息与请求路径的映射;在通过调用请求调用原接口时,基于映射转换调用目标接口;其中,调用请求携带有请求路径。该实施方式能够支持在不同程序语言的服务框架之间直接调用目标接口;无需对服务框架的源码进行扩展、或提供与服务框架对应的客户端;应用广泛。

The present invention discloses a method and device for converting a calling interface, and relates to the field of computer technology. A specific implementation of the method 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 call request, calling the target interface based on the mapping conversion; wherein the call request carries the request path. This implementation can support direct calling of the target interface between service frameworks of 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; it is widely used.

Description

Method and device for converting call interface
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for converting a call interface.
Background
Currently, there are many types of service frameworks, different service frameworks may use different programming languages, most of which are based on object profile (JSON, a lightweight data interchange format), extensible markup language (XML), or binary objects. For example, an RPC service framework, which is an inter-process communication manner, allows remote services to be invoked like local services, and includes an RPC service interface, a registry and an RPC client, where the main objective of the RPC service framework is to make remote service invocation simpler and transparent, and the RPC service framework can mask the underlying transmission manner, serialization manner and communication details, i.e. when a developer is in use, only needs to know who provides what RPC service interface at what location, and does not need to care about the underlying communication details and invocation process.
The service framework may be used to establish a stand-alone order system, payment system, merchandise system, or user system, among others. At present, service interfaces cannot be directly called among service frames using different programming languages, so that the interaction (namely, calling the service interfaces) among the service frames is mainly realized in two ways, one way is through client calling, the service frames provide corresponding clients to call the service interfaces, and for the condition that the corresponding clients are not used, the service interfaces are required to be called through phase-changed HTTP calling, namely, the source codes of the service frames are expanded and the calling function is increased; another is through registry calls, sending requests to the registry to invoke service interfaces using a specific request address format.
In the process of implementing the present invention, the inventor finds that at least the following problems exist in the prior art:
1. the service interface cannot be called across program languages;
2. if the client is not available, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service framework is upgraded;
3. The registry cannot 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, the embodiments of the present invention provide a method and apparatus for converting a call interface, which can support direct call of a target interface between service frameworks of different programming languages; the source code of the service frame is not required to be expanded, or a client corresponding to the service frame is not required to be provided; the application is wide.
To achieve the above object, according to one aspect of an embodiment of the present invention, there is provided a method of converting a call interface.
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 call request, the target interface is called based on the mapping conversion; wherein the call request carries the request path.
Optionally, the interface identification includes request address annotation and method parameter annotation; the method further comprises the following steps of: the request address annotation and the method parameter annotation are added to the target interface.
Optionally, generating the interface information of the target interface according to the interface identifier includes: obtaining interface realization class and 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; and 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 parameters of the abstract method need to be filled; invoking the target interface based on the mapping transformation includes: acquiring the request path from the call 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 array; and when the abstract method passes the inspection, the Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
Optionally, establishing the mapping of the interface information and the request path includes: annotating the request address of the target interface to obtain the request path of the target interface; and establishing a mapping between 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 of the calling 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 in the embodiment of the invention comprises: the acquisition module is used for acquiring the interface identification of the target interface; the interface identifier carries a request path of the target interface; the generation module is used 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; the conversion calling module is used for calling the target interface based on the mapping conversion when the original interface is called through the calling request; wherein the call request carries the request path.
Optionally, the interface identification includes request address annotation and method parameter annotation; 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 interface realization class and 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; and 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 parameters of the abstract method need to be filled; and the conversion calling module is further used for: acquiring the request path from the call 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 array; and when the abstract method passes the inspection, the Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
Optionally, the generating module is further configured to: annotating the request address of the target interface to obtain the request path of the target interface; and establishing a mapping between 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 of the calling 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 electronic device that converts a call interface.
The electronic equipment for converting the calling interface comprises the following components: one or more processors; and the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the method for converting the calling interface.
To achieve the above object, according to still another aspect of the 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 has stored thereon a computer program which, 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: because 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 a request path; when the original interface is called through the call request, the call target interface is converted and called through the interface identification based on the technical means of mapping and converting the call target interface, so that the problem that the service interface cannot be called across program languages is overcome; if the client is not available, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service framework is upgraded; the registry 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 technical problem of limited application is solved, and the aim of directly calling the target interface between service frameworks of different programming languages is further achieved; the source code of the service frame is not required to be expanded, or a client corresponding to the service frame is not required to be provided; the application is wide.
Further effects of the above-described non-conventional alternatives are 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 translating a call interface according to an embodiment of the invention;
FIG. 2 is a flow diagram of an implementation of a method of converting a call interface according to an embodiment of the invention;
FIG. 3 is a schematic diagram of the major modules of an apparatus for translating call interfaces 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 applied;
fig. 5 is a schematic diagram of a computer system suitable for use in implementing an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered 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 in the embodiments may be combined with each other without collision.
Fig. 1 is a schematic diagram of the main steps of a method of converting a call interface according to an embodiment of the 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 obtaining the interface identification of the target interface.
Since different service frameworks may use different programming languages, invoking a service interface between service frameworks may be performed through a generic interface (i.e., an original interface), but the original interface may be limited by certain requirements or format requirements, and the transmission efficiency or security is not as good as invoking the service interface directly. Such as a hypertext transfer protocol (HTTP) interface, which is limited to the hypertext transfer protocol, the HTTP interface needs to be invoked with an HTTP request header.
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 frame is required to provide a corresponding client, if the service frame does not provide the client, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service frame is upgraded; the registry cannot 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 and calling the interface can realize the conversion and calling of the service interface (namely the target interface) when the original interface is called through the interface identification, supports the calling of the target interface between the service frames of different programming languages, does not need to expand the source code of the service frames, or provides the client corresponding to the service frames, 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 acquired before the target interface is called.
The interface identification may include request address comments and method parameter comments. The request address annotation is an annotation indicating 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 request address annotations may be imposed on interface implementation classes and abstract methods of the target interface. The method parameter annotations may be added to the abstract method of the target interface.
Step S102: and generating interface information of the target interface according to the interface identifier, and establishing a mapping between the interface information and the request path.
After the interface identification of the target interface is obtained, the related information of the target interface is obtained according to the interface identification, and interface information is generated. 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 invention, the generation of the interface information of the target interface can be realized by the following modes: obtaining interface realization class and abstract method of the target interface according to request address annotation and 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 interface implementation classes, abstract methods and method parameter arrays.
Because the request address annotation is added on the interface realization class and the abstract method of the target interface, and the method parameter annotation is added on the abstract method of the target interface, the interface realization class and 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 further interface information is generated.
In the embodiment of the invention, the establishment of the mapping of the interface information and the request path can be realized by the following modes: annotating according to the request address of the target interface to obtain a request path of the target interface; and establishing a mapping between the interface information of the target interface and the request path of the target interface.
The request address annotation is added on 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 paths of the target interface. After the request path is obtained through the request address annotation, a mapping of 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 a parameter name of the abstract method, a check rule for indicating whether the parameters of the abstract method are necessary to be filled, and the like.
Step S103: when the original interface is called by the call request, the target interface is called based on the mapping conversion.
The call 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 call target interface is converted.
In the embodiment of the present invention, step S103 may be implemented by: acquiring a request path from a call request; acquiring interface realization classes, abstract methods and parameter arrays of the methods from the mapping based on the request path; checking the abstract method according to the method parameter array; when the abstract method passes the inspection, a Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
The mapping is the corresponding relation between the interface information and the request path, and the interface information of the target interface can be obtained through the mapping and the request path carried in the call request, so that the interface implementation class, the abstract method and the method parameter array of the target interface are obtained. According to the method parameter array, parameters of the abstract method can be checked, if the necessary parameters of the abstract method meet the requirements and the parameters are correct, the abstract method is confirmed to pass the check, and at the moment, a JAVA (JAVA-oriented object programming language) reflection technology can be utilized to realize class conversion and call the target interface according to the interface.
The JAVA reflection technique refers to: in the running state, for any one class, all the attributes and methods of the class can be known; any method and attribute can be invoked on any object. I.e. all properties and abstract methods of the interface implementation class can be known by JAVA reflection technology, so that the target interface can be invoked.
In the embodiment of the invention, the return value of the call target interface can be converted into a 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 service framework is converted and called through the original interface, the return value of the calling target interface is converted into a general preset format and then returned to a calling party, for example, a JSON format or an XML format and the like.
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 independent order systems, payment systems, merchandise systems, or user systems, etc., such as RPC service frameworks.
The method for converting and calling the interface according to the embodiment of the invention can be seen in that the interface identifier 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 a request path; when the original interface is called through the call request, the call target interface is converted and called through the interface identification based on the technical means of mapping and converting the call target interface, so that the problem that the service interface cannot be called across program languages is overcome; if the client is not available, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service framework is upgraded; the registry 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 technical problem of limited application is solved, and the aim of directly calling the target interface between service frameworks of different programming languages is further achieved; the source code of the service frame is not required to be expanded, or a client corresponding to the service frame is not required to be provided; the application is wide.
Fig. 2 is a flow diagram of an implementation of a method of converting a call interface according to an embodiment of the invention.
As shown in fig. 2, the method for converting and calling an interface according to the embodiment of the present invention may utilize a proxy server to implement a service interface for converting and calling a service framework through an original interface. Taking the conversion of the RPC service interface to the HTTP interface as an example, the method for converting the call interface is described, the annotation is selected as the interface identifier, and the specific implementation flow comprises:
first, annotations are defined, which fall into two categories:
The request address annotation (APIUrl) is an annotation for marking a request path of a target interface, and can be added on an interface implementation class and an abstract method of the target interface, APIUrl has an attribute value (value), the value is a part of the request path, the whole path of the target interface is an annotation value of the interface implementation class and an annotation value of the abstract method, for example, the annotation of the interface implementation class is @ APIUrl ("/order"), the annotation of the abstract method is @ APIUrl ("get"), and then the complete request path of the target interface is "/order/get";
The method parameter annotation (MethodParam) is an annotation of a method parameter array for marking the abstract method, the method parameter array comprises a parameter name of the abstract method, a check rule for marking whether the parameter of the abstract method is necessary to fill, and the like, 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 for marking whether the parameter is necessary to fill.
Then, a mapping is established in the proxy server:
After adding the annotation to the RPC service interface, a proxy server is needed as a proxy, which acts to accept HTTP requests, translate call RPC service interfaces, and return data. Before the proxy server provides the conversion call, the annotation of all the RPC service interfaces needs to be acquired first, the annotation can be acquired by scanning all the RPC service interfaces, the interface information of the RPC service interfaces is generated based on the annotation, and the mapping between the interface information and the request path is established. When the method for converting the call interface is applied, an initialization class can be established, and initialization is started when the proxy server is started, and the method comprises the following steps: the first step, all interface realization classes and abstract methods added with request address annotation and request paths are obtained; and a second step of: obtaining a method parameter array of the abstract method according to the method parameter annotation of the abstract method; and a third step of: packaging the interface implementation class, the abstract method and the method parameter array into a method detail object (RpcApiInfo), namely generating interface information of the RPC service interface; fourth step: and establishing a mapping between the interface information and the request path by taking the request path as a key and the interface information as a value (value) for storage.
Finally, proxy calls the request:
After the preparation work is completed, a call request of a calling party for calling the HTTP interface may be processed, specifically: the first step: 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; and a second step of: inquiring interface information of a corresponding RPC service interface in the mapping according to a request path in the call request, thereby obtaining an interface implementation class, an abstract method and a method parameter array of the RPC service interface; and a third step of: checking the abstract method according to the method parameter array; after the abstract method passes the inspection, the RPC service interface is called by using Java reflection technology, and the return value of the RPC service interface is converted into a preset format and returned to the calling party.
Fig. 3 is a schematic diagram of main modules of an apparatus 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,
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 the call request; wherein the call request carries the request path.
In an embodiment of the invention, the interface identifier comprises request address annotation and method parameter annotation; 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 the embodiment of the present invention, the generating module 302 is further configured to: obtaining interface realization class and 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; and generating the interface information based on the interface implementation class, the abstract method and the method parameter array.
In the embodiment of the invention, the method parameter array comprises a parameter name of the abstract method and a check rule for marking whether the parameters of the abstract method need to be filled; and the conversion calling module 303 is further configured to: acquiring the request path from the call 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 array; and when the abstract method passes the inspection, the Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
In an embodiment of the present invention, the generating module 302 is further configured to: annotating the request address of the target interface to obtain the request path of the target interface; and establishing a mapping between 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 of the calling target interface into a preset format and returning.
Furthermore, the target interface is an RPC service interface.
The device for converting the call interface according to the embodiment of the invention can be seen in that the interface identifier of the acquisition target interface is adopted; generating interface information of a target interface according to the interface identifier, and establishing mapping between the interface information and a request path; when the original interface is called through the call request, the call target interface is converted and called through the interface identification based on the technical means of mapping and converting the call target interface, so that the problem that the service interface cannot be called across program languages is overcome; if the client is not available, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service framework is upgraded; the registry 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 technical problem of limited application is solved, and the aim of directly calling the target interface between service frameworks of different programming languages is further achieved; the source code of the service frame is not required to be expanded, or a client corresponding to the service frame is not required to be provided; the application is wide.
Fig. 4 illustrates an exemplary system architecture 400 of a method of converting a call interface or an apparatus of converting a call interface to which embodiments 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 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc., may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server providing support for shopping-type websites browsed by the user using the terminal devices 401, 402, 403. The background management server can analyze and other processing on the received data such as the product information inquiry request and the like, and feed back processing results (such as target push information and product information) to the terminal equipment.
It should be noted that, the method for converting the call interface provided in the embodiment of the present invention is generally executed by the server 405, and accordingly, the device 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, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiment of the present invention.
As shown in fig. 5, 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 section 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, ROM 502, and RAM 503 are connected to each other through 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 section 506 including a keyboard, a mouse, and the like; an output portion 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker, and the like; 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 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, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to 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 shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
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 two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any 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 context of this document, 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, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. 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 flowcharts 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 involved in the embodiments of the present invention may be implemented in software or in hardware. The described modules may also be provided in a processor, for example, as: a processor includes an acquisition module, a generation module, and a conversion calling module. The names of these modules do not in any way limit the module itself, and the acquisition module may also be described as a "module for acquiring the interface identifier of the target interface", for example.
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 present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include: 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 a request path; step S103: when the original interface is called by the call request, the target interface is called based on the 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 a request path; when the original interface is called through the call request, the call target interface is converted and called through the interface identification based on the technical means of mapping and converting the call target interface, so that the problem that the service interface cannot be called across program languages is overcome; if the client is not available, the service interface cannot be directly called, or the HTTP call of the phase change cannot be timely supported after the service framework is upgraded; the registry 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 technical problem of limited application is solved, and the aim of directly calling the target interface between service frameworks of different programming languages is further achieved; the source code of the service frame is not required to be expanded, or a client corresponding to the service frame is not required to be provided; the application is wide.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (14)

1. A method of converting a call interface, comprising:
acquiring an interface identifier of a target interface; the interface identifier carries a request path of the target interface; the interface identification comprises request address annotation and method parameter annotation, wherein the request address annotation is added to an interface implementation class and an abstract method of a target interface, and the method parameter annotation is added to the abstract method of the target interface;
Generating interface information of the target interface according to the interface identifier, including: obtaining interface realization class and 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; the method parameter array comprises a parameter name of the abstract method and a verification rule for marking the parameters 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 of claim 1, wherein prior to obtaining the interface identification of the target interface further comprises:
The request address annotation and the method parameter annotation are added to the target interface.
3. The method of claim 2, wherein the method parameter array includes a parameter name of the abstract method and a check rule indicating whether parameters of the abstract method are necessary to be filled; invoking the target interface based on the mapping transformation includes:
Acquiring the request path from the call 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 array;
and when the abstract method passes the inspection, the Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
4. The method of claim 2, wherein establishing a mapping of the interface information and request paths comprises:
Annotating the request address of the target interface to obtain the request path of the target interface;
And establishing a mapping between the interface information of the target interface and a request path of the target interface.
5. The method according to claim 1, wherein the method further comprises:
and converting the return value of the calling target interface into a preset format and returning.
6. The method of claim 1, wherein the target interface is an RPC service interface and the original interface is an HTTP interface.
7. An apparatus for converting a call interface, comprising:
The acquisition module is used for acquiring the interface identification of the target interface; the interface identifier carries a request path of the target interface; the interface identification comprises request address annotation and method parameter annotation, wherein the request address annotation is added to an interface implementation class and an abstract method of a target interface, and the method parameter annotation is added to the abstract method of the target interface;
The generating module is configured to generate interface information of the target interface according to the interface identifier, and includes: obtaining interface realization class and 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; and establishing a mapping between the interface information and the request path; the method parameter array comprises a parameter name of the abstract method and a verification rule for marking the parameters of the abstract method;
the conversion calling module is used for calling the target interface based on the mapping conversion when the original interface is called through the calling request; wherein the call request carries the request path.
8. The apparatus of claim 7, wherein the device comprises a plurality of sensors,
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.
9. The apparatus of claim 8, wherein the method parameter array includes a parameter name of the abstract method and a check rule indicating whether parameters of the abstract method are necessary to be filled; and
The conversion calling module is also used for:
Acquiring the request path from the call 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 array;
and when the abstract method passes the inspection, the Java reflection technology is utilized to realize class conversion and call the target interface according to the interface.
10. The apparatus of claim 8, wherein the generating module is further configured to:
Annotating the request address of the target interface to obtain the request path of the target interface;
And establishing a mapping between the interface information of the target interface and a request path of the target interface.
11. The apparatus of claim 7, wherein the apparatus further comprises:
And the conversion module is used for converting the return value of the calling target interface into a preset format and returning.
12. The apparatus of claim 7, wherein the target interface is an RPC service interface and the original interface is an HTTP interface.
13. An electronic device for converting a call interface, comprising:
One or more processors;
Storage means for storing one or more programs,
When executed by the one or more processors, causes the one or more processors to implement the method of any of claims 1-6.
14. A computer readable medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the method according to any of claims 1-6.
CN201810743642.9A 2018-07-09 2018-07-09 Method and device for converting calling interface Active CN110704200B (en)

Priority Applications (1)

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

Applications Claiming Priority (1)

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

Publications (2)

Publication Number Publication Date
CN110704200A CN110704200A (en) 2020-01-17
CN110704200B true CN110704200B (en) 2024-11-22

Family

ID=69192689

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN110704200B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111258786B (en) * 2020-01-20 2023-09-05 北京有竹居网络技术有限公司 Decoupling method, device, terminal and storage medium in layered architecture
CN113391860B (en) * 2020-03-11 2024-01-30 抖音视界有限公司 Service request processing method and device, electronic equipment and computer storage medium
CN111782420B (en) * 2020-06-24 2023-09-05 中国工商银行股份有限公司 Information processing method, device, equipment and medium based on Java Web framework
CN113778637B (en) * 2021-01-18 2025-09-12 北京沃东天骏信息技术有限公司 Service call processing method and device
CN113407367A (en) * 2021-08-18 2021-09-17 万商云集(成都)科技股份有限公司 Interface configuration method and system
CN114237931B (en) * 2021-12-13 2025-06-17 平安证券股份有限公司 Interface call configuration method, device, computer equipment and storage medium
CN114816798A (en) * 2022-04-27 2022-07-29 北京沃东天骏信息技术有限公司 Interface calling method and device
CN115225624B (en) * 2022-07-22 2024-11-15 济南浪潮数据技术有限公司 Network control method, system, equipment and storage medium based on cloud platform

Citations (3)

* 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 documents of API interfaces
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

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPWO2018116933A1 (en) * 2016-12-22 2019-04-25 日本電信電話株式会社 RPC conversion processing system and RPC conversion method
CN107832045B (en) * 2017-10-16 2021-03-30 北京京东尚科信息技术有限公司 Method and apparatus for cross programming language interface conversion
CN108255513B (en) * 2017-12-28 2021-03-16 平安科技(深圳)有限公司 Electronic device, springmvc-based data interface, automatic generation method of description of springmvc-based data interface, and storage medium

Patent Citations (3)

* 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 documents of API interfaces
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

Also Published As

Publication number Publication date
CN110704200A (en) 2020-01-17

Similar Documents

Publication Publication Date Title
CN110704200B (en) Method and device for converting calling interface
CN109683998B (en) Internationalization realization method, device and system
US11368447B2 (en) Oauth2 SAML token service
CN113467775B (en) A method and device for generating a page
CN107832045A (en) Across the method and apparatus of programming language interface conversion
CN111045833B (en) Method and device for interface calling
CN105718540A (en) Data loading method and apparatus
CN110120917A (en) Method for routing and device based on content
CN112507005B (en) Method and device for processing message
CN107315646B (en) Method and device for controlling data flow between page components
CN108574604A (en) test method and device
CN113076153B (en) Interface calling method and device
CN111443909A (en) Method and apparatus for generating pages
CN115134208A (en) Message conversion method, device, electronic device and storage medium
CN110738036A (en) Method and apparatus for generating information
CN113076294A (en) Information sharing method and device
CN112764726A (en) Data synthesis method and device
CN113326060B (en) Service request processing method, device and system, and service configuration method and device
CN113992641B (en) Data processing method, device, equipment and storage medium
CN112015383B (en) A login method and device
CN113779018A (en) A data processing method and device
CN113641359B (en) A data processing method and device
AU2018390863B2 (en) Computer system and method for extracting dynamic content from websites
CN116561013B (en) Test methods, devices, electronic equipment and media based on the target service framework
CN109981546A (en) The method and apparatus for obtaining the far call relationship between application module

Legal Events

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