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

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

configure the collection with the OAIConfig xml. this breaks the split between receptionist and MR as mostly this is used by receptionist.

File size: 6.1 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 public Element oai_config = null;
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 // for oai, we don't do anything with the site config file. But we'll read it in and keep it in case need it later, eg for replace elements when retrieving metadata - which I don't think has been implemented
77 File configFile = new File(GSFile.siteConfigFile(this.site_home));
78
79 if (!configFile.exists())
80 {
81 logger.error(" site config file: " + configFile.getPath() + " not found!");
82 return false;
83 }
84
85 Document config_doc = XMLConverter.getDOM(configFile);
86 if (config_doc == null)
87 {
88 logger.error(" couldn't parse site config file: " + configFile.getPath());
89 return false;
90 }
91
92 this.config_info = config_doc.getDocumentElement();
93
94 // this is the receptionists OAIConfig.xml. Need to rethink how the MR gets this this if we ever talk to remote site, and whether it should be using it anyway
95 this.oai_config = OAIXML.getOAIConfigXML();
96 if (this.oai_config == null)
97 {
98 logger.error("Couldn't load in OAIConfig.xml");
99 return false;
100 }
101 Document doc = XMLConverter.newDOM();
102 // load up the collections
103 this.collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
104 configureCollections();
105
106 return true;
107
108 }
109
110
111 /**
112 * creates and configures a new collection if this is done for a
113 * reconfigure, the collection should be deactivated first.
114 *
115 * @param col_name
116 * the name of the collection
117 * @return true if collection created ok
118 */
119 protected boolean activateCollectionByName(String col_name)
120 {
121
122 logger.info("Activating collection: " + col_name + ".");
123 Document doc = this.collection_list.getOwnerDocument();
124 // use our special OAICollection - this will only load in oai services
125 OAICollection c = new OAICollection();
126
127 c.setCollectionName(col_name);
128 c.setSiteHome(this.site_home);
129 c.setSiteAddress(this.site_http_address);
130 c.setMessageRouter(this);
131 if (!c.configure()) {
132 logger.error("Couldn't configure collection: " + col_name + ".");
133 return false;
134 }
135
136 logger.info("have just configured collection " + col_name);
137 if (!c.hasOAI()) {
138 logger.info ("collection "+col_name+" has no OAI services. Not keeping it loaded");
139 return false;
140 }
141 if (!c.configureOAI(this.oai_config)) {
142 logger.info("couldn't configure the collection : "+col_name +" with the oai config info");
143 return false;
144 }
145 // add to list of collections
146 this.module_map.put(col_name, c);
147 Element e = doc.createElement(GSXML.COLLECTION_ELEM);
148 e.setAttribute(GSXML.NAME_ATT, col_name);
149 e.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
150 e.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp());
151 this.collection_list.appendChild(e);
152 return true;
153
154 }
155
156
157
158 //*****************************************************************
159 // auxiliary process methods
160 //*****************************************************************
161
162 /**
163 * handles requests made to the MessageRouter itself
164 *
165 * @param req
166 * - the request Element- <request>
167 * @return the result Element - should be <response>
168 */
169 protected Element processMessage(Element req) {
170 Document doc = XMLConverter.newDOM();
171 String type = req.getAttribute(GSXML.TYPE_ATT);
172 Element response = doc.createElement(GSXML.RESPONSE_ELEM);
173 response.setAttribute(GSXML.FROM_ATT, "");
174
175 if (type.equals(OAIXML.OAI_SET_LIST))
176 {
177 logger.info("oaiSetList request received");
178 //this is the oai receptionist asking for a list of oai-support collections
179 response.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SET_LIST);
180 response.appendChild(doc.importNode(this.collection_list, true));
181 return response;
182 }
183 return super.processMessage(req);
184 }
185
186
187}
Note: See TracBrowser for help on using the repository browser.