views:

42

answers:

2

I have a Perl client which is calling an http restlet service (put method). Some of the parameters in this call contain japanese text. When I printed the contents of these request parameters in the restlet service I found these chars garbled !

This is my PERL client code:

my %request_headers = (
        'DocumentName' => $document_name, --> This name is a JAPANESE String
        'DocumentDescription' => 'Test Japanese Chars',
        'content-length' => 200,
        'Content-Type' => 'application/octet-stream; charset=utf-8',
        'User-Agent' => "JPCharTester",
        );

        $s->write_request('PUT', '/test-document/TEST/TEST_DOCUMENT' , %request_headers, $content);

in this call both the values of $context and $document_name are JAPANESE Strings. But ONLY the document_name is received as garbled in my backend service.

Here goes the Service code:

String URL_ENCODING = "UTF-8";
String documentName = requestHeaders.getFirstValue("DocumentName");
System.out.println("Encoded Document Name : "+documentName+" <<<"); --> documentName is garbled here

try {
    documentName = URLDecoder.decode(documentName, URL_ENCODING);
    System.out.println(>>> Decoded Document Name : "+documentName+" <<<"); --> documentName is garbled here
} catch (java.io.UnsupportedEncodingException ex) {
    throwException(ex.getMessage(), Status.SERVER_ERROR_INTERNAL, ex);
}

both the above log statements printed GARBLED TEXT !!

Can someone tell me what is the mistake I am doing and how to fix this ?

Thanks in advance for your help.

Regards, Satish.

A: 

Could you elaborate on what you mean by "garbled"? Also, do you have an HTTP trace?

Julian Reschke
A: 

Don't forget to encode the data on the client side as UTF-8. If you say

'Content-Type' => 'application/octet-stream; charset=utf-8'

than that doesn't magically solve the problem. It's just a hint for the receiver in which form it will get the data. You must also send it with the correct format. In perl:

use utf8;
...
    'DocumentName' => utf8::encode($document_name),
...

... , utf8::encode($content) ...
Aaron Digulla