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
|