The following issue has been updated: Updater: Keith Garry Boyce (mailto:[EMAIL PROTECTED]) Date: Sun, 10 Oct 2004 11:28 PM Comment: Did some refactoring for ATG and it works for ATG. Unfortunately this does not work for Jetty jetty-4.2.22. BufferedResponseWrapper.getWriter gets called before TableTag.writeExport and even though addHeader gets called by getWriter() I never see the header in BufferedResponseWrapper.
This leads me to believe that the contract about when these things get called and if things get populated is different for different containers. Can you try it on jetty and see what you think? Changes: Attachment changed to displaytag.zip --------------------------------------------------------------------- For a full history of the issue, see: http://jira.codehaus.org/browse/DISPL-30?page=history --------------------------------------------------------------------- View the issue: http://jira.codehaus.org/browse/DISPL-30 Here is an overview of the issue: --------------------------------------------------------------------- Key: DISPL-30 Summary: Spring Interceptor for use with servlet 2.2 containers Type: New Feature Status: Unassigned Priority: Minor Original Estimate: Unknown Time Spent: Unknown Remaining: Unknown Project: DisplayTag Components: Export Versions: 1.0 RC1 Assignee: Reporter: fabrizio giustina Created: Sat, 2 Oct 2004 4:13 AM Updated: Sun, 10 Oct 2004 11:28 PM Description: Se http://forum.springframework.org/viewtopic.php?t=1004 and displaytag-user mailing list Boyce, Keith Garry I developed an interceptor to use instead of responseOverrideFilter for use in Servlet 2.2 containers with ServletWrapperController (posted on jira). Please give me credit in javadoc if you decide to use it. Here is the code: Code: /* * DisplayTagInterceptor.java * * Copyright 2004 by Electronic Data Systems * Corporation. All rights reserved. * * An unpublished work created Sep 26, 2004, 2004. This work is a * trade secret of EDS and unauthorized use or copying * is prohibited. * */ package org.springframework.web.servlet.mvc; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.displaytag.filter.BufferedResponseWrapper; import org.displaytag.tags.TableTag; import org.displaytag.tags.TableTagParameters; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.HandlerAdapter; /** * @author jztb88 * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class DisplayTagInterceptor implements HandlerInterceptor { final static Log log = LogFactory.getLog(DisplayTagInterceptor.class); /* (non-Javadoc) * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object) */ public boolean preHandle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Object handler) throws Exception { if (servletRequest.getParameter(TableTagParameters.PARAMETER_EXPORTING) == null) { if (log.isDebugEnabled()) { log.debug("Filter has been called, but PARAMETER_EXPORTING parameter has not been found."); } return true; } HttpServletRequest request = (HttpServletRequest) servletRequest; BufferedResponseWrapper wrapper = new BufferedResponseWrapper((HttpServletResponse) servletResponse); // In a portlet environment, you do not have direct access to the actual request object, so any attribute that // is added will not be visible outside of your portlet. So instead, users MUST append to the StringBuffer, so // that the portlets do not have to bind a new attribute to the request. request.setAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY, new StringBuffer(8096)); request.setAttribute(TableTag.FILTER_CONTENT_OVERRIDE_TYPE, new StringBuffer(80)); request.setAttribute(TableTag.FILTER_CONTENT_OVERRIDE_FILENAME, new StringBuffer(80)); HandlerAdapter handlerAdaptor = new SimpleControllerHandlerAdapter(); handlerAdaptor.handle(request,wrapper,handler); String pageContent; String contentType; StringBuffer buf = (StringBuffer) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY); HttpServletResponse resp = (HttpServletResponse) servletResponse; String characterEncoding = resp.getCharacterEncoding(); if (characterEncoding != null) { characterEncoding = "; charset=" + characterEncoding; } if (buf != null && buf.length() > 0) { pageContent = buf.toString(); contentType = ObjectUtils.toString(request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_TYPE)); if (log.isDebugEnabled()) { log.debug("Overriding output, writing new output with content type " + contentType); } StringBuffer filename = (StringBuffer) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_FILENAME); if (filename != null && StringUtils.isNotEmpty(filename.toString())) { if (log.isDebugEnabled()) { log.debug("Filename specified as " + filename); } resp.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); } } else { log.debug("NOT overriding input. "); pageContent = wrapper.toString(); contentType = wrapper.getContentType(); } if (contentType != null) { if (contentType.indexOf("charset") > -1) { // charset is already specified (see #921811) servletResponse.setContentType(contentType); } else { servletResponse.setContentType(contentType + StringUtils.defaultString(characterEncoding)); } } servletResponse.setContentLength(pageContent.length()); PrintWriter out = servletResponse.getWriter(); out.write(pageContent); out.close(); return false; } /* (non-Javadoc) * @see org.springframework.web.servlet.HandlerInterceptor#postHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.web.servlet.ModelAndView) */ public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3) throws Exception { // Nothing to do } /* (non-Javadoc) * @see org.springframework.web.servlet.HandlerInterceptor#afterCompletion(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception) */ public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throws Exception { // Nothing to do } } --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ displaytag-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/displaytag-devel