CN108737474B - HTTP interface calling method and device - Google Patents

HTTP interface calling method and device Download PDF

Info

Publication number
CN108737474B
CN108737474B CN201710265387.7A CN201710265387A CN108737474B CN 108737474 B CN108737474 B CN 108737474B CN 201710265387 A CN201710265387 A CN 201710265387A CN 108737474 B CN108737474 B CN 108737474B
Authority
CN
China
Prior art keywords
http interface
interface
http
callable
rules
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
CN201710265387.7A
Other languages
Chinese (zh)
Other versions
CN108737474A (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 CN201710265387.7A priority Critical patent/CN108737474B/en
Publication of CN108737474A publication Critical patent/CN108737474A/en
Application granted granted Critical
Publication of CN108737474B publication Critical patent/CN108737474B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/561Adding application-functional data or data for application control, e.g. adding metadata
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L65/00Network arrangements, protocols or services for supporting real-time applications in data packet communication
    • H04L65/1066Session management
    • H04L65/1073Registration or de-registration
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/34Network arrangements or protocols for supporting network services or applications involving the movement of software or configuration parameters 

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Library & Information Science (AREA)
  • Business, Economics & Management (AREA)
  • General Business, Economics & Management (AREA)
  • Multimedia (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the invention provides a method and a device for calling an HTTP (hyper text transport protocol) interface, which can solve the problems of high code coupling degree, poor flexibility, poor maintainability and poor readability in the development process by using a third-party toolkit. The method comprises the following steps: when the client is started, scanning the HTTP interface according to the configuration type path and the packet path to obtain an available HTTP interface; and carrying out proxy registration on the invokable HTTP interface.

Description

HTTP interface calling method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for calling an HTTP (hyper text transport protocol) interface.
Background
HTTP (HyperText Transfer Protocol) is a set of rules for computers to communicate through a network, when a client calls a server, the server provides an HTTP interface, and the client needs to write different hard codes according to different URLs and request parameters.
At present, the most common solution is to provide a common request tool class, and when the third party data is developed and used daily, the third party may provide several ways to obtain the data, such as an HTTP way and a remote invocation way. Generally, the HTTP method is the simplest and most favored by developers, and when data is acquired by using the HTTP method, a third-party toolkit such as HTTP toolkit is used for processing, and the third-party toolkit is called each time.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
1. in terms of practicability, in order to support HTTP requests and responses by using a third-party tool kit, the process-oriented characteristic of the third-party tool kit has to be accepted, namely the code coupling degree is high, when an interface changes, a large number of codes need to be modified, and the BUG is likely to be modified due to the coupling of the tool kit and business logic;
2. from the aspect of complexity, the flexibility is poor due to the complexity and diversity of HTTP URL addresses and request parameters, and the safety problems of the request parameters and response contents can bring fatal problems to each request;
3. from the feasibility point of view, the development facing the process needs to change the development habit of developers, and great challenges are faced in maintainability and readability.
Therefore, in the process of developing by using a third-party toolkit, the code coupling degree is high, the flexibility, the maintainability and the readability are poor, the standards for object-oriented development and interface-oriented development advocated by Java are not met, and meanwhile, great waste exists in the aspects of system resources, labor and time cost.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, an electronic device, and a readable medium for invoking an HTTP interface, which can solve the problems of high code coupling, poor flexibility, poor maintainability, and poor readability in a development process using a third party toolkit.
To achieve the above object, according to an aspect of the embodiments of the present invention, a method for HTTP interface invocation is provided.
The method for calling the HTTP interface comprises the following steps: when the client is started, scanning the HTTP interface according to the configuration type path and the packet path to obtain an available HTTP interface; and carrying out proxy registration on the invokable HTTP interface.
Optionally, the method further comprises: and defining the HTTP interface and adding annotation identification.
Optionally, defining the HTTP interface includes: defining the HTTP interface according to definition rules, wherein the definition rules comprise: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
Optionally, the proxy registration includes: obtaining an annotation identifier of the HTTP interface; searching whether the annotation identifier contains the identifier of the callable HTTP interface; and carrying out proxy registration on the HTTP interface containing the identification of the callable HTTP interface.
Optionally, the proxy registration further comprises: and setting instantiation information of an instantiation mode for the callable HTTP interface, wherein the instantiation information comprises information of an instantiation interface type, an instantiation mode proxy class and whether the callable HTTP interface is in a singleton mode.
To achieve the above object, according to another aspect of the embodiments of the present invention, an apparatus for HTTP interface invocation is provided.
The device for calling the HTTP interface comprises the following components: the acquisition module is used for scanning the HTTP interface according to the configuration type path and the packet path when the client is started to acquire the callable HTTP interface; and the registration module is used for carrying out proxy registration on the callable HTTP interface.
Optionally, the apparatus further comprises: and the definition module is used for defining the HTTP interface and adding annotation identification.
Optionally, the definition module is further configured to: defining the HTTP interface according to definition rules, wherein the definition rules comprise: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
Optionally, the registration module is further configured to: obtaining an annotation identifier of the HTTP interface; searching whether the annotation identifier contains the identifier of the callable HTTP interface; and carrying out proxy registration on the HTTP interface containing the identification of the callable HTTP interface.
Optionally, the registration module is further configured to: and setting instantiation information of an instantiation mode for the callable HTTP interface, wherein the instantiation information comprises information of an instantiation interface type, an instantiation mode proxy class and whether the callable HTTP interface is in a singleton mode.
To achieve the above object, according to still another aspect of the embodiments of the present invention, an electronic device implementing a method for HTTP interface invocation is provided.
An electronic device of an embodiment of the present invention includes: one or more processors; 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 realize the method called by the HTTP interface of the embodiment of the invention.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided a non-transitory computer-readable storage medium.
A computer-readable medium of an embodiment of the present invention stores thereon a computer program, which is characterized in that, when executed by a processor, the program implements a method of HTTP interface invocation of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: because the HTTP service interface-oriented programming is adopted, namely, the service of the remote server which the client depends on is extracted as the interface, the specific realization of the service of the remote server is completed through the realization class of the interface, when the logic transmission of the method of realizing the class of the server is changed, only the new realization class of the service logic needs to be written, the existing code of the client interface does not need to be rewritten, and the influence on the system is reduced; meanwhile, by adopting the project based on interface programming, the service logic is clear, the codes are easy to understand, the expansion is convenient, and the maintainability is strong; furthermore, interface-oriented programming does not need to change the development habit of developers, so that the efficiency of popularization is greatly improved, the maintenance cost is greatly reduced on the aspects of maintainability and readability of projects, and the waste is effectively solved on the aspects of manpower and time cost.
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 HTTP interface invocation according to an embodiment of the present invention;
FIG. 2 is a schematic diagram of HTTP interface scanning and registration of a method invoked by the HTTP interface according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating an HTTP interface request client model in a method invoked by an HTTP interface according to an embodiment of the present invention;
FIG. 4 is a flow chart illustrating HTTP interface invocation in a method for HTTP interface invocation according to an embodiment of the present invention;
fig. 5 is a schematic flowchart of an HTTP interface requesting client access in the HTTP interface invoking method according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of the main modules of an apparatus for HTTP interface invocation according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a computer system suitable for implementing the terminal device or the server according to the embodiment of the present application.
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.
The technical scheme of the embodiment of the invention adopts HTTP service interface-oriented programming, namely, the service of the remote server depending on the client is extracted as the interface, the specific realization of the service of the remote server is completed by the realization class of the interface, when the logic transmission of the method for realizing the class of the server is changed, only the new realization class of the service logic needs to be compiled, the existing code of the client interface does not need to be rewritten, and the influence on the system is reduced; meanwhile, by adopting the project based on interface programming, the service logic is clear, the codes are easy to understand, the expansion is convenient, and the maintainability is strong; furthermore, interface-oriented programming does not need to change the development habit of developers, so that the efficiency of popularization is greatly improved, the maintenance cost is greatly reduced on the aspects of maintainability and readability of projects, and the waste is effectively solved on the aspects of manpower and time cost.
Fig. 1 is a schematic diagram of the main steps of a method of HTTP interface invocation according to an embodiment of the present invention.
As shown in fig. 1, a method for invoking an HTTP interface according to an embodiment of the present invention mainly includes the following steps:
step S101: and when the client is started, scanning the HTTP interface according to the configuration type path and the packet path to obtain the callable HTTP interface.
When the client is started, the interfaces are scanned in the specified range, all the callable HTTP interfaces meeting the requirements in the specified range are obtained, and it should be noted that the scanned range can be specified by configuring the class path and the packet path.
In order to make the code structure clear and facilitate subsequent maintenance and management, the client first defines the called HTTP interface class according to the data required by the client. In the embodiment of the invention, the HTTP interface is defined and the annotation identifier is added.
In this embodiment of the present invention, the HTTP interface may be defined according to a definition rule, where the definition rule includes: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
The definition of the client to the HTTP interface is to classify the related services, define an interface for each classification, map the address and parameters of the request HTTP interface to the corresponding method and parameters of the HTTP interface, the request address is the method name, the request parameters are the method parameters, and the definition of the client to the HTTP interface has the following rules:
1. the interface class definition rule is characterized in that a group of HTTP interfaces in the same category are named as an interface, and can be marked by an annotation "@ Pandora", for example, interfaces related to a user, basic information (a login name, a nickname and the like) for obtaining a user name and login, user member level and the like are all operations related to the user and can be defined as a user interface;
2. the method rules, each method represents an HTTP interface, in order to be able to simply distinguish each HTTP request, each HTTP request is specified to be distinguished by a special parameter name (apiName), and the parameter must exist at each request, the comment "@ phtppost" may be used to indicate whether the HTTP request is POST or GET, the default is POST, and the comment may be modified according to the actual situation, for example, HTTP:// p.jd.comapiname ═ getuserlapicinfo & userName ═ eastern fengshao indicates that the user is the basic information of "eastern fengshao";
3. the basic parameters are necessary parameters of the HTTP interface request, and comprise apiName (HTTP interface name), security authentication Token (if the security authentication is started by a Token) and signature (signature and data integrity check), the basic parameters are transparent to a developer, and the service parameters are embodied on the interface method parameters except for configuring whether the security authentication is started or not;
4. the method parameter rules, namely the method parameters of the HTTP interface request, can use the comment "@ PParam" to represent the parameter name, the parameters are sequential, and the characteristics are used in the signature, such as field and value of form.
The HTTP interface may be defined according to any of the above rules.
Step S102: proxy registration is performed for the callable HTTP interface.
In the embodiment of the invention, the annotation identifier of the HTTP interface can be obtained in the step; searching whether the annotation identifier contains an identifier which can call an HTTP interface; proxy registration is performed for the HTTP interface containing the identification that can invoke the HTTP interface.
After the definition and annotation addition of the HTTP interface are completed, the selection and calling of the HTTP interface can be completed by screening annotation identifications of the HTTP interface, and proxy registration is carried out on the HTTP interface containing the identification capable of calling the HTTP interface.
In the embodiment of the invention, the proxy registration can be realized by setting instantiation information of an instance mode for the callable HTTP interface, wherein the instantiation information comprises information of an instance interface type, an instantiation mode proxy class and whether the instantiation mode proxy class is a singleton mode.
Fig. 2 is a schematic diagram of HTTP interface scanning and registration of a method of HTTP interface invocation according to an embodiment of the present invention.
In the embodiment of the invention, a Spring (a lightweight Java development framework) dependent injection mode is selected to obtain a Bean (instance), a Spring Ioc container is selected to manage the HTTP interface, and an annotation '@ Pandora' is selected as an annotation identifier capable of calling the HTTP interface.
When a client is started, corresponding beans and basic information during instantiation need to be loaded, such as which beans are loaded, what interfaces of the beans are, whether the beans are in a singleton mode, and the like, and the implementation scheme of specific HTTP interface scanning and registration is as follows:
step 201: and performing interface scanning according to the configured packet or class path.
When the client is started, the PandoraFactory (agent factory) scans the interface according to the configured packet or class path. Finding the HTTP interface needing loading and entrusting the Spring Ioc container to manage.
Step 202: the filter class annotation is @ Pandora.
The Spring Ioc container filter class is annotated as @ Pandora's interface, which is the HTTP interface that provides the service side.
Step 203: the Bean is registered.
A corresponding Spring generic Bean definition is defined for each HTTP interface, which is a one-stop standard Bean definition (Bean definition) that has the flexibility to set parent Bean definitions through the parentname attribute, in addition to having the same properties as other Bean definitions, specifying classes, optional configuration parameter values and attribute parameters. Generally, the genericbean definition is used to register a user-visible bean definition (visible bean definition means that a post-processor can be defined on the bean definition to operate on the bean, even to prepare for extension to configure parent name).
Step 204: settings create a Bean template.
Basic information required for instantiation of PandoraFactoryBean (instance mode) is set through GenericBeanDefinition, and includes an instance interface type, an instantiation mode proxy class C class, whether the instantiation mode proxy class C is a singleton mode, and the like.
So far, the whole interface scanning and registration are completed, and then the client can use the Spring mode to normally call the interfaces.
Fig. 3 is a schematic diagram of an HTTP interface request client model in the method of HTTP interface invocation according to an embodiment of the present invention.
In the embodiment of the invention, the HTTP interface request client is divided into two functional modules, namely a core module and Bean management, wherein the functions of the core module comprise resource configuration, agent factory, annotation, HTTP toolkit, result converter and security authentication; the 'Bean management' template comprises functions 'interface scanner' and 'FactoryBean', and the functions are as follows:
1. and the resource configuration is responsible for resource information configuration and mainly provides an HTTP request address, security authentication Token and request overtime configuration.
2. And the proxy factory is responsible for generating and calling the interface dynamic proxy class.
3. Interface annotation provides HTTP interface annotation, has three big notes "@ Pandora", "@ PHttpPost", "@ PParam" at present, and the concrete effect is as follows:
1) @ Pandora, for identifying that the current interface is an HTTP request interface; domains are classes.
2) @ PHttpPost is used to indicate that the request is a POST, the others are GET requests, the default is POST, and the scope is a method.
3) @ PParam, a service parameter key for a corresponding HTTP request is key in value format. According to the Java polymorphic characteristic, the naming of the method parameter cannot be known, so the naming of the method parameter is acquired by displaying a definition parameter annotation mode.
4. The HTTP toolkit provides an efficient and rich-function client programming toolkit supporting an HTTP protocol.
5. The result converter mainly provides analysis of the returned data and converts the returned data into an object after HTTP response, and the type of the returned result object supports four major categories: the method comprises basic types, List, Map and PDTO, wherein the PDTO is a self-defined return general type of the embodiment of the invention and supports return paging, object collection and error information.
6. The safety certification mainly comprises two functions of Token generator and signature certification, and has the following specific functions:
1) and the Token generator provides identity authentication, and the interface provided by the server can be accessed only by the Token with the identity distributed by the server.
2) And the signature authentication is used for requesting data integrity verification and ensuring that the data is not lost or tampered in the transmission process.
7. And the interface scanner is used for providing HTTP interface scanning and Bean definition registration.
8. The FactoryBean is mainly used for providing interface proxy object generation and object instantiation modes, and generates proxy classes by relying on the proxy factory.
Fig. 4 is a schematic flowchart of an execution flow of an HTTP interface call in the method for invoking the HTTP interface according to the embodiment of the present invention.
Step 401: when the HTTP interface needs to be called, a method corresponding to the HTTP interface is directly called, and the method calls a getObject method of the pandoraFactoryBean (instance class) to acquire the Bean instance object according to a registered Bean instantiation mode.
The getObject method of the pandoraFactoryBean calls a newpandoraProxy method of the proxy factory class, and the method mainly generates and executes the proxy class according to the JDK dynamic proxy.
Step 402: the method calls a Proxy (Proxy server) Class newProxyInstance static method provided by a JDK dynamic Proxy, and transmits a Class loader, a Proxy Class interface Class and a callback InvocationHandler needing processing.
Step 403: the Proxy method calls a Proxy generator method and generates a parameter constructor Proxy class $ Proxy0 according to an interface, inherits Pro xy and constructs a function parameter invotinHandler.
The PandoraProxy class implements the InvocationHandler interface, and the $ Proxy0 Proxy class calls the InvocationHandler invoke method, namely calls the PandoraProxy class invoke method.
Step 404: the PandoraProxy class invoke method calls the execute method of the PandoraMethod class and passes in interface methods and parameters to be executed.
Step 405: the execute method calls the buildBasicParams and buildbussisparams methods to generate basic parameters and service parameters.
The basic parameters include apiName (method name of interface), identity authentication Token (according to whether the server side starts verification, whether the parameter needs to be added or not is determined), and signature (to ensure the integrity of data in the transmission process);
the service parameters are converted into http body key format and are ordered, the parameter name (key) is obtained from the "@ PParam" annotation in the interface method, and the value source and the value transmitted when the interface method is called. value supports basic data types, String, array, JSON, object. Note that the data in the array also supports several of the types described above. The PMap is a self-defined type, the realization of the bottom layer of the Map structure is LinkedHashMap, any type can be stored, and only the type needs to be stored to realize the toString method. The PMap type can be automatically converted into an HTTP identifiable key value style.
And obtaining a value of a method annotation @ PHttpPost of a method corresponding to the interface to judge whether the current request mode is POST or GET, wherein the value is true, and the value is POST or GET.
After all preparation work of the HTTP request is finished, a post or get method (determined by the @ PHttpPost value) of the HttpRequest tool class is called.
Step 406: the post/get method of Http request directly requests the Http interface address provided by the server, and the server will make some security authentications (if supporting security authentication) to respond to the request and return data Res.
Res is resolved by HttpRequest and returns String responseBody.
The responseBody passes through the result translator, returning the corresponding result object. The current result object type supports 4 broad classes: base type, List, Map, PDTO; PDTO is a custom return generic type for this embodiment.
And returning the final result to the initial calling interface method for the client side method after the layer-by-layer method is returned.
Fig. 5 is a schematic flowchart of an HTTP interface requesting a client access in a method for invoking the HTTP interface according to an embodiment of the present invention.
The embodiment of the invention considers the coupling of the system, designs a non-invasive access mode, and mainly comprises the following three steps:
step 501: a jar package containing an instance template is introduced.
And importing a jar package containing an instance template in a manner of supporting maven.
Step 502: and configuring the resource file.
The resource file comprises an HTTP request address, a security authentication Token (configuration is needed if the server supports authentication, and the default is no configuration), and request timeout time configuration.
Step 503: an interface scan path is configured.
Packet and class path configuration is supported.
It should be noted that step 502 and step 503 support Spring (a lightweight Java development framework) resource file mode configuration, and conform to the development habit of the Web service developer.
According to the method for calling the HTTP interface, disclosed by the embodiment of the invention, the service interface is programmed and defined in an interface-oriented manner by adopting the HTTP interface, namely, the service of the remote server depending on the client is extracted as the interface, the specific realization of the service of the remote server is completed through the realization class of the interface, when the method logic of the realization class is changed, the realization class of the service logic is rewritten without rewriting the existing code of the client interface, and the influence on the system is reduced; meanwhile, by adopting the project based on interface programming, the service logic is clear, the codes are easy to understand, the expansion is convenient, and the maintainability is strong; furthermore, interface-oriented programming does not need to change the development habit of developers, so that the efficiency of popularization is greatly improved, the maintenance cost is greatly reduced on the aspects of maintainability and readability of projects, and the waste is effectively solved on the aspects of manpower and time cost.
FIG. 6 is a schematic diagram of the main modules of an apparatus for HTTP interface invocation according to an embodiment of the present invention;
as shown in fig. 6, the apparatus 600 for HTTP interface invocation according to the embodiment of the present invention includes: an acquisition module 601 and a registration module 602. Wherein:
an obtaining module 601, configured to scan a hypertext transfer protocol HTTP interface according to a configuration class path and a packet path when a client is started, and obtain an available HTTP interface; a registration module 602, configured to perform proxy registration on the callable HTTP interface.
Furthermore, the apparatus further comprises: and the definition module is used for defining the HTTP interface and adding annotation identification.
The definition module is further configured to: defining the HTTP interface according to definition rules, wherein the definition rules comprise: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
In addition, the registration module 602 is further configured to: obtaining an annotation identifier of the HTTP interface; searching whether the annotation identifier contains the identifier of the callable HTTP interface; and carrying out proxy registration on the HTTP interface containing the identification of the callable HTTP interface.
In addition, the registration module 602 is further configured to: and setting instantiation information of an instantiation mode for the callable HTTP interface, wherein the instantiation information comprises information of an instantiation interface type, an instantiation mode proxy class and whether the callable HTTP interface is in a singleton mode.
According to the HTTP interface calling device, the HTTP interface is adopted to call the service interface-oriented programming and define the service interface, namely, the service of the remote service end which the client depends on is extracted as the interface, the specific realization of the service of the remote service end is completed through the realization class of the interface, when the method logic of the realization class is changed, the realization class of the service logic is rewritten without rewriting the existing code of the client interface, and the influence on the system is reduced; meanwhile, by adopting the project based on interface programming, the service logic is clear, the codes are easy to understand, the expansion is convenient, and the maintainability is strong; furthermore, interface-oriented programming does not need to change the development habit of developers, so that the efficiency of popularization is greatly improved, the maintenance cost is greatly reduced on the aspects of maintainability and readability of projects, and the waste is effectively solved on the aspects of manpower and time cost.
Referring now to FIG. 7, shown is a block diagram of a computer system 700 suitable for use in implementing a terminal device of an embodiment of the present application. The terminal device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present application.
As shown in fig. 7, the computer system 700 includes a Central Processing Unit (CPU)701, which can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from a storage section 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.
The following components are connected to the I/O interface 705: an input portion 706 including a keyboard, a mouse, and the like; an output section 707 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 708 including a hard disk and the like; and a communication section 709 including a network interface card such as a LAN card, a modem, or the like. The communication section 709 performs communication processing via a network such as the internet. A drive 710 is also connected to the I/O interface 705 as needed. A removable medium 711 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 710 as necessary, so that a computer program read out therefrom is mounted into the storage section 708 as necessary.
In particular, the processes described above with respect to the main step diagrams may be implemented as computer software programs, according to embodiments of the present invention. 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 containing program code for performing the method illustrated in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from a network through the communication section 709, and/or installed from the removable medium 711. The computer program executes the above-described functions defined in the system of the present application when executed by the Central Processing Unit (CPU) 701.
It should be noted that the computer readable medium shown in the present application may 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 application, 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 this application, 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 application. 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 application 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 and a registration module. The names of these modules do not in some cases form a limitation on the module itself, and for example, the registration module may also be described as a "module that performs proxy registration for the callable HTTP interface".
As another aspect, the present application also provides a computer-readable medium, which 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: and when the client is started, scanning the HTTP interface according to the configuration type path and the packet path to obtain the callable HTTP interface.
Step S102: proxy registration is performed for the callable HTTP interface.
According to the technical scheme of the embodiment of the invention, because the HTTP interface is adopted to call the service-oriented interface programming and define the service interface, namely, the service of the remote server depending on the client is extracted as the interface, the specific realization of the service of the remote server is completed through the realization class of the interface, when the method logic of the realization class is changed, the realization class of the service logic is only needed to be rewritten without rewriting the existing code of the client interface, and the influence on the system is reduced; meanwhile, by adopting the project based on interface programming, the service logic is clear, the codes are easy to understand, the expansion is convenient, and the maintainability is strong; furthermore, interface-oriented programming does not need to change the development habit of developers, so that the efficiency of popularization is greatly improved, the maintenance cost is greatly reduced on the aspects of maintainability and readability of projects, and the waste is effectively solved on the aspects of manpower and time cost.
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 (6)

