Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store request data and reponse data into database in spring boot application

Tags:

spring-boot

I am working on to store request data and response data if there any exceptions encountered while sending response back to client I need to store the exception also.

My DB table will ID,RequestData,ResponseData,Exception,TimeTakenToRespond

lets say I have endpoint called /athenticateUser so my input data would be

RequestData :{"username":"mate","password":"swamy"}

ResponseData :{"FirstName":"mate","LastName":"swamy","Email":"[email protected]"}

Like the above way I need to store all the request data and response data if any exception while sending response back to client that also we need store and the web service time taken respond.

As I am beginner to spring boot please guide step by step

like image 305
mantelinga r Avatar asked Nov 15 '25 13:11

mantelinga r


2 Answers

Though you can write Interceptors, Filters etc for this. But don't do it.

Please try to use Spring Boot feature Actuator for tracing. It provides HTTP request logging out of the box.

There's an endpoint mapped to /trace or /actuator/httptrace which will show you last 100 HTTP requests. You can customize it to log each request, or write to a DB.

You will need spring-boot-starter-actuator dependency.

You can also whitelist endpoints.

For the guide step by step, you can check this actuator tutorial.

like image 98
Tarun Avatar answered Nov 17 '25 10:11

Tarun


You can do it by using spring boot actuator httptrace..

add below dependency:

 implementation('org.springframework.boot:spring-boot-starter-actuator')

Look at this step by step guide..

like image 26
GolamMazid Sajib Avatar answered Nov 17 '25 08:11

GolamMazid Sajib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!