Wednesday, March 30, 2011

Glassfish 3.0: Web service result encoding problem ( invalid byte 2 of 2-byte utf-8 sequence) solution

I have developed JEE 6 enterprise application with 2 web modules and EJB3 exposed as web service.

Application deployed successfully on the glassfish v3.0.1 and when viewing the WSDL everything is okay.

But when I invoked the built in web service tester, and invokeing an operation I got the following error:

javax.xml.transform.transformerexception:org.apache.xerces.impl.io.malformedbytesequenceexception:invalid byte 2 of 2-byte utf-8 sequence
So how do I enable the UTF-8 in the "test web service" page? Right now the result is returning UTF-8, but the page is not UTF-8 so it cannot display the result.
The solution as the following:
  1. From left menu choose configuration
  2. Expand server-config
  3. Click on JVM settings.
  4. Click on JVM options tab.
  5. Add -Dfile.encoding=UTF8 to JVM options.
  6. Save changes.
  7. Restart application server.
After restarting try to test again and everything should works fine.

4 comments :