Method and system for forwarding Android application requests to different environments and designated IP services

By using SharedPreferences and spring cloud gateway to store the environment gateway address and service ip address in Android development, and adding ReactiveLoadBalancerClientFilter in spring cloud gateway, the problem that application requests cannot access the application environment that developers want is implemented, and the request accuracy is achieved Forwarding and debugging.

CN118524139BActive Publication Date: 2025-02-25佛山众陶联供应链服务有限公司 +4
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410576787.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-10
Publication Date
2025-02-25
Estimated Expiration
2044-05-10

AI Technical Summary

Technical Problem

During Android development, application requests cannot access the application environment that developers want due to load balancing, making it difficult for developers to debug local service code.

Method used

By building SharedPreferences and spring cloud gateways, receive requests for the environment gateway address and service ip address, store this information, and add ReactiveLoadBalancerClientFilter in the spring cloud gateway to enable forwarding of requests to the specified environment and services.

Benefits of technology

It implements forwarding application requests to the specified environment and service instance, allowing developers to access and debug local service code, improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118524139B_ABST
    Figure CN118524139B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and system for forwarding Android application requests to different environments and designated IP services, the method comprising the following steps: receiving a request for an environment gateway address to be switched, and a request for an IP address that one of the services in the same environment wants to access; obtaining a BASEURL field from SharedPreferences, and splicing an interface address of one of the services in the same environment to obtain a request address; obtaining an IP address that the service wants to access from SharedPreferences according to a prefix of the interface address of one of the services in the same environment, and adding the IP address that the service wants to access to a request header; adding a ReactiveLoadBalancerClientFilter in a spring cloud gateway, and checking the target‑ip field in the request header, and constructing a new address according to the value of the target‑ip field, and replacing the original request address; setting the request address in the Attributes of an Exchange object in the spring cloud gateway. The present invention solves the problem that in the Android development process, application requests cannot access the application environment that the developer wants due to load balancing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method and system for forwarding an Android application request to different environments and designated IP services. Background Art

[0002] During the Android development process, application requests may not access the application environment that developers want due to load balancing. Specifically, load balancing specifies that load balancing is distributed to multiple operation units for operation. For example, a login service opens multiple services at the same time. Using load balancing will assign each request to a different login service according to the load of the service. In this way, the local service that the developer wants to debug cannot be accessed, resulting in the local service IP being unable to debug the code developed for the corresponding service. Developers need to gradually check the service startup status, firewall and network settings until they can successfully debug the local service code, which brings inconvenience to developers. Summary of the invention

[0003] In view of the above defects, the present invention proposes a method and system for forwarding Android application requests to different environments and specified IP services, aiming to solve the problem that during the Android development process, application requests cannot access the application environment desired by the developer due to load balancing.

[0004] To achieve this object, the present invention adopts the following technical solutions:

[0005] The method of forwarding Android application requests to different environments and specified IP services includes the following steps:

[0006] Step S1: Build SharedPreferences and spring cloud gateway;

[0007] Step S2: receiving a request for the gateway address of the environment to be switched, and a request for the IP address of a service in the same environment to be accessed;

[0008] Step S3: store the gateway address of the environment you want to switch to in SharedPreferences, using BASEURL as the key; and store the IP address of one of the services you want to access in the same environment in SharedPreferences, using the service name as the key;

[0009] Step S4: Get the BASEURL field from SharedPreferences, that is, the gateway address of the environment you want to switch to, and concatenate it with the interface address of one of the services in the same environment to obtain the request address;

[0010] Step S5: According to the prefix of the interface address of one of the services in the same environment, obtain the IP address that the service wants to access from SharedPreferences, and add the IP address that the service wants to access to the request header;

[0011] Step S6: Add ReactiveLoadBalancerClientFilter in spring cloud gateway, check the target-ip field in the request header, build a new address based on the value of the target-ip field, and replace the original request address;

