Quick conversion method from JavaWeb application to gRPC service

By mapping the Controller method of JavaWeb application to the interface of gRPC service and generating corresponding Proto and Desc files, the rapid conversion of JavaWeb application to gRPC service is realized, solving the problems of conversion difficulties and complex development in the existing technology, and improving development efficiency and code reusability.

CN120011104APending Publication Date: 2025-05-16BEIJING QIERBULAITE TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510089713.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-20
Publication Date
2025-05-16

Smart Images

  • Figure CN120011104A_ABST
    Figure CN120011104A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of JavaWeb application, and discloses a method for quickly converting JavaWeb application to gRPC service, which comprises the following steps of: A1, creating a Proto file; a2, creating a Desc file; and A3, the application is started, and the Server ServiceDefinition is generated. By adopting an advanced framework and technology, the development process of the gRPC service can be remarkably simplified, the code reusability is improved, in the process, the change not only greatly reduces the burden of developers, but also enables the existing Controller logic to be directly reused, so that the maximum utilization of resources and the improvement of the development efficiency are realized, and in addition, the development efficiency of the gRPC service is improved. The technical framework also shows extremely high flexibility and expandability, and provides a rapid conversion mechanism from Web service to gRPC service, so that developers can easily deal with the change of business requirements, and along with the development of the business, the framework also can support subsequent expansion and optimization work, and ensure continuous evolution and performance improvement of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of JavaWeb applications, and specifically relates to a method for quickly converting a JavaWeb application to a gRPC service. Background Art

[0002] JavaWeb, also known as Java Web, is a program developed in Java language and can be run on the World Wide Web. It involves two parts: Web server and Web client. It mainly uses communication to interact with Java. Java performs logical processing in the background, while Web displays content in the web page and presents it to users.

[0003] gRPC is a high-performance, cross-language remote procedure call (RPC) framework originally developed and open-sourced by Google. It is based on the HTTP / 2 protocol and uses Protocol Buffers (Protobuf for short) as the interface definition language (IDL) to define services and message types.

[0004] When JavaWeb needs to be applied to the gRPC service, the conversion method will be used. The general conversion method cannot directly support the gRPC protocol, requires additional configuration and development, and needs to define interfaces and implementations specifically for it, so it needs to be modified and optimized. Summary of the invention

[0005] The purpose of the present invention is to provide a method for quickly converting a JavaWeb application to a gRPC service to solve the problems raised in the above background technology.

[0006] In order to achieve the above object, the present invention provides the following technical solution: a method for quickly converting a JavaWeb application to a gRPC service, the steps of the method are:

[0007] A1, create Proto file: map the method obtained from the Controller to message and automatically generate Proto file;

[0008] A2, create Desc file: generate Desc file by compiling Proto file;

[0009] A3, start the application and generate ServerServiceDefinition: Generate ServerServiceDefinition by loading the Desc file, and establish a mapping relationship with the Controller and its method (Action).

[0010] Preferably, the steps in A1 are divided into:

[0011] B1, Analyze Java Controller: parse the methods, parameters and return types from the Controller of Java Web application;

[0012] B2, define the mapping relationship: map the Java Web application's Controller to the gRPC service, where the Controller's method is mapped to rpc, and the parameters and return values ​​in the Controller are mapped to message;

[0013] B3, Generate Proto file: Generate the corresponding Proto file according to the mapping relationship.

[0014] Preferably, the steps in A3 are:

[0015] C1, Load Desc file: When the Java Web application is started, the tool automatically loads the pre-generated Desc;

[0016] C2, ServerServiceDefinition generation: Build gRPC's ServerServiceDefinition based on the Desc file;

[0017] C3, realize parallel connection with Controller: establish mapping relationship between ServerServiceDefinition and the original Controller and its methods.

[0018] Preferably, custom mapping rules: users can define the mapping logic from Controller to gRPCService by themselves with the help of configuration files or annotations;

[0019] Security authentication: Through configuration, you can add the security authentication mechanism of gRPC.

