'Retrieve value of 'contentWritten' from 'HttpServletResponse' Object
I have a function which have 'HttpServletResponse' object named 'lResponse'. I want to get the size of the Http Response. I want to retrieve a value of attribute 'contentWritten' from that object (lResponse object) so that I will save it in the 'responseSize' variable and pass it to the next function. The current code/function is like this.
private void filterPublicRequest(HttpServletRequest lRequest, HttpServletResponse lResponse, DbRouteMonitor dbRouteMonitor, FilterChain pFilterChain) throws IOException, ServletException {
if (lRequest.getRequestURI().contains(API_ROUTE) && ConfigHelper.isMonitorEnabled()) {
int id = dbRouteMonitorService.addMonitorData(dbRouteMonitor);
pFilterChain.doFilter(lRequest, lResponse);
String responseSize = "";
//code here to get response size from 'lResponse' Object and pass to 'updateResponseData' function.
dbRouteMonitorService.updateResponseData(id, lResponse.getStatus(), responseSize);
} else {
pFilterChain.doFilter(lRequest, lResponse);
}
}
When I debug this code I am getting value of 'contentWritten' attribute in the 'HttpServletResponse' Object (for example here that value of 'contentWritten' is 445872). I want to assign it to the variable 'responseSize'. Please have look at below snapshot.
How could I get the value of the attribute 'contentWritten' from the 'HttpResponseObject'?
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

