开发者

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

开发者 https://www.devze.com 2023-02-07 02:13 出处:网络
I am building a web-service that returns a mu开发者_运维知识库ltipart 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.

I am building a web-service that returns a mu开发者_运维知识库ltipart 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.


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();


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号