[0012] Step S7: Set the request address to the Attributes of the Exchange object in the spring cloud gateway to forward the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

[0013] Preferably, in step S6, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

[0014] Preferably, in step S7, the request address is set in the Attributes of the Exchange object in the spring cloud gateway, specifically including the following sub-steps: assigning the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

[0015] Another aspect of the present invention provides a system for forwarding Android application requests to different environments and designated IP services, the system comprising:

[0016] Building modules for building SharedPreferences and spring cloud gateway;

[0017] The receiving module is used to receive a request for the gateway address of the environment to be switched, and a request for the IP address that one of the services in the same environment wants to access;

[0018] The storage module is used to store the gateway address of the environment to be switched in SharedPreferences, with BASEURL as the key; and store the IP address that one of the services in the same environment wants to access in SharedPreferences, with the service name as the key;

[0019] The first acquisition module is used to obtain the BASEURL field from SharedPreferences, that is, the gateway address of the environment to be switched;

[0020] The splicing module is used to splice the gateway address of the environment to be switched to the interface address of one of the services in the same environment to obtain the request address;

[0021] The second acquisition module is used to obtain the IP address that the service wants to access from SharedPreferences according to the prefix of the interface address of one of the services in the same environment;

[0022] The first adding module is used to add the IP address that one of the services in the same environment wants to access to the request header;

[0023] The second added module is used to add ReactiveLoadBalancerClientFilter in spring cloud gateway;

[0024] The inspection module is used to check the target-ip field in the request header, and build a new address according to the value of the target-ip field and replace the original request address;

[0025] The setting module is used to set the request address to the Attributes of the Exchange object in the spring cloud gateway to complete the forwarding of the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

[0026] Preferably, in the checking module, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

[0027] Preferably, the setting module includes an assignment submodule, and the assignment submodule is used to assign the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

[0028] The technical solution provided by the embodiments of the present application may have the following beneficial effects:

[0029] This solution sets SharedPreferences to store the environment gateway address you want to switch to and the IP address that one of the services in the same environment wants to access, so as to implement subsequent calls to the two addresses. By setting up springcloud gateway and adding custom filters to it, custom filters are used to implement load balancing. In the load balancing scenario, custom filters can access and modify the properties of requests through Exchange objects to control the forwarding of requests to specific environments and specific service instances. In this way, developers can access the local service they want to debug, so that the IP of the local service can debug the code developed for the corresponding service. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 It is a flowchart of the steps of forwarding Android application requests to different environments and specified IP services. DETAILED DESCRIPTION

[0031] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.

[0032] The method of forwarding Android application requests to different environments and specified IP services includes the following steps:

[0033] Step S1: Build SharedPreferences and spring cloud gateway;

[0034] Step S2: receiving a request for the gateway address of the environment to be switched, and a request for the IP address of a service in the same environment to be accessed;

[0035] Step S3: store the gateway address of the environment you want to switch to in SharedPreferences, using BASEURL as the key; and store the IP address of one of the services you want to access in the same environment in SharedPreferences, using the service name as the key;

[0036] Step S4: Get the BASEURL field from SharedPreferences, that is, the gateway address of the environment you want to switch to, and concatenate it with the interface address of one of the services in the same environment to obtain the request address;

[0037] Step S5: According to the prefix of the interface address of one of the services in the same environment, obtain the IP address that the service wants to access from SharedPreferences, and add the IP address that the service wants to access to the request header;

[0038] Step S6: Add ReactiveLoadBalancerClientFilter in spring cloud gateway, check the target-ip field in the request header, build a new address based on the value of the target-ip field, and replace the original request address;

[0039] Step S7: Set the request address to the Attributes of the Exchange object in the spring cloud gateway to forward the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

