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

    r27087 r28382  
    44
    55// XML classes
     6import org.w3c.dom.Document;
    67import org.w3c.dom.Node;
    78import org.w3c.dom.Element;
     
    2627    public Node process(Node message_node)
    2728    {
    28 
    2929        Element message = this.converter.nodeToElement(message_node);
    30 
     30        Document doc = message.getOwnerDocument();
     31       
    3132        // assume only one request
    3233        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     
    4546        // this should be cached somehow later on.
    4647   
    47         Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    48         Element rss_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     48        Element mr_request_message = doc.createElement(GSXML.MESSAGE_ELEM);
     49        Element rss_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    4950        mr_request_message.appendChild(rss_request);
    5051
     
    5859        addInterfaceOptions(rss_response);
    5960
    60         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    61         result.appendChild(this.doc.importNode(rss_response, true));
     61        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
     62        result.appendChild(doc.importNode(rss_response, true));
    6263        return result;
    6364
Note: See TracChangeset for help on using the changeset viewer.