sahaya / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Wrong Charset when reading the Response #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

public void test() throws Exception {
        ResponseBuilder b = new ResponseBuilder();
        b.setHeaders(new Headers());
        b.setBody(new ByteArrayInputStream("äöü".getBytes("UTF-8")));
        b.setStatusCode(200);
        b.setContentType("application/json;charset=UTF-8");
        Response r = b.build();
        // works
        assertEquals("äöü",new String(r.asByteArray(), "UTF-8"));

        b = new ResponseBuilder();
        b.setHeaders(new Headers());
        b.setBody(new ByteArrayInputStream("äöü".getBytes("UTF-8")));
        b.setStatusCode(200);
        b.setContentType("application/json;charset=UTF-8");
        r = b.build();
        // uses the Defaultcharset instead of UTF-8 eg. on Windows 1252
        assertEquals("äöü",r.asString());

        b = new ResponseBuilder();
        b.setHeaders(new Headers(new Header("charset", "UTF-8")));
        b.setBody(new ByteArrayInputStream("äöü".getBytes("UTF-8")));
        b.setStatusCode(200);
        //b.setContentType("application/json;charset=UTF-8");
        r = b.build();
        /* throws java.lang.NullPointerException: Cannot invoke method close() on null object
            at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:77)
            at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
            at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:32)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
            at com.jayway.restassured.internal.RestAssuredResponseImpl.convertStreamToString(RestAssuredResponseImpl.groovy:343)
            at com.jayway.restassured.internal.RestAssuredResponseImpl.this$2$convertStreamToString(RestAssuredResponseImpl.groovy)
            at com.jayway.restassured.internal.RestAssuredResponseImpl$this$2$convertStreamToString.callCurrent(Unknown Source)
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
            at com.jayway.restassured.internal.RestAssuredResponseImpl.asString(RestAssuredResponseImpl.groovy:131) 
        */  
        assertEquals("äöü",r.asString());

    }

What is the expected output? What do you see instead?
 See the Test.

What version of the product are you using? On what operating system?
1.5 on Windows7 64Bit

Please provide any additional information below.

Original issue reported on code.google.com by mbue...@gmail.com on 2 Feb 2012 at 3:21

GoogleCodeExporter commented 9 years ago
Hi, 

This is a known issue and it should be resolved in 1.6-SNAPSHOT. Would you 
please be so kind and try it out with the new version? If you're using Maven 
depend on version 1.6-SNAPSHOT and when adding the following repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

Original comment by johan.ha...@gmail.com on 3 Feb 2012 at 7:25

GoogleCodeExporter commented 9 years ago
I've ran your test successfully so it seems to work in the new version.

Original comment by johan.ha...@gmail.com on 3 Feb 2012 at 7:39

GoogleCodeExporter commented 9 years ago
Hi,
it works with 1.6-SNAPSHOT. Thank you and keep gooing the good work. I really 
like rest-assured

Original comment by mbue...@gmail.com on 3 Feb 2012 at 8:29

GoogleCodeExporter commented 9 years ago
Thanks! :)

Original comment by johan.ha...@gmail.com on 3 Feb 2012 at 9:14