title: Get Request/Response Body&Header in Spring AOP
body: <p>I want to get request/response body and header within my aspect before and after if it's available or how to get those .</p>
  
  <p>I mean i think with before  annotation should be work for request,</p>
  
  <p>with after annotation should be work for response. Can be ? </p>
  
  <p><strong>What I've tried so far :</strong></p>
  
  <p>I tried logbook library it's very complicated for me i could'nt figured it out how to work with that.So i gave up.</p>
  
  <p>The actuator can do trick but I am doing extra work like how many times the endpoints called etc.So therefore i can't use actuator.</p>
  
  <p>Also i tried to get request headers like below at least but i think this headers coming same all the time.I couldn't get httpservletresponse like how httpservetrequest does.</p>
  
  <pre><code>HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                  .getRequest();
  </code></pre>
  
  <p>then
  <code>request.getHeader("date")</code> but what about requestbody ?</p>
  
  <p>how to get requestbody ? responsebody ? repsonseheader ?</p>
  
  <p>My aspect file :</p>
  
  <pre><code>@Aspect
  @Component
  public class AppAspect implements ResponseInfo{
  
      @Before("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
      public void loggingStartPointRequests(JoinPoint joinPoint) {
  
  HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
                  .getRequest();
  
  }
  
  @After("execution(@(@org.springframework.web.bind.annotation.RequestMapping *) * *(..))")
      public void loggingEndPointRequests(JoinPoint joinPoint) throws IOException {
  
      }
  
  }
  </code></pre>
  
  <p>My Controller Class:</p>
  
  <pre><code>@RestController
  public class MainController {
  
      @GetMapping("/people") // 
      public ResponseEntity&lt;Poeple&gt; getAllPeople(@RequestParam(name = "page", required = false) Integer page,
              @RequestParam(name = "size", required = false) Integer size,
              @RequestParam(name = "sortBy", required = false) Boolean sortByNameOrEpCount) {
  doSomething();
  }
  
  }
  </code></pre>