Ignore:
Timestamp:
2003-12-18T09:27:11+13:00 (20 years ago)
Author:
kjdon
Message:

servlet now saves a uid with the session - this is passed around as an attribute in a request, to be used by whoever needs it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r5400 r6301  
    4242    //protected GSCGI cgi = null;
    4343    protected GSParams params = null;
     44
     45    /** user id - new one per session. This doesn't work if session state is saved between restarts - this requires this value to be saved too. */
     46    protected int next_user_id = 0;
     47
     48   
    4449    /** initialise the servlet
    4550     */
     
    4752    // always call super.init;
    4853    super.init(config);
    49 
    5054    // disable preferences - does this work anyway??
    5155    //System.setProperty("java.util.prefs.PreferencesFactory", "org.greenstone.gsdl3.util.DisabledPreferencesFactory");
     
    139143   
    140144    HttpSession session = request.getSession(true);
    141 
     145    String uid = (String)session.getAttribute(GSXML.USER_ID_ATT);
     146    if (uid ==null) {
     147        uid = ""+getNextUserId();
     148        session.setAttribute(GSXML.USER_ID_ATT, uid);
     149    }
    142150    request.setCharacterEncoding("UTF-8");
    143151    response.setContentType("text/html;charset=UTF-8");
     
    164172    // the request to the receptionist 
    165173    Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    166     Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", lang);
     174    Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", lang, uid);
    167175    xml_request.setAttribute(GSXML.OUTPUT_ATT, output);
    168176    xml_message.appendChild(xml_request);
     
    220228        String name = (String)params.nextElement();
    221229       
    222         if ( !name.equals(GSParams.LANGUAGE) ) { // lang is stored but we dont want it in the param list cos its already in the request
     230        if ( !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT)) { // lang and uid are stored but we dont want it in the param list cos its already in the request
    223231           
    224232            Element param = this.doc.createElement(GSXML.PARAM_ELEM);
     
    266274   
    267275    }
     276
     277    synchronized protected int getNextUserId() {
     278    next_user_id++;
     279    return next_user_id;
     280    }
     281
    268282}
Note: See TracChangeset for help on using the changeset viewer.