Results 1 to 6 of 6

Thread: Needs feature to specify charset in StringHttpMessageConverter

  1. #1
    Join Date
    Jun 2008
    Posts
    4

    Default 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().

    Code:
    	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.

    Code:
    	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. #2
    Join Date
    Nov 2010
    Posts
    174

    Default

    @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.

    [1] https://jira.springsource.org/browse/ANDROID-82
    Roy Clarkson
    Spring Mobile Projects Lead

  3. #3
    Join Date
    Nov 2010
    Posts
    174

    Default

    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.

    https://jira.springsource.org/browse/ANDROID-88
    Roy Clarkson
    Spring Mobile Projects Lead

  4. #4
    Join Date
    Nov 2010
    Posts
    174

    Default

    @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!
    Roy Clarkson
    Spring Mobile Projects Lead

  5. #5
    Join Date
    Jun 2008
    Posts
    4

    Default

    @Roy Clarkson

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

    https://gist.github.com/2927754

    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/libicuuc.so" 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!


    [QUOTE]
    ....
    06-14 11:34:02.236: D/charset(13485): And_charset_comparisonActivity.run: 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 >>> kr.pe.kingori.exp.charset <<<
    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/libicuuc.so

  6. #6
    Join Date
    Nov 2010
    Posts
    174

    Default

    Great. Thanks for the information!
    Roy Clarkson
    Spring Mobile Projects Lead

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •