Use a property on
the Stub for users to set. This
choice applies to the client only.
For a client, the encoding
is specified in the SOAP request. The SOAP engine serializes the request
and sends it to the web service engine. The web service engine receives
the request and deserializes the message to Java objects,
which are returned to you in a response.
When the web service
engine on the server receives the serialized request, a raw message
in the form of an input stream, is passed to the parser, which understands
Byte Order Mark (BOM). BOM is mandatory for UTF-16 encoding and it
can be used in UTF-8. The message is deserialized to a Java objects and a service invocation is made.
For two-way invocation, the engine needs to serialize the message
using a specific encoding and send it back to the caller.
The following example shows you how to use a property on
the Stub to change the character set:javax.xml.rpc.Stub stub=service.getPort("MyPortType");
((javax.xml.rpc.Stub)stub).setProperty(com.ibm.wsspi.webservices.Constants.MESSAGE_CHARACTER_SET_ENCODING,"UTF-16");
stub.invokeMethod();
In this code example, com.ibm.wsspi.webservices.Constants.MESSAGE_CHARACTER_SET_ENCODING = "com.ibm.wsspi.webservices.xmlcharset";
Use a handler to change the character set through
SOAP
with Attachments API for Java (SAAJ).
If you are using a handler, the SOAP message is transformed
to a SAAJ format from other possible forms, such as an input stream.
In such cases as a handleRequest method on the client side and a handleResponse
method on the server side, the web services engine transforms from
a SAAJ format back to the stream with appropriate character encoding.
This transformation or change is called a roundtrip transformation.
The following is an example of how you can use a handler
to specify the character encoding through SAAJ:handleResponse(MessageContext mc) {
SOAPMessageContext smc = (SOAPMessageContext) context;
javax.xml.soap.SOAPMessage msg = smc.getMessage();
msg.setProperty (javax.xml.soap.SOAPMessage.CHARACTER_SET_ENCODING, "UTF-16");
}
}