CN110278272A - Simulate the universal method of Socket request - Google Patents

Simulate the universal method of Socket request Download PDF

Info

Publication number
CN110278272A
CN110278272A CN201910550715.7A CN201910550715A CN110278272A CN 110278272 A CN110278272 A CN 110278272A CN 201910550715 A CN201910550715 A CN 201910550715A CN 110278272 A CN110278272 A CN 110278272A
Authority
CN
China
Prior art keywords
socket
message
response
configuration file
request
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.)
Granted
Application number
CN201910550715.7A
Other languages
Chinese (zh)
Other versions
CN110278272B (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.)
Sichuan XW Bank Co Ltd
Original Assignee
Sichuan XW Bank Co 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 Sichuan XW Bank Co Ltd filed Critical Sichuan XW Bank Co Ltd
Priority to CN201910550715.7A priority Critical patent/CN110278272B/en
Publication of CN110278272A publication Critical patent/CN110278272A/en
Application granted granted Critical
Publication of CN110278272B publication Critical patent/CN110278272B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0803Configuration setting
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/50Network service management, e.g. ensuring proper service fulfilment according to agreements
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present invention relates to the universal methods of simulation Socket request, comprising: A. reading socket services presetting configuration file;B., the general class of respond request is set, includes: the method for parsing Socket message, the method for generating the method for label dictionary and response message being assembled;C. start Socket service;D. according to the setting of configuration file, Socket request message is handled by general class, is configured according to the response length in configuration file, first parses response length, then read true request message;The true request message is parsed, the information extraction that subsequent processing needs is come out;E. the response message for meeting business need is generated after carrying out respective handling to the default response message for having read in memory according to the setting of configuration file.The present invention is capable of the Socket message of the various different-formats of Fast simulation, and guarantees that up-stream system will not cause the case where can not testing since downstream Socket service system is unavailable when testing inherent logic.

Description