1. A method for HTTP interface invocation, comprising:
defining an HTTP interface and adding annotation identification;
when the client is started, scanning the HTTP interface according to the configuration type path and the packet path to obtain an available HTTP interface;
carrying out proxy registration on the callable HTTP interface;
proxy registration of the callable HTTP interface includes:
obtaining an annotation identifier of the HTTP interface;
searching whether the annotation identifier contains the identifier of the callable HTTP interface;
proxy registration is carried out on the HTTP interface containing the identification of the callable HTTP interface;
the proxy registration further comprises:
and setting instantiation information of an instantiation mode for the callable HTTP interface, wherein the instantiation information comprises information of an instantiation interface type, an instantiation mode proxy class and whether the callable HTTP interface is in a singleton mode.
2. The method of claim 1, wherein defining the HTTP interface comprises:
defining the HTTP interface according to definition rules, wherein the definition rules comprise: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
3. An apparatus for HTTP interface invocation, comprising:
the definition module is used for defining the HTTP interface and adding annotation identification;
the acquisition module is used for scanning the HTTP interface according to the configuration type path and the packet path when the client is started to acquire the callable HTTP interface;
the registration module is used for carrying out proxy registration on the callable HTTP interface;
the registration module is further configured to:
obtaining an annotation identifier of the HTTP interface;
searching whether the annotation identifier contains the identifier of the callable HTTP interface;
proxy registration is carried out on the HTTP interface containing the identification of the callable HTTP interface;
the registration module is further configured to:
and setting instantiation information of an instantiation mode for the callable HTTP interface, wherein the instantiation information comprises information of an instantiation interface type, an instantiation mode proxy class and whether the callable HTTP interface is in a singleton mode.
4. The apparatus of claim 3, wherein the definition module is further configured to:
defining the HTTP interface according to definition rules, wherein the definition rules comprise: interface class definition rules, method rules, parameter classification rules, and method parameter rules.
5. An electronic device invoked by an HTTP 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 claim 1 or 2.
6. A computer-readable medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method of claim 1 or 2.
CN201710265387.7A 2017-04-21 2017-04-21 HTTP interface calling method and device Active CN108737474B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710265387.7A CN108737474B (en) 2017-04-21 2017-04-21 HTTP interface calling method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710265387.7A CN108737474B (en) 2017-04-21 2017-04-21 HTTP interface calling method and device

