Summary of the invention
The technical problem to be solved in the present invention is, for the above-mentioned waste bandwidth of prior art, cannot analytic message content, fail safe do not have the defect that guarantees, can not solve matter of semantics, provide a kind of take less bandwidth, can analytic message content, fail safe is guaranteed, the method for docking with business system and the device based on js that can solve matter of semantics.
The technical solution adopted for the present invention to solve the technical problems is: construct a kind of method of docking with business system based on js, comprise the steps:
A) client is by http agreement json(JavaScript Object Notation, the data interchange format of lightweight) data format sends request and described request is processed to jsse (a JavaScript Service Engine, js service-Engine); Described jsse comprises adapter assembly and capability component, and described adapter assembly and capability component have api interface;
B) api interface that calls described adapter assembly or capability component docks with described business system, realizes the conversion to business system interface data form.
In the method for docking with business system based on js of the present invention, described jsse also comprises main core frame and js engine.
In the method for docking with business system based on js of the present invention, described steps A) further comprise:
A1) client sends request to described main core frame according to the data format that meets the json of http agreement;
A2) described main core frame is resolved described request, and obtains the data of carrying in described request;
A3) described main core frame is loaded into described js engine in described jsse;
A4) described main core frame is loaded into the js logical file content of appointment in described jsse according to the data of carrying in described request;
A5) described main core frame is resolved and is carried out the content of described js logical file by described js engine;
In the content of the js logical file that A6) judgement is carried out, whether there is the scripted code that loads adapter assembly or capability component, in this way, execution step A7); Otherwise, do not carry out any operation;
A7) described main core frame is loaded into the adapter assembly of appointment or capability component in described jsse.
In the method for docking with business system based on js of the present invention, described step B) further comprise:
B1) calling the adapter assembly of appointment or the api interface of capability component docks with described business system;
B2) will call result and return to described main core frame;
B3) described main core frame according to meet http agreement json data format will described in call result and return to described client.
In the method for docking with business system based on js of the present invention, after executing the content of described js logical file, having responded described request or before described jsse receives client-requested the legitimacy of client unconfirmed and the integrality of client data, described js engine enters or in resting state.
The invention still further relates to a kind of device of realizing the above-mentioned method of docking with business system based on js, comprising: request transmitting unit: for making client send request and described request is processed to jsse by the data format of http agreement json; Described jsse comprises adapter assembly and capability component, and described adapter assembly and capability component have api interface;
Interface interchange converting unit: dock with described business system for calling the api interface of described adapter assembly or capability component, realize the conversion to business system interface data form.
In the device of realizing the above-mentioned method of docking with business system based on js of the present invention, described jsse also comprises main core frame and js engine.
In the device of realizing the above-mentioned method of docking with business system based on js of the present invention, described request transmitting element further comprises:
Formatted request sending module: for client is sent request to described main core frame according to the data format that meets the json of http agreement;
Parsing module: for described main core frame is resolved described request, and obtain the data of carrying in described request;
Engine load-on module: for making described main core frame that described js engine is loaded into described jsse;
Logical file loading module: for the data that described main core frame is carried according to described request are loaded into the js logical file content of appointment in described jsse;
Resolve Executive Module: for making described main core frame resolve and carry out the content of described js logical file by described js engine;
Load judge module: for judging whether the content of the js logical file of execution exists the scripted code that loads adapter assembly or capability component;
Specify load-on module: for making described main core frame that the adapter assembly of appointment or capability component are loaded into described jsse.
In the device of realizing the above-mentioned method of docking with business system based on js of the present invention, described interface interchange converting unit further comprises:
Call connection module: for calling the adapter assembly of appointment or the api interface of capability component, dock with described business system;
Call result and return to module: for calling result, return to described main core frame;
Call result form and return to module: for make described main core frame according to meet http agreement json data format will described in call result and return to described client.
In the device of realizing the above-mentioned method of docking with business system based on js of the present invention, after executing the content of described js logical file, having responded described request or before described jsse receives client-requested the legitimacy of client unconfirmed and the integrality of client data, described js engine enters or in resting state.
Implement the method for docking with business system and the device based on js of the present invention, there is following beneficial effect: because the data format of client by http agreement json sends request and request is processed to jsse; Jsse comprises adapter assembly and capability component, and adapter assembly and capability component have api interface; By calling the api interface of adapter assembly or capability component, dock with described business system, realize the conversion to business system interface data form, use json data format to simplify practicality, so take less bandwidth, mobile Internet HTML5 can resolve json data; Adapter assembly and capability component have unified api interface, be easy to realize the docking of each interface, so fail safe is guaranteed, measured javascript development language, simply write the javascript file with logic, just can realize complicated service logic, consideration matter of semantics that need not be too many, so can solve matter of semantics.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the present invention, the technical scheme in the embodiment of the present invention is clearly and completely described, obviously, described embodiment is only the present invention's part embodiment, rather than whole embodiment.Embodiment based in the present invention, those of ordinary skills, not making the every other embodiment obtaining under creative work prerequisite, belong to the scope of protection of the invention.
In the present invention is based on the method for docking with business system and device embodiment of js, the structural representation of its docking business system as shown in Figure 1.In Fig. 1, by writing javascript script, call API(existing or self-defined) ability, just can complete the docking to business system, thereby realize new business systemic-function.In the present embodiment, jsse comprises adapter assembly and capability component, and adapter assembly and capability component have api interface, and adapter assembly comprises multiple adapter, and capability component has multiple.Jsse also comprises main core frame and js engine.New operation system is by the data format request jsse of http agreement json, jsse docks with existing business system by adapter assembly or capability component, realize the conversion to existing business system interface data form, thereby realized predefine function.Use js language left-hand seat fast, learning cost is low, provides powerful API to support, measured javascript development language, by simply writing the javscript file with logic, just can realize complicated service logic.
In the present embodiment, the flow chart of the above-mentioned method of docking with business system based on js as shown in Figure 2.In Fig. 2, the method comprises the steps:
Step S01 client is sent request and request is processed to jsse by the data format of http agreement json: in this step, client (requesting party, also being equivalent to the new business system in Fig. 1) data format by http agreement json sends request and request processed to jsse, particularly point out, jsse agreement request is that the data format of http protocol transmission is json.
The api interface that step S02 calls adapter assembly or capability component docks with business system, realize the conversion to business system interface data form: in this step, the api interface that calls adapter assembly or capability component docks with business system, realizes the conversion to business system interface data form.Use json data format to simplify practicality, so take less bandwidth, mobile Internet HTML5 can resolve json data; Adapter assembly and capability component have unified api interface, be easy to realize the docking of each interface, so fail safe is guaranteed, measured javascript development language, simply write the javscript file with logic, just can realize complicated service logic, consideration matter of semantics that need not be too many, so can solve matter of semantics.
In prior art, SOA, by so-called coarse granularity services interface and classification, has improved efficiency really, after realization flow, has also really simplified development difficulty.If but this flow process is not suitable for the actual conditions of enterprise, still need personalize development.In the present embodiment, the exploitation standard of adapter assembly and capability component is provided, can customize and have more adapter or capability component targetedly, and can freely assemble between each adapter, capability component, do not rely on, can well solve the problems of the prior art.
For the present embodiment, above-mentioned steps S01 is further refinement also, and the flow chart after its refinement as shown in Figure 3.In Fig. 3, above-mentioned steps S01 further comprises:
Step S11 client sends request to main core frame according to the data format that meets the json of http agreement: in this step, client sends request to main core frame according to the data format that meets the json of http agreement.
The main core frame of step S12 is resolved request, and obtains the data of carrying in request: in this step, main core frame is resolved request, and obtains the data of carrying in request.
The main core frame of step S13 is loaded into js engine in jsse: in this step, main core frame loads js engine, and js engine is loaded in jsse.
The main core frame of step S14 is loaded into the js logical file content of appointment in jsse according to the data of carrying in request: in this step, main core frame loads the js logical file content of appointment according to the data of carrying in request, and the js logical file content of appointment is loaded in jsse.
The main core frame of step S15 is resolved and is carried out the content of js logical file by js engine: in this step, main core frame is resolved and carried out the content of js logical file by js engine.
In the content of the js logical file that step S16 judgement is carried out, whether there is the scripted code that loads adapter assembly or capability component: in this step, in the content of the js logical file that judgement is carried out, whether there is the scripted code that loads adapter assembly or capability component, if the result of judgement is yes, perform step S18; Otherwise, execution step S17.
Step S17 does not carry out any operation: if the determination result is NO for above-mentioned steps S16, carry out this step.In this step, do not carry out any operation.
The main core frame of step S18 is loaded into the adapter assembly of appointment or capability component in jsse: if judgment result is that of above-mentioned steps S16 is to carry out this step.In this step, main core frame is loaded into the adapter assembly of appointment or capability component in jsse.
For the present embodiment, above-mentioned steps S02 is further refinement also, and the flow chart after its refinement as shown in Figure 4.In Fig. 4, above-mentioned steps S02 further comprises:
Step S21 calls the adapter assembly of appointment or the api interface of capability component docks with business system: in this step, call the adapter assembly of appointment or the api interface of capability component docks with business system.
Step S22 will call result and return to main core frame: in this step, will call result and return to main core frame.
The main core frame of step S23 will be called result according to the data format that meets the json of http agreement and return to client: in this step, main core frame will be called result according to the data format that meets the json of http agreement and return to client.Based on standard js grammer, complete mutual with existing business system, realize system docking, and return to data format and the data that require according to client (requesting party).So just complete the conversion to existing business system interface data form, thereby realized predefine function.
Introduce four assemblies such as above-mentioned main core frame, js engine, adapter assembly and capability component below.The major function responsibility of main core frame has: receive, decompose the request of client, and obtain the data of carrying in request; Load js engine to jsse; According to request msg, load the content of specifying js logical file; By js engine, resolve and carry out the content of js logical file.If there is the scripted code that loads adapter or capability component in the javascript script of carrying out, main core frame is also loaded on the adapter of appointment in js logical file or capability component in js engine.
Js engine is that javascript resolves and carries out kernel, in the present embodiment, js engine adopt acquiescence in Java jdk1.7 support with Mozilla Rhino.Mozilla Rhino is a js engine implementation of increasing income that uses java language compilation completely, is mainly used in carrying out js program in java environment, for end user provides scripting ability.
There are several states in js engine, be respectively resting state, initial condition and running status in whole jsse operation tense.Program initial start-up, just can realize the js engine instance of part dormant state, and jsse executes the content of js logical file, has responded after client (requesting party's) request, and js engine just can reenter dormant state.Jsse is when the docking of doing system service, when jsse reception requesting party's request, before requesting party's unconfirmed legitimacy and the integrality of requesting party's data, for not wasting of safeguards system resource, js engine is can not load and prepare to carry out, and now js engine will be in dormant state.
When initial condition, when jsse has confirmed, after requesting party's legitimacy and the integrality of data, just can load js engine, and realize some initial loadings and prepare to carry out preparation work.When running status, when jsse carries out real system docking, the js logical file that js engine just can load and execution, and resolve the predefined logic of js logical file, call each adapter or capability component and carry out relevant treatment.
In the present embodiment, adapter assembly and capability component are mainly used in existing enterprise's system to carry out work adaptive and docking.Adapter assembly comprises multiple adapter, as SQLAdapter(database adapter), HTTPAdapter(HTTP protocol adaptor) and EmailAdapte(mail adapter) etc.; Wherein, SQLAdapter is mainly used in database to dock (Oracle, Sqlserver, DB2, Mysql ...), HttpAdapter is mainly used in docking the relevant interface (WebService, Http+Json, submission of sheet etc.) of http protocol, and EmailAdapter supports pop3 and the smtp agreement of standard to carry out the transmitting-receiving of mail, is mainly used in mailing system to dock.Capability component has multiple, as FILEEnabler(file capability component), DOCUMENTEnable(document capability component), CODECEnabler(code capability component) and ZipEnabler(compressed capability assembly) etc., wherein, FileEnabler is for the support to file protocol, support operates file system, DocumentEnabler is for processing the operation of conversion, the operational processes of ZipEnabler for compressing, decompressing to office, pdf document.Except the above-mentioned adapter of listing and capability component, also have a large amount of adapters and capability component just not to enumerate one by one in the present embodiment in addition.
The present embodiment also relates to a kind of device of realizing the above-mentioned method of docking with business system based on js, and its structural representation as shown in Figure 6.In Fig. 6, this device comprises request transmitting unit 1 and interface interchange converting unit 2; Wherein, request transmitting unit 1 is for making client be sent request and described request is processed to jsse by the data format of http agreement json; Jsse comprises adapter assembly and capability component, and adapter assembly and capability component have api interface; Interface interchange converting unit 2 is docked with business system for calling the api interface of adapter assembly or capability component, realizes the conversion to business system interface data form.In the present embodiment, jsse also comprises main core frame and js engine.Use json data format to simplify practicality, so take less bandwidth, mobile Internet HTML5 can resolve json data; Adapter assembly and capability component have unified api interface, be easy to realize the docking of each interface, so fail safe is guaranteed, measured javascript development language, simply write the javscript file with logic, just can realize complicated service logic, consideration matter of semantics that need not be too many, so can solve matter of semantics.
In the present embodiment, request transmitting unit 1 further comprises formatted request sending module 11, parsing module 12, engine load-on module 13, logical file loading module 14, resolves Executive Module 15, loads judge module 16 and specify load-on module 17; Wherein, formatted request sending module 11 is for making client send request to main core frame according to the data format that meets the json of http agreement; Parsing module 12, for main core frame is resolved request, and obtains the data of carrying in request; Engine load-on module 13 is for making main core frame that js engine is loaded into jsse; Logical file loading module 14 is loaded into the js logical file content of appointment in jsse for the data that main core frame is carried according to request; Resolve Executive Module 15 for making main core frame resolve and carry out the content of js logical file by js engine; Load judge module 16 for judging whether the content of the js logical file of execution exists the scripted code that loads adapter assembly or capability component; Specify load-on module 17 for making main core frame that the adapter assembly of appointment or capability component are loaded into jsse.
In the present embodiment, interface interchange converting unit 2 further comprises to be called connection module 21, calls result and return to module 22 and call result form and return to module 23; Wherein, call connection module 21 for calling the adapter assembly of appointment or the api interface of capability component docks with business system; Calling result returns to module 22 and returns to main core frame for calling result; Calling result form returns to module 23 and returns to client for making main core frame will call result according to the data format that meets the json of http agreement.
In the present embodiment, executing the content of js logical file, responded the request of client after or before jsse receives client-requested the legitimacy of client unconfirmed and the integrality of client data, js engine enters or in resting state.Like this can saving resource.
In a word, in the present embodiment, jsse itself can support the existing most interface protocol of docking, and jsse also develops the API of custom adapter and capability component, so just can do more personalized customization for existing enterprise's system, there is better expansion.Owing to using js language, its local exchange just possesses cross-platform characteristic, supports multiple common platform.The flexible configuration of jsse system is changeable, after system deployment success, the configuration item of the configuration file of system own and business procedure all can with the separated management of jsse system.System is disposed simple, superior performance, and system can be disposed by distributed multimachine.System supports heat to dispose, and configuration file just comes into force after revising, configuration file and system relationship, but do not rely on.In addition, system is supported various modes (development mode and deployment mode), is easy to exploitation debugging and formal deployment, has independently log system, and daily record is with module, and system is divided.Use js language, its object-oriented of programming, can reduce code redundancy well, and its rate of code reuse is higher, is more conducive to team develops the personnel effectively division of labor and management code, increases work efficiency.Js engine object pool has automatic telescopic characteristic, and the buffer memory of feasible system is realized the Automatic dispatching management to connection resource according to system busy situation.Meanwhile, object pool provides Link State automatically to detect and reconnect mechanism.
The foregoing is only preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of doing, be equal to replacement, improvement etc., within all should being included in protection scope of the present invention.