CN116055569B - Method, system, computer device and storage medium for custom switching time zone - Google Patents

Method, system, computer device and storage medium for custom switching time zone Download PDF

Info

Publication number
CN116055569B
CN116055569B CN202310331440.4A CN202310331440A CN116055569B CN 116055569 B CN116055569 B CN 116055569B CN 202310331440 A CN202310331440 A CN 202310331440A CN 116055569 B CN116055569 B CN 116055569B
Authority
CN
China
Prior art keywords
time zone
time
request
type
parameter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310331440.4A
Other languages
Chinese (zh)
Other versions
CN116055569A (en
Inventor
郭斌
沈舒男
韦锦涛
张虎涛
邓新星
王国光
郑波
金怡成
李昱
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang East China Engineering Digital Technology Co ltd
PowerChina Huadong Engineering Corp Ltd
Original Assignee
Zhejiang East China Engineering Digital Technology Co ltd
PowerChina Huadong Engineering Corp Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang East China Engineering Digital Technology Co ltd, PowerChina Huadong Engineering Corp Ltd filed Critical Zhejiang East China Engineering Digital Technology Co ltd
Priority to CN202310331440.4A priority Critical patent/CN116055569B/en
Publication of CN116055569A publication Critical patent/CN116055569A/en
Application granted granted Critical
Publication of CN116055569B publication Critical patent/CN116055569B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/14Network architectures or network communication protocols for network security for detecting or protecting against malicious traffic
    • H04L63/1433Vulnerability analysis
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/30Network architectures or network communication protocols for network security for supporting lawful interception, monitoring or retaining of communications or communication related information
    • H04L63/306Network architectures or network communication protocols for network security for supporting lawful interception, monitoring or retaining of communications or communication related information intercepting packet switched data communications, e.g. Web, Internet or IMS communications
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/146Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/2866Architectures; Arrangements
    • H04L67/30Profiles
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/08Protocols for interworking; Protocol conversion
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention discloses a method, a system, computer equipment and a storage medium for self-defining time zone switching, wherein the method comprises the following steps: creating a type converter for time data at an application server; creating a request interceptor at an application client and performing zone configuration; the application client intercepts a request sent to the server based on a request interceptor and adds a time zone identification request header; the application server side performs parameter analysis and return value processing on the received request and judges whether time zone conversion is required to be executed when the type of the parameter or the return value is converted; if necessary, the parameter or the return value is subjected to type conversion based on the type converter, and time zone conversion processing is performed in the conversion process. According to the invention, time zone conversion of time data is carried out on the messages received and returned by the application program server, so that the application program client in different time zones can process and display the time data correctly, and the use experience of a user is ensured.

Description

Method, system, computer device and storage medium for custom switching time zone
Technical Field
The invention relates to the field of message conversion of data transmission in an information system, in particular to a method, a system, computer equipment and a storage medium for self-defining time zone switching applied to a web system.
Background
Time zone refers to a region that complies with uniform standard time for legal, business, and social purposes. Previously, people have decided time by looking at the position of the sun (time angle), which makes the time in different longitude places different (when places). World countries are located in different locations on earth, so that the sunrise and sunset times of different countries, particularly countries with large east-west spans, must deviate, which is the so-called time difference. In 1863, the concept of time zone was used for the first time, and this problem was partially solved by setting up a standard time for an area. At the same time, however, time zone processing of time data in an application is plagued by many developers due to the existence of time zones. With the rise of global internationalization degree, more and more web systems start to develop internationalization, and provide services for multiple regions of the world. These systems often require different times to be displayed for different areas and different cities where different users are located, while the application server may store the received different time data using different time zones, presenting greater challenges to the application developer.
In such a web system, conventionally, a logic part for time zone conversion is added in a service code, and the time zone difference is manually coded and compared during conversion, so as to calculate, thereby achieving the purpose of time zone conversion.
However, the drawbacks are apparent from the above approach:
1) The functional code and the service code are seriously coupled, so that the code becomes complex, the later code reconstruction and maintenance are not facilitated, and the flexibility is very low.
2) The businesses in different areas usually need different teams or personnel to develop, and they usually need to write the conversion codes of the corresponding time zones by themselves, so that errors are easy to occur, and the fault probability of the system is increased.
3) In order to realize or increase the operation in one time zone, the links of application program modification, application program deployment and the like are often needed, and the operation and maintenance pressure is high.
Disclosure of Invention
Aiming at the defects in the prior art, the invention provides a method and a system for self-defining time zone switching applied to a web system, which are used for carrying out time zone conversion on time data of a message received and returned by an application server by providing a time zone processing method of time data, so that application clients in different time zones can process and display the time data correctly, and the use experience of a user is ensured. Meanwhile, when the user in the new time zone needs to be provided with service, the method can support dynamic addition and switching, does not need to redeploy an application program server, and rapidly meets the time data processing and display requirements in different time zones.
To this end, the first aspect of the present invention provides a method for custom switching time zones, comprising the steps of:
creating a type converter for time data at an application server;
creating a request interceptor at an application client and performing zone configuration;
the application client intercepts a request sent to the server based on a request interceptor and adds a time zone identification request header;
the application server side performs parameter analysis and return value processing on the received request and judges whether time zone conversion is required to be executed when the type of the parameter or the return value is converted; if so, performing type conversion on the parameter or the return value based on the type converter, and executing time zone conversion processing in the type conversion process of the parameter or the return value.
In some embodiments, time zone configuration at the application client comprises:
configuring an API address for acquiring time zone configuration information in an application program client configuration file;
calling the API when the application client starts to acquire the time zone configuration corresponding to the current client;
if the acquisition fails, the time zone configuration is constructed using the time zone in which the current application client is located.
In some embodiments, the configuration items of the time zone configuration include: global time format, global time zone ID, and special URL time zone configuration.
In some embodiments, the special URL time zone configuration includes: the current sequence number, the resource path URL, the request method type, the current URL time format, and the current URL time zone ID.
In some embodiments, the adding time zone identification request header specifically includes:
according to the intercepted path of the URL of the current request, the special URL time zone configuration data in the time zone configuration are taken out one by one for comparison, whether the corresponding resource path URL exists or not is compared, if yes, the subsequent judgment is continued, otherwise, the global time zone configuration is used for adding a time zone identification request head for the request;
if the URL of the corresponding resource path exists, the request method type of the URL path is compared with the request method type in the special URL time zone configuration data, if the request method type is inconsistent with the request method type in the special URL time zone configuration data, the global time zone configuration is used for adding the time zone identification request header for the request, and if the request method type is consistent with the request time zone identification request header for the request by using the current URL time format in the special URL time zone configuration data and the current URL time zone ID.
In some embodiments, determining whether time zone conversion is needed to be performed when converting a parameter or return value type includes:
in a type converter aiming at time data, acquiring request heads of a current request, judging whether the request heads contain time zone identification request heads or not, and if so, executing a subsequent judging flow; if not, time zone conversion processing is not added to the type conversion of the parameter or the return value;
judging whether the time zone identifier is a time zone supported by the application program server side or not: according to the obtained time zone identifier of the current request, a time format in the time zone identifier is taken out, and whether the time format is available is judged; according to the obtained time zone identifier of the current request, the time zone ID in the time zone identifier is taken out, and whether the time ID is available or not is judged; if all the above conditions are met, executing time zone conversion processing; if not, no time zone conversion process is added to the type conversion of the parameter or return value.
In some embodiments, the performing time zone conversion processing during parameter or response type conversion includes:
constructing a time formatting tool in the type converter according to the time format in the time zone identifier;
acquiring a corresponding time zone in the type converter according to the time zone ID in the time zone identifier, and setting the time zone in the time formatting tool;
a time formatting tool is used in the type converter to parse the parameters or responses.
In a second aspect, the present invention provides a system for custom switching time zones, comprising:
an application server configured with a type converter for time data;
an application client configured with a request interceptor and performing time zone configuration;
the application client intercepts a request sent to the server based on a request interceptor and adds a time zone identification request header;
the application server performs parameter analysis and return value processing on the received request, and judges whether time zone conversion is required to be executed when the type of the parameter or the return value is converted; if so, performing type conversion on the parameter or the return value based on the type converter, and executing time zone conversion processing in the type conversion process of the parameter or the return value.
A third aspect of the present invention provides a computer device comprising a memory and a processor, the memory and the processor being communicatively coupled to each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the method of custom switching time zones as described in the first aspect above.
A fourth aspect of the present invention provides a computer readable storage medium comprising a stored program, wherein the computer readable storage medium stores computer instructions for causing a computer to execute the method of custom switching time zones as described in the first aspect above when the computer is run.
The beneficial effects of the invention are as follows:
the time zone switching method of the embodiment of the invention is a brand new time zone switching method supporting the self-defined switching, and the time zone switching codes and specific service codes in the web system are mutually decoupled after the technical scheme of the invention is adopted, so that the difficulty of code reconstruction and maintenance is greatly reduced, and the subsequent function expansion can be flexibly supported.
The related functions of the embodiment of the invention can be extracted and packaged into a plug-in, and distributed to development teams or personnel of different businesses, and the requirement of self-defining time zone switching can be realized by only introducing the plug-in, so that code confusion caused by modification of different personnel is reduced, and the system fault probability is reduced.
The embodiment of the invention also provides a configuration for time formatting, which can conveniently modify the representation mode of the time data in the application program and meet the time display habit and the use habit of users in different areas.
In the embodiment of the invention, the client time zone configuration item and the time zone identification request head can be transmitted in an encrypted manner, so that the security holes of sensitive information leakage and hijacking in message transmission are solved, the configuration information or the request head can be prevented from being tampered, and the security of the system is improved.
The embodiment of the invention supports the restart validation after the time zone configuration of the application program client is changed, for example: the original time zone where the application program client is located is UTC+8 (CT/CST-original standard time), when the time zone of the application program which is required to be distributed to the user is changed into UTC+9 (JST-Japanese standard time), only the time zone configuration corresponding to the client needs to be modified; after configuration is modified, the client can take effect after restarting without redeploying the application server, and the complexity of operation and maintenance of the application server can be greatly reduced.
To sum up: by adopting the method of the invention, the robustness of the whole web system in internationalization can be greatly improved, the development workload can be reduced, and the operation and maintenance difficulty of the system can be greatly reduced.
Drawings
FIG. 1 is a flow chart illustrating a method for customizing a switching time zone of a web system according to an embodiment of the present invention.
FIG. 2 is a schematic diagram illustrating a client obtaining a time zone profile according to an embodiment of the present invention.
FIG. 3 is a schematic diagram of time zone profile content according to an embodiment of the present invention.
FIG. 4 is a diagram illustrating a specific URL time zone configuration according to an embodiment of the present invention.
FIG. 5 is a diagram illustrating a request header time zone identifier according to an embodiment of the present invention.
FIG. 6 is a flowchart of a server determining whether time zone conversion is needed when the parameter type is converted according to an embodiment of the present invention.
Detailed Description
The invention will now be described in further detail with reference to the drawings and the accompanying examples. It will be apparent that the described embodiments are some, but not all, embodiments of the invention. All other embodiments, which can be made by a person skilled in the art without creative efforts, based on the described embodiments of the present invention fall within the protection scope of the present invention.
It should be noted that, in one or more embodiments of the present application, date refers to a time form in a web system application program, and may be converted with a character string. Furthermore, unless defined otherwise, technical or scientific terms used herein should be given the ordinary meaning as understood by one of ordinary skill in the art to which this invention belongs.
FIG. 1 is a flow chart of a method for user-defined time zone switching for a web system according to an embodiment of the present invention, comprising the following steps:
s1: a type converter for the time data is created at the application server.
The application program server side is required to complete parameter analysis of the request message, a parameter analyzer (HandlerMethodadumentResolver) is required to analyze parameters of a message request sent by the application program client side, and a type Converter (Converter) is required to convert data types in the request message into data types which can be used by the application program server side in the analysis process; similarly, after the execution of the application server is completed, a return value processor (handlemethod return value handler) needs to be used for processing the operation result data, and a type Converter (Converter) needs to be used for converting the operation result data into a response message and returning the response message to the application client in the processing process.
In this embodiment, a type converter for time data needs to be created at the application server. The type converter is used for performing time zone conversion on the time data in the request and the response, and performing time zone conversion operation after judging whether the time data in the request and the response are to be subjected to time zone conversion.
The general application program adopts a specific framework to develop a server program, the web development framework which is popular in Java at present is a Spring framework (a J2EE application framework of open source codes is initiated by Rod Johnson and is a lightweight container for managing the life cycle of beans), and the framework defaults to provide a plurality of parameter resolvers, return value processors and type converters for developers to use, and meanwhile, the developers can expand the parameters to realize the enhancement function.
The application program service end of the embodiment performs parameter analysis of the request message and generation of the response message based on a parameter analyzer and a return value processor which are self-contained in the Spring framework. Spring provides a requestresponsebody method processor to perform Json (JavaScript Object Notation is a lightweight data exchange format that is easy for a person to read and write, and also easy for a machine to parse and generate) parameter parsing and return value processing of data.
It should be noted that the RequestResponseBodyMethodprocessor inherits from the Abstract MessageConverter Methodprocessor, while the Abstract MessageConverter Methodprocessor inherits from AbstractMessageConverterMethodArgumentResolver, abstractMessageConverterMethodArgumentResolver implements the HandlerMethoddAcumentResolver interface; meanwhile, the AbstractMessageConverter method processor realizes a HandlerMethodReturn value handler interface. Therefore, the RequestResponseBodyMethodProcessor can perform both parameter parsing and return value processing.
Note that the requestresponsebody method processor is only one of the parameter resolvers and the return value processor, and the Json data is one of the data that the requestresponsebody method processor can process. Other parameter resolvers, return value processors, and message data types are not described herein because of the same principle.
In the process of processing Json data by a RequestResponseBodyMethodProcessor, spring provides a MappingJackson2HttpMessageConverter to realize the interconversion of Json data and Java objects in a message. The core of the MappingJackson2HttpMessageConverter conversion is the ObjectMapper provided by Jackson. The ObjectMapper provides a method for registering modules, and this embodiment creates a custom time processing module, and adds Date-related serialization and deserialization programs to the module.
It should be noted that Jackson is a set of data processing tools suitable for Java (and JVM platforms), including streaming JSON parser/producer libraries, matching data binding libraries (POJO to JSON conversion), and additional data format libraries (supporting widely used data types). Jackson provides a simple module SimpleModule that provides the ability to register serialization and deserialization programs. Jackson provides a time serialization program JsonSerializer < Date >, which is responsible for converting Date to character strings, and a time deserializer < Date >, which is responsible for converting character strings to Date.
It should be noted that, when the custom time processing module is created in this embodiment, a program class needs to be created first. The created program class inherits SimpleModule, namely the capability of having the registration serialization program and the anti-serialization program of the inherited class, and the inherited custom time processing module can be named as FawkesTimeZoneDateModule. When creating the Date related serialization program and the reverse serialization program, two program classes need to be created, the created program classes inherit the corresponding serialization program and the reverse serialization program, that is, possess the time serialization and reverse serialization capabilities of the inherited classes, the inherited time serialization program can be named as a CustomtimTimeZoneDateSerializer, and the inherited time deserialization program can be named as a CustomtimeZoneDateDeserializer. After the time serialization and inverse serialization programs are created, the addition needs to be performed on the custom time processing module, and after the addition is completed, the module registration needs to be performed on the ObjectMapper.
It should be noted that, if the application client and the application server in the present embodiment are developed based on other frameworks, a type converter corresponding to the framework needs to be created, which is not described herein.
S2: a request interceptor is created at the application client.
To complete adding time zone identifiers to all requests sent by the application client, an Interceptor (Interceptor) is required to intercept the message requests sent by the application client. In this embodiment, a request interceptor needs to be created at the application client. The interceptor is used for intercepting the request and judging which time zone identifier is added through the time zone configuration of the application program client.
A specific framework is adopted by a general application program to develop a client program, and a front-end development framework which is popular is a Vue framework (a set of progressive JavaScript frameworks for constructing a user interface). The application client of the embodiment intercepts requests and responses based on the Axios library of the Vue framework (Axios is an HTTP library based on Promise, is an implementation version of Promise, and accords with the latest ES specification). In this embodiment, the application client intercepts requests to create a RequestInterceptors request interceptor for the Axios library.
After the request interceptor is established, registration in Axios is needed, and the interceptor after registration can be normally used.
S3: time zone configuration is performed at the application client.
The configuration file in this embodiment adopts a format YAML, which is a recursive abbreviation of "YAML Ain't a Markup Language" (YAML is not a markup language), and a file with a suffix of. yml is an intuitive data serialization format that can be recognized by a computer, is easy to read by a human, is easy to interact with a scripting language, and can be supported by multiple programming languages.
As shown in fig. 2, the time zone configuration of the client in this embodiment needs to be completed by matching the remote configuration server and the application client.
Applications often need to read some configuration information at the time of starting and running, and these configurations are usually stored in two forms: placed in the application itself; a centralized storage is provided at a remote configuration server.
The following specific steps of time zone configuration performed by the client in this embodiment are as follows:
1. in the remote time zone configuration server, a dedicated configuration file is created for client a, the file name may be named clineta. Yml, and the configuration file stores all the configuration items of the client, and the time zone configuration items are part of the configuration file. As shown in fig. 2, the configuration items A, B, C are various configuration items of the client configuration file, wherein one of the configuration items is configured as a storage time zone, and the configuration item is named as timezone.
2. At the application client, a local configuration file is created, which may be named config. The API address of the remote configuration server is stored in the configuration file along with the client name and private key.
3. When the application program client starts or manually refreshes remote configuration, calling an API of the remote configuration server, carrying an encrypted client identity, and decrypting by using a private key after a return result is obtained.
4. The time zone configuration is read from the remote configuration file to add a time zone identification to the request by the interceptor. If the time zone is not configured in the remote configuration file, the time zone configuration is constructed by using the time zone in which the client is located.
As shown in fig. 3, the application client time zone configuration item of the present embodiment includes: global time format, global time zone ID, and special URL time zone configuration. The detailed configuration is described as follows:
1. the global time format configuration item is a character string, and the default value is 'yyyy-MM-dd HH: MM: ss'. The configuration item is added to the time zone identifier in the request header when the application client sends the request message. The configuration item controls the time data representation format in the request message sent by the application client and the response message returned by the application server. The modification may be made according to the user's habits in the region where the application client is located. The configuration can flexibly control the time display format and meet the use requirements of users in different areas.
2. The global time zone ID configuration item is a string. The configuration item is added to the time zone identifier in the request header when the application client sends the request message. The configuration item controls the time zone conversion calculation of the message time data by the application program server.
The time zone ID may be abbreviated as "PST", full name such as "American/los_Angeles", or custom ID such as "GMT-8:00". The full name is suggested.
3. The special URL time zone configuration item is a specific time zone configuration for URLs of some special API interfaces.
The embodiment of the invention defaults that all the API interfaces for message transmission need to carry out time zone conversion, and can carry out special configuration on the API interface with special requirements, so that when a system meets the requirement of a specific time format and time zone for time data, the system can carry out independent configuration on the API interface. For example: generally, when a system administrator obtains a system running log, the log format needs to be unified, and standard time expression methods and time zones, such as ISO 8601 and coordinated universal time, are used.
The international standard ISO 8601 is a method for indicating date and time by the international organization for standardization, and is called "method for indicating date and time by data storage and exchange format, information exchange.
Coordinated universal time (English: coordinated Universal Time, french: temps Universel Coordonn, UTC for short) is the most dominant universal time standard, which is as close as possible to Greenwich standard time in time on the basis of the seconds of atomic time.
As shown in fig. 4, in the present embodiment, the special URL time zone configuration includes: current sequence number, resource path URL, request method type, current URL time format, current URL time zone ID. The concrete explanation is as follows:
1) The current sequence number configuration item is used for indicating the position of the URL configured in a specific time zone. Since there may be multiple URLs that need to be configured for a particular time zone, it is often necessary to store the URLs with a data structure of a collection, which may be in the form of an array, a queue, or the like. The current sequence numbers of URLs configured for each particular time zone are typically arranged in an accumulated manner starting with a natural number of 0. When the URL of the special time zone configuration is multiple, for example, when the URL is stored by using an array structure, the position in the array is usually represented by a lower index position, and when one configuration is added, the lower index value of the array is added by 1, and the lower index value of the array represents the position of the URL of the special time zone configuration.
2) The resource path URL configuration item is the URL address of the API that originated the request. In this embodiment, in order to perform special time zone configuration on URLs in batch, the resource path URL configuration item supports URL wild card matching, which is a symbol that matches whether a certain URL satisfies a rule. The following is an example of a wildcard with a "×" number. For example, when configured as "/api/, URLs beginning with"/api "all satisfy the matching rule. As another example, "/log" indicates that URLs ending in log are configured for a particular time zone, reducing the workload of a large volume configuration.
3) The request method type configuration item is configured by taking the request method type as a standard and is used for matching the request type of the current initiating API interface. In this embodiment, the request method type of the message is generally a method type adopting the HTTP protocol, and the method type of the HTTP protocol generally includes GET, POST, PUT, DELETE and the like. As the REST style (Representational State Transfer, REST for short, a software architecture style) of API interfaces of URLs prevail, URL paths of these API interfaces may be identical, however, comparing paths of API interfaces alone cannot accurately distinguish each API interface. In this embodiment, different API interfaces are distinguished by configuring the request method type, so that an error time zone conversion of an API packet is not caused.
4) The current URL time format configuration item is the same as the global time format configuration item and is not described in detail herein.
5) The current URL time zone ID configuration item is the same as the global time zone ID configuration item and is not described in detail herein.
S4: the application client intercepts a request sent to the server based on the request interceptor and adds a time zone identification request header.
Since the application client has created the interceptor and is applied as a functional component in the application client, all requests are intercepted by the interceptor after the application client has a request. The following is one specific example of an application client intercepting a request:
the request of the application program client is intercepted by the request interceptor through the request interceptor, the information of the current request such as request parameters, request heads, request methods and the like can be obtained in the request interceptor, and the intercepted request is suspended to wait for the processing of the subsequent steps;
the application client reads the time zone configuration and adds a time zone identification request header to the original request. Firstly, according to the intercepted path of the URL of the current request, special URL time zone configuration data in time zone configuration are taken out one by one for comparison, whether the corresponding resource path URL exists or not is compared, if yes, the subsequent judgment is continued, otherwise, the global time zone configuration is used for adding a time zone identification request head for the request;
if the URL of the corresponding resource path exists, the request method type of the URL path is compared with the request method type in the special URL time zone configuration data, if the request method type is inconsistent with the request method type in the special URL time zone configuration data, the global time zone configuration is used for adding the time zone identification request header for the request, and if the request method type is consistent with the request time zone identification request header for the request by using the current URL time format in the special URL time zone configuration data and the current URL time zone ID.
As shown in fig. 5, the application client adds a request header to the original request, the request header is named fawkes-timezone, and the value of the request header contains the time format and the time zone ID.
It should be noted that the time zone is identified in a plaintext json format, which is encrypted again by Base64 or other algorithm for security.
S5: and the application program server performs parameter analysis and return value processing on the request.
In this embodiment, the application server has created a parameter parser, a return value processor, and a type converter, and is applied as a functional component to the application server. After the request is entered, the parameter is analyzed by a parameter analyzer; the response is passed to the return value processor for return value processing before generation. In the process of parameter analysis and return value processing, the message data is converted into Java objects in the application program by a type converter. The following is a specific example of the parameter analysis and return value processing performed on the application server:
after a request message sent by an application program client enters an application program server, a message with Json data in a request body is submitted to a RequestResponseBodyMethodprocessor for parameter analysis, then the request message is submitted to a MappingJackson2HttpMessageConverter to convert the Json data in the request message into Java objects in the application program, and finally the request message is submitted to a CustomtimeZoneDateDeserizer to convert the time data of the character string type in the Json into Date objects; after the execution of the application server side method is finished, the return value is submitted to the RequestResponseBodyMethodprocessor for return value processing, then the return value is submitted to the MappingJackson2HttpMessageConverter for converting Java objects in the application program into Json data in response messages, and finally the return value is submitted to the CustomTimeZoneDateSerializer for converting Date objects into time data of a character string type in the Json.
S6: the application server judges whether time zone conversion is needed to be executed when the parameter or the return value type is converted.
When the application server side performs parameter or return value type conversion, it is necessary to determine whether to perform time zone conversion on a time zone identification request header in a request to which the parameter or return value belongs.
An example of the acquired time zone identification request header is described below:
assume that the request message data is: the URL path of this request is/user/001; the method type of this request is POST; the request body of the request is Json data, one Key in the Json data is 'createDate', and the value of the Key is '2023-01-10:11:45:14'; the request has a request header named fawkes-timeZone, the value of which is encrypted data, the value of which is Json data after decryption, a Key of which is 'timeFormat', the value of which is 'yyyy-MM-dd HH: MM: ss', and another Key of which is 'timeZone', the value of which is 'Asia/Shanghai'.
The subsequent judgment can be performed by taking the exemplified data as a reference, and judging whether time zone conversion is required to be performed when the type of the request parameter or the return value is converted.
As shown in fig. 6, a flowchart for determining whether time zone conversion is needed when the request parameter or the return value type is converted according to the present embodiment includes the following steps:
s61, in a corresponding type converter (CustomtimeZoneDateDeseriizer or CustomtimeZoneDateSerializer), acquiring a time zone identification request header (fawkes-timezone) in the current request, judging whether the time zone identification request header exists or not, and if so, executing a subsequent judging flow; if not, time zone conversion processing is not added to the type conversion of the parameter or the return value, and the process is ended;
s62, decrypting the value of the time zone identification request head to obtain time zone identification Json data;
s63, acquiring a time format (timeFormat) from the time zone identification Json data, judging whether the time format is empty or not, and if the time format is not empty and can be correctly identified by a time formatting tool (SimpleDateFormat), executing a subsequent judging flow; if not, time zone conversion processing is not added to the type conversion of the parameter or the return value, and the process is ended;
s64, obtaining a time zone ID (timeZone) from the time zone identification Json data, judging whether the time zone ID is empty or not and can be correctly identified by a time formatting tool (SimpleDateFormat), and executing a subsequent judging flow if the time zone ID is not empty and can be correctly identified by the time formatting tool; if not, time zone conversion processing is not added to the type conversion of the parameter or the return value, and the process is ended.
S7: the application server performs time zone conversion processing in the process of parameter or return value type conversion.
Through the judgment of the above steps, if the time zone conversion process is required to be executed when the parameter or the return value type is converted, the following steps are carried out:
s71, creating a time formatting tool in a corresponding type converter;
s72, setting a time format for the time formatting tool;
s73, setting a time zone ID for a time formatting tool;
s74, calling a time formatting tool to convert the time data of the character string type into a Date object.
In this embodiment, the implementation of the time-formatting tool may be obtained from the web site GitHub, or the tool class provided in the development framework may be used, and the packaged tool class may be used by the type converter. The tool class is used as a tool method, and is used for providing common methods in a certain non-business field without matched member variables.
When the application client of the system needs to adjust the time display format or the time zone, for example, when the user in the United states is newly served, a set of application client configuration files in the United states can be newly added in the remote configuration server, the time format is configured as 'mm/dd/yyyyyyHH: mm: ss', and the time zone ID is configured as 'American/los_Angeles'. After the application program client in the united states region is restarted or manually refreshed, the time data acquired from the application program server is changed into the time data which accords with the time zone and the use habit of the united states.
In this embodiment, the Date object converted by the type converter is stored or calculated by the application server instead of the original string-type time data. The developer can manually encode the time zone conversion of the original string-type time data without paying attention to the data, and complete the code writing of business logic by using the converted Date object.
In this embodiment, the related functions of time zone conversion at the application server may be extracted and packaged as a plug-in. The plugin encapsulated in this embodiment is based on the Starter mechanism of the Spring framework, which integrates cumbersome configuration and complex dependencies into Starter, all dependent modules follow default configurations that are custom-made, and allow us to adjust these configurations, i.e. follow the idea of "contract is larger than configuration". SpringBoot will automatically discover the required beans through classes under the classpath and register into the IOC container.
The following are specific steps of the package insert in this embodiment:
1. a SpringBoot project is newly created, and the name can be named fawkes-starter-timer.
2. Spring-boot-starter dependencies were introduced in the pore.xml file.
3. Code related to time zone conversion (namely, a type converter and a related conversion tool) of the service end in the embodiment is put into the SpringBoot project.
4. An auto-configuration class is created in which the temporal data type converter is declared as a Bean, which may be named fawkesTimeZoneAutoconfiguration.
5. The created/META-INF/spring.manufacturers file is placed under the/src/main/resources directory, in which the self-configuration class is configured.
6. Run mvn clean install packages the code to a local repository or run mvn clean reply pushes the code package to a remote repository.
After packaging the fawkes-starter-timezone plugins, other developers can use the time zone conversion function in the embodiment by only introducing fawkes-starter-timezone dependence into the pon.xml file when developing the SpringBoot project.
According to the embodiment, complicated coding of time data by developers can be reduced, the processing modes of time data by a plurality of teams are unified, the development efficiency of the application program is greatly improved, the failure probability of the application program is reduced, and the use experience of a user is improved.
The above description is only of the preferred embodiments of the present invention, but the scope of the present invention is not limited thereto, and various modifications and variations of the present invention will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.