[0040] The method of forwarding Android application requests to different environments and specified IP services in this solution, such as Figure 1As shown in the figure, the first step is to build SharedPreferences and spring cloud gateway. Specifically, SharedPreferences is a storage mechanism provided by Android for storing application data, including configuration information in the form of key-value pairs, user preferences, etc. It is stored in the device's internal storage or external storage in the form of XML files. Spring cloudgateway is a reactive API gateway based on Spring Framework 5, Spring Boot 2, and Project Reactor. It provides a simple and flexible way to build and manage external access portals in a microservice architecture. The second step is to receive the gateway address request of the environment you want to switch to, and the IP address request that one of the services in the same environment wants to access. Specifically, in the about page of the Android application, developers can enter the gateway address of the corresponding environment in the corresponding input box of the page according to the environment they want to switch to; since an application environment contains several services, such as login service, payment service, and order service, developers select one of the services and specify the IP address that the service wants to access, and enter the IP address that the selected service wants to access in the corresponding input box of the page. The third step is to store the environment gateway address you want to switch to in SharedPreferences, and use BASEURL as the key value; and store the IP address that one of the services in the same environment wants to access in SharedPreferences, and use the service name as the key value. Specifically, the environment gateway address you want to switch to and the IP address that one of the services in the same environment wants to access are stored in SharedPreferences, which is conducive to their subsequent management and calling. In one embodiment, if the IP address that the login service in the same environment wants to access is 192.xx.xx.xx, and the name of the login service is bs-xx, 192.xx.xx.xx is stored in SharedPreferences, and bs-xx is used as the key value. The fourth step is to obtain the BASEURL field from SharedPreferences, that is, the environment gateway address you want to switch to, and splice it with the interface address of one of the services in the same environment to obtain the request address. In one embodiment, if the environment gateway address you want to switch to is the BASEURL field, the interface address of the login service is bs-xx / xxx / xxx, and the request address is BASEURL / bs-xx / xxx / xxx.The fifth step is to obtain the IP address that the service wants to access from SharedPreferences based on the prefix of the interface address of one of the services in the same environment, and add the IP address that the service wants to access to the request header. In one embodiment, if the prefix of the interface address bs-xx / xxx / xxx of the login service in the same environment is bs-xx, and the IP address that the login service wants to access is 192.xx.xx.xx, add the IP address 192.xx.xx.xx that the login service bs-xx wants to access to the request header. The specific code is as follows: header.set("target-ip", 192.xx.xx.xx). The sixth step is to add ReactiveLoadBalancerClientFilter in spring cloud gateway, check the target-ip field in the request header, and build a new address based on the value of the target-ip field, and replace the original request address. In this embodiment, ReactiveLoadBalancerClientFilter is a custom filter responsible for balancing, which can modify the load balancing strategy according to customization. When the request passes through Spring CloudGateway, CustomReactiveLoadBalancerClientFilter checks the target-ip field in the request header. If this field is found, it uses its value to build a new address and replaces the original request address. Then, the new request continues to be processed through the Gateway filter chain. The seventh step is to set the request address in the Attributes of the Exchange object in the spring cloud gateway to complete the forwarding of the request to the environment you want to switch to and the IP that one of the services in the same environment wants to access. In this embodiment, in the spring cloud gateway, the Exchange object contains all the information of the request and response, such as the request header, request body, and response status code. By storing the request address in the Attributes of the Exchange object, the spring cloud gateway can forward the request to the specified address.

[0041] This solution sets SharedPreferences to store the environment gateway address you want to switch to and the IP address that one of the services in the same environment wants to access, so as to implement subsequent calls to the two addresses. By setting up springcloud gateway and adding custom filters to it, custom filters are used to implement load balancing. In the load balancing scenario, custom filters can access and modify the properties of requests through Exchange objects to control the forwarding of requests to specific environments and specific service instances. In this way, developers can access the local service they want to debug, so that the IP of the local service can debug the code developed for the corresponding service.

[0042] Preferably, in step S6, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

[0043] In this embodiment, when ReactiveLoadBalancerClientFilter checks the target-ip field in the request header and finds that the target-ip field has no value, it retains the original request address and sets the request address to the Attributes of the Exchange object in the spring cloud gateway.

