source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/RSSAction.java@ 28382

Last change on this file since 28382 was 28382, checked in by davidb, 11 years ago

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 size: 2.3 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.util.*;
4
5// XML classes
6import org.w3c.dom.Document;
7import org.w3c.dom.Node;
8import org.w3c.dom.Element;
9
10// other java stuff
11import java.util.*;
12
13import java.io.Serializable;
14
15import java.io.PrintWriter;
16import java.io.Serializable;
17import java.io.StringWriter;
18
19import org.apache.log4j.*;
20
21public class RSSAction extends Action
22{
23
24 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.RSSAction.class.getName());
25
26 /** process a request */
27 public Node process(Node message_node)
28 {
29 Element message = this.converter.nodeToElement(message_node);
30 Document doc = message.getOwnerDocument();
31
32 // assume only one request
33 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
34
35 UserContext userContext = new UserContext(request);
36 // get the param list
37 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
38 HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
39
40 String service_name = "RSSFeed"; // RSSFeed service of RSSRetrieve.java
41 String collection = (String) params.get(GSParams.COLLECTION);
42 String to = GSPath.prependLink(service_name, collection); // collection/RSSFeed
43
44 // the first part of the response is the service description
45 // for now get this again from the service.
46 // this should be cached somehow later on.
47
48 Element mr_request_message = doc.createElement(GSXML.MESSAGE_ELEM);
49 Element rss_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
50 mr_request_message.appendChild(rss_request);
51
52 Element rss_response = (Element) this.mr.process(mr_request_message);
53 rss_response = (Element) GSXML.getChildByTagName(rss_response, GSXML.RESPONSE_ELEM); // just the response tag
54 // NEED ERROR PROCESSING ?
55
56 // siteMeta and interfaceOptions are unnecessary, as rss.xsl is going to remove it anyway
57 // but may be handy when doing o=xml to view the original xml as it came through from the GS server
58 addSiteMetadata(rss_response, userContext);
59 addInterfaceOptions(rss_response);
60
61 Element result = doc.createElement(GSXML.MESSAGE_ELEM);
62 result.appendChild(doc.importNode(rss_response, true));
63 return result;
64
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.