UploadIdResponseInterceptor implements HttpResponseInterceptor { @Override public void interceptResponse(HttpResponse response) throws IOException { if (!LOG.isDebugEnabled()) { return; } String uploadId = response.getHeaders().getFirstHeaderStringValue(UPLOAD_HEADER); if (uploadId == null) { return; } GenericUrl url = response.getRequest().getUrl(); if (url.get(UPLOAD_ID_PARAM) == null && url.get(UPLOAD_TYPE_PARAM) != null) { LOG.debug( "Upload ID for url {} on worker {} is {}", url, System.getProperty("worker_id"), uploadId); } }  @Override void interceptResponse(HttpResponse response);  }
@Test public void testResponseNoLogging() throws IOException { new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, null, null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", "a", null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, "h", null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", null, null)); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, null, "type")); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("hh", "a", "type")); new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse(null, "h", "type")); expectedLogs.verifyNotLogged(""); }
@Test public void testResponseLogs() throws IOException { new UploadIdResponseInterceptor().interceptResponse(buildHttpResponse("abc", null, "type")); GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL); url.put("uploadType", "type"); String worker = System.getProperty("worker_id"); expectedLogs.verifyDebug("Upload ID for url " + url + " on worker " + worker + " is abc"); }