CN103685304A - Method and system for sharing session information - Google Patents

Method and system for sharing session information Download PDF

Info

Publication number
CN103685304A
CN103685304A CN201310725271.9A CN201310725271A CN103685304A CN 103685304 A CN103685304 A CN 103685304A CN 201310725271 A CN201310725271 A CN 201310725271A CN 103685304 A CN103685304 A CN 103685304A
Authority
CN
China
Prior art keywords
session
session information
server
http request
application server
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.)
Pending
Application number
CN201310725271.9A
Other languages
Chinese (zh)
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.)
TCL Corp
Original Assignee
TCL Corp
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 TCL Corp filed Critical TCL Corp
Priority to CN201310725271.9A priority Critical patent/CN103685304A/en
Publication of CN103685304A publication Critical patent/CN103685304A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a method and a system for sharing session information. The method comprises the steps that: A, a client initiates an http request, transfers the http request to a filter of a service end through an http server of the service end; B, the filter intercepts the http request and changes an access space of the session information based on a session ID and changes the access space from an application server memory into a memcache server; C, the filter after filtering the http request outputs the http request to an application server of the service end for service logic treatment and responds to the client. The session information is stored in the memcache server and is bound with the client through the session ID to enable each client to only have a piece of the session information and enable all the application servers to share the session information, so that the method and the system for sharing session information solve the problem that the session information cannot be shared among the servers.

Description