Claims (10)

1. A method for custom switching time zones, comprising the steps of:
creating a type converter aiming at time data at an application program server, a parameter analyzer and a return value processor;
creating a request interceptor at an application client and performing zone configuration;
the application client intercepts a request sent to the server based on a request interceptor and adds a time zone identification request header;
the application service end performs parameter analysis and return value processing on the received request based on the parameter analyzer and the return value processor, and judges whether time zone conversion is required to be executed when the parameter or return value type is converted; if so, performing type conversion on the parameter or the return value based on the type converter, executing time zone conversion processing in the type conversion process of the parameter or the return value, and storing or calculating the time data converted by the type converter instead of the original string type time data by the application program server.
2. The method for custom switching time zones of claim 1, wherein the time zone configuration at the application client comprises:
configuring an API address for acquiring time zone configuration information in an application program client configuration file;
calling the API when the application client starts to acquire the time zone configuration corresponding to the current client;
if the acquisition fails, the time zone configuration is constructed using the time zone in which the current application client is located.
3. The method for custom switching time zones according to claim 1, wherein the configuration items of the time zone configuration comprise: global time format, global time zone ID, and special URL time zone configuration.
4. The method for custom switching time zones according to claim 3, wherein said special URL time zone configuration comprises: the current sequence number, the resource path URL, the request method type, the current URL time format, and the current URL time zone ID.
5. The method for switching time zones according to claim 4, wherein the adding time zone identification request header specifically comprises:
according to the intercepted path of the URL of the current request, the special URL time zone configuration data in the time zone configuration are taken out one by one for comparison, whether the corresponding resource path URL exists or not is compared, if yes, the subsequent judgment is continued, otherwise, the global time zone configuration is used for adding a time zone identification request head for the request;
if the URL of the corresponding resource path exists, the request method type of the URL path is compared with the request method type in the special URL time zone configuration data, if the request method type is inconsistent with the request method type in the special URL time zone configuration data, the global time zone configuration is used for adding the time zone identification request header for the request, and if the request method type is consistent with the request time zone identification request header for the request by using the current URL time format in the special URL time zone configuration data and the current URL time zone ID.
6. The method for custom switching time zone according to claim 1, wherein determining whether time zone conversion is required for parameter or return type conversion comprises:
in a type converter aiming at time data, acquiring request heads of a current request, judging whether the request heads contain time zone identification request heads or not, and if so, executing a subsequent judging flow; if not, time zone conversion processing is not added to the type conversion of the parameter or the return value;
judging whether the time zone identifier is a time zone supported by the application program server side or not: according to the obtained time zone identifier of the current request, a time format in the time zone identifier is taken out, and whether the time format is available is judged; according to the obtained time zone identifier of the current request, the time zone ID in the time zone identifier is taken out, and whether the time ID is available or not is judged; if all the time zones are in accordance, executing time zone conversion processing; if not, no time zone conversion process is added to the type conversion of the parameter or return value.
7. The method for switching time zones by definition as claimed in claim 1, wherein said performing time zone conversion process in the process of parameter or response type conversion comprises:
constructing a time formatting tool in the type converter according to the time format in the time zone identifier;
acquiring a corresponding time zone in the type converter according to the time zone ID in the time zone identifier, and setting the time zone in the time formatting tool;
a time formatting tool is used in the type converter to parse the parameters or responses.
8. A system for custom switching time zones, comprising:
an application server configured with a type converter for time data, and a parameter parser and a return value processor;
an application client configured with a request interceptor and performing time zone configuration;
the application client intercepts a request sent to the server based on a request interceptor and adds a time zone identification request header;
the application service terminal performs parameter analysis and return value processing on the received request by a parameter analyzer and a return value processor, and judges whether time zone conversion is required to be executed when the parameter or the return value type is converted; if so, performing type conversion on the parameter or the return value based on the type converter, executing time zone conversion processing in the type conversion process of the parameter or the return value, and storing or calculating the time data converted by the type converter instead of the original string type time data by the application program server.
9. A computer device comprising a memory and a processor in communication with each other, the memory having stored therein computer instructions, the processor executing the computer instructions to perform the method of custom switching time zones as claimed in any of claims 1 to 7.
10. A computer readable storage medium comprising a stored program, wherein the computer readable storage medium stores computer instructions for causing a computer to execute the method of custom switching time zones according to any of claims 1-7 when the computer is run.
CN202310331440.4A 2023-03-31 2023-03-31 Method, system, computer device and storage medium for custom switching time zone Active CN116055569B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310331440.4A CN116055569B (en) 2023-03-31 2023-03-31 Method, system, computer device and storage medium for custom switching time zone

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310331440.4A CN116055569B (en) 2023-03-31 2023-03-31 Method, system, computer device and storage medium for custom switching time zone

