ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | enhydra List | August 2005 Index

<--  Date Index  --> <--  Thread Index  -->

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


Hi!

I had problems with encoding but not anymore.:)

Try to follow this steps:

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.
For Enhydra 6.3  what is the configuration parameter.

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:
comms.response.setEncoding("UTF-8");
just before the
comms.response.writeDOM(returnHTML);

3) Use a class that handle the multipart request correctly.
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.

In my case the problem was that the bytes was transformed in to String without explicit encoding.
The method that was doing wasparseValuePart(MultipartMimeInputStream part):
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();
    }
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.
To put i rigth i made a patch to the method above to use the encoding that was set at the server side:

private String parseValuePart(MultipartMimeInputStream part) throws IOException {
        byte[] buf = new byte[2048];
        StringBuffer res = new StringBuffer(2048);
        int b = 0;
        while ((b = part.read(buf,0,buf.length)) != -1) {
            res.append(new String(buf,0,b,HttpUtils.ENCODING) );
        }
        return res.toString();
    }

I hope this help.

Best regards.
João Paulo Ribeiro

PS: I apoligise already for my poor english and typos.
Im working and i don´t read this again. Sorry.





Lofi Dewanto wrote:
Hi Slobodan,

thanks for your fast reply!

<quote>
please try with
comms.request.getHttpServletRequest().setCharacterEncoding("utf-8");
before reading POST request parameters!
</quote>

This doesn't help...


Here is what I've done sofar:

1) Change the HTML file to have this line:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

2) Add this line into xmlc file:
-html:encoding utf-8

3) Add this line into presentation.conf:
Application.Encoding = "utf-8"

4) Add this to server.xml -> URIEncoding="utf-8"
...
<Connector port="9000"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="9043" acceptCount="100"
debug="0" connectionTimeout="20000" URIEncoding="utf-8"
disableUploadTimeout="true" />
...

This works for all HTML files and also all forms with GET
method but not for POST method.

I found that (maybe?) I need to add this in my POST method:
enctype="multipart/form-data; charset=utf-8"
...
<form method="post" action="" name="FileUpload" id="FormMethod" enctype="multipart/form-data; charset=utf-8">
...

But then I always get an exception in this code:
...
String contentType = comms.request.getContentType();
// Create the content header
ContentHeader contentHdr = new ContentHeader("Content-Type: " +
                                             contentType);
// Get the input stream
HttpPresentationInputStream input = comms.request.getInputStream();
// Create the multiple mime
MultipartMimeInput mime = new MultipartMimeInput(input, contentHdr);
==> EXCEPTION: MIME type error

If I change the enctype back into: enctype="multipart/form-data"
I won't get any exeception but I get wrong chars for all German
umlauts (üöäß)...

Any other hints? Thanks a lot!

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


-- 
João Paulo Ribeiro | Senior Software Engineer
jp@xxxxxxxxxxxx

PHONE: + 351 253 305 250 
FAX  : + 351 253 305 250
www.mobicomp.com
 
________________________________________________________________

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.


<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.