Announcement Announcement Module
No announcement yet.
Needs feature to specify charset in StringHttpMessageConverter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Needs feature to specify charset in StringHttpMessageConverter

    Hi, there. I'm using Spring Android 1.0.0RC1 and it works great. thanks.

    And I suggests some improvement in StringHttpMessageConverter.

    In default constructor of StringHttpMessageConverter, it searches availableCharsets using Charset.availableCharsets().

    	public StringHttpMessageConverter() {
    		super(new MediaType("text", "plain", DEFAULT_CHARSET), MediaType.ALL);
    		this.availableCharsets = new ArrayList<Charset>(Charset.availableCharsets().values());
    And in my profiling result, this method spent 50% of time in creating RestTemplate instance. So I planned to make my own StringHttpMessageConverter (I just use UTF-8 in all requests), but RestTemplate create StringHttpMessageConverter in its constructor.

    	public RestTemplate() {
    		this.messageConverters.add(new ByteArrayHttpMessageConverter());
    		this.messageConverters.add(new StringHttpMessageConverter());
    		this.messageConverters.add(new ResourceHttpMessageConverter());
    More over, Charset.availableCharsets() uses native icu4j method and it sometimes fail. So if I could specify charset in somewhere, or just not using Charset.availableCharsets(), I can improve performance and some problems that icu4j makes. Thanks.

  • #2
    @kingori thanks for the feedback! It is much appreciated. Since Rest Template in Spring for Android was ported from Spring Framework, we are continuing to identify areas for performance improvement. I've created a JIRA [1] to track this for inclusion in the next release.



    • #3
      I made some changes to support creating a custom StringHttpMessageConverter. I added two constructors, allowing you to set a default Charset, and a list of available Charsets. Setting the list prevents Charset.availableCharsets() from being called. I'm also evaluating how to modify RestTemplate to prevent the default StringHttpMessageConverter from being created.


      • #4
        @kingori, can you provide more details for which Android versions and devices you were experiencing the poor performance from Charset.availableCharsets()? Even though I've already made a change for this, I would like to document the details in the JIRA. Thanks!


        • #5
          @Roy Clarkson

          I've made a very simple android project to measure Charset.availableCharsets() * 10 times and to reproduce crash situation.

          On android 2.3.4, samsung galaxy s-II , execution took 175ms. I use Korean location. And then I press button, I've got the crash message at the bottom of this meesage.

          I assumed this crash is caused by Charset.availableCharsets() as the line "/system/lib/" is related to native ICU library and it is used by Charset.availableCharsets(). In this sample, crash occurred after 11 attempt to call the method. But in my real application, this error occurred more easy (less threads running) situation.

          So I solved this problem by making my custom StringHttpMessageConverter, RestTemplate. But the new SpringAndroid solved it all. Thanks very much!

          06-14 11:34:02.236: D/charset(13485): 11
          06-14 11:34:02.436: I/DEBUG(12725): stopped -- continuing
          06-14 11:34:02.436: I/DEBUG(12725): waitpid: n=13585 status=00000b7f
          06-14 11:34:02.436: I/DEBUG(12725): stopped -- fatal signal
          06-14 11:34:02.436: I/DEBUG(12725): pid: 13485, tid: 135
          85 >>> <<<
          06-14 11:34:02.436: I/DEBUG(12725): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000014
          06-14 11:34:02.436: I/DEBUG(12725): scr 20000010
          06-14 11:34:02.521: I/DEBUG(12725): #00 pc 0003443e /system/lib/


          • #6
            Great. Thanks for the information!