You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@ws.apache.org by Gus Mueller <gu...@mu.org> on 2003/09/17 06:25:24 UTC
getting back utf-8 data via xmlrpc call
I've got a servlet that I'm using with XmlRpcServer to call a class via
xml-rpc. I'm sending utf-8 data to it, and that's working fine, but
when I try and get utf data back out, it comes out garbled in the areas
where there were multi-byte chars... I fear I'm doing something wrong.
I've already called XmlRpc.setEncoding("UTF-8"); in my servlet's init
method...
My code looks like this (in doPost):
res.setContentType("text/xml; charset=UTF-8");
byte[] result = xmlrpc.execute(req.getInputStream());
res.setContentLength(result.length);
String xml = new String(result, "utf-8");
System.out.println(xml); // this prints out correctly, I can see the
utf-8 data just fine from the console
StringBuffer sb = new StringBuffer();
sb.append(xml);
PrintWriter out = res.getWriter();
out.print(xml.toString()); // this doesn't print out correctly.
out.close();
I've tried this with both jetty and tomcat, with the same results. I'm
running on mac osx 10.2.6, jdk 1.4.1. I've been debugging with curl,
telnet, and my web browser for a couple of hours now, and I'm about to
go nuts.
The strange thing is, when I print out the data via a doGet() like this:
res.setContentType("text/html; charset=UTF-8");
PrintWriter out = res.getWriter();
out.print(new String(myString.getBytes(), "utf-8"));
everything works perfectly. Does anyone have any suggestions?
thanks,
-gus
--
August Mueller
http://flyingmeat.com/
VoodooPad - 1st Place U.S., Second O'Reilly Mac OS X Innovaters Contest
"Christmas means carnage!" -- Ferdinand, the duck
Re: getting back utf-8 data via xmlrpc call
Posted by August Mueller <gu...@mu.org>.
On 9/19/03 8:05 PM, "Walter Christian" <wo...@sil.at> wrote:
>
> Hello,
>
>> I've got a servlet that I'm using with XmlRpcServer to call a class via
>> xml-rpc. I'm sending utf-8 data to it, and that's working fine, but
>> when I try and get utf data back out, it comes out garbled in the areas
>> where there were multi-byte chars... I fear I'm doing something wrong.
>>
>> I've already called XmlRpc.setEncoding("UTF-8"); in my servlet's init
>> method...
>
> I am doing exactly the same thing. It seems that setEncoding only works
> correct for sending data. Every xml response I receive which is encoded
> by UTF-8 also get garbled.
> I solved this problem by setting -Dfile.encoding=UTF8 and now I get
> correct results. But this is of course also only a temporary solution.
I haven't tried that... I might see what that gets me.
What I ended up doing was this:
res.setContentType("text/xml; charset=UTF-8");
byte[] result = xmlrpc.execute(req.getInputStream());
PrintStream out = new PrintStream(res.getOutputStream());
out.println(new String(result, "utf-8"));
out.close();
I however, could not send the content-length because it was generating
incorrect results after the PrintStream was done with it.
//res.setContentLength(result.length);
I'm not 100% sure this is the correct solution, but it seems to work.
Thanks,
-gus
--
August Mueller
http://flyingmeat.com/
VoodooPad - 1st Place U.S., Second O'Reilly Mac OS X Innovaters Contest
"Christmas means carnage!" -- Ferdinand, the duck
Re: getting back utf-8 data via xmlrpc call
Posted by Walter Christian <wo...@sil.at>.
Hello,
> I've got a servlet that I'm using with XmlRpcServer to call a class via
> xml-rpc. I'm sending utf-8 data to it, and that's working fine, but
> when I try and get utf data back out, it comes out garbled in the areas
> where there were multi-byte chars... I fear I'm doing something wrong.
>
> I've already called XmlRpc.setEncoding("UTF-8"); in my servlet's init
> method...
I am doing exactly the same thing. It seems that setEncoding only works
correct for sending data. Every xml response I receive which is encoded
by UTF-8 also get garbled.
I solved this problem by setting -Dfile.encoding=UTF8 and now I get
correct results. But this is of course also only a temporary solution.
Regards,
Walter Christian
--
SILVER SERVER \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\ \\
email: wolti@sil.at \ Friends don't let friends drink and su(1)
web: www.sil.at \ -- Kevin Harris