Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a java utility to produce http multi-part responses?

I am building a web-service that returns a multipart response. I know the format for constructing a multi-part response; and I will build my own tools if I can't find existing tools.

Perhaps I just need help with my google-foo. Everything I find is about POSTing or consuming multi-part messages. Nothing about producing multi-part responses.

like image 699
Fred Haslam Avatar asked Jan 26 '11 19:01

Fred Haslam


1 Answers

You can use oreilly servlets http://www.servlets.com/cos/

An example is in the javadoc: http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartResponse.html

import com.oreilly.servlet.MultipartResponse

//javax.servlet.http.HttpServletResponse res
MultipartResponse multi = new MultipartResponse(res);

multi.startResponse("text/plain");
out.println("On your mark");
multi.endResponse();

try { Thread.sleep(1000); } catch (InterruptedException e) { }

multi.startResponse("text/plain");
out.println("Get set");
multi.endResponse();

try { Thread.sleep(1000); } catch (InterruptedException e) { }

multi.startResponse("image/gif");
ServletUtils.returnFile(req.getRealPath("/images/go.gif"), out);

multi.finish();
like image 123
aweigold Avatar answered Oct 15 '22 17:10

aweigold