Third-party interface calling methods, processors, and storage media
By using Java reflection to determine the target proxy object and request method in third-party interface calls, the problem of complex calls caused by repeated interface definitions is solved, thus improving efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-26
- Publication Date
- 2026-03-10
AI Technical Summary
In existing technologies, when making calls based on third-party interfaces, especially when using the OpenFeign framework, there are problems such as repeated interface definitions leading to complex calling processes and low work efficiency.
By calling the execution function of the Java reflection mechanism, the target proxy object and target request method corresponding to the request annotation are determined, the interface class is found and the interface request is generated, avoiding duplicate interface definitions and simplifying the calling process.
It eliminates the need for repeatedly defining interfaces, simplifies the process of calling third-party interfaces, and improves work efficiency.
Smart Images

Figure CN115357298B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a method for calling a third-party interface, a processor, and a storage medium. Background Technology
[0002] Currently, there are two main methods for making third-party API calls: one is based on a third-party client, and the other is based on the OpenFeign framework. The first method, based on a third-party client, is more complex, typically involving steps such as building the client object, configuring the calling method, configuring request parameters, initiating the request, and parsing the returned results. The second method, based on the OpenFeign framework, is much simpler. However, when using OpenFeign, the consumer needs to rewrite the API in its project code, and this API is identical to the code in the service provider's project. This leads to duplicate API definitions, making the API call process complex and inefficient. Summary of the Invention
[0003] The purpose of this application is to provide a method for calling a third-party interface, a processor, and a storage medium.
[0004] To achieve the above objectives, the first aspect of this application provides a method for invoking a third-party interface, comprising:
[0005] Obtain the calling instruction for the third-party interface, which carries request annotations;
[0006] The execution function of the Java reflection mechanism is invoked, and the execution function is run to determine the target proxy object and target request method corresponding to the request annotation;
[0007] Find the interface class corresponding to the target proxy object;
[0008] The execution function is run to determine the classpath by using the path parameter of the first annotation on the interface class.
[0009] Obtain the path parameter of the function annotation of the function to be executed, and determine it as the method path;
[0010] The target service package of the target proxy object is determined based on the interface class corresponding to the target proxy object, so as to obtain the package name address of the target service package;
[0011] Determine the target request parameters corresponding to the request annotation based on the target request method;
[0012] Generate an interface request for a third-party interface based on the package name address, target request method, class path, method path, and target request parameters, and then call the third-party interface according to the interface request.
[0013] In this embodiment of the application, calling the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: calling the execution function of the Java reflection mechanism and running the execution function to scan whether the request annotation includes a second annotation; if it is determined that the request annotation includes a second annotation, the target request method is determined to be the first target request method.
[0014] In this embodiment of the application, calling the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation further includes: if it is determined that the request annotation does not include the second annotation, running the execution function to scan whether the request annotation includes the third annotation; if it is determined that the request annotation includes the third annotation, determining the target request method as the second target request method.
[0015] In this embodiment of the application, if it is determined that the request annotation does not include the third annotation, the execution function is run to scan whether the request annotation includes the first annotation; if it is determined that the request annotation includes the first annotation, the execution function is run to obtain the method parameter of the first annotation; if the method parameter is the first method parameter, the target request method is determined to be the first target request method; if the method parameter is the second method parameter, the target request method is determined to be the second target request method.
[0016] In this embodiment of the application, the method further includes: the target request method includes a first target request method, and determining the target request parameters corresponding to the request annotation according to the target request method includes: when the target request method is the first target request method, running an execution function to traverse the parameter set of the first target request method to obtain the parameter name and parameter value of each first parameter in the parameter set; and concatenating the parameter names and parameter values of multiple first parameters in a preset order to obtain the target request parameters.
[0017] In this embodiment of the application, the method further includes: the target request method includes a second target request method, and determining the target request parameter corresponding to the request annotation according to the target request method includes: when the target request method is the second target request method, running an execution function to obtain the second parameter value of the second target request method; serializing the second parameter value using JSON format to obtain the string corresponding to the second parameter value; and determining the string as the target request parameter.
[0018] In this embodiment of the application, the method further includes: before obtaining the calling instruction for the third-party interface, generating a configuration file, the configuration file including a first configuration parameter and a second configuration parameter, the first configuration parameter being associated with a specified service package, and the second configuration parameter being used to specify the package name address of each service package; finding the interface class corresponding to the target proxy object includes: obtaining the first configuration parameter in the configuration file and scanning the service package associated with the first configuration parameter; finding the interface class that includes the first annotation in the service package associated with the first configuration parameter.
[0019] In this embodiment of the application, the method further includes: after generating the configuration file, calling the Java dynamic proxy mechanism to generate a dynamic proxy object from the interface class including the first annotation; and registering the dynamic proxy object to the object storage container; running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: running the execution function to find the dynamic proxy object corresponding to the request annotation from the object storage container and determine it as the target proxy object.
[0020] In this embodiment of the application, the method further includes: after calling a third-party interface according to an interface request, receiving data returned by the third-party interface; calling the execution function of the Java reflection mechanism, running the execution function to determine the data type of the returned data; and, according to the data type, using a deserialization operation to deserialize the returned data into data of a preset format.
[0021] A second aspect of this application provides a processor configured to execute the aforementioned method of calling the third-party interface.
[0022] A third aspect of this application provides a machine-readable storage medium storing instructions that, when executed by a processor, configure the processor to perform the aforementioned invocation method of the third-party interface.
[0023] The above technical solution determines the target proxy object and target request method corresponding to the request annotation on the third-party interface call instruction by calling the execution function of the Java reflection mechanism. Then, it locates the interface class corresponding to the target proxy object. Next, it runs the execution function to determine the path parameter of the first annotation of the interface class, thus obtaining the classpath. The method path is then determined by the path parameter in the function annotation of the execution function. Following this, the target service package of the target proxy object is determined based on the interface class corresponding to the target proxy object, thus obtaining the package name address of the target service package. Furthermore, the target request parameters corresponding to the request annotation can be determined based on the target request method. Finally, an interface request for the third-party interface is generated based on the package name address, target request method, classpath, method path, and target request parameters, and then the third-party interface is called according to the interface request. This solution eliminates the need to repeatedly define interfaces, simplifying the third-party interface calling process and improving work efficiency.
[0024] Other features and advantages of the embodiments of this application will be described in detail in the following detailed description section. Attached Figure Description
[0025] The accompanying drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the following detailed description to explain the embodiments of this application, but do not constitute a limitation on the embodiments of this application. In the drawings:
[0026] Figure 1 The illustration shows a flowchart of a method for invoking a third-party interface according to an embodiment of this application;
[0027] Figure 2 The schematic diagram illustrates a flowchart of a method for invoking a third-party interface according to another embodiment of this application;
[0028] Figure 3 The diagram illustrates the internal structure of a computer device according to an embodiment of this application. Detailed Implementation
[0029] The specific embodiments of this application will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the embodiments of this application.
[0030] It should be noted that if the embodiments of this application involve directional indicators (such as up, down, left, right, front, back, etc.), the directional indicators are only used to explain the relative positions, relationships, and movements of the components in a specific posture (as shown in the figure). If the specific posture changes, the directional indicators will also change accordingly.
[0031] Furthermore, if the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, features defined with "first" or "second" may explicitly or implicitly include at least one of those features. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0032] Figure 1 The illustration shows a flowchart of a method for invoking a third-party interface according to an embodiment of this application. Figure 1As shown in one embodiment of this application, a method for invoking a third-party interface is provided, including:
[0033] Step 101: Obtain the call instruction for the third-party interface. The call instruction carries a request annotation.
[0034] Step 102: Call the execution function of the Java reflection mechanism to determine the target proxy object and target request method corresponding to the request annotation.
[0035] Step 103: Locate the interface class corresponding to the target proxy object.
[0036] Step 104: Run the execution function to determine the path parameter of the first annotation on the interface class to determine the classpath.
[0037] Step 105: Obtain the path parameter of the function annotation of the executed function to determine the method path.
[0038] Step 106: Determine the target service package of the target proxy object based on the interface class corresponding to the target proxy object, so as to obtain the package name address of the target service package.
[0039] Step 107: Determine the target request parameters corresponding to the request annotation based on the target request method.
[0040] Step 108: Generate an interface request for the third-party interface based on the package name address, target request method, class path, method path, and target request parameters, so as to call the third-party interface according to the interface request.
[0041] The consumer's call instruction to a third-party interface carries request annotations. Annotations are a syntax feature in the Java programming language, typically placed on methods, classes, or member variables. During Java runtime, these annotations are treated as attributes of the class, method, or member variable. These attributes can be obtained using Java reflection, allowing for different processing based on their parameter values. Running the Java reflection execution function yields the target proxy object and target request method corresponding to the request annotation. The target request method can then be used to determine the target request parameters corresponding to the request annotation. Java reflection allows the creation of objects of any class during program execution, revealing the class, member variables, and methods of any class, and invoking the attributes and methods of any object. The target proxy object can be the proxy object corresponding to the third-party interface being called. The proxy object's role is to perform preprocessing, filtering, forwarding, and post-processing operations on the delegate object (the object it proxies). By finding the interface class corresponding to the target proxy object, the path parameters of the first annotation on the interface class can be determined using the Java reflection execution function. The path parameter obtained from the first annotation on the interface class can be used to determine the classpath.
[0042] The execution function can be a means or method to invoke Java reflection to perform tasks. The execution function will have function annotations. By obtaining the path parameters of the function annotations, the method path can be determined. After determining the interface class corresponding to the target proxy object, the target service package corresponding to the interface class can be obtained, and then the package name address of the target service package can be obtained. In other words, the package name address of the target service package corresponding to the target proxy object can be obtained, which is the package name address of the target service package corresponding to the third-party interface invocation instruction. After determining the package name address, target request method, class path, method path, and target request parameters corresponding to the third-party interface invocation instruction, an interface request for the third party can be generated based on these parameters, thereby realizing the invocation of the third-party interface.
[0043] In one embodiment, a configuration file is generated, which may include a first configuration parameter and a second configuration parameter. The configuration file is a computer file that can configure parameters and initialize settings for some computing program. The first configuration parameter may be a `ric.package` parameter, and this first configuration parameter is associated with a specified service package. The second configuration parameter may be a `ric.url` parameter, which can be used to specify the package name address of each service package. The service package associated with the first configuration parameter has multiple interface classes, and each interface class is configured with various annotations.
[0044] In one embodiment, the Java dynamic proxy mechanism can be invoked to generate dynamic proxy objects for interface classes annotated with a first annotation in the service package specified in the configuration file. This first annotation can be `@RequestMapping`. After obtaining the proxy objects for the interface classes annotated with the first annotation, these proxy objects can be registered in an object storage container, which can be a Spring Boot bean container. The consumer's call instruction to the third-party interface carries a request annotation. Running the execution function of the Java reflection mechanism can obtain the proxy object corresponding to the request annotation. Through the proxy object, the annotation on the interface class corresponding to the request annotation can be found. Here, the interface class is the interface class under the service package associated with the first configuration parameter in the configuration file. The request annotation can determine the interface class in the configuration file corresponding to the third-party interface call instruction. Through the interface class, the service package corresponding to the third-party interface call instruction in the configuration file can be found, thus obtaining the package name address of the service package corresponding to the third-party interface call instruction.
[0045] In one embodiment, the function annotation on the execution function of the Java reflection mechanism can be any one of the first, second, or third annotations. When the function annotation is the first annotation, the path parameter in the first annotation is obtained, and this path parameter can be defined as the method path for calling the third-party interface. When the function annotation is the second annotation, the path parameter in the second annotation is obtained, and this path parameter can be defined as the method path for calling the third-party interface. When the function annotation is the third annotation, the path parameter in the third annotation is obtained, and this path parameter can be defined as the method path for calling the third-party interface. For example, the first annotation in the function annotation could be `@RequestMapping`, the second annotation could be `@GetMapping`, and the third annotation could be `@PostMapping`. By determining the category of the function annotation on the execution function to obtain the path parameter in the corresponding annotation, the path parameter corresponding to the third-party interface call instruction issued by the consumer can be determined. When the function annotation is `@RequestMapping`, the path parameter in the `@RequestMapping` annotation is determined as the path parameter corresponding to the third-party interface call instruction. When a function is annotated with `@GetMapping`, the path parameter in the `@GetMapping` annotation is determined to be the path parameter corresponding to the calling instruction of the third-party interface. Similarly, when a function is annotated with `@PostMapping`, the path parameter in the `@PostMapping` annotation is determined to be the path parameter corresponding to the calling instruction of the third-party interface.
[0046] In one embodiment, the consumer's call instruction to a third-party interface carries a request annotation, which can be any one of a first annotation, a second annotation, and a third annotation. The execution function of the Java reflection mechanism can be invoked to scan whether the request annotation includes the second annotation. If the request annotation includes the second annotation, the target request method corresponding to the request annotation can be determined to be the first target request method. For example, the second annotation could be the `@GetMapping` annotation in the request annotation. The consumer issues a call instruction to the third-party interface, and the execution function of the Java reflection mechanism scans for request annotations carried on the call instruction. If the `@GetMapping` annotation is found in the request annotation, the request method of this call instruction can be determined to be the first target request method, where the first target request method can be a GET request.
[0047] In one embodiment, a Java reflection mechanism execution function can be invoked to scan whether the request annotation includes a second annotation. If the request annotation does not include a second annotation, the execution function can be run to scan whether the request annotation includes a third annotation. If the request annotation includes a third annotation, the target request method corresponding to the request annotation can be determined to be the second target request method. For example, the third annotation could be the `@PostMapping` annotation in the request annotation. The consumer issues a call instruction to a third-party interface, and the Java reflection mechanism execution function scans for request annotations carried on the call instruction. If the `@PostMapping` annotation is found in the request annotation, the request method of this call instruction can be determined to be the second target request method, where the second target request method can be the POST method.
[0048] In one embodiment, a Java reflection execution function can be invoked to scan whether the request annotation includes a third annotation. If the request annotation does not include a third annotation, the execution function can be run to scan whether the request annotation includes a first annotation. If the request annotation includes the first annotation, the execution function is run again to obtain the method parameter of the first annotation. If the method parameter of the first annotation is the first method parameter, the target request method corresponding to the request annotation can be determined to be the first target request method. If the method parameter of the first annotation is the second method parameter, the target request method corresponding to the request annotation can be determined to be the second target request method. For example, the first annotation could be the @RequestMapping annotation in the request annotation. The consumer issues a call instruction to a third-party interface, and the Java reflection execution function scans for request annotations carried on the call instruction. If the @RequestMapping annotation is found in the request annotation, the Java reflection execution function is used again to obtain the method parameter of the @RequestMapping annotation. If the method parameter of the @RequestMapping annotation is the first method parameter, i.e., the GET parameter, the target request method corresponding to the request annotation can be determined to be the GET method. When the method parameter of the @RequestMapping annotation is the second method parameter, which is the POST parameter, it can be determined that the target request method corresponding to the request annotation is the POST method.
[0049] In one embodiment, after determining the target request method, the target request parameters corresponding to the request annotations can be determined based on the target request method. If the target request method is a first target request method, the execution function of the Java reflection mechanism can be run to traverse the parameter set of the first target request method, obtaining the parameter name and value of each parameter in the parameter set. Multiple parameter names and values of the first parameters are concatenated in a preset order to obtain the target request parameters. For example, if the target request method is the first target request method, i.e., the GET method, there are multiple parameters. Using the Java reflection mechanism, each parameter is traversed, and the parameter name and value of each parameter are concatenated in a preset order. The preset order could be the parameter name and value of the first parameter combined with the parameter name and value of the second parameter, and so on. Finally, the concatenated parameter name and value are determined as the target request parameters. Here, the target request parameters could be param1 = value1, param2 = value2.
[0050] In one embodiment, after determining the target request method, the target request parameters corresponding to the request annotation can be determined based on the target request method. If the target request method is the second target request method, the execution function of the Java reflection mechanism can be run to obtain the second parameter value of the second target request method. Then, the second parameter value of the second target request method is serialized using JSON format to obtain the string corresponding to the second parameter value, thereby determining the target request parameters. JSON format serialization refers to the process of processing a JSON object into a string. For example, if the target request method is the first target request method, i.e., the POST method, the POST method only supports one parameter. After obtaining this parameter, serializing it using JSON format can obtain the string corresponding to that parameter.
[0051] In one embodiment, after calling a third-party interface based on an interface request, it is necessary to receive the data returned by the third-party interface. The execution function running Java reflection can determine the data type of the data returned by the third-party interface. Deserialization operations can then be used to deserialize the data returned by the third-party interface into a preset format. This preset format can be a data format designed by the designers according to the different needs of the consumer.
[0052] Figure 2 The illustration shows a flowchart of a method for invoking a third-party interface according to an embodiment of this application. Figure 2As shown, the service provider sets up a core (ric) in its backend application, which contains configuration files. The configuration file has `ric.package` and `ric.url` parameters, which provide the package name and address of each service package. The `ric.package` parameter associates multiple service packages, each containing multiple interface classes, each annotated with an annotation. Interface classes annotated with `@RequestMapping` can have proxy objects generated using Java dynamic proxy mechanisms, and these proxy objects can be registered in the Spring Boot bean container. The consumer can send a third-party interface call command from the backend application calling the interface service. The third-party interface call command carries request annotations, and calling the execution function of the Java reflection mechanism retrieves the proxy object corresponding to the request annotation. On one hand, the annotations on the proxy object allow finding the corresponding interface class in the Spring Boot bean container, determining the service package to which the interface class belongs, and ultimately obtaining the package name and address. On the other hand, the annotations on the proxy object allow determining the request method, classpath, method path, and request parameters corresponding to the request annotation. Based on the parameters described above, third-party API calls can be made and the results returned to the server. This approach eliminates the need to repeatedly define APIs, simplifying the third-party API call process and improving work efficiency.
[0053] This application provides a processor configured to execute the above-described method for calling the third-party interface.
[0054] This application also provides a machine-readable storage medium storing instructions that, when executed by a processor, enable the processor to perform the third-party interface invocation method described in any of the above embodiments.
[0055] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 3As shown. The computer device includes a processor A01, a network interface A02, memory (not shown), and a database (not shown) connected via a system bus. The processor A01 provides computing and control capabilities. The memory includes internal memory A03 and a non-volatile storage medium A04. The non-volatile storage medium A04 stores an operating system B01, a computer program B02, and a database (not shown). The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 stored in the non-volatile storage medium A04. The database stores request annotations for interface call instructions and annotation data on interface classes in an object storage container. The network interface A02 communicates with external terminals via a network connection. When executed by the processor A01, the computer program B02 implements a method for calling a third-party interface.
[0056] Those skilled in the art will understand that Figure 3 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0057] This application provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: obtaining a call instruction for a third-party interface, the call instruction carrying a request annotation; calling an execution function of the Java reflection mechanism, running the execution function to determine the target proxy object and target request method corresponding to the request annotation; finding the interface class corresponding to the target proxy object; running the execution function to determine the path parameter of the first annotation on the interface class as the classpath; obtaining the path parameter of the function annotation of the execution function as the method path; determining the target service package of the target proxy object based on the interface class corresponding to the target proxy object, to obtain the package name address of the target service package; determining the target request parameters corresponding to the request annotation based on the target request method; generating an interface request for the third-party interface based on the package name address, target request method, classpath, method path, and target request parameters, to call the third-party interface according to the interface request.
[0058] In one embodiment, invoking the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: invoking the execution function of the Java reflection mechanism and running the execution function to scan whether the request annotation includes a second annotation; if it is determined that the request annotation includes a second annotation, the target request method is determined to be the first target request method.
[0059] In one embodiment, calling the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation further includes: if it is determined that the request annotation does not include the second annotation, running the execution function to scan whether the request annotation includes the third annotation; if it is determined that the request annotation includes the third annotation, determining the target request method as the second target request method.
[0060] In one embodiment, if it is determined that the request annotation does not include the third annotation, the execution function is run to scan whether the request annotation includes the first annotation; if it is determined that the request annotation includes the first annotation, the execution function is run to obtain the method parameter of the first annotation; if the method parameter is the first method parameter, the target request method is determined to be the first target request method; if the method parameter is the second method parameter, the target request method is determined to be the second target request method.
[0061] In one embodiment, the target request method includes a first target request method. Determining the target request parameters corresponding to the request annotation based on the target request method includes: when the target request method is the first target request method, running an execution function to traverse the parameter set of the first target request method to obtain the parameter name and parameter value of each first parameter in the parameter set; and concatenating the parameter names and parameter values of multiple first parameters in a preset order to obtain the target request parameters.
[0062] In one embodiment, the target request method includes a second target request method. Determining the target request parameter corresponding to the request annotation based on the target request method includes: if the target request method is the second target request method, running an execution function to obtain the second parameter value of the second target request method; serializing the second parameter value using JSON format to obtain the string corresponding to the second parameter value; and determining the string as the target request parameter.
[0063] In one embodiment, before obtaining the call instruction for the third-party interface, a configuration file is generated. The configuration file includes a first configuration parameter and a second configuration parameter. The first configuration parameter is associated with a specified service package, and the second configuration parameter is used to specify the package name address of each service package. Finding the interface class corresponding to the target proxy object includes: obtaining the first configuration parameter in the configuration file and scanning the service package associated with the first configuration parameter; finding the interface class that includes the first annotation in the service package associated with the first configuration parameter.
[0064] In one embodiment, after generating the configuration file, the Java dynamic proxy mechanism is invoked to generate a dynamic proxy object from the interface class containing the first annotation; and the dynamic proxy object is registered to the object storage container; running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: running the execution function to find the dynamic proxy object corresponding to the request annotation in the object storage container and determine it as the target proxy object.
[0065] In one embodiment, after calling a third-party interface according to an interface request, the system receives the data returned by the third-party interface; it calls the execution function of the Java reflection mechanism to determine the data type of the returned data; and based on the data type, it uses a deserialization operation to deserialize the returned data into data of a preset format.
[0066] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: obtaining a call instruction for a third-party interface, the call instruction carrying a request annotation; calling an execution function of the Java reflection mechanism, running the execution function to determine the target proxy object and target request method corresponding to the request annotation; finding the interface class corresponding to the target proxy object; running the execution function to determine the path parameter of the first annotation on the interface class to determine the classpath; obtaining the path parameter of the function annotation of the execution function to determine the method path; determining the target service package of the target proxy object according to the interface class corresponding to the target proxy object, so as to obtain the package name address of the target service package; determining the target request parameters corresponding to the request annotation according to the target request method; generating an interface request for the third-party interface according to the package name address, target request method, classpath, method path and target request parameters, so as to call the third-party interface according to the interface request.
[0067] In one embodiment, invoking the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: invoking the execution function of the Java reflection mechanism and running the execution function to scan whether the request annotation includes a second annotation; if it is determined that the request annotation includes a second annotation, the target request method is determined to be the first target request method.
[0068] In one embodiment, calling the execution function of the Java reflection mechanism and running the execution function to determine the target proxy object and target request method corresponding to the request annotation further includes: if it is determined that the request annotation does not include the second annotation, running the execution function to scan whether the request annotation includes the third annotation; if it is determined that the request annotation includes the third annotation, determining the target request method as the second target request method.
[0069] In one embodiment, if it is determined that the request annotation does not include the third annotation, the execution function is run to scan whether the request annotation includes the first annotation; if it is determined that the request annotation includes the first annotation, the execution function is run to obtain the method parameter of the first annotation; if the method parameter is the first method parameter, the target request method is determined to be the first target request method; if the method parameter is the second method parameter, the target request method is determined to be the second target request method.
[0070] In one embodiment, the target request method includes a first target request method. Determining the target request parameters corresponding to the request annotation based on the target request method includes: when the target request method is the first target request method, running an execution function to traverse the parameter set of the first target request method to obtain the parameter name and parameter value of each first parameter in the parameter set; and concatenating the parameter names and parameter values of multiple first parameters in a preset order to obtain the target request parameters.
[0071] In one embodiment, the target request method includes a second target request method. Determining the target request parameter corresponding to the request annotation based on the target request method includes: if the target request method is the second target request method, running an execution function to obtain the second parameter value of the second target request method; serializing the second parameter value using JSON format to obtain the string corresponding to the second parameter value; and determining the string as the target request parameter.
[0072] In one embodiment, before obtaining the call instruction for the third-party interface, a configuration file is generated. The configuration file includes a first configuration parameter and a second configuration parameter. The first configuration parameter is associated with a specified service package, and the second configuration parameter is used to specify the package name address of each service package. Finding the interface class corresponding to the target proxy object includes: obtaining the first configuration parameter in the configuration file and scanning the service package associated with the first configuration parameter; finding the interface class that includes the first annotation in the service package associated with the first configuration parameter.
[0073] In one embodiment, after generating the configuration file, the Java dynamic proxy mechanism is invoked to generate a dynamic proxy object from the interface class containing the first annotation; and the dynamic proxy object is registered to the object storage container; running the execution function to determine the target proxy object and target request method corresponding to the request annotation includes: running the execution function to find the dynamic proxy object corresponding to the request annotation in the object storage container and determine it as the target proxy object.
[0074] In one embodiment, after calling a third-party interface according to an interface request, the system receives the data returned by the third-party interface; it calls the execution function of the Java reflection mechanism to determine the data type of the returned data; and based on the data type, it uses a deserialization operation to deserialize the returned data into data of a preset format.
[0075] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0076] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0077] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0078] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0079] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0080] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0081] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0082] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0083] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method of invoking a third party interface, characterized by, The method comprises: generating a configuration file, the configuration file comprising a first configuration parameter and a second configuration parameter, the first configuration parameter being associated with a specified service package, and the second configuration parameter being used to specify a package name address of each service package; calling a Java dynamic proxy mechanism to generate a dynamic proxy object of an interface class comprising a first annotation; obtaining a calling instruction for a third-party interface, the calling instruction carrying a request annotation; calling an execution function of a Java reflection mechanism, and running the execution function to determine a target proxy object and a target request mode corresponding to the request annotation from the generated dynamic proxy object; finding an interface class corresponding to the target proxy object, wherein the finding of the interface class corresponding to the target proxy object comprises: obtaining the first configuration parameter in the configuration file, and scanning a service package associated with the first configuration parameter; and finding an interface class comprising the first annotation in the service package associated with the first configuration parameter; running the execution function to determine a path parameter of the first annotation on the interface class to determine a class path; obtaining a path parameter of a function annotation of the execution function to determine a method path; determining a target service package of the target proxy object according to the interface class corresponding to the target proxy object to obtain a package name address of the target service package; determining a target request parameter corresponding to the request annotation according to the target request mode; generating an interface request for the third-party interface according to the package name address, the target request mode, the class path, the method path, and the target request parameter, so as to call the third-party interface according to the interface request.
2. The method of invoking a third party interface according to claim 1, wherein, The calling of the execution function of the Java reflection mechanism, and the running of the execution function to determine the target proxy object and the target request mode corresponding to the request annotation comprise: calling the execution function of the Java reflection mechanism, and running the execution function to scan whether a second annotation is included in the request annotation; in a case where it is determined that the second annotation is included in the request annotation, determining that the target request mode is a first target request mode.
3. The method of invoking a third party interface according to claim 2, wherein, The calling of the execution function of the Java reflection mechanism, and the running of the execution function to determine the target proxy object and the target request mode corresponding to the request annotation further comprise: in a case where it is determined that the second annotation is not included in the request annotation, running the execution function to scan whether a third annotation is included in the request annotation; in a case where it is determined that the third annotation is included in the request annotation, determining that the target request mode is a second target request mode.
4. The method of invoking a third party interface according to claim 3, wherein, The calling of the execution function of the Java reflection mechanism, and the running of the execution function to determine the target proxy object and the target request mode corresponding to the request annotation further comprise: in a case where it is determined that the third annotation is not included in the request annotation, running the execution function to scan whether a first annotation is included in the request annotation; in a case where it is determined that the first annotation is included in the request annotation, running the execution function to obtain a method parameter of the first annotation; in a case where the method parameter is a first method parameter, determining that the target request mode is a first target request mode; In a case where the method parameter is a second method parameter, the target request mode is determined as a second target request mode.
5. The method of invoking a third party interface according to claim 1, wherein, The target request mode includes a first target request mode, and the determining the target request parameter corresponding to the request annotation according to the target request mode includes: In a case where the target request mode is the first target request mode, the execution function is run to traverse a parameter set of the first target request mode to obtain a parameter name and a parameter value of each first parameter in the parameter set; The parameter name and the parameter value of the plurality of first parameters are spliced in a preset order to obtain the target request parameter.
6. The method of invoking a third party interface according to claim 1, wherein, The target request mode includes a second target request mode, and the determining the target request parameter corresponding to the request annotation according to the target request mode includes: In a case where the target request mode is the second target request mode, the execution function is run to obtain a second parameter value of the second target request mode; The second parameter value is serialized in a Json format to obtain a string corresponding to the second parameter value; The string is determined as the target request parameter.
7. The method of invoking a third party interface according to claim 1, wherein, The method further includes: The dynamic proxy object is registered to an object storage container; The running the execution function to determine the target proxy object and the target request mode corresponding to the request annotation from the generated dynamic proxy object includes: The execution function is run to find the dynamic proxy object corresponding to the request annotation from the object storage container to determine the target proxy object.
8. The method of invoking a third party interface according to claim 1, wherein, The method further includes: After the third-party interface is called according to the interface request, data returned by the third-party interface is received; An execution function of a Java reflection mechanism is called, and the execution function is run to determine a data type of the returned data; According to the data type, the returned data is deserialized into data in a preset format through a deserialization operation.
9. A processor, comprising: The method is configured to execute the calling method of the third-party interface according to any one of claims 1 to 8.
10. A machine-readable storage medium having stored thereon instructions, the instructions being executable by a machine to cause the machine to: The instruction, when executed by a processor, causes the processor to be configured to execute the calling method of the third-party interface according to any one of claims 1 to 8.
Citation Information
Patent Citations
Annotation rear end checkout method and device, computer equipment and storage medium
CN108415834A
Service calling method and related equipment
CN111698205A