Forum Discussion

aaronpliu's avatar
aaronpliu
Frequent Contributor
6 years ago
Solved

Invalid xml as special character in request body

Hi Community,

 

I encountered a special character issue with my REST POST payload (request body). As request, the payload include other characters, like Simplified (测试) / Traditional(測試) Chinese. after save project, the test case will be missing due to invalid xml. I open it with XML Spy and said there are invalid characters (acutally it's mass code becoz of special characters). If I accept XML spy convertion, then this xml would be imported into ReadyAPI.

I search the same issue from forum, but seems did not find a solution. Checked the encoding, it's UTF-8 in header of xml.

Content-type of my payload is application/json, appreciated if anyone who would provide available solution for that.

 

Thanks,

/Aaron

 

  • In the ReadyAPI, what does it show when you click "Help -> System Properties" and "file.encoding"?

    Set it "UTF-8"
  • it's working after added -Dfile.encoding=UTF-8 in readyapi.vmoptions file. the chanage would be seen from Help -> System properties.

    Thanks nmraorichie

7 Replies

  • richie's avatar
    richie
    Community Hero

    Hi aaronpliu

     

    I had a similar problem with the ISO-8859-1 charset.  My testdata file included chars that weren't included within the UTR-8 charset - meaning that the project.xml file was no longer wellformed relative to the defined character set, meaning that the project.xml file couldn't be opened in REadyAPI! as ReadyAPI! requires the project.xml file to be wellformed....well - if you read certain literature - it states that XML isn't even XML until its wellformed! 

     

    anway - to 'fix' it I had to open the malformed .xml file within an app that didnt include an XML parser (something like notepad++) and then replace the substitution characters with a char that was contained within both ISO-8859-1 and  UTF-8.  When I tried using XMLSpy (app that contains an XML parser) I couldn't alter the substitution characters - hence the reason I had to use an app without an XML parser.

    #

    I had a quick look at I've found contradictory info as to whether UTF-8 supports chinese characters - but it appears UTF-16 and UTF-32 does, so to ensure this doesnt occur again - you could always adopt the approach @nmrao suggested and update your file.encoding attribute in ReadyAPI!'s system properties from whatever it is (displayed in the system properties, file.encoding attribute value) but rather than change to UTF-8 - change to UTF-16 or 32 instead?

     

    oh - one thing - UTF-8 is the default char encoding within .xml.  you can set it to other charsets - its just UTF-8 is the default one.

     

     grabbed the following from stackoverflow

    Changing the default encoding
    1. Go to SOAPUI_HOME/bin.
    2. Open soapui.bat/.sh, depending on your platform.
    3. You should be able find JAVA_OPTS , then you can add there below line in a new line set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding="iso-8859-1" on windows. ...
    4. Save the file, start SoapUI .

     

    Ok - this is a bit weird - my system properties 'file.encoding' attribute value is set as 'Cp1252'.  HOWEVER - if I look in the ready-api.bat file - the encoding value is set as 'iso-8859-1'

     

    Confused.....I would expect them to be identical! 

     

    Cheers,

     

    richie

    • aaronpliu's avatar
      aaronpliu
      Frequent Contributor

      Thanks nmrao richie

      I will try the solution and give your a feedback by then. Thank you very much

       

      Thanks,

      /Aaron

      • aaronpliu's avatar
        aaronpliu
        Frequent Contributor

        it's working after added -Dfile.encoding=UTF-8 in readyapi.vmoptions file. the chanage would be seen from Help -> System properties.

        Thanks nmraorichie

  • nmrao's avatar
    nmrao
    Champion Level 3
    In the ReadyAPI, what does it show when you click "Help -> System Properties" and "file.encoding"?

    Set it "UTF-8"