[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book/install/sword s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Thu Aug 18 13:58:49 MST 2005


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword
In directory www.crosswire.org:/tmp/cvs-serv16341/java/jsword/org/crosswire/jsword/book/install/sword

Modified Files:
	HttpSwordInstaller.java 
Log Message:
Working on getting download to work with a proxy server.
Upgrading commons-net from 1.3 to 1.4.

Index: HttpSwordInstaller.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/install/sword/HttpSwordInstaller.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** HttpSwordInstaller.java	27 Jul 2005 23:25:45 -0000	1.25
--- HttpSwordInstaller.java	18 Aug 2005 20:58:47 -0000	1.26
***************
*** 27,32 ****
  import java.net.MalformedURLException;
  import java.net.URL;
- import java.net.URLConnection;
  
  import org.crosswire.common.progress.Job;
  import org.crosswire.common.util.IOUtil;
--- 27,37 ----
  import java.net.MalformedURLException;
  import java.net.URL;
  
+ import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+ import org.apache.commons.httpclient.HttpClient;
+ import org.apache.commons.httpclient.HttpException;
+ import org.apache.commons.httpclient.HttpStatus;
+ import org.apache.commons.httpclient.methods.GetMethod;
+ import org.apache.commons.httpclient.params.HttpMethodParams;
  import org.crosswire.common.progress.Job;
  import org.crosswire.common.util.IOUtil;
***************
*** 42,45 ****
--- 47,51 ----
   * @author Mark Goodwin [goodwinster at gmail dot com]
   * @author Joe Walker [joe at eireneh dot com]
+  * @author DM Smith [dmsmith555 at yahoo dot com]
   */
  public class HttpSwordInstaller extends AbstractSwordInstaller implements Comparable
***************
*** 95,98 ****
--- 101,114 ----
          OutputStream out = null;
  
+         // Create an instance of HttpClient.
+         HttpClient client = new HttpClient();
+ 
+         // Create a method instance.
+         GetMethod method = new GetMethod(url.toExternalForm());
+         
+         // Provide custom retry handler is necessary
+         method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
+                 new DefaultHttpMethodRetryHandler(3, false));
+ 
          try
          {
***************
*** 102,112 ****
              }
  
!             // Download the index file
!             out = NetUtil.getOutputStream(dest);
  
-             URLConnection urlConnection = url.openConnection();
              try
              {
!                 in = urlConnection.getInputStream();
              }
              catch (Exception exception)
--- 118,132 ----
              }
  
!             // Execute the method.
!             int statusCode = client.executeMethod(method);
! 
!             if (statusCode != HttpStatus.SC_OK)
!             {
!                 throw new InstallException(Msg.MISSING_FILE, new Object [] { method.getStatusLine().toString() });
!             }
  
              try
              {
!                 in = method.getResponseBodyAsStream();
              }
              catch (Exception exception)
***************
*** 115,129 ****
              }
  
              byte[] buf = new byte[4096];
!             for (int count = 0; -1 != (count = in.read(buf)); )
              {
                  out.write(buf, 0, count);
              }
          }
          finally
          {
              IOUtil.close(in);
              IOUtil.close(out);
!         }
      }
  
--- 135,159 ----
              }
  
+             // Download the index file
+             out = NetUtil.getOutputStream(dest);
+ 
              byte[] buf = new byte[4096];
!             for (int count = 0; -1 != (count = in.read(buf));)
              {
                  out.write(buf, 0, count);
              }
          }
+         catch (HttpException e)
+         {
+             throw new InstallException(Msg.MISSING_FILE, e);
+         }
          finally
          {
+             // Release the connection.
+             method.releaseConnection();
+             // Close the streams
              IOUtil.close(in);
              IOUtil.close(out);
!         }  
      }
  



More information about the jsword-svn mailing list