JavierSolis / resting

Automatically exported from code.google.com/p/resting
0 stars 0 forks source link

Crash when using UTF8 to post message #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an Android application that uses this library, then do this:

ServiceResponse postResponse = Resting.post("someuri", 8081, "somemessage", 
UTF8);

3. Run the application.

What is the expected output? What do you see instead?

No crash.  Instead, an EncodingNotSupported exception is thrown on line 89 of 
PostServiceContext.cs here:

entity = new StringEntity(message,  "text/plain; 
charset=\""+encoding.getName()+"\"");

Should this line by using the 3-parameter version of the StringEntity 
constructor, as documented here:  
http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/ent
ity/StringEntity.html
I.e. passing the contentType as the mimeType argument rather than concatenating 
it with the coding argument?

What version of the product are you using? On what operating system?
0.7, Android.

Please provide any additional information below.

Can you please provide (e.g. in the wiki) some instructions on how to utilize 
this library from source on Android, rather than by using the .jar file?  This 
will allow proper debugging of such issues as well as extending features.  
Thanks :)

Original issue reported on code.google.com by peter.g....@gmail.com on 30 Jan 2012 at 5:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Here's my updated version of setMessageEntity() that doesn't crash:

    private HttpEntity setMessageEntity(String message, EncodingTypes encoding, ContentType contentType){
        StringEntity entity = null;

        try {
            entity = new StringEntity(message);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        if (encoding != null) {
            entity.setContentEncoding(encoding.getName());  
        }
        if (contentType != null) {
            entity.setContentType(contentType.getName());   
        }

        return entity;      
    }//setMessageEntity

Also, I worked out how to use the library from source - Create a new Android 
project, copy source into it, and change the Java Compliance version from 1.5 
to 1.6, then project properties - Android, select 'Is Library'.  Then you can 
reference it from another Android project.  Thanks.

Original comment by peter.g....@gmail.com on 30 Jan 2012 at 6:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Fixed in source. To be part of release 0.8.

Original comment by sujata...@gmail.com on 10 Apr 2012 at 10:59