Stelios Koussouris
Stelios Koussouris

Reputation: 145

CXF RS and JAX-WS encoded content unreadable

My Issue is 2-fold and it has to do with the encoding. I have a REST web application deployed on JBoss 7.1.1. This has adapters to an external web service for which I have created stubs with CXF java2wsdl from the provided WSDLs. During the request/responses to this external web service requests & responses can contain Bulgarian encoded content.

The issue is that this encoded content is not correctly sent/consumed by my REST services nor by my SOAP adapters whilst it is from SOAPUI. Below is an example

REST CALL passes the parameter "Тест Тест" as

@PathParam("receiverName") String receiverName

The Header contains charset=UTF-8

Server Log using the cxf logging interceptor logs the following

--------------------------------------
 Inbound Message
----------------------------
ID: 32
Address:     http://127.0.0.1:8080/rest/request/card/10122083/%D0%A2%D0%B5%D1%81%D1%82%20%D0%A2%D0%B5%D1%81%D1%82/1234124143312
Encoding: UTF-8
Http-Method: POST
Content-Type: application/json; charset=UTF-8
    Headers: {Accept=[application/json], accept-encoding=[gzip, deflate], accept-language=    [en-gb,en;q=0.5], cache-control=[no-cache], connection=[keep-alive], Content-Length=[313],     content-type=[application/json; charset=UTF-8], host=[127.0.0.1:8080], pragma=[no-cache],     user-agent=[Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1]}
----------------------------

The parameter now printed in a log by my code has the value "???? ????"

On the backend when I receive content in bulgarian again I have the issue, below is the example of such a response

Encoding: UTF-8
Content-Type: text/xml
Headers: {Accept=[*/*], 

The request was sent with Headers above according to the log and wireshark and the response is:

-----------------------------------------------------------------
ID: 2
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: text/xml
Headers: {Content-Length=[1011], content-type=[text/xml], Server=[IRS/1.0.18.0 guz]}
Payload: <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loy="http://www.location.bg/Loyalty/">
<soapenv:Header/>
<soapenv:Body>
<loy:CustLoyaltyResponse>
                <OutputRequestID>SCR0000000394</OutputRequestID>
                <OutputTimeStamp>20120918095649992</OutputTimeStamp>
                <StatusCode>0</StatusCode>
                <StatusMessage>Loyal Customer</StatusMessage>
                <CustomerCode>10122083</CustomerCode>
                <CustomerLoyalStatus>1</CustomerLoyalStatus>
                <LoyalLevel>Special</LoyalLevel>
                <CardObject>
                                <CardStatus>0</CardStatus>
                                <CardCustCode>10122083</CardCustCode>
                                <CardNo>100012624110122083</CardNo>
                                <CardState>4</CardState>
                                <Level>Special</Level>
                                <City>Р?Р°С?РЅР°</City>
                                <Postcode>9000</Postcode>
                                <Address>жк. Чайка</Address>
                                <NameOfRecipient>РўРµС?С? РўРµС?С?</NameOfRecipient>
                                <NumberOfRecipient>12345678</NumberOfRecipient>
                                <LastStatusChangeDate></LastStatusChangeDate>
                </CardObject>
</loy:CustLoyaltyResponse>
</soapenv:Body>
</soapenv:Envelope>
-----------------------------------------------------------------

The issue can be seen in the

                                <City>Р?Р°С?РЅР°</City>
                            <Address>жк. Чайка</Address>

whilst in SOAPUI the result is correct

<City>Варна</City>
<Address>жк. Чайка</Address>

Any thoughts what the problem is and how to solve it?

Upvotes: 3

Views: 3702

Answers (2)

Stelios Koussouris
Stelios Koussouris

Reputation: 145

In the end I looked at my log file type and it was not UTF-8 hence I added the following to my log4j to make it UTF-8

<param name="Encoding" type="UTF-8" /> 

as suggested by @unhillbilly. In addition, my editor (TextPad) doesn't show UTF-8 so I swapped to Notepad++ that it does and by also removing the @Encoded annotation I got the "Тест Тест"

Now the value is correctly retrieved from JAX-RS and passed to my JAX-WS Client Adapter (all the way the log shows that) and it is also sent correctly in the SOAP request (loginterceptors show this in the printout of the SOAP Request whilst the fact that the external web service now replies seems to confirm it).

Request
Address: http://192.168.3.251:4445/WSDL
Encoding: UTF-8
Content-Type: text/xml
Headers: {Accept=[*/*], 
...
<ReceiverName>Тест Тест</ReceiverName>

The problem that remains is that when I receive a response that contains Bulgarian characters both the log and the REST client do not get the correct character encoding however the same request in SOAP UI results in the correct character display

The issue can be seen in the my log and my Rest Client is the following

<City>Р?Р°С?РЅР°</City>  
<Address>жк. Чайка</Address>  

whilst in SOAPUI the result is correct

<City>Варна</City>  
<Address>жк. Чайка</Address>  

the headers for the response I receive are shown below. I thought the ISO-8859-1 may be affecting me but then again it does notexplain why SOAP UI handles it correctly. As far as I see I cannot influence the encoding returned by the web service itself from my conduit.

ID: 2 
Response-Code: 200 
Encoding: ISO-8859-1 
Content-Type: text/xml 
Headers: {Content-Length=[1011], content-type=[text/xml], 
Server=[IRS/1.0.18.0 guz]}
Payload: <?xml version="1.0" encoding="UTF-8"?>

Upvotes: 1

Dave L.
Dave L.

Reputation: 11239

Might it be that the logging facilities are not recording output as UTF-8? If you are using log4j, try adding

<param name="Encoding" value="UTF-8"/>

to its configuration.

Upvotes: 2

Related Questions