How to handle UTF-8 character encoding in http log

2020-02-14 13:29发布

问题:

We are generating xml using a web service(cobol code) in which we are doing an XML GENERATE to generate xml from a copybook. Now this generated XML consists of special characters like [·, Ý, ¨] which show correctly in SOAP response. But when the same message is viewed in http logs, the characters get converted to HEX like below : SOAP Response:

<StatusDesc>capital one bank Ýusa¨ ,n.a</StatusDesc>

Http Log:

<StatusDesc>capital one bank [0xc3][0x9d]usa[0xc2][0xa8] ,n.a</StatusDesc>

Now to handle this we tried to do an XML GENERATE using the WITH ENCODING 1208 clause to support the UTF-8 encoding. This in turn generated the XML in unreadable format, and nothing was readable in SOAP response. So not sure if we are missing out on anything here or is this not how we should be handling the HEX characters in http log.

?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:mes="http://MessageView/"                                                                                                                                        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body>mes:ÃŒ_%€ÎÃÂÊËÑ?>‚‘‚€ÃÂ>Ä?ÀÑ>łíè㘂ž ÄÄÈñ>Ã?ñ>Éê˞ìëÈ/ÈÃÂ˞ëÈ/ÈÃÂËä?ÀÞ‘™ÂÂëÈ/ÈÃÂËä?ÀÞëÃÂÊÎÃÂÊëÃ

The question is that is there a way to handle these characters so that the hex characters in the http log get converted to their proper display. Should this be done in Cobol web service or do we need some kind of conversion to handle the http logs outside z/os.

回答1:

It is possible to change encoding using below steps.

  • Go to SOAPUI_HOME/bin.
  • Open soapui.bat (or.sh), depending on your platform.
  • 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="utf-8" - on windows

    export JAVA_OPTS=$JAVA_OPTS -Dfile.encoding="utf-8" - on linux

  • Save the file, start SoapUI using soapui.bat( or .sh) utility.