getting 500 internal server error when send the request with multipart and json payload. Working in curl command

3,639 views
Skip to first unread message

Rajaram Chelledurai

unread,
Aug 31, 2017, 4:54:33 AM8/31/17
to REST assured
I am getting 500 error  when send the request with multipart and payload. If we call through curl command its working. Can someone help on this? PFB curl and rest-assured logs. 


-----------Curl Command--------------------------
curl -vv -F 'file=@test_request.json;type=application/json' 
-F 'file=@TEST.rpt;type=text/plain' 
-H 'Accept: application/json' 
-H 'Authorization-repo: basic dGVzdDpBRE1JTjo=' 
-H 'Content-Type: multipart/abcd.v1' 


----------------------CURL output----------------------
POST /docs?returnIds=true&responseWaitTime=30000 HTTP/1.1
> User-Agent: curl/7.50.3
> Accept: application/json
> Authorization-repo: basic dGVzdDpBRE1JTjo=
> Content-Length: 22267
> Expect: 100-continue
> Content-Type: multipart/abcd.v1; boundary=------------------------1cbf525395a31c29




------------rest assured code-----------------------------------------
given()
 .header("Accept", "application/json")
 .header("Authorization-repo", "basic "+sAuth)
 .queryParam("returnIds", "true")
.queryParam("responseWaitTime", "30000")
 .body(PayLoad.getArchiveJasonRequest()).contentType(ContentType.JSON)
 .multiPart("file", PayLoad.getInputFile(),"text/plain")
 .contentType("multipart/abcd.v1")
 .log().all().
when().
      post(RestResources.archiveJobResource()).
then()
.assertThat().statusCode(200).and().contentType(ContentType.JSON).log().all();
------------ rest-assured Log -----------------------------------------------------------------------
Proxy: <none>
Request params: <none>
Query params: returnIds=true
responseWaitTime=30000
Form params: <none>
Path params: <none>
Headers: Accept=application/json
Authorization-repo=basic dGVzdDpBRE1JTjo=
Content-Type=multipart/abcd.v1
Cookies: <none>
Multiparts: ------------
Content-Disposition: abcd.v1; name = inputFile1; filename = TEST.rpt
Content-Type: text/plain
\input_files\rpt\TEST.rpt
Body:
{"objects": [ { "source": {"contentUrl": "","encoding": "UTF-8"},"target": {"documentClass": "TEST","type": "txt"},"metadata": [{"name": "SEC","value": "FOO" }]}]}



FAILED: submitFTSJob
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> but was <500>.




Johan Haleby

unread,
Aug 31, 2017, 4:57:14 AM8/31/17
to rest-a...@googlegroups.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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rajaram Chelledurai

unread,
Aug 31, 2017, 5:31:19 AM8/31/17
to REST assured
I tried like below. But still getting same 500 internal error and same log as well.
given()
 .config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))

Johan Haleby

unread,
Aug 31, 2017, 5:45:04 AM8/31/17
to rest-a...@googlegroups.com
Are you using the latest version of REST Assured (3.0.3)?

Johan Haleby

unread,
Aug 31, 2017, 5:46:49 AM8/31/17
to rest-a...@googlegroups.com
I also see that you send two files in the curl command but only in rest assured. And could you also post the response log? (then().log().all())
Message has been deleted

Johan Haleby

unread,
Aug 31, 2017, 6:18:37 AM8/31/17
to rest-a...@googlegroups.com
Very hard to say, but you are missing one of the files that you specify with curl. Try adding it as an additional multipart.

On Thu, Aug 31, 2017 at 11:59 AM, Rajaram Chelledurai <rajaram.c...@gmail.com> wrote:
yes Am using  est-assured:3.0.3

compile 'io.rest-assured:rest-assured:3.0.3'
compile 'io.rest-assured:json-path:3.0.3'
compile 'io.rest-assured:xml-path:3.0.3'
compile 'io.rest-assured:json-schema-validator:3.0.3'

Response Log

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 4481
Date: Thu, 31 Aug 2017 09:55:43 GMT
Connection: close

<html>
  <head>
    <title>Apache Tomcat/8.0.36 - Error report</title>
    <style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
  </head>
  <body>
    <h1>HTTP Status 500 - java.lang.NullPointerException</h1>
    <div class="line"/>
    <p>
      <b>type</b>
 Exception report    </p>
    <p>
      <b>message</b>
      <u>java.lang.NullPointerException</u>
    </p>
    <p>
      <b>description</b>
      <u>The server encountered an internal error that prevented it from fulfilling this request.</u>
    </p>
    <p>
      <b>exception</b>
    </p>
    <pre>javax.servlet.ServletException: java.lang.NullPointerException
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
    <p>
      <b>root cause</b>
    </p>
    <pre>java.lang.NullPointerException
com.mobius.entviewservice.rest.ArchiveResource.isValidRequest(ArchiveResource.java:461)
com.mobius.entviewservice.rest.ArchiveResource.postArchive(ArchiveResource.java:377)
com.mobius.entviewservice.rest.ArchiveResource.postArchiveWithFiles(ArchiveResource.java:362)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:267)
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</pre>
    <p>
      <b>note</b>
      <u>The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs.</u>
    </p>
    <hr class="line"/>
    <h3>Apache Tomcat/8.0.36</h3>
  </body>
</html>

Rajaram Chelledurai

unread,
Aug 31, 2017, 6:21:57 AM8/31/17
to REST assured
Am adding that file as jason body here.

 .body(PayLoad.getArchiveJasonRequest()).contentType(ContentType.JSON) 

Johan Haleby

unread,
Aug 31, 2017, 6:24:10 AM8/31/17
to rest-a...@googlegroups.com
It looks to me that you supply TWO files with curl:

curl -vv -F 'file=@test_request.json;type=application/json' 
         -F 'file=@TEST.rpt;type=text/plain' 

/Johan


On Thu, Aug 31, 2017 at 12:21 PM, Rajaram Chelledurai <rajaram.c...@gmail.com> wrote:
Am adding that file as jason body here.

 .body(PayLoad.getArchiveJasonRequest()).contentType(ContentType.JSON) 

--

Rajaram Chelledurai

unread,
Aug 31, 2017, 6:27:55 AM8/31/17
to REST assured
wowwwwwwwwwwwwwwwwwww. its workinggggggggggggg. After adding payload as multipart file its working....  Thank you very much Johan for your help and valuable time.


On Thursday, August 31, 2017 at 2:24:33 PM UTC+5:30, Rajaram Chelledurai wrote:

Johan Haleby

unread,
Aug 31, 2017, 6:31:43 AM8/31/17
to rest-a...@googlegroups.com
Glad you got it working

Maciej Gawinecki

unread,
Sep 4, 2017, 11:38:29 AM9/4/17
to REST assured
Rajaram,

You can use  curl-logger (https://github.com/dzieciou/curl-logger) in combination with REST-assured. This way you can compare curl from REST-assured request with curl you crafted manually.

Disclaimer. I a developer of curl-logger.

-Maciej
Reply all
Reply to author
Forward
0 new messages