@Test public void testTrackResponse() throws Exception { String requestUri = "/v2.0/" + tenantId + "/metrics/search"; when(httpRequestMock.getUri()).thenReturn(requestUri); when(httpMethodMock.toString()).thenReturn("GET"); when(httpRequestMock.getMethod()).thenReturn(httpMethodMock); List<String> paramValues = new ArrayList<String>(); paramValues.add("locator1"); queryParams.put("query", paramValues); when((httpRequestMock).getQueryParams()).thenReturn(queryParams); when(httpResponseStatusMock.code()).thenReturn(200); when(httpResponseMock.getStatus()).thenReturn(httpResponseStatusMock); String result = "[TRACKER] Response for tenantId " + tenantId; when(httpResponseMock.content()).thenReturn(Unpooled.copiedBuffer(result.getBytes("UTF-8"))); tracker.addTenant(tenantId); tracker.trackResponse(httpRequestMock, httpResponseMock); verify(loggerMock, atLeastOnce()).info("[TRACKER] tenantId " + tenantId + " added."); verify(loggerMock, times(1)).info("[TRACKER] Response for tenantId " + tenantId + " GET request " + requestUri + "?query=locator1\n" + "RESPONSE_STATUS: 200\n" + "RESPONSE HEADERS: \n" + "RESPONSE_CONTENT:\n" + "[TRACKER] Response for tenantId " + tenantId); }
public void trackResponse(HttpRequest request, FullHttpResponse response) { if (request == null) return; if (response == null) return; String tenantId = findTid( request.getUri() ); if (isTracking(tenantId)) { HttpResponseStatus status = response.getStatus(); String messageBody = response.content().toString(Constants.DEFAULT_CHARSET); String queryParams = getQueryParameters(request); String headers = ""; for (String headerName : response.headers().names()) { headers += "\n" + headerName + "\t" + response.headers().get(headerName); } String responseContent = ""; if ((messageBody != null) && (!messageBody.isEmpty())) { responseContent = "\nRESPONSE_CONTENT:\n" + messageBody; } String logMessage = "[TRACKER] " + "Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams + "\nRESPONSE_STATUS: " + status.code() + "\nRESPONSE HEADERS: " + headers + responseContent; log.info(logMessage); } }
Tracker implements TrackerMBean { public void trackResponse(HttpRequest request, FullHttpResponse response) { if (request == null) return; if (response == null) return; String tenantId = findTid( request.getUri() ); if (isTracking(tenantId)) { HttpResponseStatus status = response.getStatus(); String messageBody = response.content().toString(Constants.DEFAULT_CHARSET); String queryParams = getQueryParameters(request); String headers = ""; for (String headerName : response.headers().names()) { headers += "\n" + headerName + "\t" + response.headers().get(headerName); } String responseContent = ""; if ((messageBody != null) && (!messageBody.isEmpty())) { responseContent = "\nRESPONSE_CONTENT:\n" + messageBody; } String logMessage = "[TRACKER] " + "Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams + "\nRESPONSE_STATUS: " + status.code() + "\nRESPONSE HEADERS: " + headers + responseContent; log.info(logMessage); } } }
Tracker implements TrackerMBean { public void trackResponse(HttpRequest request, FullHttpResponse response) { if (request == null) return; if (response == null) return; String tenantId = findTid( request.getUri() ); if (isTracking(tenantId)) { HttpResponseStatus status = response.getStatus(); String messageBody = response.content().toString(Constants.DEFAULT_CHARSET); String queryParams = getQueryParameters(request); String headers = ""; for (String headerName : response.headers().names()) { headers += "\n" + headerName + "\t" + response.headers().get(headerName); } String responseContent = ""; if ((messageBody != null) && (!messageBody.isEmpty())) { responseContent = "\nRESPONSE_CONTENT:\n" + messageBody; } String logMessage = "[TRACKER] " + "Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams + "\nRESPONSE_STATUS: " + status.code() + "\nRESPONSE HEADERS: " + headers + responseContent; log.info(logMessage); } } private  Tracker(); }
Tracker implements TrackerMBean { public void trackResponse(HttpRequest request, FullHttpResponse response) { if (request == null) return; if (response == null) return; String tenantId = findTid( request.getUri() ); if (isTracking(tenantId)) { HttpResponseStatus status = response.getStatus(); String messageBody = response.content().toString(Constants.DEFAULT_CHARSET); String queryParams = getQueryParameters(request); String headers = ""; for (String headerName : response.headers().names()) { headers += "\n" + headerName + "\t" + response.headers().get(headerName); } String responseContent = ""; if ((messageBody != null) && (!messageBody.isEmpty())) { responseContent = "\nRESPONSE_CONTENT:\n" + messageBody; } String logMessage = "[TRACKER] " + "Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams + "\nRESPONSE_STATUS: " + status.code() + "\nRESPONSE HEADERS: " + headers + responseContent; log.info(logMessage); } } private  Tracker(); static Tracker getInstance(); synchronized void register(); void addTenant(String tenantId); void removeTenant(String tenantId); void removeAllTenants(); Set getTenants(); void addMetricName(String metricName); void removeMetricName(String metricName); void removeAllMetricNames(); Set<String> getMetricNames(); void setIsTrackingDelayedMetrics(); void resetIsTrackingDelayedMetrics(); boolean getIsTrackingDelayedMetrics(); boolean isTracking(String tenantId); boolean doesMessageContainMetricNames(String logmessage); void track(HttpRequest request); void trackResponse(HttpRequest request, FullHttpResponse response); void trackDelayedMetricsTenant(String tenantid, final List<Metric> delayedMetrics); void trackDelayedAggregatedMetricsTenant(String tenantId, long collectionTimeMs, long delayTimeMs, List<String> delayedMetricNames); }
Tracker implements TrackerMBean { public void trackResponse(HttpRequest request, FullHttpResponse response) { if (request == null) return; if (response == null) return; String tenantId = findTid( request.getUri() ); if (isTracking(tenantId)) { HttpResponseStatus status = response.getStatus(); String messageBody = response.content().toString(Constants.DEFAULT_CHARSET); String queryParams = getQueryParameters(request); String headers = ""; for (String headerName : response.headers().names()) { headers += "\n" + headerName + "\t" + response.headers().get(headerName); } String responseContent = ""; if ((messageBody != null) && (!messageBody.isEmpty())) { responseContent = "\nRESPONSE_CONTENT:\n" + messageBody; } String logMessage = "[TRACKER] " + "Response for tenantId " + tenantId + " " + request.getMethod() + " request " + request.getUri() + queryParams + "\nRESPONSE_STATUS: " + status.code() + "\nRESPONSE HEADERS: " + headers + responseContent; log.info(logMessage); } } private  Tracker(); static Tracker getInstance(); synchronized void register(); void addTenant(String tenantId); void removeTenant(String tenantId); void removeAllTenants(); Set getTenants(); void addMetricName(String metricName); void removeMetricName(String metricName); void removeAllMetricNames(); Set<String> getMetricNames(); void setIsTrackingDelayedMetrics(); void resetIsTrackingDelayedMetrics(); boolean getIsTrackingDelayedMetrics(); boolean isTracking(String tenantId); boolean doesMessageContainMetricNames(String logmessage); void track(HttpRequest request); void trackResponse(HttpRequest request, FullHttpResponse response); void trackDelayedMetricsTenant(String tenantid, final List<Metric> delayedMetrics); void trackDelayedAggregatedMetricsTenant(String tenantId, long collectionTimeMs, long delayTimeMs, List<String> delayedMetricNames); static final String trackerName; }