Re: [enhydra] Problem with UTF-8 and POST method in EE 6.3

João Paulo Ribeiro <[email protected]> Wed, 31 Aug 2005 14:49:22 +0100
Newsgroups gmane.comp.java.enhydra.general
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1125496105-10599-118
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi! <br>
<br>
I had problems with encoding but not anymore.:)<br>
<br>
Try to follow this steps:<br>
<br>
1) Force the server to always assume that request from client are
utf-8. Set de server encoding has utf-8. I'm using Enhydra 5.4 and i
set de Server.enconding="utf-8" in the multiserver configuration file.<br>
For Enhydra 6.3  what is the configuration parameter.<br>
<br>
2) Force Server to always send response utf-8 encoded. In Enhydra 5.4 i
added the following to the method handleEvent(HttpPresentationComms
comms) in the BasePO class:<br>
comms.response.setEncoding("UTF-8");<br>
just before the <br>
comms.response.writeDOM(returnHTML);<br>
<br>
3) Use a class that handle the multipart request correctly.<br>
The class i had seen around dont handled correctly the encoding if you
send parameters encoded in something diferente from the default
encoding assumed by JVM.<br>
<br>
In my case the problem was that the bytes was transformed in to String
without explicit encoding.<br>
The method that was doing wasparseValuePart(MultipartMimeInputStream
part):<br>
<pre wrap="">private String parseValuePart(MultipartMimeInputStream part) throws IOException {
        StringWriter value = new StringWriter();
        int b = 0;
        while ((b = part.read()) != -1) {
            value.write(b);
        }
        return value.toString();
    }</pre>
With this code the value.write(b) do automatically the conversion
betwwen the int/byte and the char. What happens is that the JVM try to
guess the correct encoding based on some values from the JVM
environment. If, like me, you are running your JVM in environment that
is ISO-8859-1, the JVM assum that every byte read from IO to some
string encoded in ISO-8859-1.<br>
To put i rigth i made a patch to the method above to use the encoding
that was set at the server side:<br>
<br>
private String parseValuePart(MultipartMimeInputStream part) throws
IOException {<br>
        byte[] buf = new byte[2048];<br>
        StringBuffer res = new StringBuffer(2048);<br>
        int b = 0;<br>
        while ((b = part.read(buf,0,buf.length)) != -1) {<br>
            res.append(new String(buf,0,b,HttpUtils.ENCODING) );<br>
        }<br>
        return res.toString();<br>
    }<br>
<br>
I hope this help.<br>
<br>
Best regards.<br>
João Paulo Ribeiro<br>
<br>
PS: I apoligise already for my poor english and typos.<br>
Im working and i don&acute;t read this again. Sorry.<br>
<br>
<br>
<br>
<br>
<br>
Lofi Dewanto wrote:
<blockquote cite="[email protected]" type="cite">Hi Slobodan,
  <br>
  <br>
thanks for your fast reply!
  <br>
  <br>
&lt;quote&gt;
  <br>
please try with
  <br>
comms.request.getHttpServletRequest().setCharacterEncoding("utf-8");
  <br>
before reading POST request parameters!
  <br>
&lt;/quote&gt;
  <br>
  <br>
This doesn't help...
  <br>
  <br>
  <br>
Here is what I've done sofar:
  <br>
  <br>
1) Change the HTML file to have this line:
  <br>
&lt;meta http-equiv="Content-Type" content="text/html;
charset=utf-8"&gt;
  <br>
  <br>
2) Add this line into xmlc file:
  <br>
-html:encoding utf-8
  <br>
  <br>
3) Add this line into presentation.conf:
  <br>
Application.Encoding = "utf-8"
  <br>
  <br>
4) Add this to server.xml -&gt; URIEncoding="utf-8"
  <br>
...
  <br>
&lt;Connector port="9000"
  <br>
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
  <br>
enableLookups="false" redirectPort="9043" acceptCount="100"
  <br>
debug="0" connectionTimeout="20000" URIEncoding="utf-8"
  <br>
disableUploadTimeout="true" /&gt;
  <br>
...
  <br>
  <br>
This works for all HTML files and also all forms with GET
  <br>
method but not for POST method.
  <br>
  <br>
I found that (maybe?) I need to add this in my POST method:
  <br>
enctype="multipart/form-data; charset=utf-8"
  <br>
...
  <br>
&lt;form method="post" action="MainPageOfDiscussionForAssistant.html"
name="FileUpload" id="FormMethod" enctype="multipart/form-data;
charset=utf-8"&gt;
  <br>
...
  <br>
  <br>
But then I always get an exception in this code:
  <br>
...
  <br>
String contentType = comms.request.getContentType();
  <br>
// Create the content header
  <br>
ContentHeader contentHdr = new ContentHeader("Content-Type: " +
  <br>
                                             contentType);
  <br>
// Get the input stream
  <br>
HttpPresentationInputStream input = comms.request.getInputStream();
  <br>
// Create the multiple mime
  <br>
MultipartMimeInput mime = new MultipartMimeInput(input, contentHdr);
  <br>
==&gt; EXCEPTION: MIME type error
  <br>
  <br>
If I change the enctype back into: enctype="multipart/form-data"
  <br>
I won't get any exeception but I get wrong chars for all German
  <br>
umlauts (üöäß)...
  <br>
  <br>
Any other hints? Thanks a lot!
  <br>
  <pre wrap="">
<hr size="4" width="90%">

--
You receive this message as a subscriber of the <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a> mailing list.
To unsubscribe: <a class="moz-txt-link-freetext" href="mailto:[email protected]">mailto:[email protected]</a>
For general help: <a class="moz-txt-link-freetext" href="mailto:[email protected]?subject=help">mailto:[email protected]?subject=help</a>
ObjectWeb mailing lists service home page: <a class="moz-txt-link-freetext" href="http://www.objectweb.org/wws">http://www.objectweb.org/wws</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
João Paulo Ribeiro | Senior Software Engineer
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>

PHONE: + 351 253 305 250 
FAX  : + 351 253 305 250
<a class="moz-txt-link-abbreviated" href="http://www.mobicomp.com">www.mobicomp.com</a>
 
________________________________________________________________

About Solutions | Wireless World

CONFIDENTIALITY NOTICE: This message, as well as existing attached files, is confidential and intended exclusively for the individual(s) named as addressees. If you are not the intended recipient, you are kindly requested not to make any use whatsoever of its contents and to proceed to the destruction of the message, thereby notifying the sender. 
DISCLAIMER: The sender of this message can not ensure the security of its electronic transmission and consequently does not accept liability for any fact which may interfere with the integrity of its content.</pre>
</body>
</html>


------------=_1125496105-10599-118
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit


--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

------------=_1125496105-10599-118--