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

    r26133 r28382  
    2525
    2626        Element message = this.converter.nodeToElement(message_node);
    27 
     27        Document doc = message.getOwnerDocument();
     28       
    2829        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    29         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    30         Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     30        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
     31        Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
    3132        result.appendChild(page_response);
    3233
     
    6263            // we are processing stuff for the applet send a message to the service, type="query", and take out the something element, and return that as our result - the applet must take xml
    6364
    64             Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    65             Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     65            Element mr_message = doc.createElement(GSXML.MESSAGE_ELEM);
     66            Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    6667            mr_message.appendChild(mr_request);
    6768            // just append all the params for now - should filter out unneeded ones
    68             mr_request.appendChild(this.doc.importNode(cgi_param_list, true));
     69            mr_request.appendChild(doc.importNode(cgi_param_list, true));
    6970
    7071            // process the request
     
    8081        // get the applet description, and the collection info if a collection is specified
    8182
    82         Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    83         Element applet_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
     83        Element mr_message = doc.createElement(GSXML.MESSAGE_ELEM);
     84        Element applet_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
    8485        mr_message.appendChild(applet_request);
    8586
     
    8990        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
    9091        //path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
    91         Element service_elem = (Element) this.doc.importNode(GSXML.getNodeByPath(mr_response, path), true);
     92        Element service_elem = (Element) doc.importNode(GSXML.getNodeByPath(mr_response, path), true);
    9293        Element applet_elem = (Element) GSXML.getChildByTagName(service_elem, GSXML.APPLET_ELEM);
    9394        // must handle any params that have values that are not
Note: See TracChangeset for help on using the changeset viewer.