Post request throws java.lang.IllegalArgumentException: Don't know how to encode as a byte stream with custom Content-Type

1,577 views
Skip to first unread message

reachout6

unread,
Jul 18, 2015, 10:17:29 PM7/18/15
to rest-a...@googlegroups.com

http://localhost:8080/objective

Headers headers = new Headers("Content-Type=application/vnd.xxx.lrn.v1.yyy+jsonid","X-Authorization=access_token=xxxxxxx");


given().log().all().headers(headers).body("").log().all().post(requestUrl);


I am getting the following error:


FAILED: testName

java.lang.IllegalArgumentException: Don't know how to encode  as a byte stream

at com.jayway.restassured.internal.http.EncoderRegistry.encodeStream(EncoderRegistry.java:129)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1074)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at groovy.lang.Closure.call(Closure.java:423)

at com.jayway.restassured.internal.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1078)

at com.jayway.restassured.internal.http.HTTPBuilder$RequestConfigDelegate.setPropertiesFromMap(HTTPBuilder.java:992)

at com.jayway.restassured.internal.http.HTTPBuilder.post(HTTPBuilder.java:328)

at com.jayway.restassured.internal.http.HTTPBuilder$post$2.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)

at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1056)

at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendRequest(RequestSpecificationImpl.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:807)

at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)

at com.jayway.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:31)

at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)

at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)

at com.jayway.restassured.filter.log.RequestLoggingFilter.filter(RequestLoggingFilter.java:101)

at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)

at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)

at com.jayway.restassured.filter.log.RequestLoggingFilter.filter(RequestLoggingFilter.java:101)

at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)

at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)

at com.jayway.restassured.filter.FilterContext$next.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)

at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:950)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:807)

at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)

at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1373)

at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)

at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:807)

at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)

at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)

at com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy:155)

at com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy)

at com.pearson.media.tests.LearningObjectiveTests.learningObjectiveGetID(LearningObjectiveTests.java:39)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)

at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)

at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)

at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)

at org.testng.TestRunner.privateRun(TestRunner.java:767)

at org.testng.TestRunner.run(TestRunner.java:617)

at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)

at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)

at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)

at org.testng.SuiteRunner.run(SuiteRunner.java:240)

at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)

at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)

at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)

at org.testng.TestNG.run(TestNG.java:1057)

at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)

at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)

at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)




Todd Bradley

unread,
Jul 19, 2015, 10:02:52 AM7/19/15
to rest-a...@googlegroups.com
You're probably not allowed to use the equals sign in a header key. It kinda looks like you are trying to set two headers, but the syntax you're using is setting just one. Remember the key and value are two separate strings. 

And now that I look at it, the Javadoc for Headers doesn't even list a constructor that takes strings. Try creating two Header instances and passing those in to the Headers constructor. 




---
Sent from Boxer | http://getboxer.com

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

reachout6

unread,
Jul 19, 2015, 8:44:02 PM7/19/15
to rest-a...@googlegroups.com

This is what actually I am doing

public static final Header vndContentType = new Header("Content-Type",

        "application/vnd.xxx.lrn.v1.yyy+jsonid")
public static final Header auth = new Header(" X-Authorization","access_token=xxxxxxx")


Headers headers = new Headers(vndContentType, auth);



given().log().all().headers(headers).body("").log().all().post(requestUrl);



I use the same format for my other api calls it works,  I still get the same error. I think the problem could be with the custom header definition. 



Todd Bradley

unread,
Jul 19, 2015, 11:26:01 PM7/19/15
to rest-a...@googlegroups.com
What happens if you remove the leading space from " X-Authorization"? Do you get the same behavior?

On Sun, Jul 19, 2015 at 6:42 PM, reachout6 <aarth...@gmail.com> wrote:
Hi Todd,

This is what actually I am doing

public static final Header vndContentType = new Header("Content-Type",

        "application/vnd.xxx.lrn.v1.yyy+jsonid")
public static final Header auth = new Header(" X-Authorization","access_token=xxxxxxx")


Headers headers = new Headers(vndContentType, auth);



given().log().all().headers(headers).body("").log().all().post(requestUrl);



I use the same format for my other api calls it works,  I still get the same error. I think the problem could be with the custom header definition. Any help will be appreciated.







On Sunday, July 19, 2015 at 10:02:52 AM UTC-4, Todd Bradley wrote:

reachout6

unread,
Jul 20, 2015, 10:23:45 AM7/20/15
to rest-a...@googlegroups.com
Yes, same behavior.

Johan Haleby

unread,
Aug 7, 2015, 9:22:30 AM8/7/15
to rest-a...@googlegroups.com
Please try the latest snapshot (2.4.2-SNAPSHOT) to see if there's any difference. Just must add the following Maven repo:

<repositories>
        <repository>
            <id>sonatype</id>
            <snapshots />
        </repository>
</repositories>

/Johan

Reply all
Reply to author
Forward
0 new messages