Publications (2)

Publication Number Publication Date
CN108737474A CN108737474A (en) 2018-11-02
CN108737474B true CN108737474B (en) 2021-04-30

Family

ID=63933899

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710265387.7A Active CN108737474B (en) 2017-04-21 2017-04-21 HTTP interface calling method and device

Country Status (1)

Country Link
CN (1) CN108737474B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111400058A (en) * 2020-03-06 2020-07-10 中国平安人寿保险股份有限公司 Method and device for calling message, computer equipment and storage medium
CN113626225B (en) * 2021-10-11 2022-02-11 中航金网(北京)电子商务有限公司 Program calling method, terminal device and medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102479077A (en) * 2010-11-26 2012-05-30 金蝶软件(中国)有限公司 Method and device for dynamically constructing function operation, and application system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1685670B (en) * 2002-10-03 2010-05-26 思科技术公司 Method for a wireless station to determine network metrics prior to associating with an access point of a wireless network
US7417961B2 (en) * 2003-12-09 2008-08-26 Cisco Technology, Inc. Methods and apparatus for implementing a speed sensitive mobile router
CN102096631B (en) * 2009-12-11 2013-09-25 华为技术有限公司 Interface testing method and device
US9183001B2 (en) * 2011-09-12 2015-11-10 Microsoft Technology Licensing, Llc Simulation of static members and parameterized constructors on an interface-based API
US8434080B2 (en) * 2011-12-22 2013-04-30 Software Ag Usa, Inc. Distributed cloud application deployment systems and/or associated methods

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102479077A (en) * 2010-11-26 2012-05-30 金蝶软件(中国)有限公司 Method and device for dynamically constructing function operation, and application system

