CN108182120B - Interface calling method and system, storage medium and computer equipment - Google Patents

Interface calling method and system, storage medium and computer equipment Download PDF

Info

Publication number
CN108182120B
CN108182120B CN201711295827.XA CN201711295827A CN108182120B CN 108182120 B CN108182120 B CN 108182120B CN 201711295827 A CN201711295827 A CN 201711295827A CN 108182120 B CN108182120 B CN 108182120B
Authority
CN
China
Prior art keywords
interface
calling
server
target component
plug
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
CN201711295827.XA
Other languages
Chinese (zh)
Other versions
CN108182120A (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.)
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shirui Electronics Co Ltd
Original Assignee
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shirui Electronics 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 Guangzhou Shiyuan Electronics Thecnology Co Ltd, Guangzhou Shirui Electronics Co Ltd filed Critical Guangzhou Shiyuan Electronics Thecnology Co Ltd
Priority to CN201711295827.XA priority Critical patent/CN108182120B/en
Publication of CN108182120A publication Critical patent/CN108182120A/en
Application granted granted Critical
Publication of CN108182120B publication Critical patent/CN108182120B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

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

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention relates to an interface calling method and system, a storage medium and computer equipment.

Description

Interface calling method and system, storage medium and computer equipment
Technical Field
The invention relates to the technical field of computer software, in particular to an interface calling method and system, a storage medium and computer equipment.
Background
In computer languages, a component Bean can be viewed as an available object, which is an instantiated class. An object includes a number of methods, each of which can be thought of as an interface. For example, in a device management Bean, methods of adding, deleting, and modifying devices are included, and these three methods are three interfaces.
The interface in Bean can be called, however, the inventor finds that the traditional calling method is high in complexity. For example, for an HTTP (HyperText Transfer Protocol) interface, an HTTP parameter may be constructed by using a tool similar to a POST MAN, and then sent to call a method for specifically executing a service, and HTTP request parameters such as a header and a body need to be constructed. For another example, for the Dubbo interface, the call interface can only be simulated by creating a client, starting a project.
In summary, the conventional interface calling method has high complexity.
Disclosure of Invention
Based on this, it is necessary to provide an interface calling method and system, a storage medium, and a computer device, aiming at the problem that the complexity of the conventional interface calling method is high.
An interface calling method, comprising the steps of:
running an injection code on a server to obtain each component;
determining a currently called target component from the components through a plug-in, determining a calling method of the target component through the plug-in, and sending the calling method and the target component to the server;
and calling the interface of the target component on the server by using the calling method.
An interface invocation system, comprising:
the operation module is used for operating the injection codes on the server to obtain each component;
the first sending module is used for determining a currently called target component from the components through a plug-in, determining a calling method of the target component through the plug-in, and sending the calling method and the target component to the server;
and the calling module is used for calling the interface of the target component on the server by using the calling method.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, implements the interface call method.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the interface call method.
According to the interface calling method and system, the storage medium and the computer device, the injection codes are operated to obtain each component, the target component and the calling method thereof are determined through the plug-in, and finally the calling method is used for calling the interface of the target component on the server, so that complex operations such as parameter construction or client creation are not needed, and the complexity of an interface calling mode is reduced.
Drawings
FIG. 1 is a flow diagram of an interface invocation method of an embodiment;
fig. 2 is a schematic structural diagram of an interface call system according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, an embodiment of the present invention provides an interface calling method, which may include the following steps:
s1, operating the injection code on the server to obtain each component;
s2, determining a currently called target component from the components through a plug-in, determining a calling method of the target component through the plug-in, and sending the calling method and the target component to the server;
and S3, calling the interface of the target component on the server by using the calling method.
The component described in the embodiments of the present invention may be a Bean. The beans can be regarded as available objects and can be managed by a Spring framework. The object is an instantiated class, the class is simply understood to be a template, and the object is created according to the template and has a variable of the object. There are many methods in this object, each method is actually an interface, for example, a device management Bean, and there are methods of adding, deleting and modifying devices in the object, and these three methods are three interfaces. The call interface actually calls a method on a Bean. In the conventional calling method, the interface can be called by a tool such as postman. postman et al tools may have graphical interfaces for users to enter parameters, and then these tools may connect to a server to invoke methods on beans. The dubbo interface does not have a graphical interface at present, so a client needs to be constructed and then connected with a server to call the interface. The http interface is different from the dubbo in that the connection mode and the communication protocol of the server are different, but the conversion through the framework is also essentially to call a method on a certain object, and only the calling mode is different. The traditional calling method is high in complexity.
These methods can also be invoked by unit testing, but unit testing requires that the container be initialized each time, which is equivalent to starting an item. The items are bigger and bigger, more and more items are initialized, and the calling speed is slower and slower.
According to the invention, each component is obtained by operating the injection code, the target component and the calling method thereof are determined by the plug-in, and finally the interface of the target component is called on the server by using the calling method without complex operations such as parameter construction or client creation and the like, so that the complexity of the interface calling mode is reduced.
Before a method of a Bean is called, all Bean objects need to be acquired first, and the calling is possible. Spring provides a static method to get all the beans, and after getting these beans, it can just add the called method (including the method name) to call and test the method (assuming the method is without parameters). In step S1, the respective components may be acquired by running the injection code on the server. The injection code can take all beans and accept a request (with a called method) so that the Bean's method can be called. To modify the code non-invasively, java agent may be used which executes the code specifying the jar package (i.e., injects the code) before the project is started, and modifies the original code and obtains the resources of the project (including all beans mentioned above).
One effect of the plug-in is that it is necessary to automatically add a start parameter before the project is started. In one embodiment, the startup parameters may include a port number in the form of: injection code jar port number. The port number is a parameter of the jar packet, an available port number is randomly generated and transmitted to the injection code, and the injection code can be really called. The port number is used for injecting the code, and a local socket server can be started according to the port number. The plug-in can communicate with the injection code according to the port number, and send the class where the cursor is located and the calling method acquired by the plug-in to the injection code. The injection code, upon receiving the information, may then invoke the methods based on the information. Therefore, before step S1, the startup parameters may be generated by the plug-in; and sending the starting parameters to an injection code, so that the injection code starts a server according to the starting parameters.
By-java agent, the program can be made to run the code inside the jar package before it starts. This piece of code may indirectly get to the resources of the project (including beans, etc.). Taking the method of initializing all beans in a spring framework as an example, the method is executed to represent that all beans are initialized, the method adds a saveBean method before the code of the jar package returns, and the transmitted parameters are Bean resources after initialization is successful (because the initialization method is used for initializing beans, the variables have Bean information). And the saveBean implementation is also in the jar package. That is to say, the jar does not take Bean information before the project is started, but in the process of project initialization, after the spring initializes the Bean, the saveBean method is automatically called, and then the saveBean method saves the Bean, which can be used later.
In step S2, after the injection code is executed, it needs to be triggered to tell the injection code the components and methods to be called before he can call. At this time, a plug-in technology of the IntelliJ IDEA may be adopted, the currently called target component and the calling method of the target component may be obtained through the plug-in, and the calling method and the target component may be sent to the server. Further, in step S2, the calling method and the target component may be sent to the server according to the starting parameters. In one embodiment, the class and the calling method of the cursor of the editor can be obtained through a plug-in, and the currently called target component is determined according to the class of the cursor of the editor.
The IntelliJ IDEA is an editor, but the editor is not limited to the IntelliJ IDEA in practical use, and most intelligent editors, such as eclipse, support a function of improving efficiency by editing plug-ins. The plug-in is a certain function of the editor, and most functions of the editor are composed of various plug-ins. These editors provide a variety of interfaces, such as retrieving the current project name, retrieving certain file content. The method for acquiring the cursor is also an interface provided by the editor, and can be developed according to the development specification of the plug-in of the editor, and the interface provided by the editor is called to acquire the method and the class of the cursor.
In step S3, in order to speed up the call progress, a hot deployment tool may be used on the server to make a call to the interface of the target component according to the call method. Hot deployment tools, including Spring-loaded, Jrebel, etc., are designed to modify a component and then take effect quickly without restarting the project. The parameters in the method can be modified to call the method at any time by matching the use of the tools.
For example, a bean includes an int add (int a, int b) method, which is used to add two values, and when the method needs to be tested, a testing method can be added to test add:
void addTest(){
add(1,2);
}
the addTest method can be immediately effective through a hot deployment tool, then a cursor of an editor can be placed in the addTest method, a plug-in is triggered to send a request to an agent to call the addTest method, and the addTest method calls the add method, so that the add method is actually tested.
If other parameters are to be tested (e.g., parameters 1000 and 2000), only the following changes are required:
void addTest(){
add(1000,2000);
}
and the method is enabled to be effective through thermal deployment, so that other parameters can be tested.
In the above embodiments, the role of the insert includes the following points:
(1) randomly generating an available port number, and adding a starting parameter, namely java agent, an injection code and jar port number when the project is started so as to enable the injection code to take effect.
(2) And acquiring the class and the method of the cursor, and transmitting the class and the method to the injection code in a socket mode.
The role of the injected code includes the following:
(1) all beans are taken at project startup (by inserting their own code in Spring source).
(2) And starting the socket server according to the port number.
(3) And calling the method according to the information (class and method) received by the socket server.
The technical solution of the present invention is explained in detail below as an example of practical application.
If the project has a Bean of public class Authservice, which is used to call the logic method, the Bean may include a public void logic (String user name), and the method may include the service code for logging.
1. At this time, a test method can be constructed, namely public void testLogin () is added before public void logic (String user name, String password) in public class Authservice, and the test method is used for executing logic ("xiaoming", "123456"); by mouse clicking on the end of a region ("xiaoming", "123456"), the cursor appears where the mouse clicked.
2. Rapid validation of testLogin methods using a Hot deployment tool
3. Pressing a shortcut key to call a method of the plug-in. The point where the cursor is obtained is in the Authservice class, testLogin method, and the information is sent to the injection code through the socket.
4. After the injection code is taken, matching is carried out according to all beans taken during self initialization, after the corresponding Bean is found, reflection calling is carried out according to the method name, and the testLogin method is called.
The invention combines java agent, IntelliJ IDEA plug-in development and hot deployment tools, and fully exerts the advantages of the three technologies:
(1) the code is non-intrusive (the specified jar package is automatically loaded at startup without changing the code).
(2) Classes and methods are found quickly (without manual class and method input to perform).
(3) And (4) quickly adding a test method and modifying test method parameters.
The code can be used only by Spring (a very popular development framework at present), and some methods which need to rely on external triggering are called at any time, including a method of RPC (Remote Procedure Call), a method of implementing HTTP service, a method of Dao layer, and the like.
As shown in fig. 2, an embodiment of the present invention further provides an interface calling system, which may include:
the running module 10 is used for running the injection code on the server to obtain each component;
a first sending module 20, configured to determine, through a plug-in, a currently called target component from the components, determine, through the plug-in, a calling method of the target component, and send the calling method and the target component to the server;
and the calling module 30 is used for calling the interface of the target component by using the calling method on the server.
The interface calling system and the interface calling method of the invention are in one-to-one correspondence, and the technical characteristics and the beneficial effects described in the embodiment of the interface calling method are all applicable to the embodiment of the interface calling system, so that the statement is made.
In one embodiment, the present invention further provides a computer-readable storage medium on which a computer program is stored, which when executed by a processor implements the interface calling method described in any of the above embodiments.
In one embodiment, the present invention further provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the interface calling method according to any of the embodiments.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. An interface calling method, comprising the steps of:
running injection codes of jar packets on a server to obtain each component Bean;
determining a currently called target component from the components through an IntelliJ IDEA plug-in, determining a calling method of the target component through the plug-in, and sending the calling method and the target component to the server;
and calling the interface of the target component on the server by using the calling method.
2. The interface invocation method according to claim 1, further comprising, before running the injected code on the server, the steps of:
generating a starting parameter through a plug-in;
and sending the starting parameters to an injection code, so that the injection code starts a server according to the starting parameters.
3. The interface invocation method according to claim 2, wherein the step of sending the invocation method and the target component to the server includes:
and sending the calling method and the target component to the server according to the starting parameters.
4. The interface call method according to claim 1, wherein the step of obtaining the currently called target component from the components through the plug-in comprises:
determining the class of an editor cursor through a plug-in;
and determining the currently called target component according to the class of the cursor of the editor.
5. The interface calling method according to claim 1, wherein the step of calling the interface of the target component by the calling method on the server comprises:
and deploying a tool on the server through heat, and calling the interface of the target component according to the calling method.
6. The interface call method according to any one of claims 2 to 3, wherein the start parameter includes a port number.
7. An interface invocation system, comprising:
the running module is used for running the injection codes of the jar packets on the server to obtain each component Bean;
the first sending module is used for determining a currently called target component from the components through an IntelliJ IDEA plug-in, determining a calling method of the target component through the plug-in, and sending the calling method and the target component to the server;
and the calling module is used for calling the interface of the target component on the server by using the calling method.
8. The interface invocation system according to claim 7, further comprising:
the generating module is used for generating starting parameters through the plug-in;
and the second sending module is used for sending the starting parameters to the injection codes so that the injection codes start the server according to the starting parameters.
9. A computer-readable storage medium on which a computer program is stored, the program, when executed by a processor, implementing the interface call method of any one of claims 1 to 6.
10. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor executes the interface call method of any one of claims 1 to 6.
CN201711295827.XA 2017-12-08 2017-12-08 Interface calling method and system, storage medium and computer equipment Active CN108182120B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711295827.XA CN108182120B (en) 2017-12-08 2017-12-08 Interface calling method and system, storage medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711295827.XA CN108182120B (en) 2017-12-08 2017-12-08 Interface calling method and system, storage medium and computer equipment

