Non-intrusive interface expansion method and apparatus, electronic device, and storage medium
By using a non-intrusive interface extension method, the timing function and callback function parameters of the Spring application are obtained, and the target interface is defined. This solves the security risks caused by the need to modify code for function extension in the Java Virtual Machine, and achieves extension without code modification and meets business requirements.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2026-04-02
AI Technical Summary
In existing technologies, extending Spring application functions in the Java Virtual Machine requires modifying the code, which leads to security and version management risks.
By using a non-intrusive interface extension method, the timing function is obtained from the Spring application of the target virtual machine, the parameter information of the callback function is parsed, the context object and Bean object are determined, and the target interface is defined. External applications can access the target function without modifying the code.
It enables the extension of function objects without modifying the code in the Java Virtual Machine, meeting more business needs, reducing security and code management risks, and improving testing efficiency.
Smart Images

Figure CN2025124076_02042026_PF_FP_ABST
Abstract
Description
Non-intrusive interface expansion method and device, electronic equipment and storage medium
[0001] The present application claims priority from the Chinese patent application No. 202411363512.4 filed on September 27, 2024, and entitled "Non-intrusive interface expansion method and device, electronic equipment and storage medium", the whole content of which is incorporated herein by reference. TECHNICAL FIELD
[0002] The present application relates to the technical field of software development, in particular to a non-intrusive interface expansion method and device, electronic equipment and storage medium. BACKGROUND
[0003] Java language is a programming language that is widely used due to its cross-platform, object-oriented, indirect and multi-threading advantages. In the Java programming process, the Java virtual machine is the basis for the running of Java programs, which provides a stable, safe and efficient running environment for Java programs, so that Java language can realize the "write once, run anywhere" feature on different platforms.
[0004] Currently, in order to better manage Java programs, the Spring framework is introduced, which can manage Java application programs throughout their life cycle. The Spring application program is a Java application program written based on the Spring framework. The functions in the completed Spring application program can only be called internally by the Java virtual machine.
[0005] Based on the growth of testing, operation and maintenance or business needs, it is necessary to expand the functions in the Spring application program. In related technologies, the functions in the Spring application program need to be expanded by modifying the code in an intrusive manner. This method will introduce risks in version management and operation and maintenance.
[0006] At present, no effective solution has been proposed to solve the above problems. SUMMARY
[0007] The embodiments of the present application provide a non-intrusive interface expansion method and device, electronic equipment and storage medium to at least solve the technical problem that in related technologies, when the internal functions of the virtual machine are expanded outward, the modification of the code is required, which will cause security risks in the virtual machine.
[0008] According to an aspect of the embodiments of the present application, a non-intrusive interface expansion method is provided, which is applied to a non-intrusive interface expansion system. The non-intrusive interface expansion method comprises the following steps: obtaining a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function comprises at least one of the following: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, and a function object that has created a calling interface; obtaining a callback function when the timing function is called, and analyzing the callback function to obtain parameter information of the callback function; determining a context object of the Spring application based on the parameter information of the callback function, and obtaining a Bean object of the Spring application based on the context object, wherein the Bean object is an entrance to a container object in a Spring framework; obtaining a target function through the Bean object, and defining a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or a service running outside the target virtual machine.
[0009] Optionally, the step of obtaining the timing function from the Spring application comprises the following steps: monitoring the Spring application in the target virtual machine to obtain function objects called in the Spring application and calling frequencies of the function objects in a target period; and selecting the function object as the timing function in a case where the calling frequency of the function object in the target period is greater than the preset calling frequency threshold.
[0010] Optionally, the step of obtaining the timing function from the Spring application comprises the following steps: obtaining the created calling interface in the Spring application; calling a function object in the Spring program through the created calling interface, and taking the function object for which the calling is successful as the timing function.
[0011] Optionally, the step of determining the context object of the Spring application based on the parameter information of the callback function comprises the following steps: obtaining a class loader of the Spring application through the parameter information; obtaining a class object that implements a context interface through the class loader in a reflective manner; and determining the context object of the Spring application from the class object in a reflective manner.
[0012] Optionally, after the target interface is defined for the target function, the method further comprises the following steps: testing the target interface to obtain a test result; and storing the target function and the target interface corresponding to the target function to a target function storage container in a case where the test result indicates that the target interface passes the test.
[0013] Optionally, the step of testing the target interface comprises: in a test environment, calling the target function based on the target interface, obtaining data transmitted by the target function in the calling process; obtaining pre-defined transmission parameters of the target function, comparing the data transmitted by the target function in the calling process with the pre-defined transmission parameters to obtain a comparison result; and in a case where the comparison result indicates that the data transmitted by the target function in the calling process is consistent with the pre-defined transmission parameters, determining that the target interface passes the test.
[0014] Optionally, the type of the parameter information of the callback function comprises at least one of: event parameter information of a processing event involved in execution of the callback function, result parameter information of the processing event involved in execution of the callback function, and state parameter information of the processing event involved in execution of the callback function.
[0015] According to another aspect of the embodiments of the present application, a non-intrusive interface expansion device is also provided, which is applied to a non-intrusive interface expansion system. The non-intrusive interface expansion device comprises: an obtaining unit configured to obtain a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function comprises at least one of: a function object whose calling frequency in a target period is higher than a pre-set calling frequency threshold, and a function object that has created a calling interface; an analyzing unit configured to obtain a callback function when the timing function is called, and analyze the callback function to obtain parameter information of the callback function; a determining unit configured to determine a context object of the Spring application based on the parameter information of the callback function, and obtain a Bean object of the Spring application based on the context object, wherein the Bean object is an entrance to a container object in a Spring framework; and a defining unit configured to obtain a target function through the Bean object, and define a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or a service running outside the target virtual machine.
[0016] Optionally, the obtaining unit comprises: a first monitoring module configured to monitor a Spring application in the target virtual machine, and obtain a function object called in the Spring application and a calling frequency of the function object in a target period; and a first selecting module configured to select the function object as the timing function in a case where the calling frequency of the function object in the target period is greater than the pre-set calling frequency threshold.
[0017] Optionally, the obtaining unit comprises: a first obtaining module configured to obtain the created invocation interface in the Spring application; and a first calling module configured to call a function object in the Spring application through the created invocation interface, and take the function object whose calling succeeds as the timing function.
[0018] Optionally, the determining unit comprises: a second obtaining module configured to obtain a class loader of the Spring application through the parameter information; a third obtaining module configured to obtain a class object implementing a context interface through reflection using the class loader; and a first determining module configured to determine a context object of the Spring application from the class object through reflection.
[0019] Optionally, the non-intrusive interface expansion apparatus further comprises: a first testing module configured to test the target interface to obtain a testing result; and a first storage module configured to store the target function and the target interface corresponding to the target function into a target function storage container in a case where the testing result indicates that the target interface passes the test.
[0020] Optionally, the first testing module comprises: a first calling sub-module configured to call the target function based on the target interface in a testing environment to obtain data transmitted in a calling process of the target function; a first comparison sub-module configured to obtain pre-defined transmission parameters of the target function, compare the data transmitted in the calling process of the target function with the pre-defined transmission parameters to obtain a comparison result; and a first determining sub-module configured to determine that the target interface passes the test in a case where the comparison result indicates that the data transmitted in the calling process of the target function is consistent with the pre-defined transmission parameters.
[0021] Optionally, the type of the parameter information of the callback function comprises at least one of: event parameter information of a processing event involved when the callback function is executed, result parameter information of the processing event, and state parameter information of the processing event.
[0022] According to another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which comprises a stored computer program, wherein the computer program, when executed, controls a device where the computer readable storage medium is located to perform any of the above non-intrusive interface expansion methods.
[0023] According to a further aspect of the embodiments of the present application, an electronic device is also provided, which includes one or more processors and a memory configured to store one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement any of the above non-intrusive interface extension methods.
[0024] In the present application, the following steps are taken: first, obtaining a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function includes at least one of the following: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, and a function object for which a calling interface has been created; then, obtaining a callback function when the timing function is called, and analyzing the callback function to obtain parameter information of the callback function; based on the parameter information of the callback function, determining a context object of the Spring application, and based on the context object, obtaining a Bean object of the Spring application, wherein the Bean object is an entry for accessing a container object in a Spring framework; finally, obtaining a target function through the Bean object, and defining a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or service running outside the target virtual machine.
[0025] In the present application, a proper timing function is selected, a context object of a Spring application is obtained through a callback function when the timing function is called, and an entry for accessing a container object in a Spring framework is obtained according to the context object, so as to cut into a Java virtual machine, select a target function from the Java virtual machine, and define a target interface, so that an application outside the Java virtual machine can call the target function through the target interface, thereby realizing non-intrusive extension of a function object in the Java virtual machine without modifying code, meeting more business requirements, and further solving the technical problem in the related art that a virtual machine has a security risk when an internal function of the virtual machine is extended to the outside through a code modification manner. BRIEF DESCRIPTION OF DRAWINGS
[0026] The accompanying drawings, which are included to provide a further understanding of the present application and constitute a part of this application, illustrate certain illustrative embodiments of the present application and together with the description help explain the present application. In the drawings:
[0027] FIG. 1 is a flowchart of an optional non-intrusive interface extension method according to an embodiment of the present application;
[0028] FIG. 2 is an optional non-intrusive interface extension system architecture diagram according to an embodiment of the present application;
[0029] Fig. 3 is a schematic diagram of an optional non-intrusive interface expansion process according to an embodiment of the present application;
[0030] Fig. 4 is an optional target function expansion schematic diagram according to an embodiment of the present application;
[0031] Fig. 5 is a schematic diagram of an optional non-intrusive interface expansion device according to an embodiment of the present application;
[0032] Fig. 6 is a hardware structure block diagram of an electronic device (or mobile device) of a non-intrusive interface expansion method according to an embodiment of the present application. DETAILED DESCRIPTION
[0033] In order to make the personnel in the technical field better understand the present application scheme, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present application.
[0034] It should be noted that the terms "first", "second" and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0035] In order to facilitate those skilled in the art to understand the present application, the following explains some terms or names involved in the embodiments of the present application:
[0036] Java Virtual Machine, Java Virtual Machine, JVM for short, is a virtual computer that can execute Java bytecode.
[0037] JVMTI, full name JVM Tool Interface, Java Virtual Machine Tool Interface.
[0038] Bytecode enhancement technology, based on JVMTI, to obtain information and status of Java program and change the running process of Java program. It is usually used for log tracking, dynamic proxy, etc.
[0039] Spring Framework, an enterprise-level service framework for life cycle management of Java objects.
[0040] Spring application, a Java application written based on the Spring Framework.
[0041] It should be noted that the non-intrusive interface expansion method and device in the present application can be used in the case of expanding the target function in the virtual machine in the field of software development technology, and can also be used in the case of expanding the target function in the virtual machine in any field other than the field of software development technology. The application field of the non-intrusive interface expansion method and device in the present application is not limited.
[0042] It should be noted that the related information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are information and data authorized by the user or authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of related data comply with relevant laws, regulations and standards in relevant regions, necessary security measures are taken, do not violate public order and good customs, and provide corresponding operation portal for users to choose authorization or refusal. For example, an interface is provided between the system and the related users or institutions. Before obtaining the related information, the interface needs to send a request to the aforementioned user or institution, and after receiving the consent information feedback from the aforementioned user or institution, the related information is obtained.
[0043] It should be noted that in the present application, when collecting and analyzing customer information, the user is provided with a corresponding operation portal for the user to choose to agree or refuse the automatic decision result; if the user chooses to refuse, the expert decision process is entered.
[0044] The following embodiments of the present application can be applied to various non-intrusive interface expansion systems / applications / devices. The present application utilizes the event-driven characteristics of bytecode enhancement technology, determines the appropriate timing function, and cuts into the Java virtual machine through the timing function to obtain the target function object and define the target interface for it. Without modifying the code, the target function in the Java virtual machine is expanded without intrusion to meet the testing, operation and maintenance or higher business needs.
[0045] The present application will be described in detail below in conjunction with various embodiments.
[0046] Embodiment one
[0047] According to the embodiments of the present application, an embodiment of a non-intrusive interface expansion method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in a different order.
[0048] FIG. 1 is a flowchart of an optional non-intrusive interface expansion method according to an embodiment of the present application, applied to a non-intrusive interface expansion system. As shown in FIG. 1, the non-intrusive interface expansion method includes the following steps:
[0049] Step S101, obtaining an opportunity function from a Spring application corresponding to a target virtual machine, wherein the opportunity function includes at least one of the following: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, and a function object for which a calling interface has been created;
[0050] Step S102, obtaining a callback function when the opportunity function is called, and parsing the callback function to obtain parameter information of the callback function;
[0051] Step S103, determining a context object of the Spring application based on the parameter information of the callback function, and obtaining a Bean object of the Spring application based on the context object, wherein the Bean object is an entry for accessing a container object in the Spring framework;
[0052] Step S104, obtaining a target function through the Bean object, and defining a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or service running outside the target virtual machine.
[0053] Through the above steps, first, an opportunity function is obtained from a Spring application corresponding to a target virtual machine, wherein the opportunity function includes at least one of the following: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, and a function object for which a calling interface has been created. Then, a callback function when the opportunity function is called is obtained, and the callback function is parsed to obtain parameter information of the callback function. Based on the parameter information of the callback function, a context object of the Spring application is determined, and based on the context object, a Bean object of the Spring application is obtained, wherein the Bean object is an entry for accessing a container object in the Spring framework. Finally, a target function is obtained through the Bean object, and a target interface is defined for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or service running outside the target virtual machine.
[0054] In the embodiment, a proper timing function is selected, a context object of the Spring application is acquired through a callback function when the timing function is called, and an entry for accessing a container object in the Spring framework is acquired according to the context object, so as to cut into the Java virtual machine, select a target function and define a target interface in the Java virtual machine, so that the application outside the Java virtual machine can call the target function through the target interface, thereby realizing the expansion of the function object in the Java virtual machine without modifying the code, meeting more business requirements, and further solving the technical problem in the related art that the internal function of the virtual machine needs to be expanded to the outside through the way of modifying the code, which causes the security risk of the virtual machine.
[0055] The embodiment of the application will be described in detail below in combination with the above steps.
[0056] The interface expansion method provided by the embodiment of the application is non-intrusive, and the internal function of the Java virtual machine is expanded to an external interface based on the bytecode enhancement technology, so that it can be applied to more business scenarios and meet higher business requirements. The original Spring application code does not need to be modified when the Spring application interface is expanded. Many restrictions in use scenarios can be avoided, for example, the interface expansion of an application that cannot be stopped running. At the same time, the risk of code management can be avoided, for example, the risk caused by the modification of the application code in the test phase is avoided, and the application interface is expanded to improve the test efficiency or implement some test scenarios that are not easy to implement.
[0057] It should be noted that the bytecode enhancement technology can only be passively accepted by the Java application information in an event-driven manner to change the running process of the program, so as to realize the function enhancement of the original program, and cannot provide active trigger type function expansion. The embodiment of the application utilizes the event-driven characteristics of the bytecode enhancement technology, cuts into the JVM through a proper timing function, acquires a target function object from the Java virtual machine and stores it; when the application outside the Java virtual machine is actively triggered, the target function object is used to call the target interface corresponding to the target function through reflection, so as to realize the expansion of the target function, and the control of the target function is changed from active to passive.
[0058] In step S101, a timing function is acquired from the Spring application corresponding to the target virtual machine.
[0059] It should be noted that when the interface is expanded, a function that can determine the running time in the Spring application is first found, and the appropriate function is obtained, which helps to cut into the Java virtual machine faster and more accurately, so that the non-intrusive interface expansion system can access the function object in the Java virtual machine and expand it.
[0060] It should be noted that the function object of the Spring application is uniformly managed by the Spring framework in the Spring context object, so in order to obtain the target function object, the Spring context must be obtained. And to get the Spring context, you must get the ClassLoader (class loader) it is in, so choosing the right timing function is the key to getting the target function object. In the embodiment of the application, functions triggered automatically in the Spring application with a certain period or functions triggered by external interfaces can be called as timing functions, that is, the timing function can be a function object whose call frequency in a target period is higher than a preset call frequency threshold and a function object that has created a call interface.
[0061] Optionally, the step of obtaining the timing function from the Spring application comprises: monitoring the Spring application in the target virtual machine, obtaining the function object called in the Spring application and the call frequency of the function object in a target period; and selecting the function object as the timing function if the call frequency of the function object in the target period is greater than a preset call frequency threshold.
[0062] It should be noted that when selecting the timing function, the Spring application in the target Java virtual machine can be monitored to determine the function object called in the Spring application and the call frequency of the function object in a pre-set target period, and the function object that is called in a certain period according to the call frequency is selected as the timing function.
[0063] Optionally, the step of obtaining the timing function from the Spring application comprises: obtaining the created call interface in the Spring application; calling the function object in the Spring program through the created call interface, and selecting the function object that is successfully called as the timing function.
[0064] It should be noted that when selecting the appropriate timing function, the function object that has created an interface in the Spring program and can be successfully called can also be obtained as the timing function.
[0065] In step S102, the callback function when the timing function is called is obtained, and the callback function is parsed to obtain the parameter information of the callback function.
[0066] It should be noted that the timing function generally refers to a function triggered automatically at a specific time point or when a specific event occurs, and the callback function refers to a function passed as a parameter to another function and called when a specific event occurs. When the timing function is triggered, the callback function is often executed. The callback function can be predefined and obtained directly when the timing function is triggered, or registered when the timing function is triggered. The timing function internally traverses the registered callback list and calls the callback function in turn, which is usually completed in a certain phase of the timing function. The timing function passes parameters to the callback function so that the callback function can perform specific operations according to these parameters. By parsing the callback function, the parameters required by the event involved in the execution process of the timing function and the return value after the event is executed can be obtained.
[0067] Optionally, the type of the parameter information of the callback function includes at least one of the following: event parameter information of a processing event involved in execution of the callback function, result parameter information of the processing event involved in the execution of the callback function, and state parameter information of the processing event involved in the execution of the callback function.
[0068] It should be noted that the parameter information obtained by parsing the callback function in the embodiments of the present application can be: event parameter information of a processing event involved in execution of the callback function, result parameter information of the processing event involved in the execution of the callback function, and state parameter information of the processing event involved in the execution of the callback function.
[0069] In step S103, the context object of the Spring application program is determined based on the parameter information of the callback function, and the Bean object of the Spring application program is obtained based on the context object.
[0070] It should be noted that the agent or attach mode of the bytecode enhancement technology is used in the embodiments of the present application to mount on the running Spring application program. After the call event of the timing function is intercepted, the class loader of the Spring application program is obtained through reflection, and then the context object is obtained. The Bean object of the Spring application program is obtained through the context object, and then all function objects on the Spring application program are accessed through the Bean object. The Bean object is the entrance to access the container object in the Spring framework.
[0071] Optionally, the step of determining the context object of the Spring application program based on the parameter information of the callback function includes: obtaining the class loader of the Spring application program through the parameter information; using the class loader to obtain a class object implementing the context interface through reflection; and determining the context object of the Spring application program from the class object through reflection.
[0072] It should be noted that the ClassLoader of the Spring application is obtained through the parameters of the callback function. The ClassLoader is a component of the Java virtual machine responsible for dynamically loading Java classes and resources. During the runtime of a Java program, when the Java program needs to use a class (for example, instantiating an object through the new keyword or referencing a class through reflection), the ClassLoader is responsible for loading the.class file of the class into memory and creating a corresponding Class object. After determining the class loader of the Spring application, the class object that implements the context interface can be obtained through reflection based on the class loader, and then the context object of the Spring application can be obtained from the class object through reflection.
[0073] In step S104, the target function is obtained through the Bean object, and a target interface is defined for the target function.
[0074] It should be noted that the Bean object is an entry to access the container object in the Spring framework. The Bean object stores a plurality of function objects, and the target function can be obtained from the Spring program through the Bean object, and the target interface is defined for the target function to achieve the expansion of the target function.
[0075] It should be noted that after the target interface is defined, the target function is accessed by the external application program through the target interface, and the external application program represents a software program or service running outside the target virtual machine, and then the target interface corresponding to the target function is called to execute related businesses.
[0076] Optionally, after the target interface is defined for the target function, the target interface is tested to obtain a test result, and in a case where the test result indicates that the target interface passes the test, the target function and the target interface corresponding to the target function are stored to a target function storage container.
[0077] It should be noted that after the target interface is defined for the target function, the target interface needs to be tested, and in a case where the test result indicates that the target interface passes the test, the target function and the target interface corresponding to the target function are stored to a target function storage container for calling by the external application program.
[0078] Optionally, the step of testing the target interface includes: in a test environment, calling the target function based on the target interface, obtaining data transmitted by the target function in the calling process; obtaining a pre-defined transmission parameter of the target function, comparing the data transmitted by the target function in the calling process with the pre-defined transmission parameter to obtain a comparison result; and in a case where the comparison result indicates that the data transmitted by the target function in the calling process is consistent with the pre-defined transmission parameter, determining that the target interface passes the test.
[0079] It should be noted that when testing, according to the external interface definition and the target function definition, the necessary parameters and return values are adapted and transmitted to ensure that the necessary information is passed and fed back when the function is called. Specifically, in the test environment, the target function is called based on the target interface, and the comparison result between the data transmitted by the target function in the calling process and the pre-defined transmission parameters of the target function is used to determine whether the target interface passes the test. The target interface that passes the test can be expanded for external program calling.
[0080] The following will be described in detail in combination with another optional embodiment.
[0081] FIG. 2 is an optional non-intrusive interface expansion system architecture diagram according to an embodiment of the present application. As shown in FIG. 2, the non-intrusive interface expansion system interacts with the Spring application running architecture. The non-intrusive interface expansion system includes a bytecode enhancement module, a target function object acquisition module, and an external interface definition module. Specifically,
[0082] The bytecode enhancement module is a code and interface that uses JVMTI (Java Virtual Machine Tool Interface) to obtain various events, information, and states in the Java virtual machine and can intervene in the execution flow of JVM. It highly abstracts the events, information, and states that can be obtained in JVM. Other modules can program based on the interface provided by the bytecode enhancement module to define the events, information, and states that need to be obtained and the subsequent execution flow. The bytecode enhancement module can be developed based on JVMTI, or existing bytecode enhancement tools such as ASM, Javassist, Byte Buddy, etc. can be directly used.
[0083] The target function object acquisition module is configured to obtain the target function object, store it, and provide it for calling by the external interface definition module. The target function object needs to be obtained by first cutting into JVM through the bytecode enhancement module, grabbing the context object of the Spring application, and obtaining the target function object from the context object by reflection.
[0084] The external interface definition module is configured to define the interface for external users to remotely call through HTTP and other network protocols. When the external interface is called, the target function is called, and the parameters and return values of the external interface and the target function are converted and adapted as necessary to ensure that the parameters and return values are correctly passed between the external interface and the target function.
[0085] The embodiment of the present application cuts into the Java virtual machine by selecting a proper timing function, acquires the target function, and the Java virtual machine is managed by the Spring framework. The objects of the Spring application are uniformly managed in the Spring context by the Spring framework, therefore, to acquire the target function object, the Spring context must be acquired. To acquire the Spring context, the ClassLoader where the Spring context is located must be acquired, therefore, selecting a proper timing function is the key to acquiring the target function object. In the embodiment of the present application, a function triggered automatically in the Spring application with a certain period or a function triggered by an external interface is selected as the timing function. The agent or attach mode of the bytecode enhancement technology is mounted on the running Spring application, after the calling event of the timing function is intercepted, the ClassLoader is acquired by the reflection method, then the context object of the Spring application and the Bean object of the Spring application are acquired, finally the target function object is acquired and stored, waiting for the active trigger to be used.
[0086] The non-intrusive interface expansion system is used to expand the non-intrusive interface, the function in the Java virtual machine is expanded, and the function is called by the external application program. FIG. 3 is a schematic diagram of an optional non-intrusive interface expansion process according to the embodiment of the present application. As shown in FIG. 3, the non-intrusive interface expansion process includes the following steps.
[0087] Step one, determining the timing function;
[0088] A timing function that can be determined to run in the Spring application is found, for example, a function that is called cyclically with a certain period, or a function triggered by an external interface. The full name of the class where the timing function calling code is located (including the package name and the class name) and the function name of the called function are recorded.
[0089] Step two, intercepting the timing function to acquire the ClassLoader (corresponding to the above-mentioned class loader);
[0090] In the bytecode enhancement module, the callback function when the timing function calling occurs is defined and registered. In the callback function, the ClassLoader of the Spring application is acquired through the parameters of the callback function. The full name of the class that implements the ApplicationContextAware interface (corresponding to the above-mentioned context interface) in the application program is found, and the ClassLoader is used to acquire the class object through the reflection method.
[0091] Step three, acquiring the context object of the Spring application;
[0092] The static variable applicationContext (corresponding to the context object) in the implementation class of the ApplicationContextAware interface stores the Spring application context. The static variable is accessed by using the class object and the Spring application context object is obtained by reflection.
[0093] Step four, obtaining and storing the target function object;
[0094] The application context of the Spring framework is used to obtain the application bean object, and the target function object is obtained and stored from the bean object by reflection.
[0095] Step five, defining an interface to call the target function.
[0096] An external interface is defined for the obtained target function, such as an HTTP interface, in which the target function object stored in step four is obtained, and the target function is called by reflection. When calling, necessary parameters and return values are adapted and transmitted according to the external interface definition and the target function definition, so as to ensure the transmission and feedback of necessary information during function calling.
[0097] Figure 4 is a schematic diagram of an optional target function expansion principle according to an embodiment of the present application. Based on bytecode enhancement technology, the Java virtual machine can be accessed without invasion, but only through event-driven mode, and the program running process is changed after passively accepting the information of the Java application, so as to realize the function enhancement of the original program. It cannot provide active trigger type function expansion. As shown in Figure 4, the event-driven feature of the bytecode enhancement technology is used to determine the appropriate timing function, cut into the JVM (Java virtual machine), obtain the target function object and store it in the target function storage container; when actively triggered, the external user initiates a calling request, uses the target function object obtained in advance, and calls the target function by reflection, so as to realize the inversion of the control of the target function from passive to active.
[0098] The event-driven feature of the bytecode enhancement technology is used to determine the appropriate timing function, and the timing function is used to cut into the Java virtual machine, obtain the target function object and define the target interface, so as to non-invasively expand the target function in the Java virtual machine without modifying the code, so as to meet higher business requirements.
[0099] The non-invasive interface expansion method based on the embodiment of the present application expands the interface without modifying the Spring application code, which not only makes it possible to meet the needs of scenes that are restricted and cannot modify the code but need to expand the interface, but also provides a new technical route for the scene of expanding the interface.
[0100] The embodiment of the present application can greatly reduce the risk of modifying the code while expanding the interface without modifying the Spring application code; the interface expansion method in the embodiment of the present application only provides a channel for externally triggering the internal function of the Spring application, and does not interfere with or affect the original program and operation. In addition, since the bytecode enhancement technology is based on the mounting mechanism of Java, the interface expansion module can be installed or uninstalled at any time while keeping the Spring application running without stopping, greatly reducing the risk of expanding the interface.
[0101] In some scenarios, the interface expansion method of the present application can greatly improve work efficiency, for example: when testing a software product with a timing processing mechanism, an instant processing interface can be expanded to save waiting time and improve testing efficiency.
[0102] The following will be described in detail in conjunction with another embodiment.
[0103] Embodiment Two
[0104] The non-intrusive interface expansion device provided in the embodiment includes a plurality of implementation units, each implementation unit corresponding to each implementation step in the above-mentioned embodiment one, and the specific implementation manner and beneficial effects can refer to the foregoing method embodiment, which will not be described here again.
[0105] FIG. 5 is a schematic diagram of an optional non-intrusive interface expansion device according to an embodiment of the present application. As shown in FIG. 5, the non-intrusive interface expansion device can include an acquisition unit 51, an analysis unit 52, a determination unit 53, and a definition unit 54, wherein,
[0106] The acquisition unit 51 is configured to acquire a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function includes at least one of the following: a function object with a calling frequency higher than a preset calling frequency threshold in a target period, and a function object having created a calling interface;
[0107] The analysis unit 52 is configured to acquire a callback function when the timing function is called, and analyze the callback function to obtain parameter information of the callback function;
[0108] The determination unit 53 is configured to determine a context object of the Spring application based on the parameter information of the callback function, and acquire a Bean object of the Spring application based on the context object, wherein the Bean object is an entry for accessing a container object in the Spring framework;
[0109] The definition unit 54 is configured to obtain the target function through the Bean object, and define a target interface for the target function, wherein after the target interface is defined, the external application program accesses the target function through the target interface, and the external application program represents a software program or a service running outside the target virtual machine.
[0110] The non-intrusive interface expansion device obtains the timing function from the Spring application corresponding to the target virtual machine through the obtaining unit 41, wherein the timing function includes at least one of the following: a function object whose calling frequency in the target period is higher than a preset calling frequency threshold, and a function object for which a calling interface has been created; the callback function when the timing function is called is obtained through the parsing unit 42, and the callback function is parsed to obtain the parameter information of the callback function; the context object of the Spring application is determined based on the parameter information of the callback function through the determination unit 43, and the Bean object of the Spring application is obtained based on the context object, wherein the Bean object is an entrance to access the container object in the Spring framework; the target function is obtained through the Bean object through the definition unit 44, and a target interface is defined for the target function, wherein after the target interface is defined, the external application program accesses the target function through the target interface, and the external application program represents a software program or a service running outside the target virtual machine.
[0111] In this embodiment, appropriate timing functions are selected, the context object of the Spring application is obtained through the callback function when the timing function is called, the entrance to access the container object in the Spring framework is obtained according to the context object, thereby cutting into the Java virtual machine, selecting the target function from the Java virtual machine and defining the target interface, so that the application program outside the Java virtual machine can call the target function through the target interface, thereby realizing the expansion of the function object in the Java virtual machine without modifying the code, meeting more business requirements, and further solving the technical problem that in related technologies, the internal function of the virtual machine needs to be expanded to the outside through the way of modifying the code, which may cause security risks of the virtual machine.
[0112] Optionally, the obtaining unit 51 includes: a first monitoring module configured to monitor the Spring application in the target virtual machine, and obtain the function object called in the Spring application and the calling frequency of the function object in the target period; and a first selection module configured to select the function object as the timing function if the calling frequency of the function object in the target period is greater than a preset calling frequency threshold.
[0113] Optionally, the acquisition unit 51 comprises: a first acquisition module configured to acquire the created invocation interface in the Spring application; and a first execution module configured to invoke the function object in the Spring application through the created invocation interface, and take the function object successfully invoked as the timing function.
[0114] Optionally, the determination unit 53 comprises: a second acquisition module configured to acquire the class loader of the Spring application through the parameter information; a third acquisition module configured to acquire the class object implementing the context interface through reflection using the class loader; and a first determination module configured to determine the context object of the Spring application from the class object through reflection.
[0115] Optionally, the non-intrusive interface expansion device further comprises: a first test module configured to test the target interface to obtain a test result; and a first storage module configured to store the target function and the target interface corresponding to the target function into the target function storage container in a case where the test result indicates that the target interface passes the test.
[0116] Optionally, the first test module comprises: a first invocation submodule configured to invoke the target function based on the target interface in a test environment to acquire data transmitted in the invocation process of the target function; a first comparison submodule configured to acquire the pre-defined transmission parameter of the target function, and compare the data transmitted in the invocation process of the target function with the pre-defined transmission parameter to obtain a comparison result; and a first determination submodule configured to determine that the target interface passes the test in a case where the comparison result indicates that the data transmitted in the invocation process of the target function is consistent with the pre-defined transmission parameter.
[0117] Optionally, the type of the parameter information of the callback function comprises at least one of: event parameter information of a processing event involved in execution of the callback function, result parameter information of the processing event involved in execution of the callback function, and state parameter information of the processing event involved in execution of the callback function.
[0118] The non-intrusive interface expansion device can further comprise a processor and a memory, and the acquisition unit 51, the analysis unit 52, the determination unit 53, the definition unit 54, etc. are all stored in the memory as program units, and the processor executes the program units stored in the memory to realize the corresponding functions.
[0119] The processor comprises a kernel, and the kernel calls the corresponding program units from the memory. The kernel can be one or more, and the target function corresponding to the virtual machine is expanded by adjusting the kernel parameters.
[0120] The memory can include a non-persistent memory in a computer readable medium, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
[0121] According to another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which includes a stored computer program, wherein the computer program, when executed, controls the device where the computer readable storage medium is located to perform any of the above non-invasive interface expansion methods.
[0122] According to another aspect of the embodiments of the present application, an electronic device is also provided, which includes one or more processors and a memory configured to store one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement any of the above non-invasive interface expansion methods.
[0123] According to another aspect of the embodiments of the present application, a computer program product is also provided, which includes a computer program, wherein the computer program, when executed by a processor, implements any of the above non-invasive interface expansion methods.
[0124] The present application also provides a computer program product adapted to perform, when executed on a data processing device, a program of the following method steps: obtaining a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function includes at least one of the following: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, a function object that has created a calling interface; obtaining a callback function when the timing function is called, and parsing the callback function to obtain parameter information of the callback function; determining a context object of the Spring application based on the parameter information of the callback function, and obtaining a Bean object of the Spring application based on the context object, wherein the Bean object is an entrance to access a container object in the Spring framework; obtaining a target function through the Bean object, and defining a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or service running outside the target virtual machine.
[0125] The application further provides a computer program product, which is suitable for executing the program with the following method steps when executed on a data processing device: the step of obtaining the timing function from the Spring application comprises: monitoring the Spring application in the target virtual machine, obtaining the function object called in the Spring application and the calling frequency of the function object in the target period; and in the case that the calling frequency of the function object in the target period is greater than the preset calling frequency threshold, selecting the function object as the timing function.
[0126] The application further provides a computer program product, which is suitable for executing the program with the following method steps when executed on a data processing device: the step of obtaining the timing function from the Spring application comprises: obtaining the created calling interface in the Spring application; calling the function object in the Spring program through the created calling interface, and taking the function object with successful calling as the timing function.
[0127] The application further provides a computer program product, which is suitable for executing the program with the following method steps when executed on a data processing device: the step of determining the context object of the Spring application based on the parameter information of the callback function comprises: obtaining the class loader of the Spring application through the parameter information; obtaining the class object implementing the context interface through the reflection mode using the class loader; and determining the context object of the Spring application from the class object through the reflection mode.
[0128] The application further provides a computer program product, which is suitable for executing the program with the following method steps when executed on a data processing device: after the target interface is defined for the target function, the method further comprises: testing the target interface to obtain a test result; and in the case that the test result indicates that the target interface passes the test, storing the target function and the target interface corresponding to the target function to the target function storage container.
[0129] The application further provides a computer program product, which is suitable for executing the program with the following method steps when executed on a data processing device: the step of testing the target interface comprises: calling the target function based on the target interface in the test environment, and obtaining the data transmitted in the calling process of the target function; obtaining the transmission parameter defined in advance by the target function, comparing the data transmitted in the calling process of the target function with the transmission parameter defined in advance to obtain a comparison result; and in the case that the comparison result indicates that the data transmitted in the calling process of the target function is consistent with the transmission parameter defined in advance, determining that the target interface passes the test.
[0130] The application further provides a computer program product, which, when executed on a data processing device, is further adapted to execute a program of the following method steps: the type of the parameter information of the callback function comprises at least one of the following: event parameter information of a processing event involved when the callback function is executed, result parameter information of the processing event involved when the callback function is executed, and state parameter information of the processing event involved when the callback function is executed.
[0131] Fig. 6 is a hardware structure block diagram of an electronic device (or a mobile device) according to a non-intrusive interface expansion method according to an embodiment of the present application. As shown in Fig. 6, the electronic device can include one or more processors 602 (the processor 602 can include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 604 for storing data. In addition, the electronic device can further include a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which can be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply and / or a camera. Those skilled in the art can understand that the structure shown in Fig. 6 is only schematic, and does not limit the structure of the above-mentioned electronic device. For example, the electronic device can further include more or fewer components than those shown in Fig. 6, or have a different configuration from that shown in Fig. 6.
[0132] The above-mentioned serial numbers of the embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0133] In the above-mentioned embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.
[0134] In the several embodiments provided by the present application, it should be understood that the disclosed technology can be implemented in other ways. Of course, the embodiment described above is only illustrative. For example, the division of units can be a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interface, unit or module, and can be electrical or other forms.
[0135] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. they can be located in one place, or distributed on multiple units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0136] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0137] When the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in part, or all or part of the technical solutions, can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The foregoing storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, and various program codes that can store media.
[0138] The above is only the preferred embodiment of the present application, and it should be pointed out that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should be considered as the protection scope of the present application.
Claims
1. A non-intrusive interface expansion method applied to a non-intrusive interface expansion system, the non-intrusive interface expansion method comprising: obtaining a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function comprises at least one of: a function object whose calling frequency in a target period is higher than a preset calling frequency threshold, and a function object that has created a calling interface; obtaining a callback function when the timing function is called, and analyzing the callback function to obtain parameter information of the callback function; determining a context object of the Spring application based on the parameter information of the callback function, and obtaining a Bean object of the Spring application based on the context object, wherein the Bean object is an entrance to access a container object in a Spring framework; obtaining a target function through the Bean object, and defining a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or a service running outside the target virtual machine.
2. The method of claim 1, wherein, The step of obtaining the timing function from the Spring application comprises: monitoring the Spring application in the target virtual machine to obtain function objects called in the Spring application and calling frequencies of the function objects in a target period; selecting the function object as the timing function when the calling frequency of the function object in the target period is greater than the preset calling frequency threshold.
3. The method of claim 1, wherein, The step of obtaining the timing function from the Spring application comprises: obtaining the created calling interface in the Spring application; calling a function object in the Spring program through the created calling interface, and taking the function object that succeeds in calling as the timing function.
4. The method of claim 1, wherein, The step of determining the context object of the Spring application based on the parameter information of the callback function comprises: obtaining a class loader of the Spring application through the parameter information; obtaining a class object that implements a context interface through reflection using the class loader; determining the context object of the Spring application from the class object through reflection.
5. The method of claim 1, wherein, After the target interface is defined for the target function, the method further comprises: testing the target interface to obtain a test result; storing the target function and the target interface corresponding to the target function to a target function storage container when the test result indicates that the target interface passes the test.
6. The method of claim 5, wherein, The step of testing the target interface comprises: calling the target function based on the target interface in a test environment to obtain data transmitted in a calling process of the target function; obtaining transmission parameters defined in advance for the target function, comparing the data transmitted in the calling process of the target function with the transmission parameters defined in advance to obtain a comparison result; and In a case where the comparison result indicates that the target function is consistent with the predefined transmission parameter in data transmitted in a calling process, it is determined that the target interface passes the test.
7. The method of claim 1, wherein, The type of the parameter information of the callback function includes at least one of event parameter information of a processing event involved in execution of the callback function, result parameter information of the processing event, and state parameter information of the processing event. 8.A non-invasive interface expansion device applied to a non-invasive interface expansion system, the non-invasive interface expansion device comprising: an acquisition unit configured to acquire a timing function from a Spring application corresponding to a target virtual machine, wherein the timing function includes at least one of a function object whose calling frequency in a target period is higher than a preset calling frequency threshold and a function object of which a calling interface has been created; an analysis unit configured to acquire a callback function when the timing function is called and analyze the callback function to obtain parameter information of the callback function; a determination unit configured to determine a context object of the Spring application based on the parameter information of the callback function and acquire a Bean object of the Spring application based on the context object, wherein the Bean object is an entrance to a container object in a Spring framework; a definition unit configured to acquire a target function through the Bean object and define a target interface for the target function, wherein after the target interface is defined, an external application accesses the target function through the target interface, and the external application represents a software program or a service running outside the target virtual machine.
9. A computer readable storage medium comprising a stored computer program, wherein, controlling a device in which the computer-readable storage medium is located to perform the non-invasive interface expansion method of any one of claims 1 to 7 when the computer program is running.
10. An electronic device, comprising one or more processors and memory arranged to store one or more programs, wherein, The one or more programs, when executed by the one or more processors, cause the one or more processors to implement the non-invasive interface expansion method of any one of claims 1 to 7.
Citation Information
Patent Citations
OpenApi implementation method and device based on dynamic class loading
CN117632286A
Workflow engine function extension method and device, storage medium and electronic equipment
CN118276926A
Non-invasive interface expansion method and device, electronic equipment and storage medium
CN119127352A
Systems and methods for generating interfaces for callback functions in object-oriented classes
US11403074B1
Method and apparatus for injecting JAVA by tecode into target process
WO2015074526A1