source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIMessageRouter.java@ 28989

Last change on this file since 28989 was 28989, checked in by kjdon, 10 years ago

simplified MessageRouter which uses OAICollection instread of COllection. has all the oai stuff from MessageRouter.

File size: 5.6 KB
Line 
1/*
2 * OAIMessageRouter.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.core;
20
21import java.io.File;
22import java.net.Authenticator;
23import java.net.PasswordAuthentication;
24import java.util.HashMap;
25import java.util.Map;
26import java.util.Iterator;
27
28import org.apache.commons.lang3.StringUtils;
29import org.apache.log4j.Logger;
30import org.greenstone.gsdl3.collection.OAICollection;
31import org.greenstone.gsdl3.collection.ServiceCluster;
32import org.greenstone.gsdl3.comms.Communicator;
33import org.greenstone.gsdl3.comms.SOAPCommunicator;
34import org.greenstone.gsdl3.service.ServiceRack;
35import org.greenstone.gsdl3.util.GSFile;
36import org.greenstone.gsdl3.util.GSPath;
37import org.greenstone.gsdl3.util.GSXML;
38import org.greenstone.gsdl3.util.OAIXML;
39import org.greenstone.gsdl3.util.UserContext;
40import org.greenstone.gsdl3.util.XMLConverter;
41import org.greenstone.util.GlobalProperties;
42import org.w3c.dom.Document;
43import org.w3c.dom.Element;
44import org.w3c.dom.Node;
45import org.w3c.dom.NodeList;
46
47/**
48 * The hub of a Greenstone OAI server.
49 *
50 * A simplified version of MessageRouter for OAIServer. Only loads up collections that have OAI services.
51 */
52public class OAIMessageRouter extends MessageRouter
53{
54
55 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.MessageRouter.class.getName());
56
57
58 //***************************************************************
59 // public methods
60 //***************************************************************
61
62 /** constructor */
63 public OAIMessageRouter()
64 {
65 }
66
67 /**
68 * read thru own site config file - create services and connect to sites
69 */
70 protected boolean configureLocalSite()
71 {
72
73 // this may be a reconfigure, so clean up the old moduleMap
74 cleanUpModuleMapEntire();
75
76 File configFile = new File(GSFile.siteConfigFile(this.site_home));
77
78 if (!configFile.exists())
79 {
80 logger.error(" site config file: " + configFile.getPath() + " not found!");
81 return false;
82 }
83
84 Document config_doc = XMLConverter.getDOM(configFile);
85 if (config_doc == null)
86 {
87 logger.error(" couldn't parse site config file: " + configFile.getPath());
88 return false;
89 }
90
91 this.config_info = config_doc.getDocumentElement();
92
93 // for oai, we don't do anything with the config file. But we'll keep it in case need it later, eg for replace elements when retrieving metadata - which I don't think has been implemented
94
95 Document doc = XMLConverter.newDOM();
96 // load up the collections
97 this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
98 configureCollections();
99
100 return true;
101
102 }
103
104
105 /**
106 * creates and configures a new collection if this is done for a
107 * reconfigure, the collection should be deactivated first.
108 *
109 * @param col_name
110 * the name of the collection
111 * @return true if collection created ok
112 */
113 protected boolean activateCollectionByName(String col_name)
114 {
115
116 logger.info("Activating collection: " + col_name + ".");
117 Document doc = this.collection_list.getOwnerDocument();
118 // use our special OAICollection - this will only load in oai services
119 OAICollection c = new OAICollection();
120
121 c.setCollectionName(col_name);
122 c.setSiteHome(this.site_home);
123 c.setSiteAddress(this.site_http_address);
124 c.setMessageRouter(this);
125 if (!c.configure()) {
126 logger.error("Couldn't configure collection: " + col_name + ".");
127 return false;
128 }
129
130 logger.info("have just configured collection " + col_name);
131 if (!c.hasOAI()) {
132 logger.info ("collection "+col_name+" has no OAI services. Not keeping it loaded");
133 return false;
134 }
135 // add to list of collections
136 this.module_map.put(col_name, c);
137 Element e = doc.createElement(GSXML.COLLECTION_ELEM);
138 e.setAttribute(GSXML.NAME_ATT, col_name);
139 e.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
140 e.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp());
141 this.collection_list.appendChild(e);
142 return true;
143
144 }
145
146
147
148 //*****************************************************************
149 // auxiliary process methods
150 //*****************************************************************
151
152 /**
153 * handles requests made to the MessageRouter itself
154 *
155 * @param req
156 * - the request Element- <request>
157 * @return the result Element - should be <response>
158 */
159 protected Element processMessage(Element req) {
160 Document doc = XMLConverter.newDOM();
161 String type = req.getAttribute(GSXML.TYPE_ATT);
162 Element response = doc.createElement(GSXML.RESPONSE_ELEM);
163 response.setAttribute(GSXML.FROM_ATT, "");
164
165 if (type.equals(OAIXML.OAI_SET_LIST))
166 {
167 logger.info("oaiSetList request received");
168 //this is the oai receptionist asking for a list of oai-support collections
169 response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);
170 response.appendChild(doc.importNode(this.collection_list, true));
171 return response;
172 }
173 return super.processMessage(req);
174 }
175
176
177}
Note: See TracBrowser for help on using the repository browser.