A kind of method and system of shared session information
Technical field
The present invention relates to field of computer technology, particularly a kind of method and system of shared session information.
Background technology
At present, most of the Internet web application have all been used session information (in network application, be called " session ", specific to Web middle finger is exactly that user is when browsing some websites, from enter website to browser close process during this period of time, namely user browses the time that this website spends; Also can be regarded as the session cycle, a kind of mechanism that keeps User Status at server, allows object to be stored in the internal memory of server, and is saved in session end cycle always) preserve user conversation and share information.The Session information of client is to be stored in cookie(in order to distinguish user identity, to carry out session information trace and be stored in the data in subscriber's local terminal) in, when a session information is activated for the first time, a unique ID is stored in local cookie.When therefore, party A-subscriber and C server connect, residing Session information connects with party B-subscriber and C server, residing Session information is two different Session information.
Along with the growth of customer volume, server inevitably need server cluster (a lot of server centered are got up to carry out together same service, In the view of client just as if only have a server) dispose, otherwise cannot support huge visit capacity.Because session information is to be kept at respectively on each web application server, while processing on other web application servers that same user's http request is assigned with, session information will be lost, thereby causes application error.The problem of session information sharing when this disposes with regard to having drawn server cluster.
Solve at present session information sharing problem and mainly contain following several scheme:
1, by cookie, whole session information is kept to client, during each http request, pass to again server.As shown in Figure 1, client 10(http asks promoter) initiation http request, using the session information in cookie of being kept at as the parameter of httphttp request by http-server 30(http request transfer person) in be given to application server (application server be that http asks processor, have a plurality of, only example application server 20 and application server 21 in Fig. 1).Application server parses cookie, reads the information in session information.In response time,, application server write current session information in cookie, to be returned to client 10 and to preserve again.Each http request all repeats above-mentioned flow process.This cookie that uses in network preserves session information, and by transmission, cookie realizes the mode that session information is transmitted back and forth, can solve cluster environment session information dropout problem.
The shortcoming of which is to rely on client 10 to open cookie, because the size of cookie is restricted, cannot preserve larger data, also can increase certain bandwidth consumption.
2, utilizing Web server to realize session sticky(is session adhesion, refers within a session cycle, so user's http request is all directed to same web application server processes).As shown in Figure 2, described Web server 40 adopts the apache(world to use the web server software ranking the first) or high performance HTTP of nginx(and Reverse Proxy).Suppose client 10 initiation the one http requests, Web server 40 is assigned to processing in a certain fixing application server (being application server 20) according to the strategy of definition by a http request.Client 11 is initiated the 2nd http request, and Web server 40 is assigned to the 2nd http request in another fixing application server (being application server 21) and processes according to the strategy of definition.Do not changing under tactful prerequisite, the whole http requests of that client 10,11 within a session cycle all will be processed by fixing application server 20,21 corresponding to it respectively.This mode defines the http request of a client within a session cycle and only can be processed by a station server, thereby does not need to share session information.
The shortcoming of which is: if web server crashes, session information will be lost, and has Single Point of Faliure risk.
3, Session Replication(is session replication, refers between server, copy session information, makes the session information of every station server consistent) session information between Timing Synchronization replication application server.As shown in Figure 3, suppose that http-server 30 is given to session information 1, session information 2, session information 3 in respectively storage in application server 20, application server 21, application server 22.Regular execution copy operation, carries out the session information in each application server synchronously, makes all to store in all application servers session information 1, session information 2, session information 3.Like this under server cluster environment, from the http request of client, no matter be distributed to which platform application server processes, can get corresponding session information.Even if the application server of just accessing has crashed, user's http request also can be transferred to other application server automatically to obtain relevant session information.
The shortcoming of which is that efficiency is low, and the data volume of storage is larger, has delay, and user experiences poor.
4, utilize the web application server of a tomcat(lightweight) plug-in unit, session information is saved in memcache server (a high performance distributed memory object caching system), thereby realizes session information sharing.The shortcoming of which is to support tomcat, and upgrading risk is larger.
Thereby prior art need to improve.
Summary of the invention
In view of above-mentioned the deficiencies in the prior art part, the object of the present invention is to provide a kind of method and system of shared session information, to solve, prior art session information sharing is easily lost, efficiency is low, the problem of dependence particular server.
In order to achieve the above object, the present invention has taked following technical scheme:
A method for shared session information, it comprises:
A, client are initiated http request, by the http-server of service end, will in described http request, be given to the filter of service end;
B, described filter are tackled solicited message and the response message of described http request, the access space of the session information that change comprises user profile according to session id, changes to access space for storing the memcache server of session information from application server internal memory;
C, filter carry out exporting to after filtration treatment the application server of service end to described http request, described application server according to http request process service logic and to client end response.
The method of described shared session information, wherein, described step B specifically comprises:
B1, described filter are tackled described http request;
B2, judge whether to produce session id, if produced session id, carry out B3; If produce session id, do not generate a session id;
B3, with the memory address of described session id mark session information, make the memory space of session information change to memcache server from server memory.
The method of described shared session information, wherein, described step B2 specifically comprises:
B21, filter read corresponding cookie in described http request, obtain this session id from cookie;
B22, judge whether the value of described session id is 0: if, generate the unique session id of the overall situation, using the value of this session id as session information, store the key value of memcache server into, and the value of this session id is write to cookie, and be saved to client; Otherwise, execution step B3.
The method of described shared session information, wherein, described step B3 specifically comprises:
B31 inherits primary request object and session object, arranges to inherit the subclass object obtain and be respectively newRequest subclass object and newSession subclass object;
B32, in described newSession subclass object, rewrites the method for access session information in parent, makes the space of access session information in newSession subclass object transfer to memcache server from application server internal memory; In the shared space of memcache server by described session id mark;
B33, in described newRequest subclass object, rewrites the method for obtaining session object instance in parent; In the method for newRequest subclass object, return to the example of newSession subclass object.
The method of described shared session information, wherein, described newRequest subclass object comprises the first member variable jsid, the value of the first member variable jsid equates with the value of described session id.
The method of described shared session information, it also comprises: realize for the tool-class at described newSession subclass object direct control memcache server; Described tool-class comprises providing and obtains, replaces, deletes, preserves caching.
The method of described shared session information, wherein, described newSession subclass object comprises the first member variable jsid and the second member variable map; Wherein, the first member variable jsid is for storage session information is to the key value in memcache, and the second member variable map is the data structure of preservation session information.
The method of described shared session information, wherein, described step C specifically comprises: filter carries out after filtration treatment described http request, calls doFilter method and jumps out filter, and the http after output is processed asks the application server processes service logic to service end; Response.
The method of described shared session information wherein, also comprises after described step C:
Access space in Session information changes to memcache server from original application server internal memory, and application server carries out corresponding Business Processing, customer in response end to described http request; During processing business, application server is according to session information corresponding to session id access from memcache server.
For realizing a system of sharing session information, it comprises:
Client, for initiating http request;
Service end comprises:
Http-server, is given to filter for the http request that client is initiated;
Filter, for tackling solicited message and the response message of described http request, the access space of the session information that comprises user profile according to this session id change, access space is changed to for storing the memcahce server of session information from application server internal memory, and request carries out exporting to after filtration treatment the application server of service end to described http;
Application server, for the treatment of service logic and to client end response.
Compared to prior art, the method and system of shared session information provided by the invention, in service end, increase filter and memcache server, when client is initiated http request, the http that tackles http-server transfer by filter asks, according to session id, the access space of session information is changed to memcahce server from application server internal memory, and by session id, session information and client are bound, thereby each client only has a session information, all application servers are shared this part of session information, not only solved the problem that between server, session information can not be shared, also avoided increasing in prior art bandwidth consumption, session message delay, Single Point of Faliure, rely on the drawbacks such as specific web application server.
Accompanying drawing explanation
Fig. 1 is the schematic diagram that prior art solves the scheme one of session information sharing problem.
Fig. 2 is the schematic diagram that prior art solves the scheme two of session information sharing problem.
Fig. 3 is the schematic diagram that prior art solves the scheme three of session information sharing problem.
Fig. 4 is the flow chart of the method preferred embodiment of shared session information provided by the invention.
Fig. 5 is the method flow diagram of S200 in the method for shared session information provided by the invention.
Fig. 6 is the method flow diagram of S203 in the method for shared session information provided by the invention.
Fig. 7 is provided by the invention for realizing the schematic diagram of the preferred embodiment of the system of sharing session information.
Embodiment
The invention provides a kind of method and system of shared session information, for making object of the present invention, technical scheme and effect clearer, clear and definite, referring to accompanying drawing, developing simultaneously, the present invention is described in more detail for embodiment.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
The method and system of shared session information provided by the invention, in existing service end, increase filter and memcache server, before response, by filter, tackling the http that client sends asks, according to the access space of session id change sesssion information, by application server internal memory, be changed to memcache server, it has changed the preserving type of existing session information, implementation simply and not relies on any specific server, can be applicable to all web application servers.Refer to Fig. 4, the method for described shared session information, comprising:
S100, client are initiated http request, by the http-server of service end, will in described http request, be given to the filter of service end;
S200, described filter are tackled solicited message and the response message of described http request, the access space of the session information that change comprises user profile according to session id, changes to access space for storing the memcache server of session information from application server internal memory;
S300, filter carry out exporting to after filtration treatment the application server of service end to described http request, described application server according to http request process service logic and to client end response.
In the present embodiment, described client is PC(personal computer), personal computer), user sends corresponding http during by client browsing page and asks.The corresponding session id (being also the sign of session) of a common PC, sends the session id that can carry this PC when http asks.Http-server is tackled being given to filter in described http request, revises the access space of session information.After http asks serviced termination to be received, its information can be kept in request object (representing request) and response object (representing response); Filter is actual is these two objects of interception.Described session information typically refer to user account, log in the user profile such as state, also can preserve other specific information.Refer to Fig. 5, described step S200 specifically comprises:
S201, described filter are tackled described http request.
S202, judge whether to produce session id, if produced session id, carry out S203; If produce session id, do not generate a session id;
The present embodiment need to extract session information by this session id, need to first judge whether http has comprised session id (this session id keeps the overall situation unique, and qualified name, needs only other collision of variables of discord) in asking; It specifically comprises: filter reads the cookie of described http request, obtains this session id (representing with jsid) from cookie.Whether the value that judges described session id is 0: if (value is 0 and represents that client does not comprise described session id), generate the unique session id of the overall situation, using the value of this session id as session information, store the key value of memcache server into, and the value of this session id is write to cookie, and be saved to client; Otherwise (value is not 0 and represents already-existing session ID), carries out S203.
The value of the ID generating is one and neither can repeats, and is not easy again the character string of found rule to copy; It to the key value of memcache server and return to client storage, is equivalent to a memory space in the corresponding memcache server of this key value as buffer memory session information, and session information is stored in this memory space.Because the value of ID is corresponding one by one with client, so just in memcache server, for this client, distributed a fixing memory space and stored the session information of this client.
S203, with the memory address of described ID mark session information, make the memory space of session information change to memcache server from server memory.
During concrete enforcement, described S203 is that to take described ID and primary request object be that constructing variable creates HttpServletRequestWrapper object, thereby makes the memory space of session information change to memcache server from server memory.Described primary request is to liking the example of HttpServletRequest class, the primary object that belongs to javaEE structure system, relate to the object of the http request that client sends, so long as the information of asking relevant for client http, can obtain by it information such as http request header, http requesting method, http required parameter, user IP.In order to realize, the access space of session information is made into memcache server from server memory, can realize respectively in such a way HttpServletRequestWrapper class, HttpMemSessionWrapper class, MemcachedSessionFilter class, MemcacheManager class.Before this, need to first be created in for intercepting and capturing the MemcachedSession Filter class from the http request of client.
Described MemcachedSessionFilter class is a servlet filter assemblies, and it is for intercepting and capturing the http request from client.The core of this MemcachedSessionFilter class is doFilter method, and the follow-up filter that calls of mentioning is to carry out this doFilter method.This doFilter method under any circumstance all can be performed.Primary request, response enters ginseng to liking the acquiescence of this doFilter method, and they just exist when http request is created.Now need the example that creates HttpServletRequestWrapper object to replace primary request object, primary response object is not done any change, continues to transmit and uses.
The method that realizes MemcachedSessionFilter class comprises:
First state that the succession of MemcachedSessionFilter class is from HttpServlet class.Wherein, described HttpServlet class belongs to the primary class of javaEE structure system, needs to inherit HttpServlet class, and realize Filter interface in the present embodiment.Described Filter interface belongs to javaEE structure system native interface, needs to realize Filter interface in the present embodiment.In order to show that MemcachedSessionFilter class must inherit HttpServlet class, need to first state.
Then realize the doFilter method of MemcachedSessionFilter class; It specifically comprises: first from cookie, search session id, the value of judgement session id is for sky or equal at 0 o'clock, generates the unique session id of the overall situation, and is saved in client.Using the session id that generates and primary request object as constructing variable again, and the example that creates HttpServletRequestWrapper class replaces primary request object.Finally using newRequest subclass object (being the example of HttpServletRequestWrapper class) and primary response object as parameter, call the doFilter method that filter is carried out chain object.The false code of calling is filterChain.doFilter (newRequest, response), and wherein, response object remains primary response object, does not do any change.
Finally by filter deployment in application server, filter is come into force.
The function that described MemcachedSession Filter class realizes has: intercept and capture the http request from client; Generate session id; According to session id, revise the access space of session information; The example (with newRequest subclass object encoding) that creates HttpServletRequestWrapper class replaces primary request object, as the parameter of filter doFilter (newRequest, response) method.Wherein, newRequest subclass object is the example of the HttpServletRequestWrapper class being created out; Response is that (this is prior art to HttpServletResponse class, belongs to primary object, just exists, until http request response finishes after http request is created always; The present invention directly uses such) example, belong to the primary object of JavaEE architectural framework, relate to the response to client http request, can utilize it to set the message that some will respond, such as heading message, responsive state code etc.
Please refer to Fig. 6, then need to process accordingly HttpServletRequestWrapper class, MemcacheManager class, HttpMemSessionWrapper class, described S203 specifically comprises:
S2031, inherit primary request object and session object, arrange and inherit the subclass object obtaining and be respectively newRequest subclass object and newSession subclass object.Described succession refers to that an object is directly used attribute and the method for another object.
Described S2031 is equivalent to create HttpServletRequestWrapper class, rewrites the getSession information approach of HttpServletRequestWrapper class.Because session information in prior art is to be kept in session object, and the present invention need to change the memory space of session object, and the effect of HttpServletRequestWrapper class: returned to by session id mark the session object of session information storage addresses.Wherein, the implication of rewriting is: method rewrites and title method covers, if the method in subclass has identical method name, return type and parameter list with a certain method in parent, new method will cover original method.HttpServletRequestWrapper class described in this S2031 is inherited the primary class from HttpServletRequest(javaEE structure system) class; Rewrite the getSession information approach of HttpServletRequestWrapper class, by the method, return to the example of HttpMemSessionWrapper class.The method that realizes HttpServletRequestWrapper class comprises:
First state that the succession of HttpServletRequestWrapper class is from javax.servlet.http.HttpServletRequestWrapper class.Wherein, described javax.servlet.http.HttpServletRequestWrapper class belongs to the primary class of javaEE structure system, needs to inherit such in the present embodiment.
Then define the first member variable jsid, the first member variable jsid represents session id.That is to say, described newRequest subclass object comprises the first member variable jsid, and the value of the first member variable jsid equates with the value of described session id.
Then realize the building method of HttpServletRequestWrapper class, the first member variable jsid that carrys out this HttpServletRequestWrapper class of initialization with session id and the http request object of filter interception http acquisition request in this building method and the request member variable of parent.
Finally rewrite the getSession method of HttpServletRequestWrapper class.Wherein, the realization flow of described getSession method is as follows: the getSession method of first calling parent is obtained primary session object s1; Then using session id and described session object s1 as the parameter of the building method of HttpSessionMemWrapper class, the example s2 (s2 represents the title of this example) of wound HttpSessionMemWrapper class; Finally return to example s2.
S2032, in described newSession subclass object, rewrite the method for access session information in parent, make the space of access session information in newSession subclass object transfer to memcache server from application server internal memory; In the shared space of memcache server by described session id mark.
Described S2032 is equivalent to create the MemcacheManager class for initialization and destruction memcache client.Described memcache client refers to the client software of operation memcache server, uses memcache client to need initialization before, then creates it, after being finished, needs to destroy it.
Described MemcacheManager class, except for initialization and destruction memcache client, can also provide the API(application programming interfaces of operation buffer memory) method.Described API method is also tool method, refers to that cache client software offers the method that user operates buffer memory; Such as increasing, replace, delete the operations such as buffer memory.Therefore, need in MemcacheManager class, realize for the tool-class at described newSession subclass object direct control memcache server.Described tool-class comprises providing and obtains, replaces, deletes, preserves caching.That is to say, described API method comprises reads buffer memory, writes buffer memory, replaces buffer memory, removes the operations such as buffer memory, is equivalent to operations such as the session information of buffer memory in memcache server read and write, replaces, removes.In the specific implementation, the method for the described MemcacheManager of realization class comprises:
First state MemcacheManager class;
Then realize getMemCachedClient method.Described getMemCachedClient method is for returning to the instrument of operation buffer memory, without entering ginseng, its return cache client object mc.Described mc is prior art, and it is realized and adopts the technology of increasing income, and implementation is disclosed, this is not described further herein.
Then realize getSession method (obtaining session information).This getSession method to enter ginseng be session id, by session id, obtain session information.Wherein, the realization flow of described getSession method comprises: first call described getMemCachedClient method, obtain cache client object; Then call the getSession method of cache client object, obtain session information; Finally map object is returned as session information; Wherein, the data structure that described map object is session information.
Then realize again saveSession method (preserving session information).The ginseng that enters of this saveSession method is session id and session information to be preserved, and it is without return value.Wherein, the realization flow of described saveSession method comprises: first call described getMemCachedClient method, obtain cache client object; Then call the replace method of cache client object and replace old session information.
Finally realize removeSession method (removing session information).This removeSession method to enter ginseng be session id, by session id, delete corresponding session information, it is without return value.Wherein, the realization flow of described removeSession method comprises: first call described getMemCachedClient method, obtain cache client object; Then call the delete method of cache client object and delete session information.
S2033, in described newRequest subclass object, rewrite the method for obtaining session object instance in parent; In the method for newRequest subclass object, return to the example of newSession subclass object.
Described S2033 is equivalent to create HttpMemSessionWrapper class; Rewrite getAttribute method, setAttribute method, getAttributeNames method, the invalidate method of HttpMemSessionWrapper class.Described HttpMemSessionWrapper class is inherited and is realized class HttpSessionWrapper from HttpSession interface (native interface of the system of javaEE framework).NewSession subclass object comprises the first member variable jsid and the second member variable map, is equivalent to arrange this two member variable jsid and map in HttpMemSessionWrapper class.Wherein, the first member variable jsid, for storage session information is to the key value in memcache, that is to say the value of above-mentioned session id.Jsid is a name variable, and implementor can self-defined this title.The second member variable map is for preserving the data structure of session information.In memcache server, that actual storage is map.
In HttpMemSessionWrapper class, must rewrite getAttribute, setAttribute, getAttributeNames, invalidate, several methods such as removeAttribute, make the user can be with directly read and delete session information from memcache server.
Wherein, rewriteeing getAttribute method is according to the key value that is stored in the object in session, obtains corresponding object.The method that realizes HttpMemSessionWrapper class comprises:
First state that the succession of HttpMemSessionWrapper class is from HttpSessionWrapper class (it belongs to the primary class of javaEE structure system, needs to inherit it in the present embodiment).
Then define the first member variable jsid and the second member variable map.The first member variable jsid represents session id (the key value that is also equivalent to memcache server), and map represents to preserve the data structure of session information.
Then realize the building method of this HttpMemSessionWrapper class.Initialization the first member variable jsid and the second member variable map in building method.
Be finally rewrite method, comprise:
Rewrite getAttribute method.This getAttribute method is according to importing parameter into as key value, from the map of preservation session information, searches corresponding object and returns.
Rewrite getAttributeNames method.This getAttributeNames method is the set of obtaining the key value of the object in all session of storing into, by this getAttributeNames method, returns to a set.
Rewrite invalidate method.This invalidate method is that the session information in buffer memory is emptied.This invalidate method needs return value.Wherein, the realization flow of invalidate method is: first empty the data in map; Then the removeSession method of calling MemcacheManager class, empties the data in buffer memory.
Rewrite setAttribute method.This setAttribute method is that object is saved in session.This invalidate method needs return value.Wherein, the realization flow of setAttribute method comprises: first by object with key/be worth right mode to be saved in map.Then the saveSession method of calling MemcacheManager class, is saved in map in buffer memory.
During concrete enforcement, when the getAttribute method of described rewriting HttpMemSessionWrapper class, setAttribute method, getAttributeNames method, invalidate method, removeAttribute method, the API that calls MemcacheManager class operates buffer memory.
By above-mentioned S203, the memory space of session information can be changed to memcache server from server memory, to the session information realization reading and writing in memcache server, replacement, deletion, with the operation such as session id binding.Need afterwards to jump out filter, http request after filtering is transferred to application server responses, described step S300 specifically comprises: filter carries out after filtration treatment described http request, call doFilter method and jump out filter, the http after output is processed asks to the application server processes service logic of service end and to client end response.Now if desired session information is operated to (comprise and reading, revise, delete, destroy), by session information corresponding in direct control memcache server.
Pass that can be clearly all kinds of by above-described embodiment is: MemcachedSessionFilter class and HttpServletRequestWrapper class Existence dependency relationship.HttpServletRequestWrapper class has realized HttpServletRequest interface.HttpServletRequestWrapper class and HttpSessionMemWrapper class Existence dependency relationship.There is inheritance in HttpSessionMemWrapper class and HttpSessionWrapper class, HttpSessionMemWrapper class is the subclass of HttpSessionWrapper class.There is implementation relation in HttpSessionWrapper class and HttpSession class, has again compositive relation simultaneously.MemcacheManager class is as the tool-class of single example, other kindsly can directly call MemcacheManager class.
DoFilter method is doFilter (newRequest, response) method.After jumping out filter, continue down to carry out, be that step S300 also comprises afterwards: the access space in Session information changes to memcache server from original application server internal memory, application server carries out corresponding Business Processing, customer in response end to described http request; During processing business, application server is according to session information corresponding to session id access from memcache server.Application server processes service logic while needing if desired operation (comprise and reading, revise, delete, destroy) session information, reads out session information, and carries out corresponding operating, last customer in response end from memcahce server.So just completed the overall process of a http request response.
Improvement of the present invention, before http request response, is tackled http by filter and is asked, and by session id, revise the access space of session information, by application server internal memory, is changed to memcache server; And with the value of session id, this session information is identified, is convenient to distinguish with other clients.After http request is delivered to back end application server, application server is according to session id, from memcahce server, extract session information, if be necessary, the operation of session information being done to some routines (is comprised and being read, revise, delete, destroy), the result of associative operation will directly be saved in memcache server.The object of unified management session information will be reached like this.And when many application servers provide respond services simultaneously, owing to the session information of each client having been concentrated to be stored in memcache server before response, manage.For client, the http request no matter client is sent by which platform application server responses is processed, each client only has a session information, be equivalent to all application servers and all shared this session information, also just solved the problem that between server, session information can not be shared.And the shared method of session that adopts filter to realize in conjunction with memcache server, not only solve the shared problem of session, and avoided the drawbacks such as increase bandwidth consumption, session message delay, Single Point of Faliure, the specific web application server of dependence.
Refer to Fig. 7, the method of the shared session information based on above-mentioned, the present invention is also corresponding provides a kind of for realizing the system of sharing session information, it comprises client 100 and service end, and described service end comprises: http-server 200, filter 300, memcache server 400 and application server 500.Described application server 500 is a plurality of, only lists 3 application servers (501,502,503) for example in the present embodiment.
Wherein, by client 100, initiate http and ask, in the http request of client 100 being initiated by http-server 200, be given to filter 300.After transfer by solicited message and the response message of the described http request of filter 300 interception, according to session id change comprise user profile the access space of session information, access space is changed to memcache server from application server internal memory.The described session information of memcache server 400 storage.The described http request of 300 pairs of filters carries out exporting to after filtration treatment the application server (as application server 501) of service end, application server processes service logic, need if desired operation (to comprise and reading, revise, delete, destroy) during session information, from directly read out session information from memcahce server, and carry out corresponding operating, last customer in response end.
In sum, the present invention increases filter and memcache server in service end, when client is initiated http request, before http request response, by filter, tackling http asks, and by session id, revise the access space of session information, by application server internal memory, be changed to memcache server; And with the value of ID, this session information is identified, is convenient to distinguish with other clients.After http request is delivered to back end application server, application server is according to session id, from memcahce, extract session information, if be necessary, the operation of session information being done to some routines (is comprised and being read, revise, delete, destroy), the result of associative operation will directly be saved in memcache.The object of unified management session information will be reached like this.And like this when many application servers provide respond services simultaneously, owing to concentrated being stored in memcache server of the session information of each client being managed before response.For client, the http request no matter client is sent by which platform application server responses is processed, each client only has a session information and by ID, session information and client is bound, be equivalent to all application servers and all shared this session information, not only solved the problem that between server, session information can not be shared; And the problem such as the increase bandwidth consumption that adopts mode that filter is combined with memcache server can also avoid solving in prior art session information sharing mode to cause, session message delay, Single Point of Faliure, the specific web application server of dependence.
Be understandable that, for those of ordinary skills, can be equal to replacement or change according to technical scheme of the present invention and inventive concept thereof, and all these changes or replacement all should belong to the protection range of the appended claim of the present invention.

Claims (10)

1. a method for shared session information, is characterized in that, comprising:
A, client are initiated http request, by the http-server of service end, will in described http request, be given to the filter of service end;
B, described filter are tackled solicited message and the response message of described http request, the access space of the session information that change comprises user profile according to session id, changes to access space for storing the memcache server of session information from application server internal memory;
C, filter carry out exporting to after filtration treatment the application server of service end to described http request, described application server according to http request process service logic and to client end response.
2. the method for shared session information according to claim 1, is characterized in that, described step B specifically comprises:
B1, described filter are tackled described http request;
B2, judge whether to produce session id, if produced session id, carry out B3; If produce session id, do not generate a session id;
B3, with the memory address of described session id mark session information, make the memory space of session information change to memcache server from server memory.
3. the method for shared session information according to claim 2, is characterized in that, described step B2 specifically comprises:
B21, filter read corresponding cookie in described http request, obtain this session id from cookie;
B22, judge whether the value of described session id is 0: if, generate the unique session id of the overall situation, using the value of this session id as session information, store the key value of memcache server into, and the value of this session id is write to cookie, and be saved to client; Otherwise, execution step B3.
4. the method for shared session information according to claim 2, is characterized in that, described step B3 specifically comprises:
B31 inherits primary request object and session object, arranges to inherit the subclass object obtain and be respectively newRequest subclass object and newSession subclass object;
B32, in described newSession subclass object, rewrites the method for access session information in parent, makes the space of access session information in newSession subclass object transfer to memcache server from application server internal memory; In the shared space of memcache server by described session id mark;
B33, in described newRequest subclass object, rewrites the method for obtaining session object instance in parent; In the method for newRequest subclass object, return to the example of newSession subclass object.
5. the method for shared session information according to claim 4, is characterized in that, described newRequest subclass object comprises the first member variable jsid, and the value of the first member variable jsid equates with the value of described session id.
6. the method for shared session information according to claim 4, is characterized in that, also comprises: realize for the tool-class at described newSession subclass object direct control memcache server; Described tool-class comprises providing and obtains, replaces, deletes, preserves caching.
7. the method for shared session information according to claim 4, is characterized in that, described newSession subclass object comprises the first member variable jsid and the second member variable map; Wherein, the first member variable jsid is for storage session information is to the key value in memcache, and the second member variable map is the data structure of preservation session information.
8. the method for shared session information according to claim 1, it is characterized in that, described step C specifically comprises: filter carries out after filtration treatment described http request, call doFilter method and jump out filter, the http after output is processed asks the application server processes service logic to service end; Response.
9. the method for shared session information according to claim 1, is characterized in that, after described step C, also comprises:
Access space in Session information changes to memcache server from original application server internal memory, and application server carries out corresponding Business Processing, customer in response end to described http request; During processing business, application server is according to session information corresponding to session id access from memcache server.
10. for realizing a system of sharing session information, it is characterized in that, comprising:
Client, for initiating http request;
Service end comprises:
Http-server, is given to filter for the http request that client is initiated;
Filter, for tackling solicited message and the response message of described http request, the access space of the session information that comprises user profile according to this session id change, access space is changed to for storing the memcahce server of session information from application server internal memory, and request carries out exporting to after filtration treatment the application server of service end to described http;
Application server, for the treatment of service logic and to client end response.
CN201310725271.9A 2013-12-25 2013-12-25 Method and system for sharing session information Pending CN103685304A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310725271.9A CN103685304A (en) 2013-12-25 2013-12-25 Method and system for sharing session information

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310725271.9A CN103685304A (en) 2013-12-25 2013-12-25 Method and system for sharing session information

Publications (1)

Publication Number Publication Date
CN103685304A true CN103685304A (en) 2014-03-26

Family

ID=50321618

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310725271.9A Pending CN103685304A (en) 2013-12-25 2013-12-25 Method and system for sharing session information

Country Status (1)

Country Link
CN (1) CN103685304A (en)

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104468804A (en) * 2014-12-15 2015-03-25 浪潮通用软件有限公司 Web server and method and system for processing user conversations
CN105208058A (en) * 2014-06-19 2015-12-30 中国银联股份有限公司 Information exchange system based on web session sharing
CN105338095A (en) * 2015-11-17 2016-02-17 中国建设银行股份有限公司 Conversation data processing method and device
CN105357222A (en) * 2015-11-27 2016-02-24 国网信息通信产业集团有限公司 Distributed Session management middleware
CN105516264A (en) * 2015-11-30 2016-04-20 努比亚技术有限公司 Distributed cluster system based session sharing method, apparatus and system
CN106453661A (en) * 2016-12-09 2017-02-22 北京酷我科技有限公司 Session management method for HTTP server cluster
WO2017036059A1 (en) * 2015-09-01 2017-03-09 北京国双科技有限公司 Method, apparatus, terminal device and system for monitoring user access behaviors
CN106598966A (en) * 2015-10-14 2017-04-26 阿里巴巴集团控股有限公司 Webpage processing method and device
CN107395711A (en) * 2017-07-17 2017-11-24 中国农业银行股份有限公司 Heterogeneous system session access method and relevant apparatus
CN107547579A (en) * 2016-06-23 2018-01-05 北京京东尚科信息技术有限公司 For the method and apparatus for the response traffic for controlling web system
CN108259616A (en) * 2018-01-26 2018-07-06 中企动力科技股份有限公司 Session sharing method, device, electronic equipment and readable storage medium storing program for executing
CN109617953A (en) * 2018-11-28 2019-04-12 亚信科技(南京)有限公司 A kind of conversation processing method and system
CN109951567A (en) * 2019-04-02 2019-06-28 山东浪潮云信息技术有限公司 A kind of Double Data center applications dispositions method
CN111565209A (en) * 2019-08-29 2020-08-21 杭州天宽科技有限公司 Client instant messaging method, device, equipment and medium
CN112437092A (en) * 2020-12-03 2021-03-02 许昌学院 Non-invasive method for sharing session in distributed system
CN112929453A (en) * 2021-03-26 2021-06-08 建信金融科技有限责任公司 Method and device for sharing session data
CN115242876A (en) * 2022-07-21 2022-10-25 武汉众邦银行股份有限公司 Method and device for realizing session sharing based on redis

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060080664A1 (en) * 1998-01-16 2006-04-13 Aspect Communications Corporation Methods and apparatus for enabling dynamic resource collaboration
CN101039317A (en) * 2006-03-14 2007-09-19 中兴通讯股份有限公司 Method for realizing browse service COOKIE of wireless application protocol gateway
CN103067375A (en) * 2012-12-26 2013-04-24 北京思特奇信息技术股份有限公司 Method and device of connection session among network nodes
CN103200212A (en) * 2012-01-04 2013-07-10 中国移动通信集团公司 Method and system achieving distributed conversation under cloud computing environment

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060080664A1 (en) * 1998-01-16 2006-04-13 Aspect Communications Corporation Methods and apparatus for enabling dynamic resource collaboration
CN101039317A (en) * 2006-03-14 2007-09-19 中兴通讯股份有限公司 Method for realizing browse service COOKIE of wireless application protocol gateway
CN103200212A (en) * 2012-01-04 2013-07-10 中国移动通信集团公司 Method and system achieving distributed conversation under cloud computing environment
CN103067375A (en) * 2012-12-26 2013-04-24 北京思特奇信息技术股份有限公司 Method and device of connection session among network nodes

Cited By (25)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105208058B (en) * 2014-06-19 2018-10-23 中国银联股份有限公司 The information interaction system shared based on web sessions
CN105208058A (en) * 2014-06-19 2015-12-30 中国银联股份有限公司 Information exchange system based on web session sharing
CN104468804A (en) * 2014-12-15 2015-03-25 浪潮通用软件有限公司 Web server and method and system for processing user conversations
WO2017036059A1 (en) * 2015-09-01 2017-03-09 北京国双科技有限公司 Method, apparatus, terminal device and system for monitoring user access behaviors
US11044330B2 (en) 2015-09-01 2021-06-22 Beijing Gridsum Technology Co., Ltd. Method, device, terminal equipment and system for monitoring user's access behavior
CN112231606A (en) * 2015-10-14 2021-01-15 创新先进技术有限公司 Webpage processing method and device
CN106598966B (en) * 2015-10-14 2020-09-01 阿里巴巴集团控股有限公司 Webpage processing method and device
CN106598966A (en) * 2015-10-14 2017-04-26 阿里巴巴集团控股有限公司 Webpage processing method and device
CN112231606B (en) * 2015-10-14 2024-03-12 创新先进技术有限公司 Webpage processing method and device
CN105338095A (en) * 2015-11-17 2016-02-17 中国建设银行股份有限公司 Conversation data processing method and device
CN105357222A (en) * 2015-11-27 2016-02-24 国网信息通信产业集团有限公司 Distributed Session management middleware
CN105516264A (en) * 2015-11-30 2016-04-20 努比亚技术有限公司 Distributed cluster system based session sharing method, apparatus and system
CN107547579A (en) * 2016-06-23 2018-01-05 北京京东尚科信息技术有限公司 For the method and apparatus for the response traffic for controlling web system
CN107547579B (en) * 2016-06-23 2021-01-26 北京京东尚科信息技术有限公司 Method, apparatus, and computer-readable storage medium for controlling response data flow of web system
CN106453661A (en) * 2016-12-09 2017-02-22 北京酷我科技有限公司 Session management method for HTTP server cluster
CN107395711A (en) * 2017-07-17 2017-11-24 中国农业银行股份有限公司 Heterogeneous system session access method and relevant apparatus
CN108259616A (en) * 2018-01-26 2018-07-06 中企动力科技股份有限公司 Session sharing method, device, electronic equipment and readable storage medium storing program for executing
CN108259616B (en) * 2018-01-26 2021-06-15 中企动力科技股份有限公司 Session sharing method and device, electronic equipment and readable storage medium
CN109617953A (en) * 2018-11-28 2019-04-12 亚信科技(南京)有限公司 A kind of conversation processing method and system
CN109617953B (en) * 2018-11-28 2021-08-31 亚信科技(南京)有限公司 Session processing method and system
CN109951567A (en) * 2019-04-02 2019-06-28 山东浪潮云信息技术有限公司 A kind of Double Data center applications dispositions method
CN111565209A (en) * 2019-08-29 2020-08-21 杭州天宽科技有限公司 Client instant messaging method, device, equipment and medium
CN112437092A (en) * 2020-12-03 2021-03-02 许昌学院 Non-invasive method for sharing session in distributed system
CN112929453A (en) * 2021-03-26 2021-06-08 建信金融科技有限责任公司 Method and device for sharing session data
CN115242876A (en) * 2022-07-21 2022-10-25 武汉众邦银行股份有限公司 Method and device for realizing session sharing based on redis

Similar Documents

Publication Publication Date Title
CN103685304A (en) Method and system for sharing session information
JP6272933B2 (en) Remote browsing session management
CN103329113B (en) Configuration is accelerated and custom object and relevant method for proxy server and the Dynamic Website of hierarchical cache
CN110958218B (en) Data transmission method based on multi-network communication and related equipment
CN103338249B (en) Caching method and device
CN107315972B (en) A kind of big data unstructured document dynamic desensitization method and system
CN106294365A (en) The page data processing method of a kind of single page web application and equipment
CN106506703A (en) Based on the service discovery method of shared drive, apparatus and system, server
CN106059847B (en) A kind of user's brush single act detection method and device
CN102624918A (en) Proxy access method based on URL (Uniform Resource Locator) rewriting technique
CN113010818A (en) Access current limiting method and device, electronic equipment and storage medium
CN109600385B (en) Access control method and device
CN106372266A (en) Cache and accessing method of cloud operation system based on aspects and configuration documents
CN105868234A (en) Update method and device of caching data
US8352442B2 (en) Determination of an updated data source from disparate data sources
CN106909690A (en) Network data caching method
CN106789227A (en) A kind of internet behavior analysis method and internet behavior analytical equipment
CN104994139A (en) System capable of quickly responding to high-concurrency network request
CN109634753B (en) Data processing method, device, terminal and storage medium for switching browser kernels
CN109522501A (en) Content of pages management method and its device
CN105279034B (en) Consistency cache control system and method
CN106446075A (en) Page request processing method and apparatus
CN107070991A (en) Network data buffer storage and system
WO2023056797A1 (en) Blockchain-based data processing method, apparatus, and device, and storage medium
CN105554181B (en) A kind of DNS log compression method and apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20140326

RJ01 Rejection of invention patent application after publication