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/DepositorAction.java

    r28202 r28382  
    4343    {
    4444        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    45 
     45        Document doc = request.getOwnerDocument();
     46       
    4647        UserContext uc = new UserContext((Element) request);
    4748        String currentUsername = uc.getUsername();
    4849
    49         Element responseMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    50         Element response = GSXML.createBasicResponse(this.doc, this.getClass().getSimpleName());
     50        Element responseMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     51        Element response = GSXML.createBasicResponse(doc, this.getClass().getSimpleName());
    5152        responseMessage.appendChild(response);
    5253
     
    226227            formContainer.appendChild(callToPage);
    227228
    228             Element cachedValueElement = this.doc.createElement("cachedValues");
     229            Element cachedValueElement = doc.createElement("cachedValues");
    229230            response.appendChild(cachedValueElement);
    230231            try
     
    232233                for (int i = pageNum; i > 0; i--)
    233234                {
    234                     Element page = this.doc.createElement("pageCache");
     235                    Element page = doc.createElement("pageCache");
    235236                    page.setAttribute("pageNum", "" + i);
    236237                    String cachedValues = database.getUserData(currentUsername, "DE___" + collection + "___" + i + "___CACHED_VALUES");
    237238                    if (cachedValues != null)
    238239                    {
    239                         page.appendChild(this.doc.createTextNode(cachedValues));
     240                        page.appendChild(doc.createTextNode(cachedValues));
    240241                        cachedValueElement.appendChild(page);
    241242                    }
     
    287288                {
    288289                    ex.printStackTrace();
    289                     GSXML.addError(this.doc, responseMessage, "Failed to copy the deposited file into the collection.");
     290                    GSXML.addError(doc, responseMessage, "Failed to copy the deposited file into the collection.");
    290291                    return responseMessage;
    291292                }
     
    331332                }
    332333
    333                 Element buildMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
    334                 Element buildRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, "ImportCollection", uc);
     334                Element buildMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     335                Element buildRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, "ImportCollection", uc);
    335336                buildMessage.appendChild(buildRequest);
    336337
    337                 Element paramListElem = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     338                Element paramListElem = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    338339                buildRequest.appendChild(paramListElem);
    339340
    340                 Element collectionParam = this.doc.createElement(GSXML.PARAM_ELEM);
     341                Element collectionParam = doc.createElement(GSXML.PARAM_ELEM);
    341342                paramListElem.appendChild(collectionParam);
    342343                collectionParam.setAttribute(GSXML.NAME_ATT, GSXML.COLLECTION_ATT);
    343344                collectionParam.setAttribute(GSXML.VALUE_ATT, collection);
    344345
    345                 Element documentsParam = this.doc.createElement(GSXML.PARAM_ELEM);
     346                Element documentsParam = doc.createElement(GSXML.PARAM_ELEM);
    346347                paramListElem.appendChild(documentsParam);
    347348                documentsParam.setAttribute(GSXML.NAME_ATT, "documents");
     
    350351                Element buildResponseMessage = (Element) this.mr.process(buildMessage);
    351352
    352                 response.appendChild(this.doc.importNode(buildResponseMessage, true));
     353                response.appendChild(doc.importNode(buildResponseMessage, true));
    353354            }
    354355        }
     
    364365        else
    365366        {
    366             Element depositorPage = this.doc.createElement("depositorPage");
     367            Element depositorPage = doc.createElement("depositorPage");
    367368            response.appendChild(depositorPage);
    368369
    369             Element collList = getCollectionsInSite();
    370             depositorPage.appendChild(this.doc.importNode(collList, true));
     370            Element collList = getCollectionsInSite(doc);
     371            depositorPage.appendChild(doc.importNode(collList, true));
    371372        }
    372373
     
    374375    }
    375376
    376     public Element getCollectionsInSite()
     377    public Element getCollectionsInSite(Document doc)
    377378    {
    378         Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    379         Element request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
     379        Element message = doc.createElement(GSXML.MESSAGE_ELEM);
     380        Element request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", new UserContext());
    380381        message.appendChild(request);
    381382        Element responseMessage = (Element) this.mr.process(message);
Note: See TracChangeset for help on using the changeset viewer.