Announcement Announcement Module
Collapse
No announcement yet.
Data encoding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data encoding

    Hi.

    Is there some setting to define the encoding when using the FaceBookTemplate.
    When I send data via FacebookTemplate.pubish the german umlauts (...) get lost.

    If I use curl and encode the characters myself facebook displays them correctly:

    curl -F access_token=".." -F id=".." -F message="umlaute öäü" https://graph.facebook.com/feed

    So I guess this might be a RestTemplate issue.

  • #2
    update from my side:

    After some investigation I found out that the RestTemplate uses StringHttpMessageConverter to convert the messages and this class has "ISO-8859-1" als default charset. This class does however analyze the content-type header for any charset settings but the facebook template class does not set any (at least I haven't found them).

    So I guess the solution would be for FacebookTemplate to set the charset of the content-type to UTF8 since this is what Facebook expects.

    I'll file a bug report for this.

    Comment


    • #3
      in the previous post I named the wrong converter. Since the request is a POST request the FormHttpMessageConverter is used.

      The bug report for this is under

      https://jira.springframework.org/browse/SPR-7789

      Comment


      • #4
        Hi,

        I'm having a similar issue and it is with the '+' sign. The service on the other side is interpreting the plus sign as a space which is correct, so I want my client using RESTTemplate to encode the '+' as %2B.

        How did you go about changing the encoding nitgate?

        /KramKroc

        Comment


        • #5
          My current workaround is to derive from the spring FacebookTemplate and modify the charset in the FormHttpMessageConverter.

          Code:
          for (HttpMessageConverter messageConverter : ((RestTemplate)restOperations).getMessageConverters()) {
          if (messageConverter instanceof FormHttpMessageConverter) {
          	FormHttpMessageConverter converter = (FormHttpMessageConverter)messageConverter;
          	converter.setCharset(Charset.forName("UTF8"));
          	}
          }
          But I quess this is not the right solution for you. A "+" should be encoded correctly by the current implementation. Could you give an example how you use the resttemplate?

          Comment


          • #6
            Still having problems with RestTemplate, FormHttpMessageConverter and UTF8 chars

            Has anyone been able to solve the encoding problem? I have done what was suggested and set the character encoding to UTF-8

            FormHttpMessageConverter c = new FormHttpMessageConverter();
            c.setCharset(Charset.forName("UTF-8"));
            restTemplate.getMessageConverters().add(c);

            But still when sending a post parameter

            MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>();
            postParams.add("name", "ěě");

            On the receiving end I get ???? instead of ěě. I have checked that the problem is not on the receiving end.

            cheers,
            Lili

            Comment


            • #7
              BTW< I am using spring 3.0.4

              Comment


              • #8
                lnader,

                please note that adding a new FormHttpMessageConverter will not solve this problem as there already is one in the list.

                Have a look at my code above. You have to change the charset of the FormHttpMessageConverter in the list.

                By looking at the jira issue I would say that this is solved in 3.0.6

                Comment


                • #9
                  As nitegate pointed out, just adding another message converter won't do. You have to either modify the existing FormHttpMessageConverter or remove it and add a new (modified) one.

                  Also, as was already pointed out, this has been fixed in Spring 3.0.6 and we encourage you to use that version of Spring with Spring Social. If you must use Spring 3.0.4, then you'll have to adjust the encoding yourself, as described above.

                  Comment

                  Working...
                  X