Simulate the universal method of Socket request
Technical field
The present invention relates to computer development and software tests, are concretely the universal methods for simulating Socket request.
Background technique
Socket is also known as " socket ", and application program usually passes through " socket " and issues request or response network to network Request.Socket is the intervening software abstraction layer that application layer is communicated with TCP/IP protocol suite, it is a group interface.In design pattern In, Socket is a Facade, it is hidden in complicated TCP/IP protocol suite behind Socket interface, is come to user It says, one group of simple interface is exactly all, to allow Socket to remove a group organization data, to meet specified agreement.
Socekt message: the character string of fixed format hands over by Socket in recipient and sender a string Mutually.Socket message is made of 2 sections of character strings, and first segment is length character string, which sets formal Socket Message length;Second segment is true message content, and length is specified by first segment character string.
Example:
18<xml>message</xml>
It explains: the length of 18 the two string representation message contents;It is subsequent<xml>message</xml>indicate report Literary content.Length character string can have various representation methods, may be made of more character strings, and will be true using cipher mode True length degree is encrypted.
During software development perhaps test due to provide Socket service system do not develop completion or not Service can be normally provided, will cause the verifying for calling the up-stream system of the Socket service that can not carry out inherent logic.
In the prior art scheme, the message situation of Socket service to be simulated is needed by understanding, then customization melts Hair one simulates the application of the Socket service, then writes dead Socket request message and response message, to reach simulation Socket The function of service.This mode can only simulate a kind of Socket message of specific format, and respond request is write dead, does not have Logic function;Socket message if necessary to simulate another format is just not suitable for, and is needed to reopen an application and is come It is adapted to new Socket message format, when in face of needing to simulate a variety of Socket message formats different demand, applicability With regard to very poor.
Summary of the invention
The present invention provides a kind of universal methods of simulation Socket request, can be with the various different-formats of Fast simulation Socket message, to guarantee that up-stream system, will not can not due to downstream Socket service system when testing inherent logic With and cause the case where can not testing.
The present invention simulates the universal method of Socket request, comprising:
A. reading socket services presetting configuration file.By configuration file, each of Socket service can be configured Kind information automatically parses generation service by program, can quickly create Socket service;
B. the general class of setting response Socket request, including at least in the general class has: parsing Socket message Method, the method for the generation label dictionary used for external demand and according to the default report for responding Socket service The content of text, the method that response message is assembled;
C. according to configuration file, start Socket service, and default response message is read in into memory.In advance by default response Memory is read in, avoids going to read file again when each returning response, response speed can greatly be improved;
D. according to the setting of configuration file, Socket request message is handled by the general class, in processing according to Response length configuration information in configuration file, the length character of first read requests message, by the length character according to corresponding Rule of response parses real response length, and further according to the physical length reading socket data flow, acquisition is really asked Seek message;The true request message is parsed, the information extraction that subsequent processing needs is come out and saved;
E. it according to the setting of configuration file, after carrying out respective handling to the default response message for having read in memory, generates full The response message of sufficient business need.
The Socket of each different-format is requested, and a request processing class is all predefined in configuration file, this is asked Ask processing class to be integrated with the general class, by general class can templating handle Socket request, realize and do not need to change Various Socket formats can be handled by moving any code, so that high degree improves the suitability to different message formats.
Specifically, the method for parsing Socket message in step B, comprising:
Step 1: the Socket request of parsing xml format traverses wherein all labels, parses inside each label Content generates the dictionary table using label as key, using label substance as value;
Step 2: reading the list of labels configured in configuration file, the dictionary table generated by step 1 finds key name and matches The consistent key of the label configured in file is set, and obtains the dictionary value of the label;
Step 3: the label and the dictionary value that one is only had inside configuration file are generated after all key names of traversal dictionary table New dictionary, and the new dictionary is assigned to label dictionary variable.
Specifically, the method assembled in step B to response message, comprising:
Step 1: the default response message is read from memory;
Step 2: being obtained according to configuration file and need the tag name modified in default response message and corresponding replace Change content expression formula;
Step 3: assembling response message: the replacement content expression formula obtained to step 2 judges, if replacement table of contents It is tag expression formula up to formula, then is obtained in the label dictionary variable generated after the method for the parsing Socket message of step B The corresponding value of identical with tag name in tag expression formula key is taken, and removes corresponding label in replacement default response message with the value Value;
If replacing content expression formula is function expression, the function expression is called directly, it is corresponding to obtain return Value, and corresponding label value in replacement default response message is removed with the value;
If replacing content expression formula is character string, corresponding label in replacement default response message is removed with the character string Value;
Step 4: the response message after returning through step 3 assembling.
Further, it if step 3 is not able to satisfy the response demand of special Socket format, inherits described general Class realizes that the Socket of special format is responded by the method rewritten in general class.If encountering not set Socket format When, the format that the processing method in lower general class can be adapted to new Socket only need to be rewritten, is further improved to different reports The suitability of literary format.
Specifically, step D includes:
It D1. is which Socket service belonged to according to configuration file judgement according to the Socket request received;
D2. start multithreading service, distribute the Socket message received to corresponding thread;
D3. response processing class defined in the thread dispatching configuration file, handles the message received;
D4. response processing class handles Socket request message by the general class according to the setting of configuration file, According to the response length configuration information in configuration file, the length character of first read requests message, by the length character when processing Real response length is parsed according to corresponding rule of response, further according to the physical length reading socket data flow, is obtained Take true request message;The true request message is parsed, the information extraction that subsequent processing needs is come out and saved.
Preferably, step C further includes that the thread pool of each Socket service is arranged according to configuration file.By using line Cheng Chi can greatly improve service performance and response speed.
Preferably, step C further includes the delay time of return that each Socket service is arranged according to configuration file;Step E After middle generation meets the response message of business need, operating lag is carried out according to the delay time of return of the setting, is then returned Return response contents.By the way that delay time is arranged, the demand of abnormality test can satisfy.
The beneficial effect of the method for the present invention includes:
1. generating the Socket service for meeting different request message formats by configuration, a variety of systems can be simulated simultaneously The Socket service of system can be adapted to the Socket message format of different length message character string.
2. pass through configuration and fixed mode cooperated to melt hair, be capable of rapid customization Socket service request analysis and Response message customizes, being capable of Socket service of the Fast simulation with service logic.
3. the Socket message format that message length character string is encryption can be adapted to, but also can lead to according to demand The setting of configuration file is crossed, cipher mode is specified.And the prior art can only be adapted to a kind of this lattice of non-encrypted message length character string Formula.
4. being configured by configuration file to the thread pool that Socket service uses, thread pool can be dynamically produced, Greatly improve service performance.Single thread can only be used in the prior art, and service performance is bad.
5. being configured to service time-out time, the response that can simulate Socket service is returned by the reconfiguration latency time Return the time, can analog response Timeout situation, simulate abnormal scene.And by the reconfiguration latency time, pass through response message It is returned again to after spending the time of delay, so as to verify the place that up-stream system cannot at the appointed time return to Socket service Whether reason mechanism being capable of normal service.
6. injecting various mistakes by configuration response problem, Socket exception response is simulated.
7, the present invention can increase the processing class of request and response newly according to configuration and cured development process, quickly suitable With special message request.It needs completely newly write a whole set of processing message class for each format message in the prior art With response message class.And the present invention can extract the general method of request processing class and response processing class, form mark Quasi- general procedure class and general processing method.When encountering the special request message that cannot be handled, one is increased newly Particular request handles Similar integral general class and a response handles class, specific processing method is then rewritten, to realize mark The exploitation of standardization.
Specific embodiment with reference to embodiments is described in further detail above content of the invention again. But the range that this should not be interpreted as to the above-mentioned theme of the present invention is only limitted to example below.Think not departing from the above-mentioned technology of the present invention In the case of thinking, the various replacements or change made according to ordinary skill knowledge and customary means should all be included in this hair In bright range.
Detailed description of the invention
Fig. 1 is the flow chart of the universal method of present invention simulation Socket request.
Specific embodiment
The universal method of present invention simulation Socket request as shown in Figure 1, comprising:
A. reading socket services presetting configuration file.By configuration file, each of Socket service can be configured Kind information automatically parses generation service by program, can quickly create Socket service.The content of configuration file includes:
1. starting how many a Socket services;
2. the port numbers of each service and the name of each service;
3. the corresponding request of each Socket service handles class name;
4. the corresponding response of each Socket service handles class;
5. the default message content of each Socket service response;
6. the Thread Count for the thread pool that each Socket is opened;
7. the delay time of each Socket response message;
8. request and the response length character of each Socket service, which represents the letter for needing to read first Breath, is really requested by parsing the acquisition of information.
B. the general class of setting response Socket request, including at least in the general class has: parsing Socket message Method, the method for the generation label dictionary used for external demand and according to the default report for responding Socket service The content of text, the method that response message is assembled;
Wherein, the method for Socket message is parsed:
Step 1: the Socket request of parsing xml format traverses wherein all labels, parses inside each label Content generates the dictionary table using label as key, using label substance as value;
Step 2: reading the list of labels configured in configuration file, the dictionary table generated by step 1 finds key name and matches The consistent key of the label configured in file is set, and obtains the dictionary value of the label;
Step 3: the label and the dictionary value that one is only had inside configuration file are generated after all key names of traversal dictionary table New dictionary, and the new dictionary is assigned to label dictionary variable.
The method that response message is assembled:
Step 1: the default response message is read from memory;
Step 2: being obtained according to configuration file and need the tag name modified in default response message and corresponding replace Change content expression formula;
Step 3: assembling response message: the replacement content expression formula obtained to step 2 judges, if replacement table of contents It is tag expression formula (such as: requestDataMap [" key "]) up to formula, then from the side of the parsing Socket message by step B The corresponding value of acquisition key identical with tag name in tag expression formula in the label dictionary variable generated after method, and go to replace with the value Change corresponding label value in default response message;
If replacing content expression formula is function expression (such as: Util.random (10)), the function table is called directly It up to formula, obtains and returns to corresponding value, and remove corresponding label value in replacement default response message with the value;
If replacing content expression formula is character string (such as: hardCode:5111811982), go to replace with the character string Corresponding label value in default response message;
When encountering the response demand for not being able to satisfy special Socket format, then the general class is inherited, it is logical by rewriteeing The Socket response of special format is realized with the method in class.If encounter not set Socket format, need to only it rewrite down Processing method in general class can be adapted to the format of new Socket, further improve the adaptation to different message formats Property.
Step 4: the response message after returning through step 3 assembling.
C. according to configuration file, start Socket service, and default response message is read in into memory, each Socket is set The delay time of return of the thread pool of service and each Socket service.Default response is read in into memory in advance, avoids returning every time It echoes and goes to read file again when answering, response speed can greatly be improved.By using thread pool, can greatly also mention High service performance and response speed.
D. according to the setting of configuration file, Socket request message is handled:
It D1. is which Socket service belonged to according to configuration file judgement according to the Socket request received;
D2. start multithreading service, distribute the Socket message received to corresponding thread;
D3. response processing class defined in the thread dispatching configuration file, handles the message received;
D4. response processing class handles Socket request message by the general class according to the setting of configuration file, According to the response length configuration information in configuration file, the length character of first read requests message, by the length character when processing Real response length is parsed according to corresponding rule of response, further according to the physical length reading socket data flow, is obtained Take true request message;The true request message is parsed, the information extraction that subsequent processing needs is come out and saved.
E. it according to the setting of configuration file, after carrying out respective handling to the default response message for having read in memory, generates full The response message of sufficient business need carries out operating lag according to the delay time of return of the setting, then returning response content. By the way that delay time is arranged, the demand of abnormality test can satisfy.

