reficio / soap-ws

Java library, based on Spring-WS, that enables handling SOAP on a purely XML level
297 stars 145 forks source link

Problems with special characters in response #1

Closed zet4080 closed 11 years ago

zet4080 commented 11 years ago

First of all: thank you for this great lib! I like it very much. It is great to write code without using generated classes, a lib to use as easy as soap-ws was simply not out there until now!

I have an issue with special characters in the response. I think they are not handled correctly and are spoiled when printing the response.

I had a look at the code and found the method "performTransmission" in the class SOAPClient

I think converting the inputstream to a String by reading the bytes is the problem here. If the response contains multi-byte characters it can't work correctly this way, or am I missing something?

I changed the code block

        inputStream = connection.getInputStream();
        StringBuilder response = new StringBuilder();
        int inputChar;
        while ((inputChar = inputStream.read()) != -1) {
            response.append((char) inputChar);
        }
        return response.toString();

to inputStream = connection.getInputStream(); String response = IOUtils.toString(inputStream, "UTF-8"); return response;

and that did work for me. IOUtils is imported already, so I think it can be used without problems.

I do not really know if it is always ok to assume UTF-8 as encoding?

Thanks!

Regards, Jochen

tombujok commented 11 years ago

Hi

Thanks for using soap-ws and your valuable feedback! Would you be willing to contribute a JUnit test case to verify the behavior of this snippet? There's a lot of integration tests in the soap-it project that you can have a look at. You can also write a simple test in the soap-client module. I would appreciate it!

Tom

tombujok commented 11 years ago

Merged to master.