Publications (2)

Publication Number Publication Date
CN108182120A CN108182120A (en) 2018-06-19
CN108182120B true CN108182120B (en) 2020-11-24

Family

ID=62545751

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711295827.XA Active CN108182120B (en) 2017-12-08 2017-12-08 Interface calling method and system, storage medium and computer equipment

Country Status (1)

Country Link
CN (1) CN108182120B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111124424B (en) * 2019-12-27 2023-09-19 珠海金山数字网络科技有限公司 Method and device for analyzing algorithm complexity
CN111309294B (en) 2020-02-29 2022-06-07 苏州浪潮智能科技有限公司 Business processing method and device, electronic equipment and storage medium
CN111400058B (en) * 2020-03-06 2024-06-04 中国平安人寿保险股份有限公司 Method, device, computer equipment and storage medium for calling message

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2014094508A1 (en) * 2012-12-17 2014-06-26 广州市动景计算机科技有限公司 Method and device for starting external application program in browser
CN106326017A (en) * 2016-08-17 2017-01-11 广东亿迅科技有限公司 Realization system for call chain based on Annotation application
CN106909498A (en) * 2015-12-22 2017-06-30 阿里巴巴集团控股有限公司 A kind of java applet injects the method and system of failure
CN107092488A (en) * 2017-03-31 2017-08-25 武汉斗鱼网络科技有限公司 It is a kind of that application is carried out to bury realization method and system a little without intrusionization
CN107203402A (en) * 2017-04-06 2017-09-26 珠海金山网络游戏科技有限公司 It is a kind of that the multiple method of hot repair is carried out to operation code
CN107301098A (en) * 2017-06-15 2017-10-27 搜易贷(北京)金融信息服务有限公司 A kind of remote procedure call device based on Thrift agreements, method and system

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015029193A1 (en) * 2013-08-29 2015-03-05 株式会社野村総合研究所 Web server system, application development assistance system, multilingual support method in web server system, multi-device support method in web server system, and application development assistance method
CN104636248B (en) * 2013-11-13 2018-01-16 航天信息股份有限公司 A kind of automatic test based on code injection assists in identifying method
US10303531B2 (en) * 2014-07-28 2019-05-28 Red Hat, Inc. Console application through web service
CN106293967A (en) * 2016-08-03 2017-01-04 武汉斗鱼网络科技有限公司 A kind of method and system of long-range injecting codes
CN106775692B (en) * 2016-12-06 2020-06-05 腾讯科技(深圳)有限公司 Component editing method and electronic equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2014094508A1 (en) * 2012-12-17 2014-06-26 广州市动景计算机科技有限公司 Method and device for starting external application program in browser
CN106909498A (en) * 2015-12-22 2017-06-30 阿里巴巴集团控股有限公司 A kind of java applet injects the method and system of failure
CN106326017A (en) * 2016-08-17 2017-01-11 广东亿迅科技有限公司 Realization system for call chain based on Annotation application
CN107092488A (en) * 2017-03-31 2017-08-25 武汉斗鱼网络科技有限公司 It is a kind of that application is carried out to bury realization method and system a little without intrusionization
CN107203402A (en) * 2017-04-06 2017-09-26 珠海金山网络游戏科技有限公司 It is a kind of that the multiple method of hot repair is carried out to operation code
CN107301098A (en) * 2017-06-15 2017-10-27 搜易贷(北京)金融信息服务有限公司 A kind of remote procedure call device based on Thrift agreements, method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Java接口和内部类的探究;高本峰;《硅谷》;20120930;全文 *