[0044] Preferably, in step S7, the request address is set in the Attributes of the Exchange object in the spring cloud gateway, specifically including the following sub-steps: assigning the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

[0045] In this embodiment, the request address is assigned to the GATEWAY_REQUEST_URL_ATTR field in the Attributes of the Exchange object. The specific relevant code is as follows: Exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl), where Exchange.getAttributes().put() is a method for adding attributes to HTTP requests or responses, and GATEWAY_REQUEST_URL_ATTR is a string constant customized by the balancing framework. In the load balancing scenario, the function of the GATEWAY_REQUEST_URL_ATTR parameter is to store the target URL of the request in the attributes of the Exchange object. Load balancing is to distribute incoming requests to multiple backend service instances to achieve high availability and performance optimization. In the gateway or proxy server, the GATEWAY_REQUEST_URL_ATTR parameter can be used to store the URL of the target service instance selected by the load balancing algorithm.

[0046] Another aspect of the present invention provides a system for forwarding Android application requests to different environments and designated IP services, the system comprising:

[0047] Building modules for building SharedPreferences and spring cloud gateway;

[0048] The receiving module is used to receive a request for the gateway address of the environment to be switched, and a request for the IP address that one of the services in the same environment wants to access;

[0049] The storage module is used to store the gateway address of the environment to be switched in SharedPreferences, with BASEURL as the key; and store the IP address that one of the services in the same environment wants to access in SharedPreferences, with the service name as the key;

[0050] The first acquisition module is used to obtain the BASEURL field from SharedPreferences, that is, the gateway address of the environment to be switched;

[0051] The splicing module is used to splice the gateway address of the environment to be switched to the interface address of one of the services in the same environment to obtain the request address;

[0052] The second acquisition module is used to obtain the IP address that the service wants to access from SharedPreferences according to the prefix of the interface address of one of the services in the same environment;

[0053] The first adding module is used to add the IP address that one of the services in the same environment wants to access to the request header;

[0054] The second added module is used to add ReactiveLoadBalancerClientFilter in spring cloud gateway;

[0055] The inspection module is used to check the target-ip field in the request header, and build a new address according to the value of the target-ip field and replace the original request address;

[0056] The setting module is used to set the request address to the Attributes of the Exchange object in the spring cloud gateway to complete the forwarding of the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

[0057] The Android application requests of this solution are forwarded to systems with different environments and specified IP services. Through the cooperation of the construction module, the receiving module, the storage module, the first acquisition module, the splicing module, the second acquisition module, the first adding module, the second adding module, the inspection module and the setting module, the requests can be forwarded to specific environments and specific services in the load balancing scenario.

[0058] Preferably, in the checking module, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

[0059] In this embodiment, when ReactiveLoadBalancerClientFilter checks the target-ip field in the request header and finds that the target-ip field has no value, it retains the original request address and sets the request address to the Attributes of the Exchange object in the spring cloud gateway.

[0060] Preferably, the setting module includes an assignment submodule, and the assignment submodule is used to assign the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

[0061] In this embodiment, the request address is assigned to the GATEWAY_REQUEST_URL_ATTR field in the Attributes of the Exchange object. The specific relevant code is as follows: Exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl), where Exchange.getAttributes().put() is a method for adding attributes to HTTP requests or responses, and GATEWAY_REQUEST_URL_ATTR is a string constant customized by the balancing framework. In the load balancing scenario, the function of the GATEWAY_REQUEST_URL_ATTR parameter is to store the target URL of the request in the attributes of the Exchange object. Load balancing is to distribute incoming requests to multiple backend service instances to achieve high availability and performance optimization. In the gateway or proxy server, the GATEWAY_REQUEST_URL_ATTR parameter can be used to store the URL of the target service instance selected by the load balancing algorithm.

