Changeset 16111
- Timestamp:
- 2008-06-23T17:52:46+12:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java
r16098 r16111 55 55 import org.apache.commons.httpclient.HttpStatus; 56 56 57 57 58 public class RemoteGreenstoneServer 58 59 { … … 171 172 return greenstoneVersion; 172 173 } 173 174 174 175 175 // ---------------------------------------------------------------------------------------------------- … … 865 865 String zip_file_path = collection_directory_path + zip_file_name; 866 866 ZipTools.zipFiles(zip_file_path, collection_directory_path, collection_file_relative_paths); 867 867 868 868 // Upload the zip file 869 869 String upload_collection_file_command = "cmd=upload-collection-file"; … … 905 905 target_collection_directory_relative_path = target_collection_directory_relative_path.replaceAll((Utility.isWindows() ? "\\\\" : "\\/"), "|"); 906 906 progress_bar.setAction("Uploading files into collection..."); 907 907 908 908 String zip_file_name = collection_name + "-" + System.currentTimeMillis() + ".zip"; 909 909 String zip_file_path = Gatherer.getCollectDirectoryPath() + zip_file_name; … … 917 917 source_file_relative_paths[i] = getPathRelativeToDirectory(source_files[i], base_directory_path); 918 918 } 919 919 920 920 ZipTools.zipFiles(zip_file_path, base_directory_path, source_file_relative_paths); 921 921 … … 1271 1271 //For a remote GS3 1272 1272 //GS3 is running on Tomcat, and Tomcat requires a connection timeout to be set up at the client 1273 //side while uploading files. As HttpURLCon ection couldn't set the connection timeout, HttpClient.jar1273 //side while uploading files. As HttpURLConnection couldn't set the connection timeout, HttpClient.jar 1274 1274 //from Jakarta is applied to solve this problem only for uploading files. 1275 if (Gatherer.GS3){ 1275 if (Gatherer.GS3) { 1276 1276 1277 // 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 1279 1280 // construct the multipartrequest form 1280 1281 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]; 1282 1283 1283 // We insert a dummy value for the first Part. For some reason, the gliserver side doesn't1284 // 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 value1286 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);1295 1284 // The FilePart: consisting of the (cgi-arg) name and (optional) filename in the Content-Disposition 1296 1285 // of the POST request Header (see CGI.pm), and the actual zip file itself. It uses the defaults: 1297 1286 // 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 1300 1298 // set MultipartRequestEntity on the POST method 1301 1299 httppost.setRequestEntity(new MultipartRequestEntity(parts, httppost.getParams())); … … 1304 1302 //httppost.getRequestEntity().writeRequest(new FileOutputStream("request.txt", true)); // true: appends 1305 1303 1306 1307 1304 //set up the HttpClient connection 1308 1305 HttpClient client=new HttpClient(); 1309 1306 client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); 1310 1307 client.getParams().setConnectionManagerTimeout(200000); //set the connection timeout 1311 1312 1308 // get the output of the command from the server 1313 1309 String command_output = ""; … … 1325 1321 httppost.releaseConnection(); 1326 1322 } 1327 return command_output;1323 return command_output; 1328 1324 } 1329 1325
Note:
See TracChangeset
for help on using the changeset viewer.