Claims (7)

1. simulating the universal method of Socket request, feature includes:
A. reading socket services presetting configuration file;
B. the general class of setting response Socket request, including at least in the general class has: the side of parsing Socket message Method, the method for the generation label dictionary used for external demand and according to the default message for responding Socket service Content, the method that response message is assembled;
C. according to configuration file, start Socket service, and default response message is read in into memory;
D. according to the setting of configuration file, Socket request message is handled by the general class, in processing according to configuration Response length configuration information in file, the length character of first read requests message, by the length character according to corresponding response Rule parsing goes out real response length, further according to the physical length reading socket data flow, obtains true request report Text;The true request message is parsed, the information extraction that subsequent processing needs is come out and saved;
E. according to the setting of configuration file, after carrying out respective handling to the default response message for having read in memory, generation meets industry The response message that business requires.
2. the universal method of simulation Socket request as described in claim 1, it is characterized in that: Socket report is parsed in step B The method of text, comprising:
Step 1: the Socket request of parsing xml format traverses wherein all labels, parses interior inside each label Hold, generates the dictionary table using label as key, using label substance as value;
Step 2: reading the list of labels configured in configuration file, the dictionary table generated by step 1 finds key name and configuration text The consistent key of the label configured in part, and obtain the dictionary value of the label;
Step 3: the new of a label only inside configuration file and the dictionary value is generated after all key names of traversal dictionary table Dictionary, and the new dictionary is assigned to label dictionary variable.
3. as described in claim 1 simulation Socket request universal method, it is characterized in that: in step B to response message into The method of row assembling, comprising:
Step 1: the default response message is read from memory;
Step 2: being obtained in the tag name and corresponding replacement for needing to modify in default response message according to configuration file Hold expression formula;
Step 3: assembling response message: the replacement content expression formula obtained to step 2 judges, if replacement content expression formula Tag expression formula, then in the label dictionary variable generated after the method for the parsing Socket message of step B obtain and The corresponding value of the identical key of tag name in tag expression formula, and corresponding label value in replacement default response message is removed with the value;
If replacing content expression formula is function expression, the function expression is called directly, obtains and returns to corresponding value, and Corresponding label value in replacement default response message is removed with the value;
If replacing content expression formula is character string, corresponding label value in replacement default response message is removed with the character string;
Step 4: the response message after returning through step 3 assembling.
4. the universal method of simulation Socket request as claimed in claim 3, it is characterized in that: if step 3 is not able to satisfy spy The response demand of different Socket format, then inherit the general class, realizes special format by the method rewritten in general class Socket response.
5. the universal method of simulation Socket request as described in claim 1, it is characterized in that: step D includes:
It D1. is which Socket service belonged to according to configuration file judgement according to the Socket request received;
D2. start multithreading service, distribute the Socket message received to corresponding thread;
D3. response processing class defined in the thread dispatching configuration file, handles the message received;
D4. response processing class handles Socket request message by the general class, is handling according to the setting of configuration file When according to the response length configuration information in configuration file, the length character of first read requests message, by the length character according to Corresponding rule of response parses real response length, further according to the physical length reading socket data flow, obtains true Real request message;The true request message is parsed, the information extraction that subsequent processing needs is come out and saved.
6. the universal method of the simulation Socket request as described in one of claim 1 to 5, it is characterized in that: step C further includes root According to configuration file, the thread pool of each Socket service is set.
7. the universal method of the simulation Socket request as described in one of claim 1 to 5, it is characterized in that: step C further includes root According to configuration file, the delay time of return of each Socket service is set;The response message for meeting business need is generated in step E Afterwards, operating lag is carried out according to the delay time of return of the setting, then returning response content.
CN201910550715.7A 2019-06-24 2019-06-24 Universal method for simulating Socket request Active CN110278272B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910550715.7A CN110278272B (en) 2019-06-24 2019-06-24 Universal method for simulating Socket request

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910550715.7A CN110278272B (en) 2019-06-24 2019-06-24 Universal method for simulating Socket request

