Changeset 16334
- Timestamp:
- 2008-07-10T13:20:24+12:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java
r16111 r16334 166 166 // returns message "Greenstone version is: <version number of the Greenstone remote server>" 167 167 String result = performAction(new RemoteGreenstoneServerVersionAction()); 168 int index = result.indexOf(":") + 1; // includes space after colon 169 result = result.substring(index); 170 System.err.println("***** version: " + result); 168 int index = result.indexOf(":"); 169 if(index != -1) { 170 result = result.substring(index+1).trim(); // skip the space after colon, must remove surrounding spaces 171 } 171 172 int greenstoneVersion = Integer.parseInt(result); 172 173 return greenstoneVersion; 174 } 175 176 /** For constructing the preview command (the library URL) with */ 177 static public String getLibraryURL(String serverHomeURL) 178 { 179 // returns message "Greenstone library URL suffix is: <e.g. /greenstone3/library or /gsdl/cgi-bin/library>" 180 String libSuffix = performAction(new RemoteGreenstoneServerLibraryURLSuffixAction()); 181 int index = libSuffix.indexOf(":"); 182 if(index != -1) { 183 libSuffix = libSuffix.substring(index+1).trim(); // skip the space after colon and remove surrounding spaces 184 } 185 186 // serverHomeURL is of the form, http://domain/other/stuff. We want the prefix upto & including domain 187 // and prepend that to the libraryURLSuffix 188 index = -1; 189 for(int i = 0; i < 3; i++) { 190 index = serverHomeURL.indexOf("/", index+1); 191 if(index == -1) { // shouldn't happen, but if it does, we'll be in an infinite loop 192 break; 193 } 194 } 195 serverHomeURL = serverHomeURL.substring(0, index); 196 return serverHomeURL + libSuffix; 173 197 } 174 198 … … 273 297 try { 274 298 remote_greenstone_server_action.perform(); 275 299 276 300 // No exceptions were thrown, so the action was successful 277 301 remote_greenstone_server_action.processed_successfully = true; … … 290 314 remote_greenstone_server_action.processed_successfully = false; 291 315 } 316 catch (FileNotFoundException exception) { 317 // FileNotFoundException happens when there's no GS server at the user-provided 318 // url (the address of gliserver.pl is wrong). 319 exit = true; 320 DebugStream.printStackTrace(exception); 321 JOptionPane.showMessageDialog(Gatherer.g_man, 322 Dictionary.get("RemoteGreenstoneServer.Error", 323 "No gliserver.pl found. " + exception.getMessage()), 324 Dictionary.get("RemoteGreenstoneServer.Error_Title"), 325 JOptionPane.ERROR_MESSAGE); 326 remote_greenstone_server_action.processed_successfully = false; 327 } 292 328 catch (Exception exception) { 293 329 DebugStream.printStackTrace(exception); … … 568 604 throws Exception 569 605 { 570 String greenstone_version_command = "cmd=greenstone-server-version"; 571 action_output = sendCommandToServer(greenstone_version_command, null); 606 action_output = sendCommandToServer("cmd=greenstone-server-version", null); 572 607 } 573 608 } 574 609 610 static private class RemoteGreenstoneServerLibraryURLSuffixAction 611 extends RemoteGreenstoneServerAction 612 { 613 public void perform() 614 throws Exception 615 { 616 action_output = sendCommandToServer("cmd=get-library-url-suffix", null); 617 } 618 } 619 575 620 /** 576 621 * -------------------------------------------------------------------------------------------- … … 1071 1116 } 1072 1117 1118 /** Returns true or false depending on whether authentication is required for the cmd 1119 * string embedded in the given gliserver_args. No authentication is required for either 1120 * of the commands greenstone-server-version and get-library-url-suffix. */ 1121 static private boolean isAuthenticationRequired(String gliserver_args) { 1122 return ((gliserver_args.indexOf("greenstone-server-version") == -1) 1123 && (gliserver_args.indexOf("get-library-url-suffix") == -1)); 1124 } 1125 1073 1126 1074 1127 /** Returns the command output if the action completed, throws some kind of exception otherwise. */ … … 1077 1130 { 1078 1131 while (true) { 1132 1079 1133 // Check that Configuration.gliserver_url is set 1080 1134 if (Configuration.gliserver_url == null) { … … 1083 1137 1084 1138 // Ask for authentication information (if necessary), then perform the action 1085 authenticateUser(); 1139 if(isAuthenticationRequired(gliserver_args)) { 1140 authenticateUser(); 1141 } 1086 1142 String gliserver_url_string = Configuration.gliserver_url.toString(); 1087 1143 String command_output = sendCommandToServerInternal(gliserver_url_string, gliserver_args, shell); 1088 // System.err.println("Command output: " + command_output); 1089 1144 1090 1145 // Check the first line to see if authentication has failed; if so, go around the loop again 1091 1146 if (command_output.startsWith("ERROR: Authentication failed:")) { … … 1112 1167 } 1113 1168 1169 1114 1170 // There were no exceptions thrown so the action must have succeeded 1115 1171 return command_output; … … 1231 1287 1232 1288 // Add username and password, and a timestamp 1233 cgi_args += "&un=" + remote_greenstone_server_authentication.getUserName(); 1234 cgi_args += "&pw=" + new String(remote_greenstone_server_authentication.getPassword()); 1289 if(isAuthenticationRequired(cgi_args)) { 1290 cgi_args += "&un=" + remote_greenstone_server_authentication.getUserName(); 1291 cgi_args += "&pw=" + new String(remote_greenstone_server_authentication.getPassword()); 1292 } 1235 1293 cgi_args += "&ts=" + System.currentTimeMillis(); 1236 1294 if (Gatherer.GS3){
Note:
See TracChangeset
for help on using the changeset viewer.