Hi
I am using Axis2 v1.4 to consume a webservice. I have generated the stubs using
WSDL2Java with jdk1.6.0_06
While running the client, I am getting the following exception:
org.apache.axis2.AxisFault: Character Set Encoding from transport information
[ISO-8859-1] does not match with character set encoding in the received SOAP
message [UTF-8]
at
org.apache.axis2.builder.BuilderUtil.validateCharSetEncoding(BuilderUtil.java:786)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:57)
at
org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:164)
at
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:112)
at
org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:88)
at
org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:353)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at ymws.yahoo.YmwsStub.GetUserData(YmwsStub.java:1587)
I am explicitly setting charset encoding in my code as below:
stub._getServiceClient().getOptions().setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,"iso-8859-1");
However that does not seem help the exception pasted above. When tracing using
the Axis2 1.4 source, I found a possible issue at the following line
streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding);
of the SOAPBuilder class (see source below):
package org.apache.axis2.builder;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXBuilder;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
public class SOAPBuilder implements Builder {
public OMElement processDocument(InputStream inputStream, String
contentType,
MessageContext messageContext) throws
AxisFault {
XMLStreamReader streamReader;
try {
String charSetEncoding = (String) messageContext
.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
// Get the actual encoding by looking at the BOM of the
InputStream
PushbackInputStream pis =
BuilderUtil.getPushbackInputStream(inputStream);
String actualCharSetEncoding =
BuilderUtil.getCharSetEncoding(pis, charSetEncoding);
// Get the XMLStreamReader for this input stream
streamReader = StAXUtils.createXMLStreamReader(pis,
actualCharSetEncoding);
StAXBuilder builder = new StAXSOAPModelBuilder(streamReader);
SOAPEnvelope envelope = (SOAPEnvelope)
builder.getDocumentElement();
BuilderUtil
.validateSOAPVersion(BuilderUtil.getEnvelopeNamespace(contentType), envelope);
BuilderUtil.validateCharSetEncoding(charSetEncoding,
builder.getDocument()
.getCharsetEncoding(),
envelope.getNamespace().getNamespaceURI());
return envelope;
} catch (IOException e) {
throw AxisFault.makeFault(e);
} catch (XMLStreamException e) {
throw AxisFault.makeFault(e);
}
}
}
The issue seems like, the streamReader always reads in UTF-8 instead of the
specified encoding. And hence the following statement of the above class fails
BuilderUtil.validateCharSetEncoding(charSetEncoding, builder.getDocument()
.getCharsetEncoding(), envelope.getNamespace().getNamespaceURI());
How can we solve this problem?
Regards,
Harsha
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]