You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2010/06/30 23:40:23 UTC
svn commit: r959446 - in /harmony/enhanced/java/trunk/classlib/modules/luni:
./ src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/
src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/
Author: hindessm
Date: Wed Jun 30 21:40:23 2010
New Revision: 959446
URL: http://svn.apache.org/viewvc?rev=959446&view=rev
Log:
Applying modified version of the most recent patch from "[#HARMONY-6561]
[classlib][luni]HttpConnection should not throw a IOException if the
server return 401 but does not provide a WWW-Authenticate header".
I moved the additional jetty classpath entries from the top-level build file
to the luni module which needs them.
Modified:
harmony/enhanced/java/trunk/classlib/modules/luni/build.xml
harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
Modified: harmony/enhanced/java/trunk/classlib/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/build.xml?rev=959446&r1=959445&r2=959446&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/build.xml (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/build.xml Wed Jun 30 21:40:23 2010
@@ -315,6 +315,9 @@
<pathelement location="src/test/api/${hy.os.family}" />
</src>
<include name="**/*.java" />
+ <classpath location="${hy.hdk}/build/test/jetty-6.0.0.jar" />
+ <classpath location="${hy.hdk}/build/test/jetty-util-6.0.0.jar" />
+ <classpath location="${hy.hdk}/build/test/servlet-api-2.5-6.0.0.jar" />
</javac-elements>
</compile-tests>
<compile-tests description="${hy.module} impl tests"
Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java?rev=959446&r1=959445&r2=959446&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java Wed Jun 30 21:40:23 2010
@@ -1414,8 +1414,7 @@ public class HttpURLConnectionImpl exten
// keep asking for username/password until authorized
String challenge = resHeader.get("WWW-Authenticate"); //$NON-NLS-1$
if (challenge == null) {
- // luni.2E=Received authentication challenge is null
- throw new IOException(Messages.getString("luni.2E")); //$NON-NLS-1$
+ break;
}
// drop everything and reconnect, might not be required for
// HTTP/1.1
Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java?rev=959446&r1=959445&r2=959446&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java Wed Jun 30 21:40:23 2010
@@ -37,6 +37,15 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.mortbay.jetty.HttpConnection;
+import org.mortbay.jetty.Request;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.handler.DefaultHandler;
+
import tests.support.Support_Jetty;
import junit.framework.TestCase;
@@ -265,6 +274,120 @@ public class HttpURLConnectionTest exten
}
}
+ public static class ResponseServer {
+ private Server server = null;
+
+ private int port = -1;
+
+ public class MyRealmHandler extends DefaultHandler {
+ public void handle(String target, HttpServletRequest request,
+ HttpServletResponse response, int dispatch)
+ throws IOException, ServletException {
+ boolean auth = request.getHeader("Authorization") != null;
+ String resLoc = request.getPathInfo();
+ boolean noRealm = "/norealm".equals(resLoc);
+
+ Request base_request = (request instanceof Request) ? (Request) request
+ : HttpConnection.getCurrentConnection().getRequest();
+ base_request.setHandled(true);
+ response.setContentType("text/html");
+ response.addDateHeader("Date", System.currentTimeMillis());
+ if (noRealm) {
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.getWriter().print("<h1>No WWW-Authenticate</h1>");
+ } else {
+ if (auth) {
+ response.setStatus(HttpServletResponse.SC_OK);
+ } else {
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.addHeader("WWW-Authenticate",
+ "Basic realm=\"HelloWorld\"");
+ }
+ }
+ }
+ }
+
+ public void startServer(DefaultHandler handler) throws Exception {
+ server = new Server(0);
+ server.setHandler(handler);
+ server.start();
+ port = server.getConnectors()[0].getLocalPort();
+ }
+
+ public void stopServer() throws Exception {
+ if (server != null) {
+ server.stop();
+ server = null;
+ }
+ }
+
+ public int getPort() {
+ return port;
+ }
+ }
+
+ /**
+ * Test response code which need authenticate
+ */
+ public void testGetResponseCode() throws Exception {
+ ResponseServer server = new ResponseServer();
+ HttpURLConnection conn = null;
+ try {
+ server.startServer(server.new MyRealmHandler());
+ int port = server.getPort();
+ try {
+ conn = (HttpURLConnection) new URL("http://localhost:" + port
+ + "/norealm").openConnection();
+ assertEquals(401, conn.getResponseCode());
+ } finally {
+ if (conn != null) {
+ try {
+ conn.disconnect();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ try {
+ conn = (HttpURLConnection) new URL("http://localhost:" + port
+ + "/realm").openConnection();
+ assertEquals(401, conn.getResponseCode());
+ assertEquals("Basic realm=\"HelloWorld\"", conn
+ .getHeaderField("WWW-Authenticate"));
+ } finally {
+ if (conn != null) {
+ try {
+ conn.disconnect();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ try {
+ Authenticator.setDefault(new Authenticator() {
+ public PasswordAuthentication getPasswordAuthentication() {
+ return new PasswordAuthentication("test", "password"
+ .toCharArray());
+ }
+ });
+ server.startServer(server.new MyRealmHandler());
+ conn = (HttpURLConnection) new URL("http://localhost:" + port
+ + "/realm").openConnection();
+ assertEquals(200, conn.getResponseCode());
+ assertNull(conn.getHeaderField("WWW-Authenticate"));
+ } finally {
+ if (conn != null) {
+ try {
+ conn.disconnect();
+ } catch (Exception e) {
+ }
+ }
+ }
+ } finally {
+ server.stopServer();
+ }
+ }
+
/**
* ProxySelector implementation used in the test.
*/
@@ -981,4 +1104,4 @@ public class HttpURLConnectionTest exten
}
-}
\ No newline at end of file
+}