Also Published As

Publication number Publication date
CN108737474A (en) 2018-11-02

Similar Documents

Publication Publication Date Title
US11561846B2 (en) API notebook tool
US20230057335A1 (en) Deployment of self-contained decision logic
KR102220127B1 (en) Method and apparatus for customized software development kit (sdk) generation
KR102218995B1 (en) Method and apparatus for code virtualization and remote process call generation
US10956179B1 (en) Third party integration of plugins and widgets
US11449348B2 (en) Pre/post deployment customization
CN106997298B (en) Application resource acquisition method and device
CN107015804B (en) Method and system for rapidly developing project by configuring API
US11797273B2 (en) System and method for enhancing component based development models with auto-wiring
US8856736B2 (en) Web service proxy interface augmentation
JP7097958B2 (en) Systems and methods for integrating cloud applications into cloud service broker platforms using the Automatic Universal Connector Package
JP2011504256A (en) Language framework and infrastructure for secure and configurable applications
US20120227028A1 (en) Graphical programming object population user interface autogeneration
CN108279882B (en) Framework generation method, device, equipment and computer readable medium
Kim Development of Mobile Cloud Applications using UML.
CN108737474B (en) HTTP interface calling method and device
CN110874278A (en) Embedding method of external system, workflow system, device and storage medium
CN113535565B (en) Interface use case generation method, device, equipment and medium
Srinivasmurthy et al. Web2exchange: A model-based service transformation and integration environment
Sadakath Spring Boot 2.0 Projects: Build production-grade reactive applications and microservices with Spring Boot
CN113918499B (en) Open interface generation method, network device and computer readable storage medium
Feio et al. FI-MApp: a web application for managing FI-WARE environments in internet of things
Vemula et al. Getting Started with Azure Functions
CN115878396A (en) Interface testing method, device, equipment and medium for enterprise service bus

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