Communication method and device, electronic equipment and computer readable storage medium
By using the web interface to obtain and serialize internal service information in a system based on a service-oriented architecture and microservice software architecture, the problem of difficult to obtain internal service status information in the test scenario is solved, which improves the convenience of testing and reduces costs.
Patent Information
- Application Number
- CN202510004318.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-02
- Publication Date
- 2025-05-06
AI Technical Summary
In a system built on a service-oriented architecture and microservice software architecture method, it is not easy to know whether the status information inside the service process is correct in the test scenario, which increases the difficulty of testing problems.
By receiving HTTP requests based on the web interface, obtaining target object information in the service, serializing the information, and sending HTTP responses through the web interface, allowing testers to easily obtain internal information of the service.
Improves the convenience of testing, allowing testers to more easily obtain internal information of the service, reducing testing costs and complexity.
Smart Images

Figure CN119946033A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular to a communication method, device, electronic device, and computer-readable storage medium. Background Art
[0002] In a system built based on service-oriented architecture (SOA) and microservice software architecture, a large application is broken down into a group of small, functionally independent services that coordinate and cooperate with each other to provide users with complete functions. In the test scenario, during the service operation, it is not easy to know whether the status information inside the service process is correct, which increases the difficulty of troubleshooting the test. Therefore, how to improve the convenience of testing is a problem that needs to be solved. Summary of the invention
[0003] Embodiments of the present application provide a communication method, device, electronic device, and computer-readable storage medium to improve the convenience of testing.
[0004] In a first aspect, a communication method is provided, the method comprising: receiving a first hypertext transfer protocol (HTTP) request based on a web interface, the first HTTP request being used to request viewing information of a target object in a service; obtaining information of the target object from the service in response to the first HTTP request; serializing the information of the target object according to a target data format supported by the web interface; and sending a first HTTP response based on the web interface, the first HTTP response including the serialized information of the target object.
[0005] In a possible implementation, the first HTTP request includes a uniform resource locator (URL) registered for the target object, and a request method of the first HTTP request is GET.
[0006] In a possible implementation, the target object is a container object within the service, the information of the target object is information of a target element within the container object, and obtaining the information of the target object from the service in response to the first HTTP request includes: in response to the first HTTP request, checking the elements contained in the container object to determine the identifier of the target element; and obtaining the information of the target object from the service based on the identifier of the target element.
[0007] In one possible implementation, the method further includes: receiving a second HTTP request based on the web interface, the second HTTP request being used to request a remote procedure call (RPC) interface of the service; based on the second HTTP request, sending an RPC request to the service through the RPC interface to obtain RPC response information; serializing the RPC response information into the target data format; and sending a second HTTP response based on the web interface, the second HTTP response including the serialized RPC response information.
[0008] In a possible implementation, the second HTTP request includes a URL registered for the RPC interface, and a request method of the second HTTP request is POST.
[0009] In a possible implementation, sending the RPC request to the service through the RPC interface based on the second HTTP request includes: obtaining a header and a body of the RPC request from the second HTTP request; generating the RPC request according to the header and the body of the RPC request; and sending the RPC request to the service through the RPC interface.
[0010] In a possible implementation, the method further includes: receiving a third HTTP request based on the web interface, the third HTTP request being used to call an event trigger; and in response to the third HTTP request, calling the event trigger to trigger a target event during the operation of the service.
[0011] In a possible implementation, the third HTTP request includes a URL registered for the target event, and a request method of the third HTTP request is POST.
[0012] In a second aspect, a testing method is provided, which includes: sending an HTTP request; determining whether the function of the service matches the expected result based on the received HTTP response and / or the triggered target event, wherein the HTTP response or the target event is obtained according to the method described in the first aspect or any possible implementation method of the first aspect.
[0013] According to a third aspect, a communication device is provided, comprising: a receiving module for receiving a first HTTP request based on a web interface, wherein the first HTTP request is used to request to view information of a target object in a service; an acquiring module for acquiring information of the target object from the service in response to the first HTTP request; a processing module for serializing the information of the target object according to a target data format supported by the web interface; and a sending module for sending a first HTTP response based on the web interface, wherein the first HTTP response includes serialized information of the target object.
[0014] In a possible implementation, the first HTTP request includes a URL registered for the target object, and a request method of the first HTTP request is GET.
[0015] In a possible implementation, the target object is a container object within the service, the information of the target object is information of a target element within the container object, and obtaining the information of the target object from the service in response to the first HTTP request includes: in response to the first HTTP request, checking the elements contained in the container object to determine the identifier of the target element; and obtaining the information of the target object from the service based on the identifier of the target element.
[0016] In a possible implementation, the device also includes: a second receiving module, used to receive a second HTTP request based on the web interface, the second HTTP request is used to request to call the RPC interface of the service; a second sending module, used to send an RPC request to the service through the RPC interface based on the second HTTP request to obtain RPC response information; a second processing module, used to serialize the RPC response information into the target data format; and a third sending module, used to send a second HTTP response based on the web interface, the second HTTP response including the serialized RPC response information.
[0017] In a possible implementation, the second HTTP request includes a URL registered for the RPC interface, and a request method of the second HTTP request is POST.
[0018] In a possible implementation, sending the RPC request to the service through the RPC interface based on the second HTTP request includes: obtaining a header and a body of the RPC request from the second HTTP request; generating the RPC request according to the header and the body of the RPC request; and sending the RPC request to the service through the RPC interface.
[0019] In one possible implementation, the device also includes: a third receiving module, used to receive a third HTTP request based on the web interface, and the third HTTP request is used to call an event trigger; a calling module, which calls the event trigger in response to the third HTTP request to trigger a target event during the operation of the service.
[0020] In a possible implementation, the third HTTP request includes a URL registered for the target event, and a request method of the third HTTP request is POST.
[0021] In a fourth aspect, a testing device is provided, comprising: a second sending module for sending an HTTP request; a determination module for determining whether the function of the service matches the expected result based on a received HTTP response and / or a triggered target event, wherein the HTTP response or the target event is obtained according to the method described in the first aspect or any possible implementation method of the first aspect.
[0022] In a fifth aspect, an electronic device is provided, comprising: a memory; and a processor for executing a program stored in the memory to execute a method as described in the first aspect or any possible implementation of the first aspect or the second aspect or any possible implementation of the second aspect.
[0023] In a sixth aspect, a computer-readable storage medium is provided, on which a code is stored, and the code is used to execute a method as described in the first aspect or any possible implementation of the first aspect or the second aspect or any possible implementation of the second aspect.
[0024] In the test scenario, the embodiment of the present application receives HTTP requests based on the web interface to obtain the target object information in the service, serializes the target object information and then sends the HTTP response through the web interface, which makes it easy for testers to obtain the target object information in the service and improves the convenience of testing. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0026] Figure 1 It is a flow chart of a method for obtaining target object information based on a web interface provided in an embodiment of the present application.
[0027] Figure 2This is an example diagram of the process of obtaining target object information based on a web interface provided in an embodiment of the present application.
[0028] Figure 3 This is an example diagram of a service module for calling an RPC interface based on a web interface, as provided in an embodiment of the present application.
[0029] Figure 4 It is a flow chart of a method for calling an RPC interface based on a web interface provided in an embodiment of the present application.
[0030] Figure 5 This is an example diagram of the process of calling the RPC interface based on the web interface provided in an embodiment of the present application.
[0031] Figure 6 It is a flow chart of a method for calling event triggers based on a web interface provided in an embodiment of the present application.
[0032] Figure 7 This is an example diagram of a process for calling an event trigger based on a web interface provided in an embodiment of the present application.
[0033] Figure 8 This is an example diagram of testing based on a web interface provided in an embodiment of the present application.
[0034] Fig. 9 It is a schematic diagram of the structure of the communication device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0036] In a system built based on SOA and microservice software architecture methods, a large application is broken down into a group of small, functionally independent services that coordinate and cooperate with each other to provide users with complete functions. In the test scenario, during the service operation, it is not easy to know whether the status information inside the service process is correct, which increases the difficulty of troubleshooting the test. Therefore, how to improve the convenience of testing is a problem that needs to be solved.
[0037] In response to the above problems, related technologies propose to view the internal information of services through debugging tools. For example, the internal information of services can be viewed through the debugging tool gdb. However, gdb needs to intercept and analyze the execution process of the service. Therefore, when using gdb to view the internal information of services, more service resources, such as CPU or memory, will be consumed. In addition, debugging tools require testers to understand the internal operation logic of the service, which has a high threshold for testers to use.
[0038] Related technologies also propose to obtain internal service information by viewing log records. However, too little log content may result in incomplete information. However, detailed log records may result in too much log volume, which requires too many service resources. At the same time, obtaining log records often requires accessing the service, and the access process is relatively complicated.
[0039] In order to improve the convenience of testing, the embodiment of the present application proposes to obtain the target object information in the service by receiving HTTP requests based on a web interface, serializing the target object information, and then sending an HTTP response through the web interface to solve the problem. Since the web interface can obtain internal service information as required, and what is obtained is the current internal information of the service, there is no need to save historical data, and therefore, there is no need to occupy too many service resources. At the same time, information in the service can be obtained through the web interface through a variety of methods such as command line, browser, Postman, etc. The acquisition is simple and does not require understanding of the internal operating logic of the service. Therefore, this method is easy to use. In addition, serializing the target information in the service makes the information easier for testers to view and understand. Therefore, the convenience of testing can be improved.
[0040] Combine the following Figure 1 , a more detailed introduction is given to the communication method proposed in the embodiment of the present application.
[0041] In step S110 , a first HTTP request is received based on a web interface.
[0042] A web interface is a communication method provided by a system or application to the outside world. It allows the caller to exchange data and call functions through the Internet.
[0043] HTTP requests can be used for many purposes, for example, they can be used to request to view the information of the target object in the service, they can be used to request to call a service interface, or they can be used to request to call an event trigger, etc. For the sake of ease of description, the request for requesting to view the information of the target object in the service is referred to as the first HTTP request below. The information of the target object can be any information that can be obtained from the service in the test scenario. For example, it can be service internal status information, configuration parameters, performance data, debugging information, system logs, request counts or response times, etc. The type of information of the target object is not limited in this application.
[0044] The first HTTP request includes a uniform resource locator registered for the target object. A URL is a network address used to identify and locate resources, and can point to various types of resources such as web pages, pictures, videos, and files. The request method of the first HTTP request can be GET. GET is used to request to retrieve a specific resource from a service. Taking the target object information as an example of the internal status information of the service, the first HTTP request can use / info / +object name as the URL.
[0045] In step S110, in response to the first HTTP request, information of the target object is obtained from the service.
[0046] There are many ways to organize the target object, for example, it can be a singleton object or a container object. The singleton object has only one copy of information, such as configuration parameters or service internal status information. These related information are organized together to form a management object. The singleton object can include global variables. For the acquisition of singleton object information, you can bind the URL and the singleton object data collection processor to use an interface to obtain a singleton object information. Container object means that each container contains multiple element objects of the same category. When the target object is a container object in the service, the target object information is the information of the target element in the container object. That is, when the target object is a container object in the service, responding to the first HTTP request, obtaining the target object information from the service is to obtain the target element information in the container object. Element refers to a single member object inside the container object. For example, if the container object is a "user list", then each user is an element. Elements usually contain a set of information that describes the characteristics or status of the element. Add a web interface that lists all service object information to the container object, and all exposed element information can be referenced and queried through this root information interface.
[0047] The following is a detailed description of how to obtain target element information in a container object from a service. There are many ways to obtain target element information in a container object from a service. For example, when the number of object elements in a container is small, information of all target elements can be obtained at one time through a web interface. This method can quickly and completely obtain all information in the container. When the number of elements in a container object is large, obtaining information of target elements in all container objects at one time may cause data overload. Therefore, the convenience of testing can be improved by gradually obtaining target object element information in a hierarchical manner. By obtaining information of target elements in a container object in a hierarchical manner, a web interface can be defined for different levels and a data collection processor can be implemented. The method of obtaining target object information in a hierarchical manner can be, for example: the first-level web interface can determine the identifier (ID) of the target element by checking the elements contained in the container object according to the first HTTP request. The identifier of the target element is used to uniquely identify the value of the target element in the container. The identifier of the target element allows the system to quickly retrieve, reference and operate the target element. The second-level web interface can obtain information of the target object based on the identifier of the target element determined by the first-level web interface. For example, to obtain information about a target object in a container, you can add the container element ID to the URL or query parameter, such as / info / users / 123 or / info / users?id=123. Hierarchical acquisition of container object information can effectively manage and access information within the service, avoiding data overload caused by obtaining container object information at one time, thereby improving the convenience of testing.
[0048] The hierarchical approach to obtaining service internal object information is also applicable to scenarios with multi-layer container nesting. Multi-layer container nesting means that container objects contain other container objects, and these internal container objects may contain more container objects, forming a multi-level nested structure. This structure is similar to the nesting of folders, where each folder can contain other folders, and other folders may contain more folders. In scenarios where information needs to be managed hierarchically, for example, when the container structure is complex or the depth is unknown, accessing these nested containers level by level through the web interface can effectively retrieve and obtain information about the target objects in the service, improving the convenience of testing.
[0049] In step S130, the information of the target object is serialized according to the target data format supported by the web interface.
[0050] The communication protocol used by the web interface is usually the HTTP protocol. The HTTP protocol requires the data format to be suitable for network transmission. Serialization refers to converting the information of the target object into an easy-to-view data format. There are many data formats supported by the web interface, such as JSON, XML, YAML, etc. Taking the JSON format as an example, the information of the target object can be serialized into the JSON format. JSON is a lightweight data exchange format that supports different programming languages and the JSON format is easy to view and understand, which helps testers to quickly locate and solve problems, and can improve the convenience of testing. There are many ways to serialize the information of the target object. The following uses the serialization of the information of the target object in the service into JSON as an example to illustrate the serialization method. For example: it can be Java, Golang and other languages that support structure and JSON conversion; it can be using third-party tools such as protobuf to define data structures, and the generated data structure code contains the ability to convert between JSON structures; it can also be with the help of some JSON libraries, and the format conversion can be completed by manually writing code.
[0051] In step S140, a first HTTP response is sent based on the web interface.
[0052] The first HTTP response includes serialized target object information. The first HTTP response is sent to the caller through the web interface. The caller can determine the problem based on the received first HTTP response and process the service accordingly.
[0053] The above article introduces in detail how to obtain the target object information in the service through the web interface. Figure 2 , a more detailed example is given to illustrate the process of obtaining target object information in the service through the web interface.
[0054] The caller sends an HTTP request to the service, and the service's web port receives the HTTP request and starts processing it. The service parses the HTTP request, including the request line (method, URL, HTTP version), etc. The service calls different service information collectors based on the URL. The service information collector collects service information. Once the required service information is collected, the service generates an HTTP response. The caller receives the HTTP response and obtains information about the target object in the service.
[0055] The foregoing article describes in detail how obtaining target object information in a service through a web interface can improve the convenience of testing. In some embodiments, the web interface can not only obtain target object information in a service, but also call the RPC interface to make testing more convenient. In a system constructed using the microservice software architecture method, multiple microservices in a large application will involve and provide a set of application programming interfaces (APIs) for use by other services. The RPC interface allows these services to communicate remotely, making it as convenient to call other services as to call local functions. In order to ensure the performance of the interface, communication between services usually adopts a binary format, which is more efficient but not very readable. In order to ensure the security of the interface, RPC communication usually adds identity and access management (IAM) control so that only authorized services can access specific interfaces, but this also creates obstacles to interface access during testing. In addition, to call the RPC interface, it is necessary to provide an API software development kit (SDK) based on a certain programming language corresponding to the RPC interface. However, testing generally uses a more flexible programming language to trigger interface calls to complete interface function testing. The mismatch between the API SDK programming language and the test programming language will make it difficult for testers to carry out testing work.
[0056] In response to the above-mentioned problem of testing using the RPC interface, the related technologies have proposed some solutions. For example, in response to the problem that the mismatch between the API SDK programming language and the test programming language will lead to high testing costs, the related technologies propose to integrate the SDK code of the test service in the test code, and complete the interface function test by triggering the interface call in the test code. However, the SDK code of the integrated test service can generally only provide a limited number of programming languages, and still cannot avoid the problem of high testing costs caused by the mismatch between the API SDK programming language and the test programming language. In addition, this method cannot circumvent the IAM restrictions and requires some additional processing, which has caused certain obstacles to the testing work. Other related technologies propose to set up an independent gateway service and convert the RPC interface to the HTTP interface through the gateway service. Since the HTTP interface can support almost all programming languages, no matter what programming language the caller uses, the call to the interface can be completed through the HTTP interface. However, this method also has shortcomings, for example, it is necessary to maintain an additional gateway service, the gateway service needs to be updated after the service interface is changed, and it cannot be used in scenarios without gateways such as local development. Although the above solutions have improved the convenience of testing to a certain extent, they have increased the cost of testing. In order to improve the convenience of testing and reduce the cost of testing, this application proposes to solve the problem by calling the RPC interface through a web interface. Since the web interface does not require an additional gateway service to call the RPC interface, the testing cost can be saved. In addition, through the web interface testers can freely choose the test language, which can avoid the testing difficulties caused by the mismatch between the API SDK programming language and the test programming language, and improve the convenience of testing. At the same time, the web interface can not do IAM verification, or it is easy to construct verification information by passing the verification token, which also improves the convenience of testing.
[0057] The implementation of web interface calling RPC interface depends on some common components on the service. To facilitate the understanding of the process of web interface calling RPC interface, let's first combine Figure 3A brief introduction to the service modules in the service. The service module generally includes the RPC service network module, the RPC request distributor, and the RPC request processor. The RPC service network module is used to process RPC requests, which includes receiving, parsing, and responding to RPC requests. The RPC request distributor is used to route RPC requests to the RPC request processor. The RPC request processor is used to process RPC requests, execute the business logic of the response, and generate RPC response information. Calling the RPC interface through the web interface is equivalent to providing a set of web interfaces outside the RPC interface. This requires integrating a set of service modules for the web interface into the service. The service module of the web interface includes the web service network module, the web request distributor, and the web request processor. The web service network module is used to process HTTP requests, which includes receiving, parsing, and responding to HTTP requests. The web request distributor is used to route HTTP requests to the RPC request processor. The web request processor is used to process HTTP requests, execute the business logic of the response, and generate HTTP responses.
[0058] Combine the following Figure 4 , a more detailed introduction is given to the method of calling the RPC interface through the web interface proposed in the embodiment of the present application.
[0059] In step S410, a second HTTP request is received based on the web interface.
[0060] The HTTP request is received based on the web interface, and the HTTP request can be used to request to call the RPC interface of the service. For the convenience of description, the HTTP request used to request to call the RPC interface of the service is referred to as the second HTTP request below.
[0061] The second HTTP request may include a URL registered for the RPC interface. The RPC interface call may use / rpc / +interface name as the URL. The request method of the second HTTP request may be POST. POST is suitable for sending data to the service.
[0062] In step S420, based on the second HTTP request, an RPC request is sent to the service through the RPC interface to obtain RPC response information.
[0063] Based on the second HTTP request, sending the RPC request to the service through the RPC interface includes obtaining the header and body of the RPC request from the second HTTP request; generating the RPC request according to the header and body of the RPC request; and sending the RPC request to the service through the RPC interface. When the service receives the second HTTP request, it transmits the header and body of the RPC request through the header and body of the second HTTP request. After receiving the header and body of the RPC request, the service generates the RPC request.
[0064] The RPC interface can be implemented in many ways. For example, it can be implemented by defining the service interface using the interface definition language (IDL). IDL is used to describe the service methods, request and response data structures, and can provide specifications for the implementation and calling of services. Use IDL to define the service interface, and then use the framework tool to generate a service framework using the IDL file as input. The service framework binds the mapping relationship between requests and processors. By extending the framework tool, the binding of the URL of the RPC interface to the corresponding URL processor can be automatically generated. If it cannot be extended through the framework, the binding of the URL of the RPC interface to the corresponding URL processor can be implemented by manual coding.
[0065] In step S430, the RPC response information is serialized into a target data format. The target data format is a data format that is easy to view. The data format may be, for example, JSON, XML, YAML, etc. Taking JSON as an example, the response of RPC is generally in binary format, and the JSON format is based on a text format, which is easy to view and understand. Therefore, serializing the RPC response information into JSON format helps testers to quickly locate and solve problems, which can improve the convenience of testing.
[0066] In step S440, a second HTTP response is sent based on the web interface. The serialized RPC response information can be sent back to the caller through the body of the HTTP response. The second HTTP response can also include some public parameters for tracking the identification of the network request path, such as trace_ID, etc. The public parameters can be sent back to the caller through the header of the HTTP response.
[0067] The above article introduces in detail how to call the RPC interface through the web interface. Figure 5 , which gives a more detailed example of the process of calling the RPC interface through the web interface.
[0068] The service receives the second HTTP request from the caller. After receiving the second HTTP request, it starts parsing the request URL, request parameters, HTTP request header and body. The service obtains the RPC interface to be called based on the URL and request parameters or the header of the second HTTP request. The service parses the body of the HTTP request to obtain the body of the RPC request. The service uses the RPC message dispatcher to route the RPC request to the RPC interface processor. The RPC interface processor processes the RPC request after receiving it. After processing, the service serializes the RPC response information into an HTTP response. The service sends the HTTP response back to the caller.
[0069] In the test scenario, in addition to obtaining the internal information of the service or calling the RPC interface of the service, in some embodiments, it is also necessary to monitor or trigger some events to ensure that the service can respond correctly. The related technology proposes to simulate triggering through tools or triggering through real environment operations, but such triggering operations are cumbersome and the operating costs are relatively high. In order to improve the convenience of testing while reducing costs, this application also proposes to provide a web interface to call event triggers to simulate event triggering. Since the web interface can call event triggers through command lines, browsers, Postman, etc., event triggering can be simulated without complicated operations, thereby improving the convenience of testing.
[0070] Combine the following Figure 6 , a more detailed introduction is given to the method of simulating event triggering by calling an event trigger through a web interface proposed in an embodiment of the present application.
[0071] In step S610, a third HTTP request is received based on the web interface. The third HTTP request can be used to call an event trigger. There are many types of events, such as user behavior, system state change, external signal, etc. The required events can be defined according to the test needs, and a list of events that need to be simulated can be listed to define the event URL. The defined event URL is bound to the event trigger to simulate the event generation and trigger the processing logic corresponding to the event. For ease of description, the HTTP request used to call the event trigger is referred to as the third HTTP request below. The third HTTP request includes a URL registered for the target event. The URL may include / event / +event name. The request method of the third HTTP request may be POST. POST is used to submit data to the service.
[0072] In step S620, in response to the third HTTP request, an event trigger is called to trigger a target event during the service operation.
[0073] In the service, map the defined event URL to the corresponding event trigger. This way, when the service receives an HTTP request for a specific URL, it knows which event trigger to call.
[0074] Optionally, in some embodiments, the web interface can call an event trigger custom event. Custom events can implement event triggering in certain specific scenarios, such as simulating periodic triggering events. This can reduce the operating costs of testers and improve the convenience of testing.
[0075] Optionally, in some embodiments, the web interface for custom events can be combined with the web interface for obtaining target information in the service to obtain some new capabilities, such as simulating periodic triggering events and monitoring service status, etc., which can further reduce the operating costs of testers and improve the convenience of testing.
[0076] The above article introduces in detail how to simulate event triggering through the web interface. Figure 7 , a more detailed example is given to illustrate the process of simulating event triggering through the web interface.
[0077] The web interface receives HTTP requests. After receiving the HTTP request, the service will parse the URL and other information of the HTTP request. Each URL corresponds to a corresponding event or processing logic. The service will call the corresponding event trigger based on the requested URL. The event trigger simulates the actual event and performs the predetermined operation. After the event processing is completed, the system will generate an HTTP response and send it back to the caller.
[0078] Combine the following Figure 8 The embodiments of the present application are described in more detail. It should be noted that this example is only to help those skilled in the art understand the embodiments of the present application, rather than to limit the embodiments of the present application to the specific types or scenarios illustrated. Those skilled in the art can obviously make various equivalent modifications or changes based on the examples given below, and such modifications or changes also fall within the scope of the embodiments of the present application.
[0079] The web interface receives HTTP requests. After receiving the HTTP request, the service will parse the URL and other information of the HTTP request. The service determines the type of HTTP request based on the URL and other information of the HTTP request. If the web interface receives the first HTTP request, the service collects service-related information and serializes the information and returns it to the client caller as a response. If the web interface receives not only the first HTTP request but also the second HTTP request, the service not only collects service-related information and serializes the information and returns a response, but also calls the RPC interface to complete the conversion of the second HTTP request to the RPC request, the distribution of the RPC request, and the processing of the RPC request and returns a response. If the web interface receives not only the first HTTP request but also the third HTTP request, the service not only collects service-related information and serializes the information and returns a response, but also calls the event trigger according to the third HTTP request to simulate the event trigger and return a response.
[0080] The above text respectively introduces in detail the scheme of viewing the target object information in the service based on the web interface, the scheme of calling the RPC interface of the service based on the web interface, and the scheme of calling the event trigger based on the web interface. The above technical schemes can be used alone to improve the convenience of testing, or they can be used in any combination to improve the convenience of testing. It should be understood that the above technical schemes alone or in any combination belong to the protection scheme of the embodiments of the present application.
[0081] Optionally, an embodiment of the present application also provides a testing method. The testing method includes: sending an HTTP request; determining whether the function of the service matches the expected result based on the received HTTP response and / or the triggered target event, and the HTTP response or the target event can be obtained according to the communication method described in any of the above embodiments. The function of the service may refer to the specific operation or task that the service should perform or the preconditions of the service configuration, etc. The expected result may refer to the output result or status that the tester expects to obtain after the service performs its function. By using this testing method to determine whether the function of the service matches the expected result, it is convenient for the tester to verify whether the service works normally as designed or required.
[0082] Combination of the above Figures 1 to 8 The method embodiment of the present application is described in detail, and the device embodiment of the present application is described in detail below. It should be understood that the description of the device embodiment corresponds to the description of the method embodiment, so the part not described in detail can refer to the previous method embodiment.
[0083] The present application also provides a communication device, such as Fig. 9 As shown, the device includes: a receiving module 910, an acquisition module 920, a processing module 930 and a sending module 940. The receiving module 910 is used to receive a first HTTP request based on a web interface, and the first HTTP request is used to request to view the information of the target object in the service; the acquisition module 920 is used to respond to the first HTTP request and obtain the information of the target object from the service; the processing module 930 is used to serialize the information of the target object according to the target data format supported by the web interface; the sending module 940 is used to send a first HTTP response based on the web interface, and the first HTTP response contains the serialized information of the target object.
[0084] Optionally, in some embodiments, the first HTTP request includes a URL registered for the target object, and the request method of the first HTTP request is GET.
[0085] Optionally, in some embodiments, the target object is a container object within the service, the information of the target object is information of a target element within the container object, and obtaining the information of the target object from the service in response to the first HTTP request includes: in response to the first HTTP request, checking the elements contained in the container object to determine the identifier of the target element; and obtaining the information of the target object from the service based on the identifier of the target element.
[0086] Optionally, in some embodiments, the device also includes: a second receiving module, used to receive a second HTTP request based on the web interface, the second HTTP request is used to request to call the RPC interface of the service; a second sending module, used to send an RPC request to the service through the RPC interface based on the second HTTP request to obtain RPC response information; a second processing module, used to serialize the RPC response information into the target data format; and a third sending module, used to send a second HTTP response based on the web interface, the second HTTP response including the serialized RPC response information.
[0087] Optionally, in some embodiments, the second HTTP request includes a URL registered for the RPC interface, and the request method of the second HTTP request is POST.
[0088] Optionally, in some embodiments, sending an RPC request to the service through the RPC interface based on the second HTTP request includes: obtaining a header and a body of the RPC request from the second HTTP request; generating the RPC request according to the header and the body of the RPC request; and sending the RPC request to the service through the RPC interface.
[0089] Optionally, in some embodiments, the device also includes: a third receiving module, used to receive a third HTTP request based on the web interface, and the third HTTP request is used to call an event trigger; a calling module, in response to the third HTTP request, calls the event trigger to trigger a target event during the operation of the service.
[0090] Optionally, in some embodiments, the third HTTP request includes a URL registered for the target event, and the request method of the third HTTP request is POST.
[0091] An embodiment of the present application also provides a testing device, including: a second sending module, used to send an HTTP request; a determination module, used to determine whether the function of the service matches the expected result based on the received HTTP response and / or the triggered target event, wherein the HTTP response or the target event is obtained according to the communication method described in any of the preceding embodiments.
[0092] The embodiment of the present application further provides an electronic device, comprising: a memory and a processor. The processor is used to execute a program stored in the memory to execute the method described in any of the above embodiments.
[0093] An embodiment of the present application further provides a computer-readable storage medium, on which codes are stored, and the codes are used to execute the method described in any of the above embodiments.
[0094] It should be understood that in the embodiment of the present application, "B corresponding to A" means that B is associated with A, and B can be determined according to A. However, it should also be understood that determining B according to A does not mean determining B only according to A, and B can also be determined according to A and / or other information.
[0095] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0096] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0097] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0098] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0099] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0100] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, service or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, service or data center. The computer-readable storage medium may be any available medium that can be read by a computer or a data storage device such as a service, data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital video disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0101] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A communication method, characterized in that: The method comprises: Receiving a first HTTP request based on a web interface, where the first HTTP request is used to request to view information of a target object in a service; In response to the first HTTP request, obtaining information of the target object from the service; Serializing the information of the target object according to the target data format supported by the web interface; A first HTTP response is sent based on the web interface, where the first HTTP response includes serialized information of the target object.
2. The method according to claim 1, characterized in that: The first HTTP request includes a URL registered for the target object, and a request method of the first HTTP request is GET.
3. The method according to claim 1, characterized in that: The target object is a container object in the service, and the information of the target object is information of a target element in the container object. The step of obtaining the target object information from the service in response to the first HTTP request includes: In response to the first HTTP request, checking the elements contained in the container object to determine the identifier of the target element; Based on the identifier of the target element, information of the target object is obtained from the service.
4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Receiving a second HTTP request based on the web interface, where the second HTTP request is used to request to call the RPC interface of the service; Based on the second HTTP request, sending an RPC request to the service through the RPC interface to obtain RPC response information; Serializing the RPC response information into the target data format; A second HTTP response is sent based on the web interface, wherein the second HTTP response includes the serialized RPC response information.
5. The method according to claim 4, characterized in that The second HTTP request includes a URL registered for the RPC interface, and a request method of the second HTTP request is POST.
6. The method according to claim 4, characterized in that The sending an RPC request to the service through the RPC interface based on the second HTTP request includes: Obtaining a header and a body of the RPC request from the second HTTP request; Generate the RPC request according to the header and body of the RPC request; An RPC request is sent to the service through the RPC interface.
7. The method according to any one of claims 1 to 3, characterized in that The method further comprises: receiving a third HTTP request based on the web interface, wherein the third HTTP request is used to invoke an event trigger; In response to the third HTTP request, the event trigger is called to trigger a target event during the operation of the service.
8. The method according to claim 7, characterized in that The third HTTP request includes a URL registered for the target event, and a request method of the third HTTP request is POST.
9. A testing method, characterized in that: The test method includes: Send HTTP request; Determine whether the function of the service matches the expected result based on the received HTTP response and / or the triggered target event, wherein the HTTP response or the target event is obtained according to the communication method according to any one of claims 1-8.
10. A communication device, characterized in that: The device comprises: A receiving module, configured to receive a first HTTP request based on a web interface, wherein the first HTTP request is used to request to view information of a target object in a service; an acquisition module, configured to acquire information of the target object from the service in response to the first HTTP request; A processing module, configured to serialize the information of the target object according to a target data format supported by the web interface; A sending module is used to send a first HTTP response based on the web interface, wherein the first HTTP response includes serialized information of the target object.
11. A testing device, characterized in that: The testing device comprises: The second sending module is used to send HTTP requests; A determination module is used to determine whether the function of the service matches the expected result based on the received HTTP response and / or the triggered target event, wherein the HTTP response or the target event is obtained according to the communication method according to any one of claims 1-8.
12. An electronic device, characterized in that: include: Memory; A processor, configured to execute the program stored in the memory to perform the method according to any one of claims 1 to 9.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores codes for executing the method according to any one of claims 1 to 9.