You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by jb...@apache.org on 2007/04/16 10:49:55 UTC

svn commit: r529171 - in /incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src: main/java/org/apache/wicket/request/target/resource/ main/java/org/apache/wicket/util/resource/ test/java/org/apache/wicket/protocol/http/

Author: jbq
Date: Mon Apr 16 01:49:54 2007
New Revision: 529171

URL: http://svn.apache.org/viewvc?view=rev&rev=529171
Log:
WICKET-473 Allow IResourceStream.length() to return -1

Modified:
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestTarget.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/IResourceStream.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/WebExternalResourceStream.java
    incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestTarget.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestTarget.java?view=diff&rev=529171&r1=529170&r2=529171
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestTarget.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/request/target/resource/ResourceStreamRequestTarget.java Mon Apr 16 01:49:54 2007
@@ -178,8 +178,12 @@
 				response.detectContentType(requestCycle, requestCycle.getRequest().getRelativeURL());
 		}
 
-		// and the content length
-		response.setContentLength((int)resourceStream.length());
+		// WICKET-473 Allow IResourceStream.length() to return -1
+		if (resourceStream.length() >= 0)
+		{
+			// and the content length
+			response.setContentLength(resourceStream.length());
+		}
 
 		// and content disposition if any
 		String file = getFileName();

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/IResourceStream.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/IResourceStream.java?view=diff&rev=529171&r1=529170&r2=529171
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/IResourceStream.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/IResourceStream.java Mon Apr 16 01:49:54 2007
@@ -57,7 +57,7 @@
 	/**
 	 * Gets the size of this resource
 	 * 
-	 * @return The size of this resource in the number of bytes
+	 * @return The size of this resource in the number of bytes, or -1 if unknown
 	 */
 	long length();
 

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/WebExternalResourceStream.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/WebExternalResourceStream.java?view=diff&rev=529171&r1=529170&r2=529171
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/WebExternalResourceStream.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/WebExternalResourceStream.java Mon Apr 16 01:49:54 2007
@@ -70,7 +70,7 @@
 	 */
 	public long length()
 	{
-		throw new WicketRuntimeException("Not implemented");
+		return -1;
 	}
 
 	public void close() throws IOException

Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java?view=diff&rev=529171&r1=529170&r2=529171
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java Mon Apr 16 01:49:54 2007
@@ -56,20 +56,23 @@
 		cycle.setRequestTarget(rt);
 		tester.processRequestCycle(cycle);
 		assertTrue(getContentType().startsWith("text/html"));
-		// FIXME WebExternalResourceRequestTarget does not set Content-Length
+		// WebExternalResourceRequestTarget does not set Content-Length
 		// assertEquals(23, getContentLength());
 	}
 
 	// FIXME WebExternalResourceStream does not implement length()
-	public void bugTestWebExternalResource() throws Exception
+	public void testWebExternalResource() throws Exception
 	{
 		WebExternalResourceStream resource = new WebExternalResourceStream("/index.html");
 		ResourceStreamRequestTarget rt = new ResourceStreamRequestTarget(resource);
 		tester.setupRequestAndResponse();
+		// We fake the browser URL, otherwise Wicket doesn't know the requested URL and cannot guess the Content-Type
+		tester.getServletRequest().setPath("/index.html");
 		WebRequestCycle cycle = tester.createRequestCycle();
 		cycle.setRequestTarget(rt);
 		tester.processRequestCycle(cycle);
 		assertTrue(getContentType().startsWith("text/html"));
-		assertEquals(23, getContentLength());
+		// WebExternalResourceStream does not set Content-Length
+		// assertEquals(23, getContentLength());
 	}
 }