You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Oliver Flasch <of...@gmx.de> on 2007/07/25 15:50:38 UTC

Weird character encoding problem

Hi,

I'm using a "wsdl2java"-generated CXF Client to talk to a .NET  
Webservice. When sending a string containing some special characters  
(german "umlaute" in my case), these characters seem to be "mangled  
up" by some CXF component. For example, I have this "hardcoded"  
string in my (UTF-8 encoded) Java source file:

[...]
request.setToken("ä ö ü Ä Ö Ü ß");
[...]

When sending this request, CXF creates the following HTTP POST request:

[...]
POST /MyRESWebServiceV1_0.asmx HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "http://webservices.hotel.de/MyRES/V1_0/ 
GetMaintainableProperties"
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.5.0_07
Host: 127.0.0.1:8080
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
Content-Length: 626

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/ 
envelope/"><soap:Body><GetMaintainableProperties xmlns="http:// 
webservices.hotel.de/MyRES/ 
V1_0"><objRequest><WebServiceConsumerID>18</ 
WebServiceConsumerID><WebServiceConsumerPassword>XXXXX</ 
WebServiceConsumerPassword><Token>ä ö ü Ä Ö  
Ü ß</Token><CustomerNumberHotelde>0</ 
CustomerNumberHotelde><CustomerEmailHotelde>foo@bar.de</ 
CustomerEmailHotelde><CustomerPasswordHotelde> XXXXX </ 
CustomerPasswordHotelde></objRequest></GetMaintainableProperties></ 
soap:Body></soap:Envelope>
[...]

As you can see, the string is mangled into "<Token>ä ö ü  
Ä Ö Ü ß</Token>". Strings without special characters  
are transferred correctly. This looks like some very weird Unicode  
character encoding problem to me. Even more strangely, it seems to  
work when I encode my source file as ASCII under Linux, but not when  
I encode the same source file as ASCII under Mac OS X, which is my  
main development plattform. I'm totally puzzled by this behaviour and  
would appreciate any helping remarks.

I tried both CXF 2.0 and CXF 2.1 (incubator-20070628.012602-1), with  
equal results.


Thank you in advance and best regards,

Oliver


-- 
Oliver Flasch
oflasch@gmx.de



Re: Weird character encoding problem

Posted by Oliver Flasch <ol...@cs.uni-dortmund.de>.
Thank you very much for your quick help!  This fixed my problem. I  
used the "wsdl2java" generated build.xml to build with Ant and  
therefore didn't pay much attention to the compiler options specified  
there. Changing the javac task invocation to

<javac srcdir="${build.src.dir}" destdir="${build.classes.dir}"  
debug="true" encoding="utf8">"

fixed the problem.


Am 25.07.2007 um 15:56 schrieb Dale Peakall:

