1

I have a Java client which calls one REST web service. The web service accepts data in JSON format and produces data in multipart format. The content-type I have set here for calling the web service is 'application/json'

Now, in the java client I have to get the response and separate multiple files that are there in the multipart response. I have used following code to get the response.

ByteArrayDataSource ds = new ByteArrayDataSource(conn.getInputStream(), "multipart/form-data;boundary=" + boundary); MimeMultipart multipart = new MimeMultipart(ds); System.out.println(multipart.getCount());

When final line is executed, I get following exception

javax.mail.MessagingException: Missing start boundary.

I understand that when it tries to count the files in the response, it does not understand where to start and stop. So, should the webservice set the boundary where files are separated? If yes, how it is done? If no, what can be done?

Vinit Divekar
  • 55
  • 3
  • 7

2 Answers2

0

I think your boundary is wrong The right boundary starts with "--" and then followed by a hash. Try to change the boundary parameter to

"--" + boundary

to see if that helps.

0

I have also faced a similar problem and found a workaround here: https://stackoverflow.com/a/42548549/5236494

Basically I am using javax mail's MimeMultipart class to parse the Multipart response.

kleash
  • 1,211
  • 1
  • 12
  • 31