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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:25:03+00:00 2026-06-18T00:25:03+00:00

I have controllers that return JSON to the client. The controllers methods are marked

  • 0

I have controllers that return JSON to the client. The controllers methods are marked using mvc annotation such as:

@RequestMapping("/delete.me")
public @ResponseBody Map<String, Object> delete(HttpServletRequest request, @RequestParam("ids[]") Integer[] ids) {

Spring knows to return JSON since Jackson is on the class path and the client is requesting a JSON response. I would like to log the response of these requests and all other controllers. In the past I have used an interceptor to do this. However, I got the response body from the ModelAndView. How can I get the response body in the inteceptor now that I’m using @ResponseBody? Specifically, how can I get the response body in this method?

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
  • 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-06-18T00:25:04+00:00Added an answer on June 18, 2026 at 12:25 am

    You can log everything by using CustomizableTraceInterceptor
    you can either set it in your application context xml config and use AOP: (log level Trace)

        <bean id="customizableTraceInterceptor"  
            class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">  
            <property name="exitMessage" value="Leaving $[methodName](): $[returnValue]" />  
        </bean>  
    

    or you can completly customize it by implementing it in Java and use the method setExitMessage():

    public class TraceInterceptor extends CustomizableTraceInterceptor {
    
        private Logger log = LoggerFactory.getLogger("blabla");
    
        @Override
        protected void writeToLog(Log logger, String message, Throwable ex) {
            //Write debug info when exception is thrown
            if (ex != null) {
                log.debug(message, ex);
            }
              ....
        }
    
        @Override
        protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) {
            return true;
        }
    
        @Override
        public void setExitMessage(String exitMessage) {
                .... //Use PlaceHolders
        }
    }
    

    and use the placeholders such as ‘$[returnValue]’. You can find the complete list in the spring api documentation.

    EDIT: Also, if you want to get the value of your @ResponseBody in another interceptor, I think it’s not possible until version > 3.1.1. Check this issue: https://jira.springsource.org/browse/SPR-9226

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

Sidebar

Related Questions

In one of my controllers, I do have a return that looks like this:
I have an ASP.NET MVC (using the release candidate) application that works with a
I am using Jackson and a ContentNegotiatingViewResolver to return JSON from Spring controllers. When
i have an MVC Controller that returns: public JsonResult ValidateUser(string siteId, string userName, string
I am using asp.net MVC to develop an application that will have ajax interactions.
I have a controller method that returns a jSON object and in one calling
In my controller I have model operations that can return empty results. I've setup
I have the following getJSON that calls an MVC controller which returns inforamtion back:
I have many controllers that will have some similar behavior, e.g. the user should
I have two view controllers that allow changes to the Address Book. The first

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.