You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by wa...@techno-infinitus.co.jp on 2000/10/19 13:42:17 UTC

[PATCH]non ascii character handling

Current SOAP implementation dose not works well when
non ascii character like japanese(may beothers too) comes.

(1)Add entry that contains japanese character to AddressBook.java.

  Result:
  GetAllListings -> non ascii character becomes '?'. 
  GetAddress -> SAXParseException occurs.

(2)Try to add entry that contains japanese character by PutAddress

   Result:
   Put Address -> SAXParseException occurs.

This patch fixes these problem.

----------------------------
Masatake Wada
wada@techno-infinitus.co.jp
----------------------------


Index: ServerHTTPUtils.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/server/http/ServerHTTPUtils.java,v
retrieving revision 1.3
diff -u -r1.3 ServerHTTPUtils.java
--- ServerHTTPUtils.java	2000/10/17 12:03:41	1.3
+++ ServerHTTPUtils.java	2000/10/19 10:36:31
@@ -117,9 +117,9 @@
     int contentLength = req.getContentLength ();
 
     if ((contentType == null) ||
-        !contentType.equals (Constants.HEADERVAL_CONTENT_TYPE)) {
+        !contentType.equalsIgnoreCase (Constants.HEADERVAL_CONTENT_TYPE_UTF8)) {
       res.sendError (res.SC_BAD_REQUEST, "Content type must be: '" + 
-                     Constants.HEADERVAL_CONTENT_TYPE + "'.");
+                     Constants.HEADERVAL_CONTENT_TYPE_UTF8 + "'.");
       return null;
     } else if (contentLength < 0) {
       res.sendError (res.SC_BAD_REQUEST, "Content length must be specified.");
@@ -127,12 +127,16 @@
     }
 
     // read the stuff
-    Reader requestReader = req.getReader ();
-    char[] payload = new char[contentLength];
+    BufferedInputStream requestReader = new BufferedInputStream (req.getInputStream());
+    byte[] byte_payload = new byte[contentLength];
+    char[] payload = null;
     int    offset = 0;
     while (offset < contentLength) {
-      offset += requestReader.read (payload, offset, contentLength - offset);
+      offset += requestReader.read (byte_payload, offset, contentLength - offset);
     }
+    try {
+      payload = (new String (byte_payload, "UTF8")).toCharArray();
+    } catch (UnsupportedEncodingException uee) {}
 
     // Parse the stuff
     XMLParserLiaison xpl = new XercesParserLiaison ();
Index: SOAPHTTPConnection.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/transport/http/SOAPHTTPConnection.java,v
retrieving revision 1.4
diff -u -r1.4 SOAPHTTPConnection.java
--- SOAPHTTPConnection.java	2000/09/18 15:10:33	1.4
+++ SOAPHTTPConnection.java	2000/10/19 10:38:01
@@ -106,7 +106,7 @@
                    (action != null) ? ('\"' + action + '\"') : "");
 
       HTTPUtils.Response response = HTTPUtils.post (sendTo, headers,
-               Constants.HEADERVAL_CONTENT_TYPE,
+               Constants.HEADERVAL_CONTENT_TYPE_UTF8,
                payloadSW.toString (), timeout);
 
       responseReader = response.content;
Index: HTTPUtils.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v
retrieving revision 1.6
diff -u -r1.6 HTTPUtils.java
--- HTTPUtils.java	2000/09/18 15:12:09	1.6
+++ HTTPUtils.java	2000/10/19 10:38:17
@@ -109,8 +109,10 @@
    */
   public static Response post (URL url, Hashtable headers,
                                String contentType, String content, int timeout)
-               throws IllegalArgumentException {
-    PrintWriter out = null;
+               throws IllegalArgumentException , IOException{
+    StringWriter out_string_stream = new StringWriter();
+    PrintWriter out = new PrintWriter (out_string_stream);
+    BufferedOutputStream out_stream = null;  
     BufferedReader in = null;
     try {
       int port = url.getPort ();
@@ -120,30 +122,34 @@
 
       Socket s = new Socket (url.getHost (), port);
       s.setSoTimeout(timeout);
-      out = new PrintWriter (s.getOutputStream ());
-      in = new BufferedReader (new InputStreamReader (s.getInputStream ()));
+      out_stream = new BufferedOutputStream (s.getOutputStream());
+      in = new BufferedReader (new InputStreamReader (s.getInputStream (), "UTF8"));
     } catch (Exception e) {
       throw new IllegalArgumentException ("error opening socket: " +
                                           e.getMessage ());
     }
 
     /* send it out */
-    out.print (HTTP_POST + " " + url.getFile() + " HTTP/" + HTTP_VERSION + 
-               "\r\n");
-    out.print (HEADER_HOST + ": " + url.getHost () + ':' + url.getPort () +
-               "\r\n");
-    out.print (HEADER_CONTENT_TYPE + ": " + contentType + "\r\n");
-    out.print (HEADER_CONTENT_LENGTH + ": " + content.length () + "\r\n");
-    for (Enumeration e = headers.keys (); e.hasMoreElements (); ) {
-      Object key = e.nextElement ();
-      out.print (key + ": " + headers.get (key) + "\r\n");
+    try {
+      out.print (HTTP_POST + " " + url.getFile() + " HTTP/" + HTTP_VERSION + "\r\n");
+      out.print (HEADER_HOST + ": " + url.getHost () + ':' + url.getPort () + "\r\n");
+      out.print (HEADER_CONTENT_TYPE + ": " + contentType + "\r\n");
+      out.print (HEADER_CONTENT_LENGTH + ": " + content.getBytes("UTF8").length + "\r\n");
+      for (Enumeration e = headers.keys (); e.hasMoreElements (); ) {
+	Object key = e.nextElement ();
+	out.print (key + ": " + headers.get (key) + "\r\n");
+      }
+      out.print ("\r\n");
+      out.print (content);
+      out.print ("\r\n\r\n");
+      out.flush ();
+      //    out.close ();
+      String tosend = out_string_stream.toString();
+      out_stream.write ( tosend.getBytes ("UTF8"), 0, tosend.getBytes ("UTF8").length );
+      out_stream.flush();
+    } catch (UnsupportedEncodingException uee) {
+	// never occured
     }
-    out.print ("\r\n");
-    out.print (content);
-    out.print ("\r\n\r\n");
-    out.flush ();
-    //    out.close ();
-
     /* read the status line */
     int statusCode = 0;
     String statusString = null;