You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Al...@cs.com on 2006/11/01 00:10:55 UTC

Re: Converting from UTF-8 to ISO-8859-I with Axis2 and Java

Internally (like when your code says: java.lang.String text = "abcd"; ) Java 
uses Unicode to encode the value of "abcd".

When you are reading or writing this String from/to a Stream you need to 
specify what encoding the incoming or outgoing data should have.
Consider this example, it uses UTF-8 as encoding for both: outgoing SOAP 
request message and incoming response.

In your case you would use "ISO8859_1" instead of "UTF-8". 
Of course, this example is not using Axis, but it should work just fine for 
debug purposes and calling any sync webservice (just replace the highlighted 
values).

        Socket socket = new Socket();
        InetSocketAddress isa = new InetSocketAddress(HOST_NAME, PORT);
        socket.setSoTimeout(TIME_OUT);
        socket.connect(isa, TIME_OUT);
        BufferedWriter w = new BufferedWriter(new 
OutputStreamWriter(socket.getOutputStream(), "UTF8"));
        w.write("POST " + PATH + " HTTP/1.0\r\n");
        w.write("Content-Length: " + request.getBytes("UTF8").length + 
"\r\n");
        w.write("Content-Type: text/xml\r\n");
        w.write("SOAPAction: " + SOAP_ACTION + "\r\n");
        w.write("\r\n");
        w.write(request);
        w.flush();
        
        BufferedReader r = new BufferedReader(new 
InputStreamReader(socket.getInputStream(), "UTF8"));

        String response = "";
        String resp;
            while ((resp = r.readLine()) != null)
            {
                response = response + resp.trim();
            }

I suspect there is an easy way to do it Axis2 as well. Perhaps by providing 
some parameter to a sender method or maybe it even recognizes the encoding 
specified on the payload message itself. 

hth,
AL


In a message dated 10/31/2006 5:19:25 PM Eastern Standard Time, 
bnegrao@gmail.com writes: 
> Guys, I'm developing a JAVA GUI that runs on Windows XP where the user can 
> enter account data that will be stored on a linux+postgre server. 
> 
> The data is sent from the GUI to the postgre server using soap. I'm using 
> axis2 on the client side. (the server-side uses Perl SOAP) 
> 
> The problem is the server is configured to use ISO-8859-1, while my Java 
> application is sending the data using UTF-8. All the strings containing 
> non-ascii characters are being stored incorrectly on the server. The server is not 
> converting from utf-8 to iso-8859-i before storing the data. 
> 
> Since the people on the server-side say "we cannot change nothing", and they 
> suggested "you have to send this data in iso-8859-1", I'm obligated to send 
> my SOAP post's using ISO-8859-1 strings instead of UTF-8. 
> 
> I have no idea of how can I do this. Can someone give some hints on this?
> 
> Thank you very much,
> 
> bruno.

Re: Converting from UTF-8 to ISO-8859-I with Axis2 and Java

Posted by Bruno Negrao <bn...@gmail.com>.
Hi Alelikov, thank you for answering.

But, if I understood what you meant, wouldn't I need to use the ISO-8859-1
in my POST method instead of UTF-8?


> BufferedWriter w = new BufferedWriter(*new OutputStreamWriter(
> socket.getOutputStream(), "UTF8")*);


BufferedWriter w = new BufferedWriter(*new OutputStreamWriter(
socket.getOutputStream(), "ISO-8859-1")*);


> w.write("Content-Length: " + request.getBytes("*UTF8*").length + "\r\n");
>
w.write("Content-Length: " + request.getBytes("ISO-8859-1").length +
"\r\n");

Because the server only understands ISO-8859-1.

Also, I'd like to know the correct way of doing this using axis2. I cannot
use a code like your example at this point of my project...

Thank you,
bruno