I am sending xml to a web service and there I am converting input xml to string and now I am having a problem setting its encoding. Here is a code:
Element soapinElement = (Element) streams.getSoapin().getValue().getAny();
Node node = (Node) soapinElement;
Document document = node.getOwnerDocument();
DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
LSSerializer serializer = domImplLS.createLSSerializer();
LSOutput output = domImplLS.createLSOutput();
output.setEncoding("UTF-8");
Writer stringWriter = new StringWriter();
output.setCharacterStream(stringWriter);
serializer.write(document, output);
String soapinString = stringWriter.toString();
This code makes a String from request xml. The problem is that when the request XML is encoded not in UTF-8 it produces unreadable characters inside xml elements:
<some element>РћР’Р” Р’РћР</some element>
When I send UTF-8 encoded xml there is no problem. So the question is how to set UTF-8 encoding when converting xml to String.
Default encoding used by JVM is ISO8859-1.