harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r771717 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol: http/HttpURLConnectionTest.java https/HttpsURLConnectionTest.java
Date Tue, 05 May 2009 13:27:36 GMT
Author: odeakin
Date: Tue May  5 13:27:36 2009
New Revision: 771717

URL: http://svn.apache.org/viewvc?rev=771717&view=rev
Log:
Make sure messages sent and received are treated with a consistent charset.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java

Modified: harmony/enhanced/classlib/trunk/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/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java?rev=771717&r1=771716&r2=771717&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
Tue May  5 13:27:36 2009
@@ -147,7 +147,7 @@
                             buff[num++] = (byte) bytik;
                         }
                         // int num = is.read(buff);
-                        String message = new String(buff, 0, num);
+                        String message = new String(buff, 0, num, "UTF-8");
                         if (DEBUG) {
                             System.out
                                     .println("---- Server got request: ----\n"
@@ -164,7 +164,7 @@
                                         .println("---- Server read client's data: ----");
                             }
                             num = is.read(buff);
-                            message = new String(buff, 0, num);
+                            message = new String(buff, 0, num, "UTF-8");
                             if (DEBUG) {
                                 System.out.println("'" + message + "'");
                                 System.out
@@ -181,7 +181,7 @@
                                                 + "Content-type: text/html\n"
                                                 + "Content-length: "
                                                 + response.length() + "\n\n" + response)
-                                                .getBytes());
+                                                .getBytes("UTF-8"));
 
                         if (responseCode != OK_CODE) {
                             // wait while test case check closed connection
@@ -231,7 +231,7 @@
                         .write(
                                 ("HTTP/1.0 407 Proxy authentication required\n"
                                         + "Proxy-authenticate: Basic realm=\"remotehost\"\n\n")
-                                        .getBytes());
+                                        .getBytes("UTF-8"));
                 num = socket.getInputStream().read(buff);
                 if (num == -1) {
                     // this connection was closed, create new one:
@@ -239,12 +239,12 @@
                     socket.setSoTimeout(5000);
                     num = socket.getInputStream().read(buff);
                 }
-                String request = new String(buff, 0, num);
+                String request = new String(buff, 0, num, "UTF-8");
                 acceptedAuthorizedRequest = request.toLowerCase().indexOf(
                         "proxy-authorization:") > 0;
                 if (acceptedAuthorizedRequest) {
                     socket.getOutputStream().write(
-                            ("HTTP/1.1 200 OK\n\n").getBytes());
+                            ("HTTP/1.1 200 OK\n\n").getBytes("UTF-8"));
                 }
             } catch (IOException e) {
             }
@@ -568,7 +568,7 @@
         while ((bytesRead = is.read(buffer)) > 0) {
             if (DEBUG) {
                 System.out.println("Client got response: '"
-                        + new String(buffer, 0, bytesRead) + "'");
+                        + new String(buffer, 0, bytesRead, "UTF-8") + "'");
             }
             totalBytes += bytesRead;
         }
@@ -585,7 +585,7 @@
         while ((bytesRead = is.read(buffer)) > 0) {
             if (DEBUG) {
                 System.out.println("Client got response: '"
-                        + new String(buffer, 0, bytesRead) + "'");
+                        + new String(buffer, 0, bytesRead, "UTF-8") + "'");
                 totalBytes += bytesRead;
             }
         }
@@ -664,7 +664,7 @@
         c.setDoOutput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
-        c.getOutputStream().write(httpServer.clientPost.getBytes());
+        c.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
 
         InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
@@ -732,7 +732,7 @@
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
-        c2.getOutputStream().write(httpServer.clientPost.getBytes());
+        c2.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
@@ -766,7 +766,7 @@
         c.setDoInput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
-        c.getOutputStream().write(httpServer.clientPost.getBytes());
+        c.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
         InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
@@ -783,7 +783,7 @@
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
-        c2.getOutputStream().write(httpServer.clientPost.getBytes());
+        c2.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();
@@ -820,7 +820,7 @@
         c.setDoInput(true);
         c.setConnectTimeout(5000);
         c.setReadTimeout(5000);
-        c.getOutputStream().write(httpServer.clientPost.getBytes());
+        c.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
         InputStream is = c.getInputStream();
         int bytes2Read = httpServer.response.length();
         byte[] buffer = new byte[httpServer.response.length()];
