oodt-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mattmann, Chris A (388J)" <chris.a.mattm...@jpl.nasa.gov>
Subject Re: svn commit: r1131269 - in /oodt/branches/protocol/protocol-http/src: main/java/org/apache/oodt/cas/protocol/http/ test/org/apache/oodt/cas/protocol/http/ test/org/apache/oodt/cas/protocol/http/util/
Date Fri, 03 Jun 2011 22:40:03 GMT
you rock!

On Jun 3, 2011, at 3:28 PM, <bfoster@apache.org> <bfoster@apache.org> wrote:

> Author: bfoster
> Date: Fri Jun  3 22:28:12 2011
> New Revision: 1131269
> 
> URL: http://svn.apache.org/viewvc?rev=1131269&view=rev
> Log:
> 
> - formatting
> - unit-tests improved
> - bug fixes exposed by unit-tests
> 
> --------------------
> OODT-194
> 
> Modified:
>   oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
>   oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
>   oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java
>   oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
>   oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
> 
> Modified: oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
> URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java?rev=1131269&r1=1131268&r2=1131269&view=diff
> ==============================================================================
> --- oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
(original)
> +++ oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java
Fri Jun  3 22:28:12 2011
> @@ -31,23 +31,23 @@ import java.net.URL;
> */
> public class HttpFile extends ProtocolFile {
> 
> -    private static final long serialVersionUID = -7780059889413081800L;
> +	private static final long serialVersionUID = -7780059889413081800L;
> 
> -    private URL link;
> -    private HttpFile parent;
> +	private URL link;
> +	private HttpFile parent;
> 
> -    public HttpFile(String virtualPath, boolean isDir, URL link, HttpFile parent) {
> -        super(virtualPath, isDir);
> -        Validate.notNull(link, "URL link must not be NULL");
> -        this.link = link;
> -        this.parent = parent;
> -    }
> +	public HttpFile(String virtualPath, boolean isDir, URL link, HttpFile parent) {
> +		super(virtualPath, isDir);
> +		Validate.notNull(link, "URL link must not be NULL");
> +		this.link = link;
> +		this.parent = parent;
> +	}
> 
> -    public URL getLink() {
> -        return this.link;
> -    }
> +	public URL getLink() {
> +		return this.link;
> +	}
> 
> -    public ProtocolFile getParent() {
> -        return this.parent;
> -    }
> +	public ProtocolFile getParent() {
> +		return this.parent;
> +	}
> }
> 
> Modified: oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
> URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java?rev=1131269&r1=1131268&r2=1131269&view=diff
> ==============================================================================
> --- oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
(original)
> +++ oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java
Fri Jun  3 22:28:12 2011
> @@ -30,7 +30,6 @@ import java.io.FileOutputStream;
> import java.io.InputStream;
> import java.io.OutputStream;
> import java.net.HttpURLConnection;
> -import java.net.URI;
> import java.net.URL;
> import java.util.ArrayList;
> import java.util.HashMap;
> @@ -54,7 +53,6 @@ public class HttpProtocol implements Pro
>  private HttpFile parentFile;
>  private HttpFile currentFile;
>  private boolean isConnected;
> -  private URL currentURL;
> 
>  public HttpProtocol() {
>    isConnected = false;
> @@ -64,7 +62,7 @@ public class HttpProtocol implements Pro
>    try {
>    	HttpFile httpFile = null;
>    	if (!(file instanceof HttpFile)) {
> -    		URL link = HttpUtils.resolveUri(currentURL.toURI(), file.getPath()).toURL();
> +    		URL link = HttpUtils.resolveUri(currentFile.getLink().toURI(), file.getPath()).toURL();
>  			httpFile = new HttpFile(file.getPath(), file.isDir(), link, null);
>      } else {
>        httpFile = (HttpFile) file;
> @@ -84,9 +82,9 @@ public class HttpProtocol implements Pro
>  public void connect(String host, Authentication auth)
>      throws ProtocolException {
>    try {
> -      currentURL = new URL("http://" + host + "/");
> -      currentURL.openStream().close();
> -      currentFile = parentFile = new HttpFile("/", true, currentURL, null);
> +      URL url = new URL("http://" + host + "/");
> +      url.openStream().close();
> +      currentFile = parentFile = new HttpFile("/", true, url, null);
>      isConnected = true;
>    } catch (Exception e) {
>      throw new ProtocolException("Failed to connect to http://" + host + " : "
> @@ -108,7 +106,7 @@ public class HttpProtocol implements Pro
>      if (fromFile instanceof HttpFile) {
>    	  in = ((HttpFile) fromFile).getLink().openStream();
>      } else {
> -    	  in = currentURL.toURI().relativize(new URI(fromFile.getPath())).toURL().openStream();
> +    	  in = HttpUtils.resolveUri(currentFile.getLink().toURI(), fromFile.getPath()).toURL().openStream();
>      }
> 
>      byte[] buffer = new byte[1024];
> 
> Modified: oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java
> URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java?rev=1131269&r1=1131268&r2=1131269&view=diff
> ==============================================================================
> --- oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java
(original)
> +++ oodt/branches/protocol/protocol-http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java
Fri Jun  3 22:28:12 2011
> @@ -16,10 +16,6 @@
> */
> package org.apache.oodt.cas.protocol.http;
> 
> -//JDK imports
> -import java.util.logging.Level;
> -import java.util.logging.Logger;
> -
> //OODT imports
> import org.apache.oodt.cas.protocol.ProtocolFactory;
> 
> @@ -31,16 +27,9 @@ import org.apache.oodt.cas.protocol.Prot
> */
> public class HttpProtocolFactory implements ProtocolFactory {
> 
> -	private static final Logger LOG = Logger.getLogger(HttpProtocolFactory.class.getName());
> -	
> -    public HttpProtocol newInstance() {
> -        try {
> -            return new HttpProtocol();
> -        } catch (Exception e) {
> -        	LOG.log(Level.SEVERE, "Failed to create HttpProtocol : " + e.getMessage(),
e);
> -            return null;
> -        }
> -    }
> +	public HttpProtocol newInstance() {
> +		return new HttpProtocol();
> +	}
> 
> 	public String getSchema() {
> 		return "http";
> 
> Modified: oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
> URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java?rev=1131269&r1=1131268&r2=1131269&view=diff
> ==============================================================================
> --- oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
(original)
> +++ oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java
Fri Jun  3 22:28:12 2011
> @@ -17,11 +17,17 @@
> package org.apache.oodt.cas.protocol.http;
> 
> //JUnit imports
> +import java.io.File;
> +import java.io.IOException;
> +import java.net.URL;
> import java.util.List;
> +import java.util.Scanner;
> 
> +import org.apache.commons.io.FileUtils;
> import org.apache.oodt.cas.protocol.ProtocolFile;
> import org.apache.oodt.cas.protocol.auth.NoAuthentication;
> import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
> +import org.apache.oodt.cas.protocol.http.util.HttpUtils;
> 
> import junit.framework.TestCase;
> 
> @@ -31,7 +37,7 @@ import junit.framework.TestCase;
> * @author bfoster
> */
> public class TestHttpProtocol extends TestCase {
> -
> +	
> 	public void testConnection() throws InstantiationException, ProtocolException {
> 		HttpProtocol httpProtocol = new HttpProtocol();
> 		assertFalse(httpProtocol.connected());
> @@ -39,7 +45,7 @@ public class TestHttpProtocol extends Te
> 		assertTrue(httpProtocol.connected());
> 	}
> 	
> -	public void testLS() throws ProtocolException, InstantiationException {
> +	public void testLSandCD() throws ProtocolException, InstantiationException {
> 		HttpProtocol httpProtocol = new HttpProtocol();
> 		httpProtocol.connect("svn.apache.org", new NoAuthentication());
> 		assertTrue(httpProtocol.connected());
> @@ -54,4 +60,37 @@ public class TestHttpProtocol extends Te
> 		}
> 		assertTrue(foundFile);
> 	}
> +	
> +	public void testPWD() throws ProtocolException {
> +		HttpProtocol httpProtocol = new HttpProtocol();
> +		httpProtocol.connect("svn.apache.org", new NoAuthentication());
> +		assertTrue(httpProtocol.connected());
> +		ProtocolFile gotoDir = new ProtocolFile("repos/asf/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http",
true);
> +		httpProtocol.cd(gotoDir);
> +		ProtocolFile currentDir = httpProtocol.pwd();
> +		assertEquals(gotoDir, currentDir);
> +	}
> +	
> +	public void testGET() throws ProtocolException, IOException {
> +		HttpProtocol httpProtocol = new HttpProtocol();
> +		httpProtocol.connect("svn.apache.org", new NoAuthentication());
> +		assertTrue(httpProtocol.connected());
> +		httpProtocol.cd(new ProtocolFile("repos/asf/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http",
true));
> +		File bogus = File.createTempFile("bogus", "bogus");
> +		File tmpDir = new File(bogus.getParentFile(), "TestHttpProtocol");
> +		bogus.delete();
> +		tmpDir.mkdirs();
> +		File toFile = new File(tmpDir, "TestHttpProtocol.java");
> +		httpProtocol.get(new ProtocolFile("TestHttpProtocol.java", false), toFile);
> +		assertTrue(toFile.exists());
> +		assertNotSame(0, toFile.length());
> +		
> +		String fileContent = "";
> +		Scanner scanner = new Scanner(toFile);
> +		while(scanner.hasNextLine()) {
> +			fileContent += scanner.nextLine();
> +		}
> +		assertEquals(fileContent, HttpUtils.readUrl(HttpUtils.connect(new URL("http://svn.apache.org/repos/asf/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java"))));
> +		FileUtils.forceDelete(tmpDir);
> +	}
> }
> 
> Modified: oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
> URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java?rev=1131269&r1=1131268&r2=1131269&view=diff
> ==============================================================================
> --- oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
(original)
> +++ oodt/branches/protocol/protocol-http/src/test/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java
Fri Jun  3 22:28:12 2011
> @@ -153,7 +153,6 @@ public class TestHttpUtils extends TestC
> 		URL url = new URL(APACHE_SVN_SITE + PARENT_URL_OF_THIS_TEST);
> 		HttpFile parent = new HttpFile(PARENT_URL_OF_THIS_TEST, true, url, null);
> 		HttpURLConnection conn = HttpUtils.connect(url);
> -		System.out.println(HttpUtils.readUrl(conn));
> 		List<HttpFile> httpFiles = HttpUtils.findLinks(parent);
> 		boolean foundThisTest = false;
> 		for (HttpFile httpFile : httpFiles) {
> 
> 


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chris Mattmann, Ph.D.
Senior Computer Scientist
NASA Jet Propulsion Laboratory Pasadena, CA 91109 USA
Office: 171-266B, Mailstop: 171-246
Email: chris.a.mattmann@nasa.gov
WWW:   http://sunset.usc.edu/~mattmann/
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adjunct Assistant Professor, Computer Science Department
University of Southern California, Los Angeles, CA 90089 USA
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Mime
View raw message