Publications (2)

Publication Number Publication Date
CN110278272A true CN110278272A (en) 2019-09-24
CN110278272B CN110278272B (en) 2022-04-15

Family

ID=67961655

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910550715.7A Active CN110278272B (en) 2019-06-24 2019-06-24 Universal method for simulating Socket request

Country Status (1)

Country Link
CN (1) CN110278272B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112597000A (en) * 2020-12-09 2021-04-02 山东浪潮通软信息科技有限公司 WebScoket protocol-based automatic testing method for instant messaging software
CN114070902A (en) * 2021-11-11 2022-02-18 中国工商银行股份有限公司 DELPHI-based message processing method and device
CN115190055A (en) * 2022-07-08 2022-10-14 武汉众邦银行股份有限公司 TCP message customized conversion method, device and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120254891A1 (en) * 2011-04-01 2012-10-04 International Business Machines Corporation Identification of a protocol used in a message
CN104363212A (en) * 2014-10-31 2015-02-18 北京思特奇信息技术股份有限公司 Socket communication semantics analysis method, adapter and application system based on Lua
CN108897691A (en) * 2018-06-29 2018-11-27 百度在线网络技术(北京)有限公司 Data processing method, device, server and medium based on interface analog service

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120254891A1 (en) * 2011-04-01 2012-10-04 International Business Machines Corporation Identification of a protocol used in a message
CN104363212A (en) * 2014-10-31 2015-02-18 北京思特奇信息技术股份有限公司 Socket communication semantics analysis method, adapter and application system based on Lua
CN108897691A (en) * 2018-06-29 2018-11-27 百度在线网络技术(北京)有限公司 Data processing method, device, server and medium based on interface analog service

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112597000A (en) * 2020-12-09 2021-04-02 山东浪潮通软信息科技有限公司 WebScoket protocol-based automatic testing method for instant messaging software
CN112597000B (en) * 2020-12-09 2023-10-03 浪潮通用软件有限公司 Instant messaging software automatic test method based on WebScokey protocol
CN114070902A (en) * 2021-11-11 2022-02-18 中国工商银行股份有限公司 DELPHI-based message processing method and device
CN114070902B (en) * 2021-11-11 2024-03-29 中国工商银行股份有限公司 Message processing method and device based on DELPHI
CN115190055A (en) * 2022-07-08 2022-10-14 武汉众邦银行股份有限公司 TCP message customized conversion method, device and storage medium

