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

    r25636 r28382  
    44
    55// XML classes
     6import org.w3c.dom.Document;
    67import org.w3c.dom.Node;
    78import org.w3c.dom.Element;
     
    2829    public Node process(Node message_node)
    2930    {
    30 
    3131        Element message = this.converter.nodeToElement(message_node);
    32 
     32        Document doc = message.getOwnerDocument();
     33       
    3334        // assume only one request
    3435        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     
    4041        HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
    4142
    42         Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
     43        Element result = doc.createElement(GSXML.MESSAGE_ELEM);
    4344
    4445        String coll = (String) params.get(GSParams.SYSTEM_CLUSTER);
     
    5051        }
    5152
    52         Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    53         Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, to, userContext);
     53        Element mr_request_message = doc.createElement(GSXML.MESSAGE_ELEM);
     54        Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_SYSTEM, to, userContext);
    5455        mr_request_message.appendChild(mr_request);
    5556
    56         Element system = this.doc.createElement(GSXML.SYSTEM_ELEM);
     57        Element system = doc.createElement(GSXML.SYSTEM_ELEM);
    5758        mr_request.appendChild(system);
    5859
     
    109110                // for now just have an error
    110111                logger.error("bad subaction type");
    111                 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     112                Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
    112113                result.appendChild(page_response);
    113114
     
    118119        Node response_message = this.mr.process(mr_request_message);
    119120
    120         Element response = GSXML.duplicateWithNewName(this.doc, (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true);
     121        Element response = GSXML.duplicateWithNewName(doc, (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true);
    121122        addSiteMetadata(response, userContext);
    122123        addInterfaceOptions(response);
Note: See TracChangeset for help on using the changeset viewer.