Also Published As

Publication number Publication date
CN108182120A (en) 2018-06-19

Similar Documents

Publication Publication Date Title
CN108650149B (en) Server testing method, device, equipment and computer readable storage medium
US11599348B2 (en) Container image building using shared resources
CN108182120B (en) Interface calling method and system, storage medium and computer equipment
Zheng et al. Automated test input generation for android: Towards getting there in an industrial case
CN107733847B (en) Method and device for platform login website, computer equipment and readable storage medium
CN110275831B (en) Mock data verification method and device of protocol interface
CN106294102B (en) Application program testing method, client, server and system
CN104298604A (en) Testing system and testing method for robustness of cloud service
CN111865629B (en) Method, apparatus and computer program product for configuring service instances
CN112162753A (en) Software deployment method and device, computer equipment and storage medium
CN108681662A (en) A kind of method and device of installation procedure
CN108964993B (en) Fault simulation method, device and equipment based on dynamic proxy and readable storage medium
US8448151B2 (en) Method for binarizing initial script on operating system and operating method of binary script
WO2017041499A1 (en) Software upgrade method and system, and computer-readable storage medium
Arnatovich et al. Achieving high code coverage in android UI testing via automated widget exercising
CN111880987A (en) Dynamic monitoring method and device of application program, storage medium and electronic device
Kim et al. Reuse-oriented reverse engineering of functional components from x86 binaries
CN108650243B (en) Connection establishment method, system, device and computer readable storage medium
CN114610640A (en) Fuzzy testing method and system for trusted execution environment of Internet of things
Libes expect: Scripts for controlling interactive processes
CN115757014A (en) Power consumption testing method and device
CN113360377B (en) Test method and device
CN112100620A (en) Code security detection method, device, equipment and readable storage medium
CN115658165A (en) Method and device for starting tenant plug-in and realizing in-process communication
Bracciali et al. Adapting components with mismatching behaviours

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