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

  • Home
  • SEARCH
  • 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 580571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:29:13+00:00 2026-05-13T14:29:13+00:00

I’m looking for a way to inspect the contents of a HttpServletResponse to sign

  • 0

I’m looking for a way to inspect the contents of a HttpServletResponse to sign them with a MD5 hash.

The pseudocode might look like this

process(Response response, Request request){

defaultProcessingFor(response,request);

dispatcher.handle(response,request);

// Here I want to read the contents of the Response object (now filled with data) to create a MD5 hash with them and add it to a header.
}

Is that possible?

  • 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-13T14:29:14+00:00Added an answer on May 13, 2026 at 2:29 pm

    Yes, that’s possible. You need to decorate the response with help of HttpServletResponseWrapper wherein you replace the ServletOutputStream with a custom implementation which writes the bytes to both the MD5 digest and the “original” outputstream. Finally provide an accessor to obtain the final MD5 sum.

    Update I just for fun played a bit round it, here’s a kickoff example:

    The response wrapper:

    public class MD5ServletResponse extends HttpServletResponseWrapper {
    
        private final MD5ServletOutputStream output;
        private final PrintWriter writer;
    
        public MD5ServletResponse(HttpServletResponse response) throws IOException {
            super(response);
            output = new MD5ServletOutputStream(response.getOutputStream());
            writer = new PrintWriter(output, true);
        }
    
        public PrintWriter getWriter() throws IOException {
            return writer;
        }
    
        public ServletOutputStream getOutputStream() throws IOException {
            return output;
        }
    
        public byte[] getHash() {
            return output.getHash();
        }
    
    }
    

    The MD5 outputstream:

    public class MD5ServletOutputStream extends ServletOutputStream {
    
        private final ServletOutputStream output;
        private final MessageDigest md5;
    
        {
            try {
                md5 = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException e) {
                throw new ExceptionInInitializerError(e);
            }
        }
    
        public MD5ServletOutputStream(ServletOutputStream output) {
            this.output = output;
        }
    
        public void write(int i) throws IOException {
            byte[] b = { (byte) i };
            md5.update(b);
            output.write(b, 0, 1);
        }
    
        public byte[] getHash() {
            return md5.digest();
        }
    
    }
    

    How to use it:

    // Wrap original response with it:
    MD5ServletResponse md5response = new MD5ServletResponse(response);
    
    // Now just use md5response instead or response, e.g.:
    dispatcher.handle(request, md5response);
    
    // Then get the hash, e.g.:
    byte[] hash = md5response.getHash();
    StringBuilder hashAsHexString = new StringBuilder(hash.length * 2);
    for (byte b : hash) {
        hashAsHexString.append(String.format("%02x", b));
    }
    System.out.println(hashAsHexString); // Example af28cb895a479397f12083d1419d34e7.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.