{"action":"created","issue":{"url":"https://api.github.com/repos/jayway/rest-assured/issues/686","repository_url":"https://api.github.com/repos/jayway/rest-assured","labels_url":"https://api.github.com/repos/jayway/rest-assured/issues/686/labels{/name}","comments_url":"https://api.github.com/repos/jayway/rest-assured/issues/686/comments","events_url":"https://api.github.com/repos/jayway/rest-assured/issues/686/events","html_url":"https://github.com/jayway/rest-assured/issues/686","id":151548976,"number":686,"title":"Unable to upload file using rest assured","user":{"login":"srivastavas007","id":17219945,"avatar_url":"https://avatars.githubusercontent.com/u/17219945?v=3","gravatar_id":"","url":"https://api.github.com/users/srivastavas007","html_url":"https://github.com/srivastavas007","followers_url":"https://api.github.com/users/srivastavas007/followers","following_url":"https://api.github.com/users/srivastavas007/following{/other_user}","gists_url":"https://api.github.com/users/srivastavas007/gists{/gist_id}","starred_url":"https://api.github.com/users/srivastavas007/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/srivastavas007/subscriptions","organizations_url":"https://api.github.com/users/srivastavas007/orgs","repos_url":"https://api.github.com/users/srivastavas007/repos","events_url":"https://api.github.com/users/srivastavas007/events{/privacy}","received_events_url":"https://api.github.com/users/srivastavas007/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-04-28T04:50:47Z","updated_at":"2016-05-02T07:05:27Z","closed_at":"2016-04-29T08:39:38Z","body":"I am trying to upload file using below code snippet, but getting class not found issue all the time.\r\n public void multiPartUploadingWorksForByteArrays() throws Exception {\r\n        // Given\r\n        final byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream(\"/pic.png\"));\r\n        // When\r\n        given().multiPart(\"file\", \"myFile\", bytes).expect().statusCode(200).body(is(new String(bytes))).when().post(\"---API---\");\r\n    }\r\n\r\nClasses imported are:\r\nimport static com.jayway.restassured.RestAssured.*;\r\n\r\nimport static org.hamcrest.Matchers.is;\r\nimport java.util.ArrayList;\r\nimport org.json.JSONException;\r\nimport org.json.JSONObject;\r\nimport org.testng.Assert;\r\nimport org.testng.annotations.Test;\r\nimport com.jayway.restassured.RestAssured;\r\nimport com.jayway.restassured.builder.RequestSpecBuilder;\r\nimport com.jayway.restassured.response.Response;\r\nimport com.jayway.restassured.specification.RequestSpecification;\r\nimport org.apache.commons.io.IOUtils;\r\n\r\n\r\nVersions used:\r\nRes-assured 2.9.0\r\ngroovy-all 2.3.0\r\nhttpclient 4.2\r\nhttp core 4.2.3\r\nhttpmime 4.3\r\nhamcrestall 1.0\r\nhttpclient cache 4.3.5\r\n\r\nPlease suggest for resolution."},"comment":{"url":"https://api.github.com/repos/jayway/rest-assured/issues/comments/216119824","html_url":"https://github.com/jayway/rest-assured/issues/686#issuecomment-216119824","issue_url":"https://api.github.com/repos/jayway/rest-assured/issues/686","id":216119824,"user":{"login":"johanhaleby","id":187029,"avatar_url":"https://avatars.githubusercontent.com/u/187029?v=3","gravatar_id":"","url":"https://api.github.com/users/johanhaleby","html_url":"https://github.com/johanhaleby","followers_url":"https://api.github.com/users/johanhaleby/followers","following_url":"https://api.github.com/users/johanhaleby/following{/other_user}","gists_url":"https://api.github.com/users/johanhaleby/gists{/gist_id}","starred_url":"https://api.github.com/users/johanhaleby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanhaleby/subscriptions","organizations_url":"https://api.github.com/users/johanhaleby/orgs","repos_url":"https://api.github.com/users/johanhaleby/repos","events_url":"https://api.github.com/users/johanhaleby/events{/privacy}","received_events_url":"https://api.github.com/users/johanhaleby/received_events","type":"User","site_admin":false},"created_at":"2016-05-02T07:05:27Z","updated_at":"2016-05-02T07:05:27Z","body":"Could you add log().all() after \"expect()\" and show us your logs?\n\nOn Mon, May 2, 2016 at 8:58 AM, srivastavas007 <notifications@github.com>\nwrote:\n\n> Hi Johan,\n>\n> Thanks for your reply.\n> The solution worked for class not found issue.\n> But now when I am trying to upload file I am getting protocol exception:\n>\n> org.apache.http.client.ClientProtocolException\n> at\n>\n> org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:886)\n> at\n>\n> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)\n> at\n>\n> org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)\n> at org.apache.http.client.HttpClient$execute$0.call(Unknown Source)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1974)\n> at\n> com.jayway.restassured.internal.http.HTTPBuilder.post(HTTPBuilder.java:341)\n> at com.jayway.restassured.internal.http.HTTPBuilder$post$2.call(Unknown\n> Source)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1159)\n> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n> at\n>\n> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n> at\n>\n> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n> at java.lang.reflect.Method.invoke(Method.java:497)\n> at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)\n> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)\n> at\n>\n> com.jayway.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)\n> at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)\n> at\n>\n> com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)\n> at\n>\n> com.jayway.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)\n> at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)\n> at\n>\n> com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:73)\n> at com.jayway.restassured.filter.FilterContext$next.call(Unknown Source)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1596)\n> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n> at\n>\n> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n> at\n>\n> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n> at java.lang.reflect.Method.invoke(Method.java:497)\n> at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)\n> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:58)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy:164)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy)\n> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n> at\n>\n> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n> at\n>\n> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n> at java.lang.reflect.Method.invoke(Method.java:497)\n> at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)\n> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1210)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1019)\n> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:810)\n> at\n>\n> com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)\n> at\n>\n> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)\n> at\n>\n> com.jayway.restassured.internal.ResponseSpecificationImpl.post(ResponseSpecificationImpl.groovy:293)\n> at\n>\n> com.jayway.restassured.internal.ResponseSpecificationImpl.post(ResponseSpecificationImpl.groovy)\n> at rest.SearchAPI.multiPartUploading(SearchAPI.java:85)\n> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n> at\n>\n> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n> at\n>\n> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n> at java.lang.reflect.Method.invoke(Method.java:497)\n> at\n>\n> org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)\n> at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)\n> at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)\n> at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)\n> at\n>\n> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)\n> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)\n> at org.testng.TestRunner.privateRun(TestRunner.java:782)\n> at org.testng.TestRunner.run(TestRunner.java:632)\n> at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)\n> at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)\n> at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)\n> at org.testng.SuiteRunner.run(SuiteRunner.java:268)\n> at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)\n> at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)\n> at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)\n> at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)\n> at org.testng.TestNG.run(TestNG.java:1064)\n> at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)\n> at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)\n> at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)\n> Caused by: org.apache.http.ProtocolException: Content-Length header already\n> present\n> at org.apache.http.protocol.RequestContent.process(RequestContent.java:96)\n> at\n>\n> org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132)\n> at\n>\n> org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:166)\n> at\n>\n> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:485)\n> at\n>\n> org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)\n> ... 101 more\n>\n>\n> *I have added content length in header and code snippet is:*\n>\n> public void multiPartUploading() throws Exception {\n> // Given\n> final byte[] bytes =\n> IOUtils.toByteArray(getClass().getResourceAsStream(\"/resume.pdf\"));\n> File file = new File(\"--path to resume.pdf--\");\n> long length = file.length();\n> System.out.println(length);\n> Map<String, String> expectedHeaders = new HashMap<String, String>();\n> expectedHeaders.put(\"Content-Length\", \"\"+length);\n> // When\n> given().\n> multiPart(\"file\", \"myFile\", bytes).\n> headers(expectedHeaders).\n> expect().\n> statusCode(200).\n> body(is(new String(bytes))).\n> when().\n> post(\"--API--\");\n> }\n> }\n>\n> And when I am not adding content length in header then I am getting http\n> response 411.\n>\n> Please help with the resolution.\n>\n>\n>\n>\n> Thanks,\n> Pradeep Srivastava\n> +91-8288880192\n>\n> On Fri, Apr 29, 2016 at 2:09 PM, Johan Haleby <notifications@github.com>\n> wrote:\n>\n> > Closed #686 <https://github.com/jayway/rest-assured/issues/686>.\n> >\n> > —\n> > You are receiving this because you authored the thread.\n> > Reply to this email directly or view it on GitHub\n> > <https://github.com/jayway/rest-assured/issues/686#event-645311253>\n> >\n>\n> —\n> You are receiving this because you modified the open/close state.\n> Reply to this email directly or view it on GitHub\n> <https://github.com/jayway/rest-assured/issues/686#issuecomment-216118924>\n>\n"}}