Ignore:
Timestamp:
2013-10-10T17:21:30+13:00 (11 years ago)
Author:
davidb
Message:

Elimination of the 'this.doc' field from the Action baseclass and the subclasses that rely on it. For Greenstone3 purposes it is unsafe to create this object in the constructor to the action and then store it for other methods to access. This is because the Greenstone 3 (and in particular calls to 'process' operate in a multi-threaded context, that is managed by the Servlet server (e.g. Tomcat by default). Calls to DOM methods are not guaranteed to be thread safe, this became apparent when we started looking in to an exception that was being thrown, and centred around use of the DOM method 'item(i)'. The change this commit makes is to remove 'this.doc' being stored as a field. A document is now created in the top level of a call to 'process()' and when a DOM reference is needed in a subsequent method an Element variable (typically passed in as a parameter to the method) is used (through 'Document doc = element.getOwnerDocument()') to gain access to the DOM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java

    r27617 r28382  
    1010import org.greenstone.gsdl3.util.UserContext;
    1111import org.greenstone.util.GlobalProperties;
     12import org.w3c.dom.Document;
    1213import org.w3c.dom.Element;
    1314import org.w3c.dom.Node;
     
    2627    {
    2728        Element message = this.converter.nodeToElement(message_node);
     29        Document doc = message.getOwnerDocument();
     30       
    2831        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    2932        Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     
    4447            page_name = HOME_PAGE;
    4548        }
    46         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
     49        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
    4750        Element response;
    4851        if (page_name.equals(HOME_PAGE))
     
    6669        }
    6770
    68         Element formatMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    69         Element formatRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, collection, new UserContext(request));
     71        Element formatMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     72        Element formatRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, collection, new UserContext(request));
    7073        formatMessage.appendChild(formatRequest);
    7174        Element formatResponseMessage = (Element) this.mr.process(formatMessage);
     
    7881        }
    7982
    80         result.appendChild(this.doc.importNode(response, true));
     83        result.appendChild(doc.importNode(response, true));
    8184        logger.debug("page action result: " + this.converter.getPrettyString(result));
    8285
     
    8689    protected Element homePage(Element request)
    8790    {
     91        Document doc = request.getOwnerDocument();
     92       
    8893        UserContext userContext = new UserContext(request);
    8994        // first, get the message router info
    90         Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    91         Element coll_list_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);
     95        Element info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     96        Element coll_list_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);
    9297        info_message.appendChild(coll_list_request);
    9398        Element info_response_message = (Element) this.mr.process(info_message);
     
    113118            if (colls.getLength() > 0)
    114119            {
    115                 sendMultipleRequests(colls, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
     120                sendMultipleRequests(doc, colls, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
    116121            }
    117122        }
     
    124129            if (services.getLength() > 0)
    125130            {
    126                 sendMultipleRequests(services, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
     131                sendMultipleRequests(doc, services, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
    127132            }
    128133        }
     
    135140            if (clusters.getLength() > 0)
    136141            {
    137                 sendMultipleRequests(clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
     142                sendMultipleRequests(doc, clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
    138143
    139144            }
     
    149154    protected Element aboutPage(Element request)
    150155    {
     156        Document doc = request.getOwnerDocument();
     157       
    151158        UserContext userContext = new UserContext(request);
    152159        // extract the params from the cgi-request,
     
    159166            logger.error("about page requested with no collection or cluster specified!");
    160167            // return an empty response
    161             Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     168            Element response = doc.createElement(GSXML.RESPONSE_ELEM);
    162169            addSiteMetadata(response, userContext);
    163170            addInterfaceOptions(response);
     
    166173
    167174        // get the collection or cluster description
    168         Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    169 
    170         Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
     175        Element coll_about_message = doc.createElement(GSXML.MESSAGE_ELEM);
     176
     177        Element coll_about_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
    171178        coll_about_message.appendChild(coll_about_request);
    172179        Element coll_about_response = (Element) this.mr.process(coll_about_message);
     
    213220        if (services.getLength() > 0)
    214221        {
    215             sendMultipleRequests(services, coll_name, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
     222            sendMultipleRequests(doc, services, coll_name, GSXML.REQUEST_TYPE_DESCRIBE, userContext);
    216223        }
    217224
     
    231238    protected Element unknownPage(Element request)
    232239    {
     240        Document doc = request.getOwnerDocument();
     241       
    233242        UserContext userContext = new UserContext(request);
    234243        String page_name = request.getAttribute(GSXML.SUBACTION_ATT);
     
    242251        {
    243252            // just return an empty response
    244             Element response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     253            Element response = doc.createElement(GSXML.RESPONSE_ELEM);
    245254            addSiteMetadata(response, userContext);
    246255            addInterfaceOptions(response);
     
    252261        // if there is a service specified should we get the service description instead??
    253262        // get the collection or cluster description
    254         Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    255 
    256         Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
     263        Element coll_about_message = doc.createElement(GSXML.MESSAGE_ELEM);
     264
     265        Element coll_about_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
    257266        coll_about_message.appendChild(coll_about_request);
    258267
     
    269278    }
    270279
    271     protected boolean sendMultipleRequests(NodeList items, String path_prefix, String request_type, UserContext userContext)
     280    protected boolean sendMultipleRequests(Document doc, NodeList items, String path_prefix, String request_type, UserContext userContext)
    272281    {
    273282        // we will send all the requests in a single message
    274         Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     283        Element message = doc.createElement(GSXML.MESSAGE_ELEM);
    275284        for (int i = 0; i < items.getLength(); i++)
    276285        {
     
    281290                path = GSPath.appendLink(path_prefix, path);
    282291            }
    283             Element request = GSXML.createBasicRequest(this.doc, request_type, path, userContext);
     292            Element request = GSXML.createBasicRequest(doc, request_type, path, userContext);
    284293            message.appendChild(request);
    285294        }
     
    317326    protected Element gli4gs3Page(Element request)
    318327    {
     328        Document doc = request.getOwnerDocument();
     329       
    319330        String lang = request.getAttribute(GSXML.LANG_ATT);
    320331        String uid = request.getAttribute(GSXML.USER_ID_ATT);
    321332
    322         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
    323 
    324         Element applet_elem = this.doc.createElement("Applet");
     333        Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
     334
     335        Element applet_elem = doc.createElement("Applet");
    325336        page_response.appendChild(applet_elem);
    326337        applet_elem.setAttribute("ARCHIVE", "SignedGatherer.jar");
     
    329340        applet_elem.setAttribute("HEIGHT", "50");
    330341        applet_elem.setAttribute("WIDTH", "380");
    331         Element gwcgi_param_elem = this.doc.createElement("PARAM");
     342        Element gwcgi_param_elem = doc.createElement("PARAM");
    332343        gwcgi_param_elem.setAttribute("name", "gwcgi");
    333344        String library_name = GlobalProperties.getGSDL3WebAddress();
     
    335346        applet_elem.appendChild(gwcgi_param_elem);
    336347
    337         Element gsdl3_param_elem = this.doc.createElement("PARAM");
     348        Element gsdl3_param_elem = doc.createElement("PARAM");
    338349        gsdl3_param_elem.setAttribute("name", "gsdl3");
    339350        gsdl3_param_elem.setAttribute("value", "true");
Note: See TracChangeset for help on using the changeset viewer.