Publications (2)

Publication Number Publication Date
CN116055569A CN116055569A (en) 2023-05-02
CN116055569B true CN116055569B (en) 2023-06-06

Family

ID=86122146

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310331440.4A Active CN116055569B (en) 2023-03-31 2023-03-31 Method, system, computer device and storage medium for custom switching time zone

Country Status (1)

Country Link
CN (1) CN116055569B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112685447A (en) * 2020-12-17 2021-04-20 贵阳语玩科技有限公司 Cross-time-zone operation database system, data query method, medium, and server

Family Cites Families (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2003211141A1 (en) * 2002-02-22 2003-09-09 Bea Systems, Inc. Web services runtime architecture
US7747645B2 (en) * 2007-03-17 2010-06-29 Informed Control Inc. System and method for calendar-based anomalous access detection
CN101997714A (en) * 2009-08-27 2011-03-30 华为技术有限公司 Time processing method, device and system
CN105068801A (en) * 2015-08-06 2015-11-18 福建天晴数码有限公司 Method and system for modifying json date format
CN111931080A (en) * 2020-07-24 2020-11-13 上海泛微网络科技股份有限公司 Method, system and storage medium for automatically displaying time in multiple time zones
CN113726770B (en) * 2021-08-30 2023-06-30 平安国际融资租赁有限公司 Data interception method, device, computer equipment and storage medium
CN113867913A (en) * 2021-09-27 2021-12-31 平安国际智慧城市科技股份有限公司 Business request processing method, device, equipment and storage medium for microservice
CN113918770B (en) * 2021-12-16 2022-03-25 上海冰鉴信息科技有限公司 Method and device for converting character string and time field
CN115712468A (en) * 2022-09-30 2023-02-24 超聚变数字技术有限公司 Time information processing method and device, computing equipment and storage medium
CN115718601A (en) * 2022-11-23 2023-02-28 安徽工程大学 Non-invasive data interaction method and device under front-end and back-end separation scene

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112685447A (en) * 2020-12-17 2021-04-20 贵阳语玩科技有限公司 Cross-time-zone operation database system, data query method, medium, and server

Also Published As

Publication number Publication date
CN116055569A (en) 2023-05-02

Similar Documents

Publication Publication Date Title
US9323647B2 (en) Request-based activation of debugging and tracing
KR101784784B1 (en) Managing objects using a client-server bridge
JP6494609B2 (en) Method and apparatus for generating a customized software development kit (SDK)
US20050027559A1 (en) Generic framework for applying object-oriented models to multi-tiered enterprise applications
CN104821954B (en) A kind of cross-platform remote procedure calling (PRC) method
US6738781B1 (en) Generic command interface for multiple executable routines having character-based command tree
US8438418B2 (en) Simplifying automated software maintenance of data centers
CN103283209A (en) Application service platform system and implementation method thereof
CN106100936A (en) Webpage method for monitoring performance and device and the webserver, client
KR100845234B1 (en) Apparatus and method for parsing domain profile in software communication architecture
US10574724B2 (en) Automatic discovery of management nodes and generation of CLI using HA module
US6865732B1 (en) Providing an embedded application specific web server
US7454761B1 (en) Method and apparatus for correlating output of distributed processes
US11294740B2 (en) Event to serverless function workflow instance mapping mechanism
US11552868B1 (en) Collect and forward
CN113778897B (en) Automatic test method, device and equipment for interface and storage medium
CN113448655B (en) C standard dynamic library calling method and device
CN116204239A (en) Service processing method, device and computer readable storage medium
CN104753860B (en) Network service system based on middleware
CN113360377A (en) Test method and device
US9374437B2 (en) Schema validation proxy
CN116055569B (en) Method, system, computer device and storage medium for custom switching time zone
CN117194064A (en) Remote calling method and device
US20090240987A1 (en) Test amplification for datacenter applications via model checking
CA2297597A1 (en) Method and system for testing internet-based applications

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant