source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/SystemAction.java@ 34018

Last change on this file since 34018 was 34018, checked in by kjdon, 4 years ago

check for error element in response - add that in if present, instead of the complete response. then it can be displayed on the page

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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 SystemAction extends Action
22{
23
24 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName());
25
26 String tempVal = "";
27
28 /** process a request */
29 public Node process(Node message_node)
30 {
31 Element message = GSXML.nodeToElement(message_node);
32 Document doc = message.getOwnerDocument();
33
34 // assume only one request
35 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
36
37 String subaction = request.getAttribute(GSXML.SUBACTION_ATT);
38 UserContext userContext = new UserContext(request);
39 // get the param list
40 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
41 HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
42
43 Element result = doc.createElement(GSXML.MESSAGE_ELEM);
44
45 String coll = (String) params.get(GSParams.SYSTEM_CLUSTER);
46
47 String to = "";
48 if (coll != null && !coll.equals(""))
49 {
50 to = coll;
51 }
52 else if(subaction.equals("authenticated-ping")) {
53 to = "RemoteAuthentication"; // not "Authentication/RemoteAuthentication": MessageRouter knows to map the RemoteAuthentication service to the Authentication module
54 }
55
56 Element mr_request_message = doc.createElement(GSXML.MESSAGE_ELEM);
57 Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_SYSTEM, to, userContext);
58 mr_request_message.appendChild(mr_request);
59
60 Element system = doc.createElement(GSXML.SYSTEM_ELEM);
61 mr_request.appendChild(system);
62
63 // will need to change the following if can do more than one system request at once
64 if (subaction.equals("c"))
65 { // configure
66 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE);
67 String info = (String) params.get(GSParams.SYSTEM_SUBSET);
68 system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info);
69 }
70 else if (subaction.equals("ping")) { // can ping the server or a collection
71 String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME);
72
73 if(name != null && !name.equals("")) {
74 // Pinging a collection (or module) with ?a=s&sa=ping&st=collection&sn=<colName>
75 // is a collection-level (servicecluster/module level) ping
76
77 String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE);
78 if(type == null || type.equals("")) {
79 type = "collection"; // if the st=collection was omitted, assume collection
80 }
81 // ping action set to moduleType=Collection and moduleName=colName
82 system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
83 system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
84 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING);
85 } // else SYSTEM_MODULE_NAME given by the "sn" GSParam is null or empty
86 // meaning server-level ping: ?a=s&sa=ping
87
88 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING);
89 }
90 else if (subaction.equals("authenticated-ping")) { // can check whether a given username and password authenticates
91
92 String username = (String) params.get(GSParams.UN);
93 String password = (String) params.get(GSParams.PW);
94
95
96 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_AUTHENTICATED_PING);
97 system.setAttribute(GSXML.USERNAME_ATT, username);
98 system.setAttribute(GSXML.PASSWORD_ATT, password);
99
100 if(params.containsKey("col")) {//params.containsKey(GSParams.COLLECTION)) {
101 String collection = (String) params.get("col");//(String) params.get(GSParams.COLLECTION);
102 system.setAttribute(GSXML.COLLECTION_ATT, collection);
103 }
104
105 }
106
107 //else if (subaction.equals("is-persistent")){
108 // system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ISPERSISTENT);
109 //}
110 else
111 {
112 String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME);
113 String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE);
114
115 system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
116 system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
117
118 if (subaction.equals("d"))
119 { // delete
120 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE);
121
122 }
123 else if (subaction.equals("a"))
124 { // add
125 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE);
126 }
127 else
128 {
129 // create the default response
130 // for now just have an error
131 logger.error("bad subaction type");
132 Element page_response = doc.createElement(GSXML.RESPONSE_ELEM);
133 result.appendChild(page_response);
134
135 return result;
136 }
137 }
138
139 Node response_message = this.mr.process(mr_request_message);
140 Element response = doc.createElement(GSXML.RESPONSE_ELEM);
141 if (processErrorElements((Element)response_message, response)) {
142 } else {
143 response = GSXML.duplicateWithNewName(doc, (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true);
144 }
145 addSiteMetadata(response, userContext);
146 addInterfaceOptions(response);
147
148 result.appendChild(response);
149 return result;
150
151 }
152
153}
Note: See TracBrowser for help on using the repository browser.