You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/03/29 08:42:45 UTC
svn commit: r523585 - in /harmony/enhanced/classlib/trunk:
modules/luni/make/ modules/luni/src/test/java/tests/api/java/net/
support/src/test/java/tests/support/ support/src/test/resources/config/
Author: pyang
Date: Wed Mar 28 23:42:44 2007
New Revision: 523585
URL: http://svn.apache.org/viewvc?view=rev&rev=523585
Log:
Apply patch for HARMONY-3434([classlib][luni]move out tests/api/java/net/URLConnectionTest.java)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java
harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java
harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpTests.java
harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
harmony/enhanced/classlib/trunk/support/src/test/resources/config/localhosttest.ini
Modified: harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/make/exclude.common Wed Mar 28 23:42:44 2007
@@ -1,4 +1,3 @@
tests/api/java/net/URLClassLoaderTest.java
-tests/api/java/net/URLConnectionTest.java
tests/api/java/net/URLTest.java
tests/api/java/net/ExcludedProxyTest.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java Wed Mar 28 23:42:44 2007
@@ -46,6 +46,7 @@
import tests.support.Support_HttpServer;
import tests.support.Support_HttpServerSocket;
import tests.support.Support_HttpTests;
+import tests.support.Support_Jetty;
import tests.support.Support_PortManager;
import tests.support.Support_URLConnector;
import tests.support.resource.Support_Resources;
@@ -56,6 +57,17 @@
URLConnection uc;
+ private static int port;
+
+ static {
+ // run-once set up
+ try {
+ port = Support_Jetty.startDefaultHttpServer();
+ } catch (Exception e) {
+ fail("Exception during setup jetty : " + e.getMessage());
+ }
+ }
+
/**
* @tests java.net.URLConnection#getAllowUserInteraction()
*/
@@ -71,15 +83,11 @@
/**
* @tests java.net.URLConnection#getContent()
*/
- public void test_getContent() {
- try {
- byte[] ba = new byte[600];
- ((InputStream) uc.getContent()).read(ba, 0, 600);
- String s = new String(ba);
- assertTrue("Incorrect content returned", s.indexOf("20060107") > 0);
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
+ public void test_getContent() throws IOException {
+ byte[] ba = new byte[600];
+ ((InputStream) uc.getContent()).read(ba, 0, 600);
+ String s = new String(ba);
+ assertTrue("Incorrect content returned", s.indexOf("Hello OneHandler") > 0);
}
/**
@@ -94,9 +102,9 @@
/**
* @tests java.net.URLConnection#getContentLength()
*/
- public void test_getContentLength() {
- assertTrue("getContentLength failed: " + uc.getContentLength(), uc
- .getContentLength() == 943);
+ public void test_getContentLength() throws IOException {
+ assertEquals("getContentLength failed: " + uc.getContentLength(),25, uc
+ .getContentLength());
}
/**
@@ -105,7 +113,7 @@
public void test_getContentType() {
// should not be known for a file
assertTrue("getContentType failed: " + uc.getContentType(), uc
- .getContentType().equals("text/html"));
+ .getContentType().contains("text/html"));
try {
File resources = Support_Resources.createTempFolder();
@@ -229,14 +237,14 @@
FileNameMap map = URLConnection.getFileNameMap();
// These types are defaulted
- assertEquals("text/html", map.getContentTypeFor("htm"));
- assertEquals("text/html", map.getContentTypeFor("html"));
- assertEquals("text/plain", map.getContentTypeFor("text"));
- assertEquals("text/plain", map.getContentTypeFor("txt"));
+ assertEquals("text/html", map.getContentTypeFor(".htm"));
+ assertEquals("text/html", map.getContentTypeFor(".html"));
+ assertEquals("text/plain", map.getContentTypeFor(".text"));
+ assertEquals("text/plain", map.getContentTypeFor(".txt"));
// These types come from the properties file
- assertEquals("application/pdf", map.getContentTypeFor("pdf"));
- assertEquals("application/zip", map.getContentTypeFor("zip"));
+ assertEquals("application/pdf", map.getContentTypeFor(".pdf"));
+ assertEquals("application/zip", map.getContentTypeFor(".zip"));
URLConnection.setFileNameMap(new FileNameMap() {
public String getContentTypeFor(String fileName) {
@@ -250,6 +258,9 @@
// unset the map so other tests don't fail
URLConnection.setFileNameMap(null);
}
+ // RI fails since it does not support fileName that does not begin with
+ // '.'
+ assertEquals("image/gif", map.getContentTypeFor("gif"));
}
/**
@@ -426,19 +437,19 @@
}
hf = uc.getHeaderField("Content-Length");
if (hf != null) {
- assertTrue(
- "Wrong value returned for header field 'Content-Length': "
- + hf, hf.equals("943"));
- }
+ assertEquals(
+ "Wrong value returned for header field 'Content-Length': ",
+ "25", hf);
+ }
hf = uc.getHeaderField("Content-Type");
if (hf != null) {
assertTrue("Wrong value returned for header field 'Content-Type': "
- + hf, hf.equals("text/html"));
+ + hf, hf.contains("text/html"));
}
hf = uc.getHeaderField("content-type");
if (hf != null) {
assertTrue("Wrong value returned for header field 'content-type': "
- + hf, hf.equals("text/html"));
+ + hf, hf.contains("text/html"));
}
hf = uc.getHeaderField("Date");
if (hf != null) {
@@ -493,17 +504,8 @@
+ uc.getHeaderFieldDate("Date", 22L), uc.getHeaderFieldDate(
"Date", 22L) > 930000000000L);
- try {
- URL url = new URL(Support_Resources.getResourceURL("/RESOURCE.TXT"));
- URLConnection connection = url.openConnection();
- long time = connection.getHeaderFieldDate("Last-Modified", 0);
- assertTrue("Wrong date: " + time,
- time == Support_Configuration.URLConnectionDate);
- } catch (MalformedURLException e) {
- fail("MalformedURLException : " + e.getMessage());
- } catch (IOException e) {
- fail("IOException : " + e.getMessage());
- }
+ long time = uc.getHeaderFieldDate("Last-Modified", 0);
+ assertEquals("Wrong date: ", time , Support_Configuration.URLConnectionLastModified);
}
/**
@@ -534,38 +536,20 @@
/**
* @tests java.net.URLConnection#getInputStream()
*/
- public void test_getInputStream() {
- try {
- InputStream is = uc.getInputStream();
- byte[] ba = new byte[600];
- is.read(ba, 0, 600);
- is.close();
- String s = new String(ba);
- assertTrue("Incorrect input stream read", s.indexOf("20060107") > 0);
-
- boolean exception = false;
- try {
- is.available();
- } catch (IOException e) {
- exception = true;
- }
- assertTrue("available() after close() should cause IOException",
- exception);
- } catch (Exception e) {
- fail("Exception during test1 : " + e.getMessage());
- }
-
- try {
- // open an non-existent file
- URL url = new URL(Support_Resources.getResourceURL("/fred-zz6.txt"));
- InputStream is = url.openStream();
- assertTrue("available() less than 0", is.available() >= 0);
- is.close();
- fail("Error: data returned on opening a non-existent file.");
- } catch (FileNotFoundException e) {
- } catch (Exception e) {
- fail("Exception during test2: " + e);
- }
+ public void test_getInputStream() throws IOException {
+ InputStream is = uc.getInputStream();
+ byte[] ba = new byte[600];
+ is.read(ba, 0, 600);
+ is.close();
+ String s = new String(ba);
+ assertTrue("Incorrect input stream read",
+ s.indexOf("Hello OneHandler") > 0);
+
+ // open an non-existent file
+ URL url = new URL("http://localhost:" + port + "/fred-zz6.txt");
+ is = url.openStream();
+ assertTrue("available() less than 0", is.available() >= 0);
+ is.close();
// create a serversocket
Support_HttpServerSocket serversocket = new Support_HttpServerSocket();
@@ -594,7 +578,6 @@
final String authTestUrl = "http://localhost:" + server.getPort()
+ Support_HttpServer.AUTHTEST;
- InputStream is;
// Authentication test
try {
@@ -668,138 +651,107 @@
/**
* @tests java.net.URLConnection#getOutputStream()
*/
- public void test_getOutputStream() {
- boolean exception = false;
- URL test;
- java.net.URLConnection conn2 = null;
- try {
- test = new URL("http://" + Support_Configuration.HomeAddress
- + "/cgi-bin/test.pl");
- conn2 = (java.net.URLConnection) test.openConnection();
- } catch (IOException e) {
- fail("Unexpected I/O exception: " + e);
- }
-
- try {
- conn2.getOutputStream();
- } catch (java.net.ProtocolException e) {
- // correct
- exception = true;
- } catch (IOException e) {
- fail("Wrong kind of exception thrown : " + e);
- }
- assertTrue("Failed to throw ProtocolException", exception);
-
- try {
- conn2.setDoOutput(true);
- conn2.getOutputStream();
- conn2.connect();
- conn2.getOutputStream();
- } catch (IOException e) {
- fail("Unexpected IOException : " + e.getMessage());
- }
-
- exception = false;
- try {
- conn2.getInputStream();
- conn2.getOutputStream();
- } catch (ProtocolException e) {
- exception = true;
- } catch (IOException e) {
- e.printStackTrace();
- fail("Wrong exception thrown2: " + e);
- }
- assertTrue("Failed to throw ProtocolException2", exception);
-
- try {
- URL u = new URL("http://" + Support_Configuration.HomeAddress
- + "/cgi-bin/test.pl");
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- OutputStream out = conn.getOutputStream();
- String posted = "this is a test";
- out.write(posted.getBytes());
- out.close();
- conn.getResponseCode();
- InputStream is = conn.getInputStream();
- String response = "";
- byte[] b = new byte[1024];
- int count = 0;
- while ((count = is.read(b)) > 0)
- response += new String(b, 0, count);
- assertTrue("Response to POST method invalid 1", response
- .equals(posted));
- } catch (Exception e) {
- fail("Unexpected exception 1 : " + e.getMessage());
- }
-
- try {
- String posted = "just a test";
- URL u = new URL("http://" + Support_Configuration.HomeAddress
- + "/cgi-bin/test.pl");
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length()));
- OutputStream out = conn.getOutputStream();
- out.write(posted.getBytes());
- out.close();
- conn.getResponseCode();
- InputStream is = conn.getInputStream();
- String response = "";
- byte[] b = new byte[1024];
- int count = 0;
- while ((count = is.read(b)) > 0)
- response += new String(b, 0, count);
- assertTrue("Response to POST method invalid 2", response
- .equals(posted));
- } catch (Exception e) {
- fail("Unexpected exception 2 : " + e.getMessage());
- }
-
- try {
- String posted = "just another test";
- URL u = new URL("http://" + Support_Configuration.HomeAddress
- + "/cgi-bin/test.pl");
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- conn.setRequestProperty("Content-length", String.valueOf(posted
- .length()));
- OutputStream out = conn.getOutputStream();
- out.write(posted.getBytes());
- // out.close();
- conn.getResponseCode();
- InputStream is = conn.getInputStream();
- String response = "";
- byte[] b = new byte[1024];
- int count = 0;
- while ((count = is.read(b)) > 0)
- response += new String(b, 0, count);
- assertTrue("Response to POST method invalid 3", response
- .equals(posted));
- } catch (Exception e) {
- fail("Unexpected exception 3 : " + e.getMessage());
- }
-
- try {
- URL u = new URL("http://" + Support_Configuration.HomeAddress
- + "/cgi-bin/test.pl");
- java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
- .openConnection();
- conn.setDoOutput(true);
- conn.setRequestMethod("POST");
- int result = conn.getResponseCode();
- assertTrue("Unexpected response code: " + result, result == 200);
- } catch (Exception e) {
- fail("Unexpected exception 4 : " + e.getMessage());
- }
-
+ public void test_getOutputStream() throws Exception {
+ int port = Support_Jetty.startDefaultServlet();
+ try {
+ boolean exception = false;
+ URL test;
+ java.net.URLConnection conn2 = null;
+
+ test = new URL("http://localhost:" + port + "/");
+ conn2 = (java.net.URLConnection) test.openConnection();
+
+ try {
+ conn2.getOutputStream();
+ fail("should throw ProtocolException");
+ } catch (java.net.ProtocolException e) {
+ // correct
+ }
+
+ conn2.setDoOutput(true);
+ conn2.getOutputStream();
+ conn2.connect();
+ conn2.getOutputStream();
+
+ try {
+ conn2.getInputStream();
+ conn2.getOutputStream();
+ fail("should throw ProtocolException");
+ } catch (ProtocolException e) {
+ // expected.
+ }
+
+ URL u = new URL("http://localhost:" + port + "/");
+ java.net.HttpURLConnection conn = (java.net.HttpURLConnection) u
+ .openConnection();
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ OutputStream out = conn.getOutputStream();
+ String posted = "this is a test";
+ out.write(posted.getBytes());
+ out.close();
+ conn.getResponseCode();
+ InputStream is = conn.getInputStream();
+ String response = "";
+ byte[] b = new byte[1024];
+ int count = 0;
+ while ((count = is.read(b)) > 0)
+ response += new String(b, 0, count);
+ assertEquals("Response to POST method invalid 1", posted, response);
+
+ posted = "just a test";
+ u = new URL("http://localhost:" + port + "/");
+ conn = (java.net.HttpURLConnection) u.openConnection();
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-length", String.valueOf(posted
+ .length()));
+ out = conn.getOutputStream();
+ out.write(posted.getBytes());
+ out.close();
+ conn.getResponseCode();
+ is = conn.getInputStream();
+ response = "";
+ b = new byte[1024];
+ count = 0;
+ while ((count = is.read(b)) > 0)
+ response += new String(b, 0, count);
+ assertTrue("Response to POST method invalid 2", response
+ .equals(posted));
+
+
+
+ posted = "just another test";
+ u = new URL("http://localhost:" + port + "/");
+ conn = (java.net.HttpURLConnection) u
+ .openConnection();
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-length", String.valueOf(posted
+ .length()));
+ out = conn.getOutputStream();
+ out.write(posted.getBytes());
+ // out.close();
+ conn.getResponseCode();
+ is = conn.getInputStream();
+ response = "";
+ b = new byte[1024];
+ count = 0;
+ while ((count = is.read(b)) > 0)
+ response += new String(b, 0, count);
+ assertTrue("Response to POST method invalid 3", response
+ .equals(posted));
+
+ u = new URL("http://localhost:" + port + "/");
+ conn = (java.net.HttpURLConnection) u.openConnection();
+ conn.setDoOutput(true);
+ conn.setRequestMethod("POST");
+ int result = conn.getResponseCode();
+ assertTrue("Unexpected response code: " + result, result == 200);
+
+ } finally {
+ Support_Jetty.startDefaultServlet();
+ }
}
/**
@@ -811,7 +763,7 @@
assertTrue("Permission of wrong type: " + p.toString(),
p instanceof java.net.SocketPermission);
assertTrue("Permission has wrong name: " + p.getName(), p.getName()
- .indexOf(Support_Configuration.HomeAddress + ":80") >= 0);
+ .contains("localhost:"+port));
URL fileUrl = new URL("file:myfile");
Permission perm = new FilePermission("myfile", "read");
@@ -825,8 +777,8 @@
assertTrue("Wrong file: permission 2:" + perm + " , " + result,
result.equals(perm));
- fileUrl = new URL("file://host/volume/file");
- perm = new FilePermission("//host/volume/file", "read");
+ fileUrl = new URL("file:///host/volume/file");
+ perm = new FilePermission("/host/volume/file", "read");
result = fileUrl.openConnection().getPermission();
assertTrue("Wrong file: permission 3:" + perm + " , " + result,
result.equals(perm));
@@ -909,20 +861,17 @@
/**
* @tests java.net.URLConnection#guessContentTypeFromStream(java.io.InputStream)
*/
- public void test_guessContentTypeFromStreamLjava_io_InputStream() {
- try {
- InputStream in = uc.getInputStream();
- byte[] bytes = new byte[in.available()];
- in.read(bytes, 0, bytes.length);
- in.close();
- assertEquals("Should have returned text/html",
- "text/html", URLConnection.guessContentTypeFromStream(
- new ByteArrayInputStream(bytes))
- );
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
+ public void test_guessContentTypeFromStreamLjava_io_InputStream() throws IOException {
+ InputStream in = uc.getInputStream();
+ byte[] bytes = new byte[in.available()];
+ in.read(bytes, 0, bytes.length);
+ in.close();
+ // RI fails and it's a non-bug difference.
+ assertEquals("Should have returned text/html", "text/html",
+ URLConnection
+ .guessContentTypeFromStream(new ByteArrayInputStream(
+ bytes)));
+ }
/**
* @tests java.net.URLConnection#setAllowUserInteraction(boolean)
@@ -999,23 +948,19 @@
/**
* @tests java.net.URLConnection#setIfModifiedSince(long)
*/
- public void test_setIfModifiedSinceJ() {
- try {
- URL url = new URL("http://localhost:8080/");
- URLConnection connection = url.openConnection();
- Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
- cal.clear();
- cal.set(2000, Calendar.MARCH, 5);
- connection.setIfModifiedSince(cal.getTime().getTime());
- assertEquals("Wrong date set", "Sun, 05 Mar 2000 00:00:00 GMT", connection.getRequestProperty(
- "If-Modified-Since")
- );
- } catch (MalformedURLException e) {
- fail("MalformedURLException : " + e.getMessage());
- } catch (IOException e) {
- fail("IOException : " + e.getMessage());
- }
- }
+ public void test_setIfModifiedSinceJ() throws IOException {
+ URL url = new URL("http://localhost:8080/");
+ URLConnection connection = url.openConnection();
+ Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
+ cal.clear();
+ cal.set(2000, Calendar.MARCH, 5);
+
+ long sinceTime = cal.getTime().getTime();
+ connection.setIfModifiedSince(sinceTime);
+ assertEquals("Wrong date set", sinceTime, connection
+ .getIfModifiedSince());
+
+ }
/**
* @tests java.net.URLConnection#setRequestProperty(java.lang.String,
@@ -1093,18 +1038,13 @@
*/
public void test_toString() {
assertTrue("Wrong toString: " + uc.toString(), uc.toString().indexOf(
- "URLConnectionTest/Harmony.html") > 0);
+ "URLConnection") > 0);
}
- protected void setUp() {
- try {
- url = new URL(Support_Resources
- .getResourceURL("/URLConnectionTest/Harmony.html"));
- uc = url.openConnection();
- } catch (Exception e) {
- fail("Exception during setup : " + e.getMessage());
- }
- }
+ protected void setUp() throws IOException {
+ url = new URL("http://localhost:" + port + "/");
+ uc = (HttpURLConnection) url.openConnection();
+ }
protected void tearDown() {
((HttpURLConnection) uc).disconnect();
Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Configuration.java Wed Mar 28 23:42:44 2007
@@ -44,7 +44,7 @@
public static String HomeAddressResponse = "HTTP/1.1 200 OK";
- public static String HomeAddressSoftware = "Apache/1.3.33 (Win32)";
+ public static String HomeAddressSoftware = "Jetty(6.0.x)";
public static String ProxyServerTestHost = "jcltest.apache.org";
Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpServer.java Wed Mar 28 23:42:44 2007
@@ -458,7 +458,6 @@
in.read();
in.read();
while (len > 0) {
- data.write('C');
for (int i = 0; i < len; i++) {
data.write(in.read());
}
Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpTests.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpTests.java?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpTests.java (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_HttpTests.java Wed Mar 28 23:42:44 2007
@@ -184,8 +184,7 @@
is.close();
connector.close();
String result = new String(bout.toByteArray(), "ISO8859_1");
- Assert.assertTrue("Error sending data 2: " + result, ("C" + toWrite)
- .equals(result));
+ Assert.assertEquals(toWrite, result);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception during test e: " + e);
@@ -335,7 +334,7 @@
connector.close();
c = is.read();
-
+
if (testCodes[i] == Support_HttpServer.NOT_MODIFIED) {
// accept either the message-body or nothing, since the spec
// says there MUST NOT be a message body on 304 responses.
Modified: harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/java/tests/support/Support_Jetty.java Wed Mar 28 23:42:44 2007
@@ -18,8 +18,10 @@
package tests.support;
import java.io.IOException;
+import java.io.InputStream;
import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -28,12 +30,18 @@
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
import org.mortbay.jetty.handler.ResourceHandler;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
public class Support_Jetty {
public static Server DEFAULT_SERVER = null;
public static int DEFAULT_PORT = 0;
+ public static Server DEFAULT_SERVLET = null;
+
+ public static int DEFAULT_SERVLET_PORT = 0;
+
public static Server SERVER = null;
public static int PORT = 0;
@@ -44,6 +52,7 @@
try {
stopDefaultServer();
stopServer();
+ stopDefaultServlet();
} catch (Exception e) {
e.printStackTrace();
}
@@ -51,6 +60,24 @@
});
}
+ public static class HYDefaultServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = -7650071946216123835L;
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ InputStream in = request.getInputStream();
+ int i;
+ StringBuilder s = new StringBuilder();
+ while((i = in.read())!=-1){
+ s.append((char)i);
+ }
+ response.setContentType("text/html");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().print(s);
+ }
+ }
+
public static class HYDefaultHandler extends AbstractHandler
{
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
@@ -58,8 +85,10 @@
Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
base_request.setHandled(true);
response.setContentType("text/html");
+ response.addDateHeader("Date", System.currentTimeMillis());
+ response.addDateHeader("Last-Modified", Support_Configuration.URLConnectionLastModified);
response.setStatus(HttpServletResponse.SC_OK);
- response.getWriter().println("<h1>Hello OneHandler</h1>");
+ response.getWriter().print("<h1>Hello OneHandler</h1>");
}
}
@@ -67,25 +96,39 @@
if (DEFAULT_SERVER != null){
return DEFAULT_PORT;
}
- DEFAULT_PORT = Support_PortManager.getNextPortForUDP();
- DEFAULT_SERVER = new Server(DEFAULT_PORT);
+ DEFAULT_SERVER = new Server(0);
DEFAULT_SERVER.setHandler(new HYDefaultHandler());
+ Context context = new Context(DEFAULT_SERVER,"/",Context.SESSIONS);
+ context.addServlet(new ServletHolder(new HYDefaultServlet()), "/servlet");
DEFAULT_SERVER.start();
+ DEFAULT_PORT = DEFAULT_SERVER.getConnectors()[0].getLocalPort();
return DEFAULT_PORT;
}
+ public static int startDefaultServlet() throws Exception{
+ if (DEFAULT_SERVLET != null){
+ return DEFAULT_SERVLET_PORT;
+ }
+ DEFAULT_SERVLET = new Server(0);
+ Context context = new Context(DEFAULT_SERVLET,"/",Context.SESSIONS);
+ context.addServlet(new ServletHolder(new HYDefaultServlet()), "/*");
+ DEFAULT_SERVLET.start();
+ DEFAULT_SERVLET_PORT = DEFAULT_SERVLET.getConnectors()[0].getLocalPort();
+ return DEFAULT_SERVLET_PORT;
+ }
+
public static int startHttpServerWithDocRoot(String root)
throws Exception {
if (SERVER != null) {
SERVER.stop();
SERVER = null;
}
- PORT = Support_PortManager.getNextPortForUDP();
- SERVER = new Server(PORT);
+ SERVER = new Server(0);
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setResourceBase(root);
SERVER.setHandler(resource_handler);
SERVER.start();
+ PORT = SERVER.getConnectors()[0].getLocalPort();
return PORT;
}
@@ -100,6 +143,13 @@
if (SERVER != null) {
SERVER.stop();
SERVER = null;
+ }
+ }
+
+ private static void stopDefaultServlet() throws Exception {
+ if (DEFAULT_SERVLET != null) {
+ DEFAULT_SERVLET.stop();
+ DEFAULT_SERVLET = null;
}
}
}
Modified: harmony/enhanced/classlib/trunk/support/src/test/resources/config/localhosttest.ini
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/support/src/test/resources/config/localhosttest.ini?view=diff&rev=523585&r1=523584&r2=523585
==============================================================================
--- harmony/enhanced/classlib/trunk/support/src/test/resources/config/localhosttest.ini (original)
+++ harmony/enhanced/classlib/trunk/support/src/test/resources/config/localhosttest.ini Wed Mar 28 23:42:44 2007
@@ -2,7 +2,7 @@
WebName=localhost.
TestResourcesDir=/testres231
HomeAddressResponse=HTTP/1.1 200 OK
-HomeAddressSoftware=Apache/2.0.55 (Win32)
+HomeAddressSoftware=Jetty(6.0.x)
ProxyServerTestHost=localhost
SocksServerTestHost=localhost
SocksServerTestPort=2080