Changeset 16111 for gli


Ignore:
Timestamp:
2008-06-23T17:52:46+12:00 (13 years ago)
Author:
ak19
Message:

In uploadFileInternal(), undid introduction of dummy value and cgi-args are once again passed to the constructor of the PostMethod

File:
1 edited

Legend:

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

    r16098 r16111  
    5555import org.apache.commons.httpclient.HttpStatus;
    5656
     57
    5758public class RemoteGreenstoneServer
    5859{
     
    171172    return greenstoneVersion;
    172173    }
    173 
    174174
    175175    // ----------------------------------------------------------------------------------------------------
     
    865865        String zip_file_path = collection_directory_path + zip_file_name;
    866866        ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths);
    867 
     867       
    868868        // Upload the zip file
    869869        String upload_collection_file_command = "cmd=upload-collection-file";
     
    905905        target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|");
    906906        progress_bar.setAction("Uploading files into collection...");
    907 
     907       
    908908        String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip";
    909909        String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name;
     
    917917        source_file_relative_paths[i] = getPathRelativeToDirectory(source_files[i], base_directory_path);
    918918        }
    919 
     919       
    920920        ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths);
    921921
     
    12711271    //For a remote GS3
    12721272    //GS3 is running on Tomcat, and Tomcat requires a connection timeout to be set up at the client
    1273     //side while uploading files. As HttpURLConection couldn't set the connection timeout, HttpClient.jar
     1273    //side while uploading files. As HttpURLConnection couldn't set the connection timeout, HttpClient.jar
    12741274    //from Jakarta is applied to solve this problem only for uploading files.
    1275     if (Gatherer.GS3){
     1275    if (Gatherer.GS3) {
     1276
    12761277        // Setup the POST method
    1277         PostMethod httppost = new PostMethod(upload_cgi);
    1278            
     1278        PostMethod httppost = new PostMethod(upload_cgi+"?"+cgi_args); // cgi_args: QUERY_STRING on perl server side
     1279                   
    12791280        // construct the multipartrequest form
    12801281        String[] cgi_array=cgi_args.split("&");// get parameter-value pairs from cgi_args string
    1281         Part[] parts=new Part[cgi_array.length+6];
     1282        Part[] parts=new Part[cgi_array.length+5];
    12821283       
    1283         // We insert a dummy value for the first Part. For some reason, the gliserver side doesn't
    1284         // read the first Part (whether it's the file or a CGI argument like the cmd=upload-collection-file)
    1285         parts[0]= new StringPart("dummy_arg", "dummy_value");  // unread dummy value
    1286        
    1287         // find all parameters of cgi-args and add them into Part[]
    1288         for (int i=0; i<cgi_array.length;i++) {
    1289         parts[i+1]=new StringPart(cgi_array[i].substring(0,cgi_array[i].indexOf("=")),cgi_array[i].substring(cgi_array[i].indexOf("=")+1,cgi_array[i].length()));
    1290         }
    1291         parts[cgi_array.length+1]= new StringPart("un", remote_greenstone_server_authentication.getUserName());
    1292         parts[cgi_array.length+2]= new StringPart("pw", new String(remote_greenstone_server_authentication.getPassword()));
    1293         parts[cgi_array.length+3]= new StringPart("ts", String.valueOf(System.currentTimeMillis()));
    1294         parts[cgi_array.length+4]= new StringPart("site", Configuration.site_name);
    12951284        // The FilePart: consisting of the (cgi-arg) name and (optional) filename in the Content-Disposition
    12961285        // of the POST request Header (see CGI.pm), and the actual zip file itself. It uses the defaults:
    12971286        // Content-Type: application/octet-stream; charset=ISO-8859-1,Content-Transfer-Encoding: binary
    1298         parts[cgi_array.length+5]= new FilePart("uploaded_file", "zipFile", new File(file_path));
    1299        
     1287        parts[0]= new FilePart("uploaded_file", "zipFile", new File(file_path));
     1288
     1289        parts[1]= new StringPart("un", remote_greenstone_server_authentication.getUserName());
     1290        parts[2]= new StringPart("pw", new String(remote_greenstone_server_authentication.getPassword()));
     1291        parts[3]= new StringPart("ts", String.valueOf(System.currentTimeMillis()));
     1292        parts[4]= new StringPart("site", Configuration.site_name);
     1293        // find all parameters of cgi-args and add them into Part[]
     1294        for (int i=0; i<cgi_array.length;i++){
     1295        parts[5+i]=new StringPart(cgi_array[i].substring(0,cgi_array[i].indexOf("=")),cgi_array[i].substring(cgi_array[i].indexOf("=")+1,cgi_array[i].length()));
     1296        }
     1297
    13001298        // set MultipartRequestEntity on the POST method
    13011299        httppost.setRequestEntity(new MultipartRequestEntity(parts, httppost.getParams()));
     
    13041302        //httppost.getRequestEntity().writeRequest(new FileOutputStream("request.txt", true)); // true: appends
    13051303       
    1306 
    13071304        //set up the HttpClient connection
    13081305        HttpClient client=new HttpClient();
    13091306        client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false);
    13101307        client.getParams().setConnectionManagerTimeout(200000); //set the connection timeout
    1311        
    13121308        // get the output of the command from the server
    13131309        String command_output = "";
     
    13251321        httppost.releaseConnection();
    13261322        }
    1327     return command_output;
     1323        return command_output;
    13281324    }
    13291325
Note: See TracChangeset for help on using the changeset viewer.