greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16334

Show
Ignore:
Timestamp:
2008-07-10 13:20:24 (3 months ago)
Author:
ak19
Message:

Three changes: 1. Added method and corresponding Action class to get the Library URL suffix (for the GLI preview URL); 2. isAuthenticationRequired() method that will return false when the cmds to be sent to the gliserver are either get-greenstone-version or get-library-suffix-url; 3. FileNotFoundException? handled when trying to connect to gliserver.pl and the wrong url for it is provided (program exits)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java

    r16111 r16334  
    166166        // returns message "Greenstone version is: <version number of the Greenstone remote server>" 
    167167        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        } 
    171172        int greenstoneVersion = Integer.parseInt(result); 
    172173        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; 
    173197    } 
    174198 
     
    273297                    try { 
    274298                        remote_greenstone_server_action.perform(); 
    275  
     299                         
    276300                        // No exceptions were thrown, so the action was successful 
    277301                        remote_greenstone_server_action.processed_successfully = true; 
     
    290314                        remote_greenstone_server_action.processed_successfully = false;                  
    291315                    } 
     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                    } 
    292328                    catch (Exception exception) { 
    293329                        DebugStream.printStackTrace(exception); 
     
    568604            throws Exception 
    569605        { 
    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); 
    572607        }        
    573608    } 
    574609 
     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     
    575620    /** 
    576621     * -------------------------------------------------------------------------------------------- 
     
    10711116    } 
    10721117 
     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 
    10731126 
    10741127    /** Returns the command output if the action completed, throws some kind of exception otherwise. */ 
     
    10771130    { 
    10781131        while (true) { 
     1132             
    10791133            // Check that Configuration.gliserver_url is set 
    10801134            if (Configuration.gliserver_url == null) { 
     
    10831137 
    10841138            // Ask for authentication information (if necessary), then perform the action 
    1085             authenticateUser(); 
     1139            if(isAuthenticationRequired(gliserver_args)) { 
     1140                authenticateUser(); 
     1141            } 
    10861142            String gliserver_url_string = Configuration.gliserver_url.toString(); 
    10871143            String command_output = sendCommandToServerInternal(gliserver_url_string, gliserver_args, shell); 
    1088             // System.err.println("Command output: " + command_output); 
    1089  
     1144             
    10901145            // Check the first line to see if authentication has failed; if so, go around the loop again 
    10911146            if (command_output.startsWith("ERROR: Authentication failed:")) { 
     
    11121167            } 
    11131168 
     1169             
    11141170            // There were no exceptions thrown so the action must have succeeded 
    11151171            return command_output; 
     
    12311287 
    12321288        // 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        } 
    12351293        cgi_args += "&ts=" + System.currentTimeMillis(); 
    12361294        if (Gatherer.GS3){