0

When I enable http trace in SpringBoot application (https://stackoverflow.com/a/59115579/6700081) then using the /httptrace endpoint I am able to view all the requests (only headers. not request body) that hit the application.

Is it possible to also view all the requests sent out from the application to other applications like Rest services, webservices, etc in /httptrace endpoint?

I want to know what are all the external services that my application is connecting to, when I send a particular request to the application

firstpostcommenter
  • 2,328
  • 4
  • 30
  • 59
  • 2
    `requests sent out from the application to other applications like Rest services, webservices` Yes. but it depends on what are you using to connect to other apps. are you using RestTemplate, WebServiceTemplate etc? If so, create a bean of these classes, provide logging interceptor and use the autowired instance of these beans to do calls to other apps – gtiwari333 Sep 30 '20 at 17:49

1 Answers1

0

if you are using RestTemplate for your Rest call, then you can add an ClientHttpRequestInterceptor as suggested by gtiwari333.

    public class LoggingInterceptor implements ClientHttpRequestInterceptor {
     
        static Logger log = LoggerFactory.getLogger(LoggingInterceptor.class);
     
        @Override
        public ClientHttpResponse intercept(HttpRequest req, byte[] reqBody, ClientHttpRequestExecution ex)
          throws IOException {
            log.debug("Request body: {}", new String(reqBody, StandardCharsets.UTF_8));
            ClientHttpResponse response = ex.execute(req, reqBody);
            InputStreamReader isr = new InputStreamReader(response.getBody(), StandardCharsets.UTF_8);
            String body = new BufferedReader(isr)
              .lines()
              .collect(Collectors.joining("\n"));
            log.debug("Response body: {}", body);
            return response;
        }
    }
Katy
  • 1,023
  • 7
  • 19