[0020] Preferably, the mapping relationship refers to a user-defined rule for corresponding or associating the original Controller and its methods with the gRPCService.

[0021] Preferably, the software for compiling the Proto file in A2 is a Proto compiler (protoc), and the Proto compiler (protoc) is integrated in the tool.

[0022] Preferably, the gRPC is a remote procedure call protocol;

[0023] proto is the extension of Protocol Buffers file;

[0024] desc is the Grpc description file;

[0025] ServerServiceDefinition is the server service definition.

[0026] Preferably, the Proto compiler is a Protocol Buffers compiler, which is used to compile .proto files into codes in multiple programming languages.

[0027] The beneficial effects of the present invention are as follows:

[0028] By adopting advanced frameworks and technologies, the present invention can significantly simplify the development process of gRPC services and improve code reusability. In this process, the biggest highlight is that there is no need to manually write cumbersome gRPC service definitions. This change not only greatly reduces the burden on developers, but also enables the existing Controller logic to be directly reused, thereby maximizing resource utilization and improving development efficiency. In addition, the technical framework also demonstrates extremely high flexibility and scalability. It provides a fast conversion mechanism from Web services to gRPC services, allowing developers to easily respond to changes in business needs. As the business develops, the framework can also support subsequent expansion and optimization work to ensure the continuous evolution and performance improvement of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 The present invention is a flow chart of the method of the present invention;

[0030] Figure 2 A schematic diagram of the process of creating a Proto file for A1 of the present invention;

[0031] Figure 3 A schematic diagram of the process of starting an application and generating a ServerServiceDefinition according to the present invention;

[0032] Figure 4 The figure is a simplified flow chart of the rapid conversion method of the present invention. DETAILED DESCRIPTION

[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] like Figures 1 to 4 As shown, an embodiment of the present invention provides a method for quickly converting a Java Web application to a gRPC service, the steps of the method are:

[0035] A1, create Proto file: map the method obtained from the Controller to message and automatically generate Proto file;

[0036] A2, create Desc file: generate Desc file by compiling Proto file;

[0037] A3, start the application and generate ServerServiceDefinition: Generate ServerServiceDefinition by loading the Desc file, and establish a mapping relationship with the Controller and its method (Action).

[0038] By adopting advanced frameworks and technologies, we can significantly simplify the development process of gRPC services and improve code reusability. The biggest highlight of this process is that there is no need to manually write tedious gRPC service definitions. This change not only greatly reduces the burden on developers, but also enables the existing Controller logic to be directly reused, thereby maximizing resource utilization and improving development efficiency. In addition, the technical framework also demonstrates extremely high flexibility and scalability. It provides a fast conversion mechanism from Web services to gRPC services, allowing developers to easily respond to changes in business needs. As the business develops, the framework can also support subsequent expansion and optimization work to ensure the continuous evolution and performance improvement of the system.

[0039] The steps in A1 are as follows:

[0040] B1, Analyze Java Controller: parse the methods, parameters and return types from the Controller of Java Web application;

[0041] B2, define the mapping relationship: map the Controller of the JavaWeb application to the gRPC service, where the Controller method is mapped to rpc, and the parameters and return values ​​in the Controller are mapped to message;

[0042] B3, Generate Proto file: Generate the corresponding Proto file according to the mapping relationship.

[0043] By deeply analyzing the Java Controller, we extracted key information such as methods, parameters, and return types. This step provides a solid foundation for the entire conversion process and ensures that the subsequent steps can accurately capture the core points of the business logic. By defining the mapping relationship between the Java Controller and the gRPC service, we convert the Controller method into the gRPC rpc method, and convert the parameters and return values ​​into the gRPC message type. This step not only ensures that the business logic of the Java Web application can be accurately reflected in the gRPC service, but also realizes cross-language and cross-platform communication capabilities. According to the mapping relationship, the corresponding Proto file is generated. This file is the core definition of the gRPC service, which contains the service interface definition, message type, and necessary metadata. By generating the Proto file, we have achieved seamless docking between the Java Web application and the gRPC service, and it has greatly facilitated the subsequent code generation, compilation, and deployment.