[0062] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0063] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A method for forwarding Android application requests to different environments and designated IP services, characterized in that: The following steps are involved: Step S1: Build SharedPreferences and spring cloud gateway, where SharedPreferences is a storage mechanism provided by Android for storing application data; spring cloud gateway is a reactive API gateway based on Spring Framework 5, Spring Boot 2, and Project Reactor, which provides a simple and flexible way to build and manage external access portals in a microservice architecture; Step S2: receiving a request for the gateway address of the environment to be switched, and a request for the IP address of a service in the same environment to be accessed; Step S3: store the gateway address of the environment you want to switch to in SharedPreferences, using BASEURL as the key; and store the IP address of one of the services you want to access in the same environment in SharedPreferences, using the service name as the key; Step S4: Get the BASEURL field from SharedPreferences, that is, the gateway address of the environment you want to switch to, and concatenate it with the interface address of one of the services in the same environment to obtain the request address; Step S5: According to the prefix of the interface address of one of the services in the same environment, obtain the IP address that the service wants to access from SharedPreferences, and add the IP address that the service wants to access to the request header; Step S6: Add ReactiveLoadBalancerClientFilter in spring cloud gateway, check the target-ip field in the request header, build a new address based on the value of the target-ip field, and replace the original request address; Step S7: Set the request address to the Attributes of the Exchange object in the spring cloud gateway to forward the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

2. The method for forwarding Android application requests to different environments and designated IP services according to claim 1, characterized in that: In step S6, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

3. The method for forwarding Android application requests to different environments and designated IP services according to claim 1, characterized in that: In step S7, the request address is set in the Attributes of the Exchange object in the spring cloud gateway, specifically including the following sub-steps: assigning the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

4. Android application requests are forwarded to different environments and designated IP service systems, characterized by: Using the method for forwarding Android application requests to different environments and designated IP services as described in any one of claims 1 to 3, the system includes: Building modules for building SharedPreferences and spring cloud gateway. SharedPreferences is a storage mechanism provided by Android for storing application data. Spring cloud gateway is a reactive API gateway based on Spring Framework 5, Spring Boot 2, and Project Reactor. It provides a simple and flexible way to build and manage external access points in a microservice architecture. The receiving module is used to receive a request for the gateway address of the environment to be switched, and a request for the IP address that one of the services in the same environment wants to access; The storage module is used to store the gateway address of the environment to be switched in SharedPreferences, with BASEURL as the key; and store the IP address that one of the services in the same environment wants to access in SharedPreferences, with the service name as the key; The first acquisition module is used to obtain the BASEURL field from SharedPreferences, that is, the gateway address of the environment to be switched; The splicing module is used to splice the gateway address of the environment to be switched to the interface address of one of the services in the same environment to obtain the request address; The second acquisition module is used to obtain the IP address that the service wants to access from SharedPreferences according to the prefix of the interface address of one of the services in the same environment; The first adding module is used to add the IP address that one of the services in the same environment wants to access to the request header; The second added module is used to add ReactiveLoadBalancerClientFilter in spring cloud gateway; The inspection module is used to check the target-ip field in the request header, and build a new address according to the value of the target-ip field and replace the original request address; The setting module is used to set the request address to the Attributes of the Exchange object in the spring cloud gateway to complete the forwarding of the request to the environment you want to switch to and the IP address that one of the services in the same environment wants to access.

5. The system for forwarding Android application requests to different environments and designated IP services according to claim 4, characterized in that: In the inspection module, when checking the target-ip field in the request header, if the value of the target-ip field is empty, the original request address is returned.

6. The system for forwarding Android application requests to different environments and designated IP services according to claim 4, characterized in that: The setting module includes an assignment submodule, and the assignment submodule is used to assign the request address to the GATEWAY_REQUEST_URL_ATTR parameter in the Attributes of the Exchange object.

Citation Information

Patent Citations

  • Load balancing method and system for SSL VPN security gateway

    CN115987900A

  • Custom load balancing device, method and equipment based on gateway and storage medium

    CN117221325A