Claudia Claudia - 1 month ago 22
Java Question

How to write Restfuse HttpTest with MULTIPART_FORM_DATA?

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

Answer

Take a look at this answer and full explanation here

You need to add this header to your request:

 Accept-Encoding:multipart/form-data