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 927541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:52:14+00:00 2026-05-15T19:52:14+00:00

In order to debug failing requests I would like to print all information coming

  • 0

In order to debug failing requests I would like to print all information coming from HttpServletRequest.

Now, it’s possible that a request will partially fail (for ex. Several matches are successful, yet one has failed) in which case I would like to catch the exception in the internal method that failed, print the error + the ServletUtil.toStringHttpServletRequest() and continue providing service (degraded but still useful vs. complete request failure).

Our current implementation either catches the exception and prints dumb info (“getRules failed”) or throws the exception all the way to doGet() (effectively canceling service for the user) where as in doGet() I have access to HttpServletRequest where I can print at the relevant debug info (headers, parameters…).

Passing HttpServletRequest to every function called during the request that might fail seems a bit ugly, I will do it if no other elegant solution will pop up.

Making a before head ServletUtil.toStringHttpServletRequest() and storing it in a ThreadLocal map would be wasteful both in memory and CPU time. For some reason it feels wrong to store the HttpServletRequest object in ThreadLocal (please correct if I’m wrong).

Debug information is written both to local machine log and is emailed directly to devs (Great work log4j TLSSMTPAppender), so logging in several places won’t be practical (Will need to assemble several emails to understand what’s going on) and ssh’ing into the server is old age 🙂 (We’re all cloudy here… server might not exist by the time I get to look at the error)

So, my solution is gaining access to a “PrintErrorUtility” (TODO: better name it). That will receive (String errorMsg, Throwable t, HttpServletRequest) which will print the error together will all the relevant info… This will be called from internal try {} catch blocks that will notify about the error but will not cancel the request because of it.

Obviously I’m taking about servers running in production.

Comments? Please advise.

Thank you, Maxim.

  • 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-15T19:52:15+00:00Added an answer on May 15, 2026 at 7:52 pm

    Do this task in a Filter after the FilterChain#doFilter() call. The ServletRequest object is already there. In the business code where this exception is to be suppressed gracefully, store the exception as a request attribute and just let the Filter check/grab it from the request.


    Update: as per the comments, here’s an example:

    public class Context { 
        private static ThreadLocal<Context> instance = new ThreadLocal<Context>();
        private HttpServletRequest request;
        private List<Exception> exceptions = new ArrayList<Exception>();
    
        private Context(HttpServletRequest request) {
            this.request = request;
            this.request.setAttribute("exceptions", exceptions);
        }
    
        public static Context getCurrentInstance() {
            return instance.get();
        }
    
        public static Context newInstance(HttpServletRequest request) {
            Context context = new Context(request);
            instance.set(context);
            return context;
        }
    
        public void release() {
            instance.remove();
        }
    
        public void addException(Exception exception) {
            exceptions.add(exception);
        }
    }
    

    And here’s how to use it in your controller servlet:

    Context context = Context.newInstance(request);
    try {
        executeBusinessCode();
    } finally {
        context.release();
    }
    

    And here’s how you could use it in the executed business code:

    } catch (Exception e) {
        Context.getCurrentInstance().addException(e);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to debug I would like to dump certain variables on to my
In order to debug an issue with our usage of Hibernate, I would like
In order to develop and debug mobile and tablet applications, I'd like to be
Order deny,allow deny from all allow from xx.xx.x.xx RewriteRule . - [F] I have
In order to debug strange behavior in a Swing-application I'd like to replace the
is it possible to configure gdb in order to debug assembly code when there
I would like to monitor(debug) a linux dynamic library written in C. I want
in order to recover data from server I use XMLHttpRequest and my code is
In order to debug a production issue, I need a tool to decrypt an
I have a class that modifies data via some extension methods. In order to

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.