ws-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Masatake Wada <w...@techno-infinitus.co.jp>
Subject Re: Character encodings
Date Tue, 21 Nov 2000 03:42:11 GMT
I rewrote the non-ascii character patch for current CVS.

It seems everyone have forgotten about i18n...but I think
it is important.

Regards,

Masatake Wada
wada@techno-infinitus.co.jp


Index: RPCRouterServlet.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java,v
retrieving revision 1.9
diff -u -r1.9 RPCRouterServlet.java
--- RPCRouterServlet.java	2000/11/15 13:38:32	1.9
+++ RPCRouterServlet.java	2000/11/21 01:30:31
@@ -181,6 +181,12 @@
   public void doPost (HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
     /*
+     * convert UTF8 byte Stream to unicode charcter stream.
+     */
+    String requestReaderString = convertStream (req);
+    StringReader requestReader = new StringReader( requestReaderString );
+
+    /*
      * Begin Transport-Hook-Extension
      */
     // Invokes EnvelopeEditor (editIncoming)
@@ -190,7 +196,7 @@
     if (opt != null && editor != null) {
       try {
         StringWriter sout = new StringWriter();
-        editor.editIncoming(req.getReader(), sout);
+        editor.editIncoming(requestReader, sout);
         String xml = sout.getBuffer().toString();
         in = new StringReader(xml);
         contentLength = xml.length();
@@ -200,8 +206,8 @@
         return;
       }
     } else {
-      in = req.getReader();
-      contentLength = req.getContentLength();
+      in = requestReader;
+      contentLength = requestReaderString.length();
     }
     /*
      * End Transport-Hook-Extension
@@ -354,5 +360,26 @@
     res.setContentLength (bytes.size ());
     res.setStatus(status);
     bytes.writeTo (res.getOutputStream ());
+  }
+
+  /**
+   * convert UTF8 byte Stream to Unicode Character String
+   */
+  private String convertStream( HttpServletRequest req ) throws IOException {
+    StringBuffer readBuffer= new StringBuffer();
+    try{
+        InputStreamReader isr = new InputStreamReader (req.getInputStream(),"UTF8");
+        BufferedReader utf8Reader = new BufferedReader (isr);
+
+        final int BUFFER_SIZE = 256;
+        char[] buf = new char[ BUFFER_SIZE ];
+        int readByte = 0;
+        while( (readByte = utf8Reader.read( buf , 0 , BUFFER_SIZE ) ) != -1 ){
+            readBuffer.append( buf , 0 , readByte );
+        }
+    }catch( UnsupportedEncodingException uee ){
+        // never thrown
+    }
+    return readBuffer.toString();
   }
 }
Index: HTTPUtils.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v
retrieving revision 1.8
diff -u -r1.8 HTTPUtils.java
--- HTTPUtils.java	2000/11/14 07:33:24	1.8
+++ HTTPUtils.java	2000/11/21 01:30:50
@@ -128,8 +128,9 @@
         s = new Socket (HTTP_PROXY_HOST, HTTP_PROXY_PORT);
       }
       s.setSoTimeout(timeout);
-      out = new PrintWriter (s.getOutputStream ());
-      in = new BufferedReader (new InputStreamReader (s.getInputStream ()));
+      out = new PrintWriter (new OutputStreamWriter (s.getOutputStream(),"UTF8"));
+      in = new BufferedReader (new InputStreamReader (s.getInputStream (),"UTF8"));
+
     } catch (Exception e) {
       throw new IllegalArgumentException ("error opening socket: " +
                                           e.getMessage ());
@@ -145,7 +146,13 @@
     }
     out.print (HEADER_HOST + ": " + url.getHost () + ':' + port + "\r\n");
     out.print (HEADER_CONTENT_TYPE + ": " + contentType + "\r\n");
-    out.print (HEADER_CONTENT_LENGTH + ": " + content.length () + "\r\n");
+    try{
+      // in I18N environment,contentLength is not character number
+      int byteLength = content.getBytes ("UTF8").length;
+      out.print (HEADER_CONTENT_LENGTH + ": " + byteLength + "\r\n");
+    }catch( UnsupportedEncodingException uee ){
+      // never thrown
+    }
     for (Enumeration e = headers.keys (); e.hasMoreElements (); ) {
       Object key = e.nextElement ();
       out.print (key + ": " + headers.get (key) + "\r\n");

Mime
View raw message