Also Published As

Publication number Publication date
CN110278272B (en) 2022-04-15

Similar Documents

Publication Publication Date Title
US7631227B2 (en) Automated testing and control of networked devices
US7813292B2 (en) Communication protocol testing system
US7512071B2 (en) Distributed flow enforcement
US7760730B2 (en) Rule set verification
US7505463B2 (en) Rule set conflict resolution
CN110278272A (en) Simulate the universal method of Socket request
US6373822B1 (en) Data network protocol conformance test system
CN102279737B (en) System and method for analytic process design
CN109829296A (en) The sandbox implementation method of intelligent contract based on alliance&#39;s chain
US20200092168A1 (en) Production software application performance and resiliency testing
US20160277357A1 (en) Firewall testing
CN111367818B (en) System component testing method and device based on dynamic data return
CN109858286A (en) For the security policy manager system of credible calculating platform
US8285822B2 (en) Policy configuration and simulation
US10823782B2 (en) Ensuring completeness of interface signal checking in functional verification
CN109375943A (en) A kind of program file generation method and device
CN106529241A (en) Virtual machine user account and password resetting method and system
EP1297457A2 (en) Accessing state information in a hardware/software co-simulation
US9183117B2 (en) Method for developing and testing a connectivity driver for an instrument
US20180123899A1 (en) Technology agnostic network simulation
US20040168064A1 (en) System of generating procedure for digital signature and encryption to XML
US20140372460A1 (en) Trusted download toolkit
CN114281307A (en) Low-code multi-environment synchronous publishing platform
CN102843269A (en) Method and system of analog microcode business processing flow
Jacobsson Building integrated remote control systems for electronics boards

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