wood burning stoves 2.0*
The moose likes Web Services and the fly likes How to  make SOAP request with UTF8 charactes in message body Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to  make SOAP request with UTF8 charactes in message body" Watch "How to  make SOAP request with UTF8 charactes in message body" New topic
Author

How to make SOAP request with UTF8 charactes in message body

pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
Hi all,

I am new to web services technology. My question is how do we call a web service with UTF8 characters in the request body. I am using following code for calling a web service. But, when I receive a request on server side it displays ??? instead of UTF8 characters.

Any help would be appreciated.

Thanks and Regards,
Pranav Thakker
[ June 08, 2007: Message edited by: pranav thakker ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41797
    
  62
Where does it display those characters - somewhere that knows how to display Unicode? E.g., not all consoles and editors can display Unicode. Are the byte values that get transferred correct?


Ping & DNS - my free Android networking tools app
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
Thanks for prompt reply. It displays this characters in WYSIWYG editor. Earlier we were using php client for making request, in that it was working fine. I doubt problem is with some java code.

- Pranav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41797
    
  62
Is that editor (and the font it's using) capable of displaying Unicode?

And again, are the bytes transferred correctly?
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
yes, editor is capable of displaying UTF8 and also bytes are transfered correctly.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41797
    
  62
In that case it seems that the editor does not recognize the characters as being UTF-8 encoded.

But if the bytes are transferred correctly, then all is well, isn't it?
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
Thanks Ulf for your kind help. I am completely new to web services, thus not sure about many things. Let me describe you my problem more descriptively.

1. We are having request body, in which some elements might contain UTF8 characters.
2. When we send a SOAP request, just before the invoke() method I have checked that request body contains proper UTF8 characters.
3. But, when the request reaches to the server, it displays ??? instead of UTF8 characters.
4. Same request we have tried sending using PHP client, at this time server could able to see UTF characters. Please, note that that PHP client has used utf8_encode() method available in php to encode the request body.
5. So, I doubt that if I have to do similar kind of encoding in java to send it properly.

It would be nice if you can send me any working example of web service which uses UTF8 in the request body.

Once again thanks for your help.

Best Regards,
Pranav Thakker
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by pranav thakker:
It would be nice if you can send me any working example of web service which uses UTF8 in the request body.


As the character encoding is declared in the Content-Type HTTP header of the HTTP request that carries the SOAP request it is unlikely that you can mix UTF-16 and UTF-8 in the same request. You would therefore have to force the entire SOAP request into UTF-8. Alternately if the SOAP request is entirely in UTF-16, simply encode the payload to UTF-8 after receiving it and before passing it on.

My question is how do we call a web service with UTF8 characters.


Your code snippet implies that you are sending a String. Java Strings are composed of 16 bit unicode code points. So if you read UTF-8 content into a String that content would lose its "UTF-8-ness" even before the web services client sends it out.

Byte Encodings and Strings
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

But, when I receive a request on server side it displays ??? instead of UTF8 characters.


You haven't been clear what is receiving the SOAP request on the server side. I have the suspicion it isn't one of the common Java-based SOAP stacks and it may not even be Java based. Are you telling us that the web service endpoint can only receive SOAP requests that are UTF-8 encoded?

Example: if you are using the Axis 1.x client libraries you should be able to set the character set encoding for the request with the CHARACTER_SET_ENCODING property.

Class Call
[ June 08, 2007: Message edited by: Peer Reynders ]
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
Hi Peer,

This is to update you, I have tried using call.setProperty(Call.CHARACTER_SET_ENCODING, "UTF-8"); but it also didn't work. Please let me know if you have anything for me to try.

Thanks,
Pranav
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by pranav thakker:
I have tried using call.setProperty(Call.CHARACTER_SET_ENCODING, "UTF-8"); but it also didn't work.


That's unfortunate.
So does that mean that you are using the Axis client libraries? Client libraries from other SOAP stacks may implement different ways of changing the message character encoding. The other problem is that there is rarely clear documentation which values are in fact valid. SAAJ seems to be using "utf-8", so I don't know if letter case matters. You may want to do a call.getProperty(Call.CHARACTER_SET_ENCODING) before you set it and see what the initial value is - that might give you a clue to what the valid values are.

Have you used tcpmon to get a good look at the SOAP requests that are being exchanged.

You also haven't mentioned the SOAP stack that the server is using.
pranav thakker
Greenhorn

Joined: Nov 21, 2005
Posts: 20
Hi Peer,

Thanks for reply. Yes I am using Axis client libraries only. On the server side we have a web service written in the PHP and running on Apache server. Please note that, service works fine with PHP client. Anyway, I'll try to use TCPMON to debug SOAP request. Will keep on updating you for the same.

Thanks,
Pranav Thakker
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make SOAP request with UTF8 charactes in message body