6

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.

2
  • A more useful Google keyword may be comet and/or multipart/x-mixed-replaced. Commented Jan 26, 2011 at 21:07
  • Did you find a suitable library or did you end up building your own? I'm hitting the same problem now. Commented May 4, 2011 at 10:26

2 Answers 2

6

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();
Sign up to request clarification or add additional context in comments.

Comments

-1

Have you tried the Apache HttpClient project? I haven't looked at it since it broke out from the Apache Commons stuff, but I know it did a lot with multi-part responses.

This is for consuming - not sure if there is anything for producing, but it might be a place to start.

http://hc.apache.org/httpclient-3.x/methods/multipartpost.html

2 Comments

This is not for consuming multipart responses. HttpClient produces multipart requests. An example of a consumer of multipart requests would be the Commons FileUpload. OP is specifically asking for producing multipart responses. I'm not sure if HttpClient supports consuming multipart responses. Multipart responses are pretty rare.
HttpClient will consume multi-part responses. I could not find any facility for producing mulit-part responses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.