> Are you specifying an encoding when you compile your Java classes?  
> i.e. javac -encoding utf8 MyClass.java?
>
> Oliver Flasch wrote:
>> Hi,
>>
>> I'm using a "wsdl2java"-generated CXF Client to talk to a .NET  
>> Webservice. When sending a string containing some special  
>> characters (german "umlaute" in my case), these characters seem to  
>> be "mangled up" by some CXF component. For example, I have this  
>> "hardcoded" string in my (UTF-8 encoded) Java source file:
>>
>> [...]
>> request.setToken("ä ö ü Ä Ö Ü ß");
>> [...]
>>
>> When sending this request, CXF creates the following HTTP POST  
>> request:
>>
>> [...]
>> POST /MyRESWebServiceV1_0.asmx HTTP/1.1
>> Content-Type: text/xml; charset=UTF-8
>> SOAPAction: "http://webservices.hotel.de/MyRES/V1_0/ 
>> GetMaintainableProperties"
>> Cache-Control: no-cache
>> Pragma: no-cache
>> User-Agent: Java/1.5.0_07
>> Host: 127.0.0.1:8080
>> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
>> Connection: keep-alive
>> Content-Length: 626
>>
>> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/ 
>> envelope/"><soap:Body><GetMaintainableProperties xmlns="http:// 
>> webservices.hotel.de/MyRES/ 
>> V1_0"><objRequest><WebServiceConsumerID>18</ 
>> WebServiceConsumerID><WebServiceConsumerPassword>XXXXX</ 
>> WebServiceConsumerPassword><Token>ä ö ü Ä Ö  
>> Ü ß</Token><CustomerNumberHotelde>0</ 
>> CustomerNumberHotelde><CustomerEmailHotelde>foo@bar.de</ 
>> CustomerEmailHotelde><CustomerPasswordHotelde> XXXXX </ 
>> CustomerPasswordHotelde></objRequest></GetMaintainableProperties></ 
>> soap:Body></soap:Envelope>
>> [...]
>>
>> As you can see, the string is mangled into "<Token>ä ö  
>> ü Ä Ö Ü ß</Token>". Strings without special  
>> characters are transferred correctly. This looks like some very  
>> weird Unicode character encoding problem to me. Even more  
>> strangely, it seems to work when I encode my source file as ASCII  
>> under Linux, but not when I encode the same source file as ASCII  
>> under Mac OS X, which is my main development plattform. I'm  
>> totally puzzled by this behaviour and would appreciate any helping  
>> remarks.
>>
>> I tried both CXF 2.0 and CXF 2.1 (incubator-20070628.012602-1),  
>> with equal results.
>>
>>
>> Thank you in advance and best regards,
>>
>> Oliver
>>
>>
>

-- 
Oliver Flasch
oliver.flasch@cs.uni-dortmund.de
0171 6447868




Re: Weird character encoding problem

Posted by Dale Peakall <d....@oclcpica.org>.
Are you specifying an encoding when you compile your Java classes? i.e. 
javac -encoding utf8 MyClass.java?

Oliver Flasch wrote:
> Hi,
>
> I'm using a "wsdl2java"-generated CXF Client to talk to a .NET 
> Webservice. When sending a string containing some special characters 
> (german "umlaute" in my case), these characters seem to be "mangled 
> up" by some CXF component. For example, I have this "hardcoded" string 
> in my (UTF-8 encoded) Java source file:
>
> [...]
> request.setToken("ä ö ü Ä Ö Ü ß");
> [...]
>
> When sending this request, CXF creates the following HTTP POST request:
>
> [...]
> POST /MyRESWebServiceV1_0.asmx HTTP/1.1
> Content-Type: text/xml; charset=UTF-8
> SOAPAction: 
> "http://webservices.hotel.de/MyRES/V1_0/GetMaintainableProperties"
> Cache-Control: no-cache
> Pragma: no-cache
> User-Agent: Java/1.5.0_07
> Host: 127.0.0.1:8080
> Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
> Connection: keep-alive
> Content-Length: 626
>
> <soap:Envelope 
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetMaintainableProperties 
> xmlns="http://webservices.hotel.de/MyRES/V1_0"><objRequest><WebServiceConsumerID>18</WebServiceConsumerID><WebServiceConsumerPassword>XXXXX</WebServiceConsumerPassword><Token>ä 
> ö ü Ä Ö Ü 
> ß</Token><CustomerNumberHotelde>0</CustomerNumberHotelde><CustomerEmailHotelde>foo@bar.de</CustomerEmailHotelde><CustomerPasswordHotelde> 
> XXXXX 
> </CustomerPasswordHotelde></objRequest></GetMaintainableProperties></soap:Body></soap:Envelope> 
>
> [...]
>
> As you can see, the string is mangled into "<Token>ä ö ü 
> Ä Ö Ü ß</Token>". Strings without special characters 
> are transferred correctly. This looks like some very weird Unicode 
> character encoding problem to me. Even more strangely, it seems to 
> work when I encode my source file as ASCII under Linux, but not when I 
> encode the same source file as ASCII under Mac OS X, which is my main 
> development plattform. I'm totally puzzled by this behaviour and would 
> appreciate any helping remarks.
>
> I tried both CXF 2.0 and CXF 2.1 (incubator-20070628.012602-1), with 
> equal results.
>
>
> Thank you in advance and best regards,
>
> Oliver
>
>