Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 284377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:27:11+00:00 2026-05-12T05:27:11+00:00

The JavaEE API comes with the HttpServletResponseWrapper which, to quote the javadoc, provides a

  • 0

The JavaEE API comes with the HttpServletResponseWrapper which, to quote the javadoc, “provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet.” Without subclassing, this class just passes all calls through to the wrapped response object. There’s a similar wrapper for requests.

Can anyone point me at any utility libraries that provide useful subclass implementations of these classes? Particularly, I’m looking for a subclass of the response wrapper that captures the written response (as a String, byte[], whatever’s appropriate) and exposes it via an API method.

I’ve written a rather half-baked version myself, but frankly, I shouldn’t have to, and I’d rather throw it away and use one off the shelf.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:27:11+00:00Added an answer on May 12, 2026 at 5:27 am

    I am not aware of any implementation, even though the gzip example can be adapted easily by just writing to a ByteArrayOutputStream. You can also take ideas by looking at other response wrapper implementations at:

    • SiteMesh
    • DWR also uses it

    Original answer:

    There is the classic article in JavaWorld Filter code with Servlet 2.3 model. You can find examples for wrapped request and response:

    • Compression the response

      public class CompressionResponseWrapper extends HttpServletResponseWrapper {
        protected ServletOutputStream stream = null;
        protected PrintWriter writer = null;
        protected int threshold = 0;
        protected HttpServletResponse origResponse = null;
        public CompressionResponseWrapper(HttpServletResponse response) {
      super(response);
      origResponse = response;
        }
        public void setCompressionThreshold(int threshold) {
      this.threshold = threshold;
        }
        public ServletOutputStream createOutputStream() throws IOException {
      return (new CompressionResponseStream(origResponse));
        }
        public ServletOutputStream getOutputStream() throws IOException {
      if (writer != null) {
        throw new IllegalStateException("getWriter() has already been " +
                                        "called for this response");
      }
      if (stream == null) {
        stream = createOutputStream();
      }
      ((CompressionResponseStream) stream).setCommit(true);
      ((CompressionResponseStream) stream).setBuffer(threshold);
      return stream;
        }
        public PrintWriter getWriter() throws IOException {
      if (writer != null) {
        return writer;
      }
      if (stream != null) {
        throw new IllegalStateException("getOutputStream() has already " +
                                        "been called for this response");
      }
      stream = createOutputStream();
      ((CompressionResponseStream) stream).setCommit(true);
      ((CompressionResponseStream) stream).setBuffer(threshold);
      writer = new PrintWriter(stream);
      return writer;
        }
      }
      
    • Handling file upload

      public class MultipartWrapper extends HttpServletRequestWrapper {
        MultipartRequest mreq = null;
        public MultipartWrapper(HttpServletRequest req, String dir)
                                       throws IOException {
      super(req);
      mreq = new MultipartRequest(req, dir);
        }
        // Methods to replace HSR methods
        public Enumeration getParameterNames() {
      return mreq.getParameterNames();
        }
        public String getParameter(String name) {
      return mreq.getParameter(name);
        }
        public String[] getParameterValues(String name) {
      return mreq.getParameterValues(name);
        }
        public Map getParameterMap() {
      Map map = new HashMap();
      Enumeration enum = getParameterNames();
      while (enum.hasMoreElements()) {
        String name = (String) enum.nextElement();
        map.put(name, mreq.getParameterValues(name));
      }
      return map;
        }
        // Methods only in MultipartRequest
        public Enumeration getFileNames() {
      return mreq.getFileNames();
        }
        public String getFilesystemName(String name) {
      return mreq.getFilesystemName(name);
        }
        public String getContentType(String name) {
      return mreq.getContentType(name);
        }
        public File getFile(String name) {
      return mreq.getFile(name);
        }
      }
      

    The code is a bit old (june 2001!), but it demonstrate the usage well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 310k
  • Answers 310k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Starting with element loaded up in $elem var $closestRelativeParent =… May 13, 2026 at 10:13 pm
  • Editorial Team
    Editorial Team added an answer My issue was the jquery dialog box I was using… May 13, 2026 at 10:13 pm
  • Editorial Team
    Editorial Team added an answer You can create it like any other controls. place a… May 13, 2026 at 10:13 pm

Related Questions

I work for a insurance company. We have our own development department made-up of
So we ran into an interesting issue today. We have a Java EE web
I'm currently in the research phase of my dissertation project. My project is a
I was always using JDBC in JavaSE on single-threaded environment. But now I need

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.