Changeset 18969 for greenstone3
- Timestamp:
- 2009-04-15T14:53:44+12:00 (15 years ago)
- Location:
- greenstone3/trunk/src/java/org/greenstone/server
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/server/BaseServer.java
r18868 r18969 62 62 reloadConfigProperties(); 63 63 64 dictionary = new Dictionary("server", lang, this.getClass().getClassLoader()); 65 64 dictionary = new Dictionary("server", lang, this.getClass().getClassLoader()); 66 65 } 67 66 … … 69 68 { 70 69 String auto_start = config_properties.getProperty(BaseServer.Property.AUTOSTART, "true"); 71 72 70 if (auto_start.equals("true") || auto_start.equals("1")) { 73 71 String start_browser = config_properties.getProperty(BaseServer.Property.START_BROWSER, "true"); … … 78 76 else{ 79 77 start(); 80 } 78 } 79 80 server_control_.setState(java.awt.Frame.ICONIFIED); // minimise the server interface window 81 81 } else { 82 82 reload(); // browser URL or other important properties may not yet be initialised … … 86 86 } 87 87 88 // package access method 88 // package access methods 89 89 BaseServerControl getServerControl() { 90 90 return server_control_; … … 103 103 public abstract void reload(); // reload properties, since they may have changed 104 104 protected void preStop() {} 105 105 protected void postStart() {} 106 106 107 public void reconfigRequired() 107 108 { … … 126 127 recordError(CONFIGURE_CMD); 127 128 } 128 reload(); 129 reload(); // work out the browserURL again 129 130 configure_required_ = false; 130 131 } … … 137 138 if (state != RunTarget.SUCCESS){ 138 139 recordError(START_CMD); 139 server_state_ = SERVER_START_FAILED; 140 140 server_state_ = SERVER_START_FAILED; 141 141 } 142 142 else{ 143 143 recordSuccess(START_CMD); 144 144 server_state_ = SERVER_STARTED; 145 postStart(); 145 146 } 146 147 -
greenstone3/trunk/src/java/org/greenstone/server/BaseServerControl.java
r18868 r18969 165 165 } 166 166 default:{ 167 enter_button.setText(BaseServer.dictionary.get("ServerControl.EnterLibrary")); 167 168 enter_button.setEnabled(false); 168 169 fMenu.setEnabled(false); … … 175 176 info_label.setText(stringToHTML("<br>"+message)); 176 177 } 177 178 178 179 private class MyAdapter extends WindowAdapter{ 179 180 public void windowClosing(WindowEvent env){ -
greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java
r18868 r18969 60 60 } 61 61 62 String auto_start_str = server.config_properties.getProperty(BaseServer.Property.AUTOSTART) ;63 if ( (auto_start_str.trim()).equals("true")) {62 String auto_start_str = server.config_properties.getProperty(BaseServer.Property.AUTOSTART).trim(); 63 if (auto_start_str.equals("true") || auto_start_str.equals("1")) { 64 64 this.autoStart = true; 65 65 } else { … … 272 272 newFileLines = scriptReadWrite.queryReplace(oldFileLines, BaseServer.Property.WEB_PORT, portNum+""); 273 273 274 String newAutoEnter = (new Boolean(autoEnter.isSelected())).toString();275 newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);276 277 274 // call the subclass' save() method to save custom elements 278 275 save(scriptReadWrite, newFileLines); … … 287 284 newFileLines); 288 285 server.reloadConfigProperties(); 286 server.reload(); // work out the URL again in case it has changed 289 287 if (require_restart){ 290 288 JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSetting.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE); 289 if(autoStart) { 290 server.autoStart(); 291 server.getServerControl().updateControl(); 292 } 291 293 } 292 294 } -
greenstone3/trunk/src/java/org/greenstone/server/BrowserLauncher.java
r18558 r18969 94 94 String lower_name = prog_name.toLowerCase(); 95 95 if (lower_name.indexOf("mozilla") != -1 || lower_name.indexOf("firefox") != -1) { 96 logger.info("found mozilla or firefox, trying remoteit");96 logger.info("found mozilla or firefox, trying to remotely launch it"); 97 97 // mozilla and netscape, try using a remote command to get things in the same window 98 98 String new_command = prog_name +" -raise -remote openURL("+url+",new-tab)"; -
greenstone3/trunk/src/java/org/greenstone/server/Server2.java
r18868 r18969 2 2 package org.greenstone.server; 3 3 4 import java.io.BufferedReader; 4 5 import java.io.File; 5 6 import java.io.FileInputStream; 6 7 import java.io.FileOutputStream; 8 import java.io.InputStreamReader; 9 import java.io.IOException; 10 import java.net.ServerSocket; 11 import java.net.Socket; 12 import java.net.URL; 13 //import java.net.URLConnection; 7 14 import java.util.Properties; 8 15 import java.util.ArrayList; … … 17 24 protected String libraryURL; 18 25 19 public Server2(String gsdl2_home, String lang, String configfile) 26 private class QuitListener extends Thread 27 { 28 int quitPort = -1; 29 ServerSocket serverSocket = null; 30 31 public QuitListener(int quitport) throws Exception { 32 ///Server2.this.recordSuccess("In QuitListener constructor"); 33 this.quitPort = quitport; 34 serverSocket = new ServerSocket(quitPort); 35 } 36 37 public void run() { 38 // Server2.this.recordSuccess("In QuitListener.run()"); 39 40 Socket connection = null; 41 42 try { 43 // wait for a connection 44 connection = serverSocket.accept(); 45 46 ///Server2.this.recordSuccess("In QuitListener - accepted connection"); 47 48 // read input 49 try { 50 BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); 51 String line = null; 52 if((line = reader.readLine()) != null) { 53 // Server2.this.recordSuccess("In QuitListener - Got a line"); 54 if(line.equals("QUIT")) { 55 // Server2.this.recordSuccess("In QuitListener - line is QUIT"); 56 reader.close(); 57 reader = null; 58 serverSocket.close(); 59 serverSocket = null; 60 } 61 } 62 } catch(Exception e) { 63 Server2.this.recordError("Exception in QuitListener thread."); 64 } finally { 65 Server2.this.stop(); 66 System.exit(0); 67 } 68 } catch(IOException ioe) { 69 Server2.this.recordError("Server2.QuitListener: Unable to make the connection with the client socket." + ioe); 70 } 71 } 72 } 73 74 75 public Server2(String gsdl2_home, String lang, String configfile, int quitPort) 20 76 { 21 77 super(gsdl2_home, lang, configfile, "etc"+File.separator+"logs-gsi"); 22 78 // configfile can be either glisite.cfg or llssite.cfg 23 79 24 25 80 Property = new Server2Property(); 26 81 27 82 String frame_title = dictionary.get("ServerControl.Frame_Title"); 28 83 server_control_ = new Server2Control(this,frame_title); 29 84 30 /* *Make command tagets for managing Web server */85 /* Make command tagets for managing Web server */ 31 86 START_CMD = "web-start"; 32 87 RESTART_CMD = "web-restart"; … … 34 89 STOP_CMD = "web-stop"; 35 90 91 // now we can monitor for the quit command if applicable 92 // First check if given port is within the range of allowed ports 93 if(!PortFinder.isAssignablePortNumber(quitPort)) { 94 recordError("QuitPort provided is not within acceptable range: (" 95 + PortFinder.PORTS_RESERVED + " - " + PortFinder.MAX_PORT + "]" ); 96 quitPort = -1; 97 } 98 99 if(quitPort != -1) { 100 try { 101 new QuitListener(quitPort).start(); 102 } catch(Exception e) { 103 Server2.this.recordError("Exception constructing the QuitListener thread."); 104 } 105 } 106 36 107 autoStart(); 37 108 } … … 98 169 // default values, to be replaced with what's in gsdlsite.cfg 99 170 String host = "localhost"; 100 String port = "80 80";171 String port = "80"; 101 172 String gwcgi; 102 173 String httpprefix = "greenstone"; … … 123 194 recordError("Could not open gsdlsite_cfg for reading, using default library prefix."); 124 195 } 125 reloadConfigProperties();196 //reloadConfigProperties(); 126 197 port = config_properties.getProperty("portnumber", port); 127 128 198 } catch(Exception e) { 129 199 recordError("Exception trying to load properties from gsdlsite_cfg. Using default library prefix.", e); 130 200 suffix = httpprefix + suffix; 131 201 } 132 202 133 203 libraryURL = "http://" + host + ":" + port + suffix; 134 135 // the URL has been changed 136 // write the URL to the file since this should work like GS2's Local Lib Server for Windows 137 ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 138 ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 139 scriptReadWrite.replaceOrAddLine(fileLines, "url", libraryURL, true); 140 scriptReadWrite.writeOutFile(config_properties_file, fileLines); 141 } 204 } 205 206 public void reloadConfigProperties() { 207 super.reloadConfigProperties(); 208 209 // make sure the port is okay, otherwise find another port 210 // first choice is port 80, second choice starts at 8282 211 String port = config_properties.getProperty("portnumber", "80"); 212 int portDefault = 8282; 213 try { 214 int portNum = Integer.parseInt(port); 215 216 if(!PortFinder.isPortAvailable(portNum)) { 217 218 PortFinder portFinder = new PortFinder(portDefault, 101); 219 portNum = portFinder.findPortInRange(); 220 port = (portNum == -1) ? Integer.toString(portDefault) : Integer.toString(portNum); 221 config_properties.setProperty("portnumber", port); // store the correct port 222 223 // write this updated port to the config file, since the configure target uses the file to run 224 ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 225 ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 226 scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 227 scriptReadWrite.writeOutFile(config_properties_file, fileLines); 228 229 configure_required_ = true; 230 } 231 } catch (Exception e) { 232 recordError("Exception in Server2.reload(): " + e.getMessage()); 233 port = Integer.toString(portDefault); 234 } 235 236 } 237 142 238 143 239 // About to stop the webserver … … 153 249 } 154 250 251 // Called when the URL has been changed (called after a reload() and starting the server). 252 // By the time we get here, reload() would already have been called and have set 253 // both the port and worked out libraryURL 254 // This method needs to write the URL to the configfile since things should work 255 // like GS2's Local Lib Server for Windows 256 protected void postStart() { 257 258 URL libURL = null; 259 try { 260 libURL = new URL(libraryURL); 261 } catch (Exception e) { 262 recordError("Unable to convert library URL string into a valid URL, Server2.java." + e); 263 } 264 265 // 1. Test that the server is running at the libraryURL before writing it out to glisite.cfg/configfile 266 // A quick test involves opening a connection to get the home page for this collection 267 if(libURL != null) { 268 269 boolean ready = false; 270 for(int i = 0; i < 60 && !ready; i++) { 271 try { 272 libURL.openConnection(); 273 //URLConnection connection = new URL(libraryURL).openConnection(); 274 //connection.getContent(); 275 ready = true; 276 recordSuccess("Try connecting to server on url: '" + libraryURL + "'"); 277 } catch (IOException bad_url_connection) { 278 // keep looping 279 recordSuccess("NOT YET CONNECTED. Waiting to try again..."); 280 try { 281 Thread.sleep(1000); 282 } catch (InterruptedException ie) { 283 ready = true; 284 recordError("Unexpected: got an InterruptedException in sleeping thread, Server2.java." + ie); 285 } 286 } catch (Exception e) { 287 ready = true; 288 recordError("Got an Exception while waiting for the connection to become live, Server2.java." + e); 289 } 290 } 291 } 292 293 // 2. Now write the URL to the config file 294 String port = config_properties.getProperty("portnumber"); 295 296 ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 297 ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 298 scriptReadWrite.replaceOrAddLine(fileLines, "url", libraryURL, true); 299 scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 300 scriptReadWrite.writeOutFile(config_properties_file, fileLines); 301 } 302 303 155 304 public static void main (String[] args) 156 305 { 157 if ((args.length < 1) || (args.length > 3)) { 158 System.err.println("Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang] [--config=configfile]"); 306 if ((args.length < 1) || (args.length > 4)) { 307 System.err.println( 308 "Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang] [--config=configfile] [--quitport=portNum]"); 159 309 System.exit(1); 160 310 } … … 170 320 171 321 // if no config file is given, then the following defaults to llssite.cfg 172 String configfile = (args.length ==3 && args[2].startsWith("--config=")) ? args[2] : gsdl2_home+File.separator+"llssite.cfg";322 String configfile = (args.length>=3 && args[2].startsWith("--config=")) ? args[2] : gsdl2_home+File.separator+"llssite.cfg"; 173 323 int equalSign = configfile.indexOf('='); 174 324 if(equalSign != -1) { … … 176 326 } 177 327 178 new Server2(gsdl2_home,lang,configfile); 328 String quitport = (args.length == 4 && args[3].startsWith("--quitport=")) ? args[3] : ""; 329 equalSign = quitport.indexOf('='); 330 int port = -1; 331 if(equalSign != -1) { 332 try { 333 quitport = quitport.substring(equalSign+1); 334 port = Integer.parseInt(quitport); 335 } catch(Exception e) { // parse fails 336 System.err.println("Port must be numeric. Continuing without it."); 337 } 338 } 339 340 //System.err.println("Running server with config file: " + configfile); 341 342 new Server2(gsdl2_home, lang, configfile, port); 179 343 } 180 344 } -
greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java
r18868 r18969 38 38 public String onSave() 39 39 { 40 return ""; 40 String result = ""; 41 if (!server.getBrowserURL().equals(prefix_combobox.getSelectedItem())) { 42 result += "changed"; 43 result += "restart"; 44 } 45 return result; 41 46 } 42 47 43 48 public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines) 44 49 { 45 String newAutoEnter = autoEnter.isSelected() ? "1" : "0"; 46 newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 50 boolean auto_enter = autoEnter.isSelected(); 51 if(autoStart != auto_enter) { 52 String newAutoEnter = auto_enter ? "1" : "0"; 53 newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 54 } 47 55 } 48 56
Note:
See TracChangeset
for help on using the changeset viewer.