- Timestamp:
- 2014-02-27T11:37:20+13:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/OAIServer.java
r25717 r28852 27 27 import javax.servlet.ServletConfig; 28 28 import javax.servlet.ServletException; 29 import javax.servlet.UnavailableException; 29 30 import javax.servlet.http.HttpServletRequest; 30 31 import javax.servlet.http.HttpServletResponse; … … 75 76 76 77 /** 77 * a converter class to parse XML and create Docs This is only used for 78 * generating internal requests passed to MessageRouter. The response 79 * message is generated by parsing an existing xml skeleton file 80 * (web/WEB-INF/oaixml/oaiversion2.xml, for example). 78 * a converter class to parse XML and create Documents for 79 * XML generation 81 80 */ 82 81 protected XMLConverter converter = null; 83 /**84 * container Document to create XML Nodes (but only request to the oai85 * receptionist, not response (which is created in OAIXML.java) created by86 * converter class87 */88 protected Document doc = null;89 82 90 83 /** A HashSet which contains all the legal verbs. */ … … 101 94 protected String site = ""; 102 95 96 // can be overriddden in OAIConfig.xml 103 97 // do we output the stylesheet processing instruction? 104 98 protected boolean use_oai_stylesheet = true; … … 136 130 if (remote_site_name == null || remote_site_type == null || remote_site_address == null) 137 131 { 138 System.err.println("initialisation paramters not all set!");139 System.err.println("if site_name is not set, then you must have remote_site_name, remote_site_type and remote_site_address set");140 System.exit(1);132 logger.error("initialisation paramters not all set!"); 133 logger.error("if site_name is not set, then you must have remote_site_name, remote_site_type and remote_site_address set"); 134 throw new UnavailableException("OAIServer: incorrect servlet parameters"); 141 135 } 142 136 } … … 150 144 // the receptionist -the servlet will talk to this 151 145 this.recept = new OAIReceptionist(); 152 146 // the converter - used to get new Documents to generate XML messages 147 this.converter = new XMLConverter(); 153 148 // the receptionist uses a MessageRouter or Communicator to send its requests to. We either create a MessageRouter here for the designated site (if site_name set), or we create a Communicator for a remote site. The is given to teh Receptionist, and the servlet never talks to it again.directly. 154 149 if (site_name != null) … … 169 164 catch (Exception e) 170 165 { // cant use this new one, so use normal one 171 System.err.println("OAIServlet configure exception when trying to use a new MessageRouter " + mr_name + ": " + e.getMessage()); 172 e.printStackTrace(); 173 message_router = new MessageRouter(); 166 logger.error("OAIServlet configure exception when trying to use a new MessageRouter " + mr_name, e); 167 message_router = new MessageRouter(); 174 168 } 175 169 } … … 177 171 message_router.setSiteName(site_name); 178 172 // lots of work is done in this step; see MessageRouter.java 179 message_router.configure(); 173 if (!message_router.configure()) { 174 throw new UnavailableException("OAIServer: Couldn't configure MessageRouter"); 175 } 180 176 this.recept.setSiteName(site_name); 181 177 this.recept.setMessageRouter(message_router); … … 187 183 Communicator communicator = null; 188 184 // we need to create the XML to configure the communicator 189 Element site_elem = this.doc.createElement(GSXML.SITE_ELEM); 185 Document site_doc = this.converter.newDOM(); 186 Element site_elem = site_doc.createElement(GSXML.SITE_ELEM); 190 187 site_elem.setAttribute(GSXML.TYPE_ATT, remote_site_type); 191 188 site_elem.setAttribute(GSXML.NAME_ATT, remote_site_name); … … 198 195 else 199 196 { 200 System.err.println("OAIServlet.init Error: invalid Communicator type: " + remote_site_type);201 System.exit(1);197 logger.error("OAIServlet.init Error: invalid Communicator type: " + remote_site_type); 198 throw new UnavailableException("OAIServer: invalid communicator type"); 202 199 } 203 200 204 201 if (!communicator.configure(site_elem)) 205 202 { 206 System.err.println("OAIServlet.init Error: Couldn't configure communicator");207 System.exit(1);203 logger.error("OAIServlet.init Error: Couldn't configure communicator"); 204 throw new UnavailableException("OAIServer: Couldn't configure communicator"); 208 205 } 209 206 this.recept.setSiteName(remote_site_name); 210 207 this.recept.setMessageRouter(communicator); 211 208 } 212 // used for composing internal xml requests, but not xml responses.213 // the converter may be used to get pretty xml, though.214 this.converter = new XMLConverter();215 this.doc = this.converter.newDOM();216 209 217 210 // Read in OAIConfig.xml (residing web/WEB-INF/classes/) and 218 //use it to configure the receptionist. The init() is also called in which 219 //the resumption token file is read in and all expired tokens cleared. 211 //use it to configure the receptionist. 220 212 Element oai_config = OAIXML.getOAIConfigXML(); 221 213 if (oai_config == null) 222 214 { 223 215 logger.error("Fail to parse oai config file OAIConfig.xml."); 224 return;216 throw new UnavailableException("OAIServer: Couldn't parse OAIConfig.xml"); 225 217 } 226 218 // pass it to the receptionist 227 this.recept.configure(oai_config); 228 219 if (!this.recept.configure(oai_config)) { 220 logger.error("Couldn't configure receptionist"); 221 throw new UnavailableException("OAIServer: Couldn't configure receptionist"); 222 } 229 223 // also, we have something we want to get from here - useOAIStylesheet 230 224 this.configure(oai_config); 225 // Initialise the resumption tokens 226 OAIResumptionToken.init(); 227 231 228 }//end of init() 232 229 … … 331 328 { 332 329 logUsageInfo(request); 333 //out.println("url="+request.getRequestURL());// /oaiserver334 //out.println("query="+request.getQueryString());// is /greenstone3335 330 336 331 // oai always requires the content type be text/xml … … 355 350 String[] pairs = (query == null) ? null : query.split("&");//split into key/value pairs 356 351 String verb = getVerb(query); 357 Element xml_response = OAIXML.createBasicResponse(verb, pairs); 352 Document response_doc = this.converter.newDOM(); 353 Element xml_response = OAIXML.createBasicResponse(response_doc, verb, pairs); 358 354 Element verb_elem = null; 359 355 … … 363 359 { 364 360 logger.error(OAIXML.BAD_VERB + ": " + query); 365 verb_elem = OAIXML.createErrorElement( OAIXML.BAD_VERB, OAIXML.ILLEGAL_OAI_VERB);361 verb_elem = OAIXML.createErrorElement(response_doc, OAIXML.BAD_VERB, OAIXML.ILLEGAL_OAI_VERB); 366 362 } 367 363 else … … 369 365 //must be something else other than bad verbs caused an error, so bad argument 370 366 logger.error(OAIXML.BAD_ARGUMENT + ": " + query); 371 verb_elem = OAIXML.createErrorElement( OAIXML.BAD_ARGUMENT, "");367 verb_elem = OAIXML.createErrorElement(response_doc, OAIXML.BAD_ARGUMENT, ""); 372 368 } 373 369 xml_response.appendChild(verb_elem); … … 384 380 // The query is valid, we can now 385 381 // compose the request message to the receptionist 386 Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 387 Element xml_request = this.doc.createElement(GSXML.REQUEST_ELEM); 382 Document request_doc = this.converter.newDOM(); 383 Element xml_message = request_doc.createElement(GSXML.MESSAGE_ELEM); 384 Element xml_request = request_doc.createElement(GSXML.REQUEST_ELEM); 388 385 // The type attribute is set to be 'oaiService' from OAIServer to OAIReceptionist. 389 386 //xml_request.setAttribute(GSXML.TYPE_ATT, OAIXML.OAI_SERVICE); … … 399 396 { 400 397 logger.info("xml_result is null"); 401 verb_elem = OAIXML.createErrorElement( "Internal error", "");398 verb_elem = OAIXML.createErrorElement(response_doc, "Internal error", ""); 402 399 xml_response.appendChild(verb_elem); 403 400 } … … 410 407 * is optional! </resumptionToken> </verb> </response> </message> 411 408 */ 412 Node res = GSXML.getChildByTagName(xml_result, OAIXML.RESPONSE);409 Node res = GSXML.getChildByTagName(xml_result, GSXML.RESPONSE_ELEM); 413 410 if (res == null) 414 411 { 415 412 logger.info("response element in xml_result is null"); 416 verb_elem = OAIXML.createErrorElement( "Internal error", "");413 verb_elem = OAIXML.createErrorElement(response_doc, "Internal error", ""); 417 414 } 418 415 else … … 421 418 } 422 419 423 if (OAIXML.oai_version.equals(OAIXML.OAI_VERSION2) || verb_elem.getTagName().equals(OAIXML.ERROR)) 424 { 425 xml_response.appendChild(xml_response.getOwnerDocument().importNode(verb_elem, true)); 420 if ( verb_elem.getTagName().equals(OAIXML.ERROR)) 421 { 422 xml_response.appendChild(response_doc.importNode(verb_elem, true)); 423 } 424 else if (OAIXML.oai_version.equals(OAIXML.OAI_VERSION2)) { 425 xml_response.appendChild(response_doc.importNode(verb_elem, true)); 426 426 } 427 427 else … … 442 442 public void addParams(Element request, String[] pairs) 443 443 { 444 Document doc = request.getOwnerDocument(); 444 445 // no params apart from the verb 445 446 if (pairs == null || pairs.length < 2) … … 456 457 if (index != -1) 457 458 { //just a double check 458 Element param = this.doc.createElement(OAIXML.PARAM); 459 param.setAttribute(OAIXML.NAME, pairs[i].substring(0, index)); 460 param.setAttribute(OAIXML.VALUE, OAIXML.oaiDecode(pairs[i].substring(index + 1))); 461 request.appendChild(param); 459 Element param = GSXML.createParameter(doc, pairs[i].substring(0, index), OAIXML.oaiDecode(pairs[i].substring(index + 1))); 460 request.appendChild(param); 462 461 } 463 462 }
Note:
See TracChangeset
for help on using the changeset viewer.