[0044] The steps in A3 are:

[0045] C1, Load Desc file: When the Java Web application is started, the tool automatically loads the pre-generated Desc;

[0046] C2, ServerServiceDefinition generation: Build gRPC's ServerServiceDefinition based on the Desc file;

[0047] C3, realize parallel connection with Controller: establish mapping relationship between ServerServiceDefinition and the original Controller and its methods.

[0048] By loading the Desc file, when the JavaWeb application starts, the system will automatically load the pre-generated Desc file, which describes in detail the interface, message type and other key information of the gRPC service. Through this step, the application can fully obtain the definition of the gRPC service, laying a solid foundation for the smooth progress of subsequent steps. By generating ServerServiceDefinition, it is the core link in the integration process. After successfully loading the Desc file, the application will build the gRPC ServerServiceDefinition according to the information in it. This step is crucial because it converts the service definition in the Desc file into a format that the gRPC framework can recognize, providing the necessary preparation for service registration and request processing. By implementing parallel connection with the Controller, the application will establish a mapping relationship between the ServerServiceDefinition and the original Controller and its methods, which means that the rpc method in the gRPC service and the Controller method in the JavaWeb application will be matched, ensuring that when the gRPC request arrives, the corresponding Controller method can be accurately called for processing. The implementation of this step not only ensures the seamless integration of the JavaWeb application and the gRPC service, but also enables the application to support traditional Web requests and gRPC requests at the same time, thereby greatly improving the flexibility and scalability of the system.

[0049] Among them, custom mapping rules: users can define the mapping logic from Controller to gRPCService by themselves with the help of configuration files or annotations;

[0050] Security authentication: Through configuration, you can add the security authentication mechanism of gRPC.

[0051] Defining mapping rules provides users with great flexibility. In traditional integration methods, the mapping logic from Controller to gRPCService is often automatically completed by the framework or tool, which limits the user's customization capabilities to a certain extent. However, by introducing custom mapping rules, users can now use configuration files or annotations to define the mapping logic themselves. This method not only makes the mapping process more transparent and controllable, but also allows users to flexibly adjust it according to their business needs. For example, users can define different mapping strategies based on the naming rules, parameter types, or return value types of Controller methods, thereby achieving more refined service division and calling. Security authentication is an indispensable part of gRPC services. In distributed systems, communication between services often involves the transmission and access control of sensitive data, so the security authentication mechanism is particularly important. By configuring the security authentication mechanism, the gRPC service can verify and authorize the client identity, thereby ensuring that only legitimate clients can access the service. This security authentication mechanism can be implemented based on a variety of authentication methods, such as SSL / TLS certificates, API keys, OAuth2, etc. Through reasonable configuration, users can easily add a layer of security to their gRPC services to effectively prevent unauthorized access and data leakage.

[0052] The mapping relationship refers to a user-defined rule for corresponding or associating the original Controller and its methods with the gRPCService.

[0053] By customizing the mapping rules, users can precisely control which Controller methods should be exposed as interfaces of gRPC services, and how to associate these interfaces with the rpc methods of gRPC. This not only makes the service division clearer, but also facilitates subsequent service calls and maintenance. At the same time, the custom mapping relationship also provides users with more freedom, allowing them to flexibly adjust the correspondence between Controller and gRPC Service according to their own business logic and architecture requirements, thereby building a distributed system that better meets actual needs.

[0054] The software for compiling the Proto file in A2 is a Proto compiler (protoc), and the Proto compiler (protoc) is integrated in the tool.

[0055] The Proto compiler (protoc) is integrated into the tool as software for compiling Proto files. It is used to compile .proto files (the extension of Protocol Buffers files) into code in multiple programming languages. This step is the basis for building gRPC services, which ensures that the interface definition of the service can be consistent between different languages.

