Changeset 10285
- Timestamp:
- 2005-07-25T15:28:42+12:00 (19 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServer.java.in
r10124 r10285 1 1 /* 2 * SOAPServer.java 2 * SOAPServer.java.in: a template for a new SOAPServer 3 3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org 4 4 * … … 20 20 package org.greenstone.gsdl3; 21 21 22 import org.greenstone.gsdl3.core.*; 22 import org.greenstone.gsdl3.core.MessageRouter; 23 import org.greenstone.gsdl3.util.GlobalProperties; 23 24 import org.greenstone.gsdl3.util.GSFile; 24 25 import org.greenstone.gsdl3.util.GSXML; 25 26 import org.w3c.dom.Element; 26 27 import java.io.File; 27 import java.io.BufferedReader;28 import java.io.FileReader;29 import java.net.URL;30 28 31 29 /** … … 38 36 public class SOAPServer@sitename@ 39 37 { 40 private String config_file_name = "SOAPServer.cfg";41 38 42 /** The message router we're talking to */ 43 MessageRouter mr_=null; 39 /** The message router we're talking to */ 40 protected MessageRouter mr=null; 41 /** the name of the site we are serving */ 42 protected String site_name = @sitename@; 44 43 45 /** The no-args constructor */44 /** The no-args constructor */ 46 45 public SOAPServer@sitename@() { 47 // find out gsdl3home - need to use the web app class loader 48 ClassLoader class_loader = this.getClass().getClassLoader(); 49 URL url = class_loader.getResource(config_file_name); 50 if (url == null) { 51 System.err.println("Couldn't find the config file "+config_file_name+". Can't initialise the SOAP server"); 46 String gsdl3_home = GlobalProperties.getGSDL3Home(); 47 if (gsdl3_home == null || gsdl3_home.equals("")) { 48 System.err.println("Couldn't access GSDL3Home from GlobalProerties.getGSDL3HOME, can't initialize the SOAP Server."); 52 49 return; 53 50 } 54 String gsdl3_home = readInFile(url); 55 if (gsdl3_home == null || gsdl3_home.equals("")) { 56 return; 57 } 58 String site_home = GSFile.siteHome(gsdl3_home, "@sitename@"); 51 String site_home = GSFile.siteHome(gsdl3_home, this.site_name); 59 52 60 53 File site_file = new File(site_home); 61 54 if (!site_file.isDirectory()) { 62 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initial sie the SOAP server.");55 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server."); 63 56 return; 64 57 } 65 mr _= new MessageRouter();66 mr _.setSiteHome(site_home);67 mr _.configure();58 mr = new MessageRouter(); 59 mr.setSiteName(this.site_name); 60 mr.configure(); 68 61 } 62 69 63 70 64 public Element [] process (Element [] xml_in) { … … 80 74 } 81 75 Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true); 82 Element r = mr _.process(new_req);76 Element r = mr.process(new_req); 83 77 // add the namespace back on 84 78 //Element new_res = r; … … 89 83 } 90 84 return result; 91 } 92 93 private String readInFile(URL url) { 94 String file_name = url.getFile(); 95 // any spaces are encoded as %20 96 file_name = file_name.replaceAll("%20", " "); 97 try { 98 BufferedReader reader = new BufferedReader(new FileReader(file_name)); 99 String line = reader.readLine(); 100 line = line.trim(); 101 return line; 102 } catch (Exception e) { 103 System.err.println("Exception occurred when reading in the file "+file_name+": "+e); 104 } 105 return null; 106 } 107 85 } 108 86 } 109 87 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/SOAPServerlocalsite.java
r10123 r10285 17 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 18 */ 19 19 20 package org.greenstone.gsdl3; 20 21 21 import org.greenstone.gsdl3.core.*; 22 import org.greenstone.gsdl3.core.MessageRouter; 23 import org.greenstone.gsdl3.util.GlobalProperties; 22 24 import org.greenstone.gsdl3.util.GSFile; 23 25 import org.greenstone.gsdl3.util.GSXML; 24 26 import org.w3c.dom.Element; 25 27 import java.io.File; 26 import java.io.BufferedReader;27 import java.io.FileReader;28 import java.net.URL;29 28 30 29 /** … … 32 31 * 33 32 * @author <a href="mailto:[email protected]">Katherine Don</a> 34 * @version $Revision$35 33 * @see <a href="http://www.w3.org/TR/SOAP/">Simple Object Access Protocol (SOAP) 1.1 </a> 36 34 */ 37 35 38 36 public class SOAPServerlocalsite 39 //implements ModuleInterface {40 37 { 41 private String config_file_name = "SOAPServer.cfg";42 43 /** The message router we're talking to*/44 MessageRouter mr_=null;45 46 /** The no-args constructor */38 /** The message router we're talking to */ 39 protected MessageRouter mr=null; 40 /** the name of the site we are serving */ 41 protected String site_name = "localsite"; 42 43 /** The no-args constructor */ 47 44 public SOAPServerlocalsite() { 48 // find out gsdl3home - need to use the web app class loader 49 ClassLoader class_loader = this.getClass().getClassLoader(); 50 URL url = class_loader.getResource(config_file_name); 51 if (url == null) { 52 System.err.println("Couldn't find the config file "+config_file_name+". Can't initialise the SOAP server"); 45 String gsdl3_home = GlobalProperties.getGSDL3Home(); 46 if (gsdl3_home == null || gsdl3_home.equals("")) { 47 System.err.println("Couldn't access GSDL3Home from GlobalProerties.getGSDL3HOME, can't initialize the SOAP Server."); 53 48 return; 54 49 } 55 String gsdl3_home = readInFile(url); 56 if (gsdl3_home == null || gsdl3_home.equals("")) { 57 return; 58 } 59 String site_home = GSFile.siteHome(gsdl3_home, "localsite"); 50 String site_home = GSFile.siteHome(gsdl3_home, this.site_name); 60 51 61 52 File site_file = new File(site_home); 62 53 if (!site_file.isDirectory()) { 63 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initial sie the SOAP server.");54 System.err.println("The site directory "+site_file.getPath()+" doesn't exist. Can't initialize the SOAP Server."); 64 55 return; 65 56 } 66 mr _= new MessageRouter();67 mr _.setSiteHome(site_home);68 mr _.configure();57 mr = new MessageRouter(); 58 mr.setSiteName(this.site_name); 59 mr.configure(); 69 60 } 70 61 71 72 /** Process a String request */ 73 // public String process(String xml_in) { 74 // return mr_.process(xml_in); 62 public Element [] process (Element [] xml_in) { 75 63 76 // }77 78 // /** Process an Element request */79 // public Element process(Element xml_in) {80 // return mr_.process(xml_in);81 // }82 83 public Element [] process (Element [] xml_in) {84 64 Element [] result = new Element[xml_in.length]; 85 65 for (int i=0; i<xml_in.length; i++) { … … 88 68 String tag_name = req.getTagName(); 89 69 String namespace=""; 90 Element new_req = req;91 70 if (tag_name.indexOf(':')!= -1) { 92 71 namespace = tag_name.substring(0, tag_name.indexOf(':')); 93 tag_name = tag_name.substring(tag_name.indexOf(':')+1); 94 new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true); 72 tag_name = tag_name.substring(tag_name.indexOf(':')+1); 95 73 } 96 Element r = mr_.process(new_req); 74 Element new_req = GSXML.duplicateWithNewName(req.getOwnerDocument(), req, tag_name, true); 75 Element r = mr.process(new_req); 97 76 // add the namespace back on 98 77 //Element new_res = r; 99 78 //if (!namespace.equals("")) { 100 79 // new_res = GSXML.duplicateWithNewName(r.getOwnerDocument(), r, namespace+r.getTagName(), true); 101 80 //} 102 81 result[i] = r; 103 82 } 104 83 return result; 105 } 106 107 private String readInFile(URL url) { 108 String file_name = url.getFile(); 109 // any spaces are encoded as %20 110 file_name = file_name.replaceAll("%20", " "); 111 try { 112 BufferedReader reader = new BufferedReader(new FileReader(file_name)); 113 String line = reader.readLine(); 114 line = line.trim(); 115 return line; 116 } catch (Exception e) { 117 System.err.println("Exception occurred when reading in the file "+file_name+": "+e); 118 } 119 return null; 120 } 121 84 } 122 85 } 123 86
Note:
See TracChangeset
for help on using the changeset viewer.