Hello,
I'm working on a project where we send XML data to servlets. The data can
be sent by a process that either opens a connection to the servlet and sends
it directly (via an HTTP POST method), or as an uploaded file via a form on
a web
page. Now, what we need to do is if the XML data is sent via direct
connection and POST we send the data back as a "text/xml" content type. If
the data is 'uploaded' via a form we send the response back as a file and
set the content-disposition like this:
reply.getMimeHeaders().setHeader("content-disposition", "attachment;
filename=download.xml");
The problem is that we want to move this functionality into a filter. That
way we can have various servlets that can support the same capability
without copying code. The *problem* is that if the response data is over a
certain size the content-dispostion is being ignored.... I inherited the
filter code from another programmer, and what seems to be happening is that
before we can change the content-disposition in the filter part of the data
has already been flushed out. My question is, how do I buffer or "hold
back" the output stream that's now hitting the filter code on the way back
to the client and modify the content-disposition accordingly.
I've included code snippets of our approach so you can see what we're
doing... Any suggestions would be much appreciated. I've thought about
perhaps making a custom HttpServletResponseWrapper and possibly buffering
the output there until the filter is ready to work with it
private String MULTIPART_CONTENT_TYPE = "multipart/form-data";
private String XML_CONTENT_TYPE = "text/xml";
(in doFilter)
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
String contentType = httpServletRequest.getContentType();
if (contentType == null) return;
boolean fileUploadDownload = contentType.indexOf(MULTIPART_CONTENT_TYPE)
!= -1;
//wrapperX extends HttpServletRequestWrapper and includes a few
overridden bethods to
//support our efforts - among them are setContentType and setInputStream
WrapperX wrapperX = new WrapperX((HttpServletRequest)request);
if (fileUploadDownload) {
wrapperX.setContentType(XML_CONTENT_TYPE);
wrapperX.setInputStream(new
WrapperS(getInputStream(httpServletRequest)));
}
filterChain.doFilter(wrapperX, response);
if (fileUploadDownload) {
HttpServletResponse httpServletResponse =
(HttpServletResponse)response;
counter++;
httpServletResponse.setHeader("Content-Disposition:","attachment;
filename=SubmitResponse_" + counter + ".xml" );
System.out.println("getBufferSize()"+httpServletResponse.getBufferSize());
}
--
David Orriss Jr.
Please email me if you want my ICQ/AIM/IM ID's.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html