[0056] Wherein, the gRPC is a remote procedure call protocol;

[0057] proto is the extension of Protocol Buffers file;

[0058] desc is the Grpc description file;

[0059] ServerServiceDefinition is the server service definition.

[0060] As a remote procedure call protocol, gRPC has greatly promoted the efficient and reliable communication of services in distributed systems. Its cross-language and cross-platform capabilities have significantly improved the flexibility and scalability of the system. In the process of building gRPC services, the Desc file (Grpc description file) plays a vital role. It records key information such as service interfaces and message types in detail, and provides applications with the necessary definitions for building services. ServerServiceDefinition, as a core component in the gRPC framework, defines the interface and implementation methods of the service, ensuring that the service can be correctly registered and called. In summary, gRPC, Desc files, and ServerServiceDefinition together constitute the basis for building efficient and reliable gRPC services.

[0061] The Proto compiler is a Protocol Buffers compiler, which is used to compile .proto files into codes in multiple programming languages.

[0062] The Proto compiler is a dedicated compiler for Protocol Buffers. Its key role is to compile .proto files into code in multiple programming languages. This process provides developers with the ability to maintain data consistency between different programming languages ​​and is the basis for cross-language communication. Through the Proto compiler, developers can easily convert .proto files into code suitable for their project programming language, thereby simplifying the data exchange and communication process of services in distributed systems and improving the flexibility and interoperability of the system.

[0063] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0064] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for quickly converting a JavaWeb application to a gRPC service, characterized in that: The steps of this method are: A1, create Proto file: map the method obtained from the Controller to message and automatically generate Proto file; A2, create Desc file: generate Desc file by compiling Proto file; A3, start the application and generate ServerServiceDefinition: Generate ServerServiceDefinition by loading the Desc file, and establish a mapping relationship with the Controller and its method (Action).

2. According to claim 1, a method for quickly converting a JavaWeb application to a gRPC service is characterized in that: The steps in A1 are as follows: B1, Analyze Java Controller: parse the methods, parameters and return types from the Controller of Java Web application; B2, define the mapping relationship: map the Java Web application's Controller to the gRPC service, where the Controller's method is mapped to rpc, and the parameters and return values ​​in the Controller are mapped to message; B3, Generate Proto file: Generate the corresponding Proto file according to the mapping relationship.

3. According to claim 1, a method for quickly converting a JavaWeb application to a gRPC service is characterized in that: The steps in A3 are: C1, Load Desc file: When the Java Web application is started, the tool automatically loads the pre-generated Desc; C2, ServerServiceDefinition generation: Build gRPC's ServerServiceDefinition based on the Desc file; C3, realize parallel connection with Controller: establish mapping relationship between ServerServiceDefinition and the original Controller and its methods.

4. According to claim 1, a method for rapid conversion of JavaWeb applications to gRPC services is characterized in that: Custom mapping rules: Users can define the mapping logic from Controller to gRPCService by themselves with the help of configuration files or annotations; Security authentication: Add gRPC security authentication mechanism through configuration.

5. According to claim 1, a method for rapid conversion of JavaWeb applications to gRPC services is characterized in that: The mapping relationship refers to the rules defined by the user that correspond or associate the original Controller and its methods with the gRPC Service.

6. According to claim 1, a method for rapid conversion of JavaWeb applications to gRPC services is characterized in that: The software for compiling the Proto file in A2 is a Proto compiler (protoc), which is integrated in the tool.

7. According to claim 1, a method for rapid conversion of JavaWeb applications to gRPC services is characterized in that: The gRPC is a remote procedure call protocol; proto is the extension of the Protocol Buffers file; desc is a Grpc description file; ServerServiceDefinition is a server service definition.

8. According to claim 1, a method for rapid conversion of JavaWeb applications to gRPC services, characterized in that: The Proto compiler is a compiler for Protocol Buffers, which is used to compile .proto files into codes in multiple programming languages.