Changeset 10292 for trunk/gsdl3/src
- Timestamp:
- 2005-07-25T16:10:42+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/core/MessageRouter.java
r9914 r10292 34 34 // other java classes 35 35 import java.io.File; 36 import java.util.HashMap;37 import java.util.Iterator;38 36 import java.io.Reader; 39 37 import java.io.StringReader; 40 38 import java.net.Authenticator; 41 39 import java.net.PasswordAuthentication; 40 import java.util.HashMap; 41 import java.util.Iterator; 42 import java.util.Properties; 42 43 43 44 /** … … 61 62 public class MessageRouter implements ModuleInterface { 62 63 64 /** the (directory) name of the site */ 65 protected String site_name = null; 63 66 /** site home - the home directory for the site */ 64 67 protected String site_home=null; … … 66 69 protected String site_http_address=null; 67 70 68 /** the global name for this site */69 protected String global_site_name=null;70 71 71 /** map of names to Module objects */ 72 72 protected HashMap module_map=null; … … 86 86 /** list of sites that can be reached */ 87 87 protected Element site_list = null; 88 88 89 89 90 /** a converter class to parse XML and create Docs */ 90 91 protected XMLConverter converter=null; 91 92 93 92 94 //*************************************************************** 93 95 // public methods … … 108 110 } 109 111 } 110 /** site_home must be set before configure called */ 111 public void setSiteHome(String home) {112 this.site_home = home; 113 } 114 112 113 /** site_name must be set before configure is called */ 114 public void setSiteName(String site_name) { 115 this.site_name = site_name; 116 } 115 117 /** 116 118 * configures the system 117 119 * 118 120 * looks in site_home/collect for collections, reads config file 119 * site_home/site cfg.xml121 * site_home/siteConfig.xml 120 122 * 121 123 */ … … 124 126 System.out.println("MessageRouter:configuring site"); 125 127 126 if (this.site_ home==null) {127 System.err.println("MessageRouter: You must set site_ home before calling configure");128 if (this.site_name==null) { 129 System.err.println("MessageRouter: You must set site_name before calling configure"); 128 130 return false; 129 131 } 130 132 this.site_home = GSFile.siteHome(GlobalProperties.getGSDL3Home(), this.site_name); 133 this.site_http_address = GlobalProperties.getGSDL3WebAddress()+"/sites/"+this.site_name; 134 135 // are we behind a firewall?? - is there a better place to set up the proxy? 136 String host = GlobalProperties.getProperty("proxy.host"); 137 String port = GlobalProperties.getProperty("proxy.port"); 138 final String user = GlobalProperties.getProperty("proxy.user"); 139 final String passwd = GlobalProperties.getProperty("proxy.password"); 140 141 if (host != null && !host.equals("") && port !=null && !port.equals("")) { 142 System.setProperty("http.proxyType", "4"); 143 System.setProperty("http.proxyHost", host); 144 System.setProperty("http.proxyPort", port); 145 System.setProperty("http.proxySet", "true"); 146 // have we got a user/password? 147 if (user != null && !user.equals("") && passwd != null && !passwd.equals("")) { 148 try { 149 // set up the authenticator 150 Authenticator.setDefault(new Authenticator(){ 151 protected PasswordAuthentication getPasswordAuthentication(){ 152 return new PasswordAuthentication(user, new String(passwd).toCharArray()); 153 } 154 }); 155 156 } catch (Exception e) { 157 System.err.println("MessageRouter Error: couldn't set up an authenticator the proxy"); 158 159 } 160 } 161 } 162 131 163 // read thru own config file - create services and connect to sites 132 164 File configFile = new File(GSFile.siteConfigFile(this.site_home)); … … 137 169 } 138 170 139 this.module_map = new HashMap();140 141 171 Document config_doc = this.converter.getDOM(configFile); 142 172 if (config_doc == null) { … … 144 174 return false; 145 175 } 176 146 177 Element config_elem = config_doc.getDocumentElement(); 147 178 148 Element local_site_name = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_NAME_ELEM); 149 if (local_site_name == null) { 150 System.err.println("MessageRouter configure error:no site name in config file"); 151 return false; 152 } else { 153 this.global_site_name = local_site_name.getAttribute(GSXML.VALUE_ATT); 154 } 155 156 Element http_address = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_HTTP_ADDRESS_ELEM); 157 if (http_address == null) { 158 System.err.println("MessageRouter configure error: no http address in config file"); 159 return false; 160 } else { 161 this.site_http_address = http_address.getAttribute(GSXML.VALUE_ATT); 162 } 163 164 Element proxy = (Element)GSXML.getChildByTagName(config_elem, "proxy"); 165 if (proxy != null) { 166 String host = proxy.getAttribute("host"); 167 String port = proxy.getAttribute("port"); 168 final String user = proxy.getAttribute("user"); 169 final String passwd = proxy.getAttribute("password"); 170 if (host.equals("") || port.equals("") || user.equals("")||passwd.equals("")) { 171 System.err.println("MessageRouter.configure Error: A proxy was specified in the config file, but attributes host, port, user, password were not all present"); 172 } else { 173 try { 174 // set up the proxy 175 System.setProperty("http.proxyType", "4"); 176 System.setProperty("http.proxyHost", host); 177 System.setProperty("http.proxyPort", port); 178 System.setProperty("http.proxySet", "true"); 179 Authenticator.setDefault(new Authenticator(){ 180 protected PasswordAuthentication getPasswordAuthentication(){ 181 return new PasswordAuthentication(user, new 182 String(passwd).toCharArray()); 183 } 184 }); 185 186 } catch (Exception e) { 187 System.err.println("MessageRouter Error: couldn't set up the proxy"); 188 } 189 } 190 } 191 179 this.module_map = new HashMap(); 180 192 181 // load up the services 193 182 Element service_rack_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SERVICE_CLASS_ELEM+GSXML.LIST_MODIFIER); … … 379 368 } 380 369 381 protected boolean configureClusters(Element c luster_list) {370 protected boolean configureClusters(Element config_cluster_list) { 382 371 383 372 this.cluster_list = this.doc.createElement(GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER); 384 373 // load up the service clusters 385 374 System.out.println("loading service clusters ..."); 386 if (c luster_list == null) {375 if (config_cluster_list == null) { 387 376 System.out.println("... none to be loaded"); 388 377 return true; 389 378 } 390 NodeList service_clusters = c luster_list.getElementsByTagName(GSXML.CLUSTER_ELEM);379 NodeList service_clusters = config_cluster_list.getElementsByTagName(GSXML.CLUSTER_ELEM); 391 380 if (service_clusters.getLength()==0) { 392 381 System.out.println("... none to be loaded"); … … 428 417 String colName = contents[i].getName(); 429 418 if (!colName.startsWith("CVS")) { 430 activateCollection (colName);419 activateCollectionByName(colName); 431 420 } 432 421 } … … 436 425 } 437 426 438 protected boolean configureSites(Element site_list) {427 protected boolean configureSites(Element config_site_list) { 439 428 440 429 this.site_list = this.doc.createElement(GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 441 430 // load up the sites 442 431 System.out.println("loading external sites..."); 443 if ( site_list ==null ) {432 if (config_site_list ==null ) { 444 433 System.out.println("...none found"); 445 434 return true; 446 435 } 447 NodeList sites = site_list.getElementsByTagName(GSXML.SITE_ELEM); 436 437 NodeList sites = config_site_list.getElementsByTagName(GSXML.SITE_ELEM); 448 438 if (sites.getLength()==0) { 449 439 System.out.println("...none found"); 450 440 return true; 451 441 } 442 443 // this is a name to identify the current site in the Communicator 444 String local_site_name = config_site_list.getAttribute(GSXML.LOCAL_SITE_NAME_ATT); 445 if (local_site_name.equals("")) { 446 local_site_name = site_name; 447 } 448 452 449 for (int i=0; i<sites.getLength(); i++) { 453 450 Element s = (Element)sites.item(i); 454 Communicator comm=null; 455 String type = s.getAttribute(GSXML.TYPE_ATT); 456 String name = s.getAttribute(GSXML.NAME_ATT); 457 if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 458 comm = new SOAPCommunicator(); 459 if (comm.configure(s)) { 460 comm.setLocalSiteName(this.global_site_name); 461 462 // add to map of modules 463 this.module_map.put(name, comm); 464 this.site_list.appendChild(this.doc.importNode(s, true)); 465 // need to get collection list and service 466 // list from here- if the site isn't up yet, the site will 467 // have to be added later 468 if (!getRemoteSiteInfo(comm, name)) { 469 System.err.println("MessageRouter: couldn't get info from site "+name); 470 } 471 } else { 472 System.err.println("MessageRouter: couldn't configure soap site:"+name); 473 } 451 activateSite(s, local_site_name); 452 } 453 return true; 454 } 455 456 protected boolean activateSite(Element site_elem, String local_site_name) { 457 Communicator comm=null; 458 String type = site_elem.getAttribute(GSXML.TYPE_ATT); 459 String name = site_elem.getAttribute(GSXML.NAME_ATT); 460 if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 461 comm = new SOAPCommunicator(); 462 if (comm.configure(site_elem)) { 463 comm.setLocalSiteName(local_site_name); 474 464 465 // add to map of modules 466 this.module_map.put(name, comm); 467 this.site_list.appendChild(this.doc.importNode(site_elem, true)); 468 // need to get collection list and service 469 // list from here- if the site isn't up yet, the site will 470 // have to be added later 471 if (!getRemoteSiteInfo(comm, name)) { 472 System.err.println("MessageRouter: couldn't get info from site "+name); 473 } 475 474 } else { 476 System.err.print ("MessageRouter: cant talk to server of type:"+type);477 System.err.println(", so not making a connection to "+name);475 System.err.println("MessageRouter: couldn't configure soap site:"+name); 476 return false; 478 477 } 479 478 479 } else { 480 System.err.print("MessageRouter: cant talk to server of type:"+type + ", so not making a connection to "+name); 481 return false; 480 482 } 481 483 return true; 482 484 } 483 484 485 485 486 /** get site info from external site … … 668 669 } else if (action.equals(GSXML.SYSTEM_TYPE_ACTIVATE)) { 669 670 if (module_type.equals(GSXML.COLLECTION_ELEM)) { 670 success = activateCollection (module_name);671 success = activateCollectionByName(module_name); 671 672 } else if (module_type.equals(GSXML.SITE_ELEM)) { 672 success = activateSite (module_name);673 success = activateSiteByName(module_name); 673 674 } else if (module_type.equals(GSXML.CLUSTER_ELEM)) { 674 success = activateServiceCluster (module_name);675 success = activateServiceClusterByName(module_name); 675 676 } 676 677 if (success) { … … 761 762 *@return true if collection created ok 762 763 */ 763 protected boolean activateCollection (String col_name) {764 protected boolean activateCollectionByName(String col_name) { 764 765 765 766 System.out.println("MessageRouter:Activating collection: "+col_name+"."); … … 809 810 } 810 811 811 protected boolean activateSite (String site_name) {812 protected boolean activateSiteByName(String site_name) { 812 813 System.out.println("MessageRouter:Activating site: "+site_name+"."); 813 814 … … 827 828 Element config_elem = config_doc.getDocumentElement(); 828 829 829 Element site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER);830 if ( site_list ==null ) {830 Element config_site_list = (Element)GSXML.getChildByTagName(config_elem, GSXML.SITE_ELEM+GSXML.LIST_MODIFIER); 831 if (config_site_list ==null ) { 831 832 System.err.println("MessageRouter:activateSite, no sites found"); 832 833 return false; 833 834 } 834 Element this_site_elem = GSXML.getNamedElement(site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, site_name); 835 // this is a name to identify the current site in the Communicator 836 String local_site_name = config_site_list.getAttribute("localSiteName"); 837 if (local_site_name.equals("")) { 838 local_site_name = site_name; 839 } 840 841 Element this_site_elem = GSXML.getNamedElement(config_site_list, GSXML.SITE_ELEM, GSXML.NAME_ATT, site_name); 835 842 if (this_site_elem == null) { 836 843 System.err.println("MessageRouter:activateSite, site "+site_name+" not found"); … … 838 845 } 839 846 840 Communicator comm=null; 841 String type = this_site_elem.getAttribute(GSXML.TYPE_ATT); 842 if (type.equals(GSXML.COMM_TYPE_SOAP_JAVA)) { 843 comm = new SOAPCommunicator(); 844 if (comm.configure(this_site_elem)) { 845 comm.setLocalSiteName(this.global_site_name); 846 847 // add to map of modules 848 this.module_map.put(site_name, comm); 849 this.site_list.appendChild(this.doc.importNode(this_site_elem, true)); 850 // need to get collection list and service 851 // list from here- if the site isn't up yet, the site will 852 // have to be added later 853 if (!getRemoteSiteInfo(comm, site_name)) { 854 System.err.println("MessageRouter: couldn't get info from site "+site_name); 855 } 856 } else { 857 System.err.println("MessageRouter: couldn't configure soap site:"+site_name); 858 return false; 859 } 860 861 } else { 862 System.err.print("MessageRouter: cant talk to server of type:"+type); 863 System.err.println(", so not making a connection to "+site_name); 864 return false; 865 } 866 return true; 867 868 } 869 870 protected boolean activateServiceCluster(String cluster_name) { 847 return activateSite(this_site_elem, local_site_name); 848 } 849 850 protected boolean activateServiceClusterByName(String cluster_name) { 871 851 return false; 872 852 873 853 } 874 854 875 protected boolean activateServiceRack (String module_name) {855 protected boolean activateServiceRackByName(String module_name) { 876 856 return false; 877 857 } … … 934 914 NodeList modules = module_list.getElementsByTagName(module_name); 935 915 // will this work?? 936 for (int i= 0; i<modules.getLength(); i++) {916 for (int i=modules.getLength()-1; i>=0; i--) { 937 917 938 918 String name = ((Element)modules.item(i)).getAttribute(GSXML.NAME_ATT); 939 919 if (GSPath.getFirstLink(name).equals(site_name)) { 940 920 module_list.removeChild(modules.item(i)); 941 i--; // move the pointer back942 921 } 943 922 }
Note:
See TracChangeset
for help on using the changeset viewer.