Support for
Universal Transformation Format (UTF)-16 encoding
is required by the WS-I Basic Profile 1.0. WebSphere® Application
Server conforms to the WS-I Basic Profile 1.1. UTF-16 is a kind of
unicode encoding scheme using 16-bit values to store Universal Character
Set (UCS) characters. UTF-8 is the most common encoding that is used
on the Internet and UTF-16 encoding is typically used for Java™ and Windows product
applications. You can change the encoding in a SOAP message from UTF-8
to UTF-16.
Before you begin
To learn more about the requirements of the Web
Services-Interoperability
Basic Profile (WS-I), including UTF-16, see Web Services-Interoperability
Basic Profile information.
About this task
Support for UTF-16
encoding is required by WS-I Basic
Profile. The application server only supports UTF-8 and UTF-16 encoding
of SOAP messages.
You can change the character encoding in one
of two ways:
Procedure
- 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");
}
}
Results
You have modified
the character encoding from UTF-8 to UTF-16
in the web service SOAP message.