Changeset 14308 for gli/trunk/src/org/greenstone
- Timestamp:
- 2007-08-06T10:55:19+12:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java
r14261 r14308 33 33 import java.util.zip.*; 34 34 import javax.swing.*; 35 import java.io.ByteArrayOutputStream; 35 36 import org.greenstone.gatherer.Configuration; 36 37 import org.greenstone.gatherer.DebugStream; … … 42 43 import org.greenstone.gatherer.util.UnzipTools; 43 44 import org.greenstone.gatherer.util.Utility; 44 45 import org.apache.commons.httpclient.HttpClient; 46 import org.apache.commons.httpclient.methods.PostMethod; 47 import org.apache.commons.httpclient.methods.GetMethod; 48 import org.apache.commons.httpclient.HttpException; 49 import org.apache.commons.httpclient.methods.multipart.FilePart; 50 import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; 51 import org.apache.commons.httpclient.methods.multipart.Part; 52 import org.apache.commons.httpclient.methods.multipart.*; 53 import org.apache.commons.httpclient.params.*; 54 import org.apache.commons.httpclient.HttpStatus; 45 55 46 56 public class RemoteGreenstoneServer … … 85 95 return performAction(new RemoteGreenstoneServerDownloadCollectionFileAction(collection_name, collection_file)); 86 96 } 87 97 98 // get web.xml from the server -- for a remote gli of GS3 99 static public String downloadWebXMLFile() 100 { 101 return performAction(new RemoteGreenstoneServerDownloadWebXMLFileAction()); 102 } 88 103 89 104 static public String getScriptOptions(String script_name, String script_arguments) … … 91 106 return performAction(new RemoteGreenstoneServerGetScriptOptionsAction(script_name, script_arguments)); 92 107 } 93 108 109 //get all available site names from the server -- for a remote gli of GS3 110 static public String getSiteNames() 111 { 112 return performAction(new RemoteGreenstoneServerGetSiteNamesAction()); 113 } 94 114 95 115 static public String moveCollectionFile(String collection_name, File source_collection_file, File target_collection_file) … … 532 552 } 533 553 554 /** 555 * -------------------------------------------------------------------------------------------- 556 * DOWNLOAD web.xml FILE --for a remote GS3 557 * -------------------------------------------------------------------------------------------- 558 */ 559 static private class RemoteGreenstoneServerDownloadWebXMLFileAction 560 extends RemoteGreenstoneServerAction 561 { 562 public RemoteGreenstoneServerDownloadWebXMLFileAction() 563 {} 564 565 public void perform() 566 throws Exception 567 { 568 String web_xml_directory_path=(Configuration.gli_user_directory_path); 569 String download_web_xml_file_command = "cmd=download-web-xml-file"; 570 download_web_xml_file_command += "&file=" + URLEncoder.encode("web.xml", "UTF-8"); 571 String zip_file_name = "web-xml.zip"; 572 String zip_file_path = web_xml_directory_path + zip_file_name; 573 action_output = downloadFile(download_web_xml_file_command, zip_file_path); 574 575 // Unzip the web.xml file just downloaded 576 UnzipTools.unzipFile(zip_file_path,web_xml_directory_path); 577 } 578 } 534 579 535 580 /** … … 564 609 } 565 610 611 /** 612 * -------------------------------------------------------------------------------------------- 613 * GET ALL NAMES OF SITES // for a remote GS3 614 * -------------------------------------------------------------------------------------------- 615 */ 616 static private class RemoteGreenstoneServerGetSiteNamesAction 617 extends RemoteGreenstoneServerAction 618 { 619 public RemoteGreenstoneServerGetSiteNamesAction() 620 {} 621 622 public void perform() 623 throws Exception 624 { 625 progress_bar.setAction("Getting names of sites ..."); 626 627 String get_script_options_command = "cmd=get-site-names"; 628 action_output = sendCommandToServer(get_script_options_command, null); 629 } 630 } 566 631 567 632 /** … … 780 845 // static private PasswordAuthentication remote_greenstone_server_authentication = new PasswordAuthentication(System.getProperty("user.name"), new char[] { }); 781 846 847 static public void set_remote_greenstone_server_authentication_to_null(){ 848 remote_greenstone_server_authentication = null; 849 } 782 850 783 851 static private class RemoteGreenstoneServerAuthenticateTask … … 800 868 protected String getMessageString() 801 869 { 870 if (Gatherer.GS3){ 871 return (Dictionary.get("RemoteGreenstoneServer.Authentication_Message_gs3") + " " + Configuration.site_name); 872 } 802 873 return Dictionary.get("RemoteGreenstoneServer.Authentication_Message"); 803 874 } … … 989 1060 cgi_args += "&pw=" + new String(remote_greenstone_server_authentication.getPassword()); 990 1061 cgi_args += "&ts=" + System.currentTimeMillis(); 1062 if (Gatherer.GS3){ 1063 cgi_args += "&site=" + Configuration.site_name; 1064 } 991 1065 992 1066 URL download_url = new URL(download_cgi); … … 1042 1116 cgi_args += "&pw=" + new String(remote_greenstone_server_authentication.getPassword()); 1043 1117 cgi_args += "&ts=" + System.currentTimeMillis(); 1118 if (Gatherer.GS3){ 1119 cgi_args += "&site=" + Configuration.site_name; 1120 } 1044 1121 1045 1122 URL gliserver_url = new URL(gliserver_url_string + "?" + cgi_args); … … 1071 1148 throws Exception 1072 1149 { 1073 DebugStream.println("gliserver URL: " + upload_cgi); 1150 //For a remote GS3 1151 //GS3 is running on Tomcat, and Tomcat requires a connection timeout to be set up at the client 1152 //side while uploading files. As HttpURLConection couldn't set the connection timeout, HttpClient.jar 1153 //from Jakarta is applied to solve this problem only for uploading files. 1154 if (Gatherer.GS3){ 1155 System.err.println("gliserver URL: " + upload_cgi); 1156 System.err.println("gliserver args: " + cgi_args); 1157 1158 // Setup the POST method 1159 PostMethod httppost = new PostMethod(upload_cgi+"?"+cgi_args); 1160 1161 //read the zip file into a byte array 1162 InputStream in = new FileInputStream (file_path); 1163 File f = new File (file_path); // in order to get the length of the bytes array 1164 ByteArrayOutputStream out = new ByteArrayOutputStream ((int)f.length()); 1165 int r = 0; // amount read 1166 byte[] buf = new byte[1024]; 1167 while((r = in.read(buf, 0, buf.length)) != -1) { 1168 out.write(buf, 0, r); 1169 } 1170 in.close(); 1171 byte[] result = out.toByteArray(); 1172 1173 // construct the multipartrequest form 1174 PartSource partSource = new ByteArrayPartSource("zipFile", result); 1175 FilePart filePart = new FilePart("uploaded_file", partSource); 1176 1177 String[] cgi_array=cgi_args.split("&");// get parameter-value paires from cgi_args string 1178 Part[] parts=new Part[cgi_array.length+5]; 1179 parts[0]=filePart; 1180 parts[1]= new StringPart("un", remote_greenstone_server_authentication.getUserName()); 1181 parts[2]= new StringPart("pw", new String(remote_greenstone_server_authentication.getPassword())); 1182 parts[3]= new StringPart("ts", String.valueOf(System.currentTimeMillis())); 1183 parts[4]= new StringPart("site", Configuration.site_name); 1184 // find all parameters of cgi-agrs and add them into Part[] 1185 for (int i=0; i<cgi_array.length;i++){ 1186 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())); 1187 } 1188 // set MutilartRequestEntity on the POST method 1189 httppost.setRequestEntity(new MultipartRequestEntity(parts, httppost.getParams())); 1190 //set up the HttpClient connection 1191 HttpClient client=new HttpClient(); 1192 client.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, false); 1193 client.getParams().setConnectionManagerTimeout(200000); //set the connection timeout 1194 // get the output of the command from the server 1195 client.executeMethod(httppost); 1196 String command_output = ""; 1197 try{ 1198 client.executeMethod(httppost); 1199 if (httppost.getStatusCode() == HttpStatus.SC_OK) { 1200 command_output = httppost.getStatusLine().toString(); 1201 } else { 1202 command_output = httppost.getStatusLine().toString(); 1203 System.out.println("Unexpected failure: " + httppost.getStatusLine().toString()); 1204 } 1205 }catch(IOException e){ 1206 e.printStackTrace(); 1207 }finally{ 1208 httppost.releaseConnection(); 1209 } 1210 return command_output; 1211 } 1212 1213 //For a remote GS2 1214 System.err.println("gliserver URL: " + upload_cgi); 1074 1215 System.err.println("gliserver args: " + cgi_args); 1075 1076 1216 // Add username and password, and a timestamp 1077 1217 cgi_args += "&un=" + remote_greenstone_server_authentication.getUserName();
Note:
See TracChangeset
for help on using the changeset viewer.