0

I can not figure out, how to write the Rest Test. Please help me out.

I have a RestService:

@POST
@Path("/insertDataInDB")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response insertDataInDB(@FormDataParam("inputfile")
MultipartFormDataInput inputfile) {

    do Stuff
}

The Service works, i tested it with Chromes Rest Console.

Request URI:

http://localhost:8080/persDB/rest/r/insertDataInDB

Content Type:

multipart/form-data

Attachements Files:

Test.xlsx 

Parameter Key:

inputfile

How does the Rest Test look? I tried this
But i can't quite figure it out, where to put the parameter key etc.

@HttpTest(method = Method.POST, path = "persDB/rest/r/insertDataInDB", content = "{}", type = MediaType.MULTIPART_FORM_DATA, file = "inputfile.xlsx")
public void insertDataInDB() { 
  do Stuff
}

and i'm getting a java.io.IOException:

2014-02-04 16:01:30,825   [http-/0.0.0.0:8080-2] SEVERE org.jboss.resteasy.core.SynchronousDispatcher - Failed executing POST r/insertDataInDB: org.jboss.resteasy.spi.ReaderException: java.io.IOException: Unable to get boundary for multipart
cloudy
  • 162
  • 2
  • 14

2 Answers2

0

The problem is that when you set the "Content-Type = multipart/form-data" without a boundary, the server is unable to read the form data appropiately.

The rest server expects something like this: Content-Type = multipart/form-data; boundary=MY_CUSTOM_BOUNDARY

or

Content-Type = multipart/form-data; boundary=-----------------------------28947758029299

If you want to know more about the boundary you can see this link: [What is the boundary in multipart/form-data?

Community
  • 1
  • 1
Ariel Carrera
  • 5,113
  • 25
  • 36
-1

Take a look at this answer and full explanation here

You need to add this header to your request:

 Accept-Encoding:multipart/form-data
Community
  • 1
  • 1
delkant
  • 2,304
  • 1
  • 29
  • 28
  • "The Accept-Encoding request-header field is similar to Accept, but restricts the content-codings (section 3.5) that are acceptable in the response." https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html The exception is clear... "java.io.IOException: Unable to get boundary for multipart" it is because they use "Content-Type: multipart/form-data" in the request without to set the boundary param. – Ariel Carrera Oct 28 '16 at 20:52