@@ -837,7 +837,7 @@
         c2.setDoInput(true);
         c2.setConnectTimeout(5000);
         c2.setReadTimeout(5000);
-        c2.getOutputStream().write(httpServer.clientPost.getBytes());
+        c2.getOutputStream().write(httpServer.clientPost.getBytes("UTF-8"));
         is = c2.getInputStream();
         buffer = new byte[httpServer.response.length()];
         bytes2Read = httpServer.response.length();

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java?rev=771717&r1=771716&r2=771717&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
Tue May  5 13:27:36 2009
@@ -1254,7 +1254,7 @@
                     }
 
                     num = is.read(buff);
-                    String message = new String(buff, 0, num);
+                    String message = new String(buff, 0, num, "UTF-8");
                     log("Got request:\n" + message);
                     log("------------------");
 
@@ -1264,7 +1264,7 @@
                             // client connection sent some data
                             log("try to read client data");
                             num = is.read(buff);
-                            message = new String(buff, 0, num);
+                            message = new String(buff, 0, num, "UTF-8");
                             log("client's data: '" + message + "'");
                             // check the received data
                             assertEquals(clientsData, message);
@@ -1272,7 +1272,7 @@
                         // just send the response
                         os
                                 .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
-                                        .getBytes());
+                                        .getBytes("UTF-8"));
                         log("Simple NON-Proxy work is DONE");
                         continue;
                     }
@@ -1281,7 +1281,7 @@
                     if (needProxyAuthentication) {
                         log("Authentication required ...");
                         // send Authentication Request
-                        os.write(respAuthenticationRequired.getBytes());
+                        os.write(respAuthenticationRequired.getBytes("UTF-8"));
                         // read response
                         num = is.read(buff);
                         if (num == -1) {
@@ -1295,7 +1295,7 @@
                             os = peerSocket.getOutputStream();
                             num = is.read(buff);
                         }
-                        message = new String(buff, 0, num);
+                        message = new String(buff, 0, num, "UTF-8");
                         log("Got authenticated request:\n" + message);
                         log("------------------");
                         // check provided authorization credentials
@@ -1310,7 +1310,7 @@
                         // over persistent connection
                         os
                                 .write(("HTTP/1.1 " + OK_CODE + "\n" + httpsResponseTail)
-                                        .getBytes());
+                                        .getBytes("UTF-8"));
                         log("Sent OK RESPONSE over SSL");
                     } else {
                         // The content of this response will reach proxied
@@ -1320,7 +1320,7 @@
                         // will just indicate that connection with remote
                         // host has been done
                         // (i.e. SSL tunnel has been established).
-                        os.write(plainResponse.getBytes());
+                        os.write(plainResponse.getBytes("UTF-8"));
                         log("Sent OK RESPONSE");
                     }
 
@@ -1344,7 +1344,7 @@
                         // read the HTTP request sent by secure connection
                         // (HTTPS request)
                         num = is.read(buff);
-                        message = new String(buff, 0, num);
+                        message = new String(buff, 0, num, "UTF-8");
                         log("[Remote Server] Request from SSL tunnel:\n"
                                 + message);
                         log("------------------");
@@ -1353,7 +1353,7 @@
                             // client connection sent some data
                             log("[Remote Server] try to read client data");
                             num = is.read(buff);
-                            message = new String(buff, 0, num);
+                            message = new String(buff, 0, num, "UTF-8");
                             log("[Remote Server] client's data: '" + message
                                     + "'");
                             // check the received data
@@ -1364,7 +1364,7 @@
                         // send the response with specified response code
                         os
                                 .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
-                                        .getBytes());
+                                        .getBytes("UTF-8"));
                     }
                     log("Work is DONE");
                 }
@@ -1417,7 +1417,7 @@
                         + connection.usingProxy());
                 if (connection.getDoOutput()) {
                     // connection configured to post data, do so
-                    connection.getOutputStream().write(clientsData.getBytes());
+                    connection.getOutputStream().write(clientsData.getBytes("UTF-8"));
                 }
                 // read the content of HTTP(s) response
                 InputStream is = connection.getInputStream();
@@ -1429,7 +1429,7 @@
                         && ((byt = is.read()) != -1)) {
                     buff[num++] = (byte) byt;
                 }
-                String message = new String(buff, 0, num);
+                String message = new String(buff, 0, num, "UTF-8");
                 log("Got content:\n" + message);
                 log("------------------");
                 log("Response code: " + connection.getResponseCode());



Mime
View raw message