@Test public void testWithProperties() { registerRequestToken("testBasic"); addTraceTokenProperties("key-b", "value-b", "key-a", "value-a", "key-c", "value-c"); TraceTokenRequestFilter filter = new TraceTokenRequestFilter(); Request original = prepareGet().setUri(URI.create("http: Request filtered = filter.filterRequest(original); assertNotSame(filter, original); assertEquals(filtered.getUri(), original.getUri()); assertEquals(original.getHeaders().size(), 0); assertEquals(filtered.getHeaders().size(), 1); assertEquals(filtered.getHeaders().get(TRACETOKEN_HEADER), ImmutableList.of("{\"id\":\"testBasic\",\"key-b\":\"value-b\",\"key-a\":\"value-a\",\"key-c\":\"value-c\"}")); }
@Override public Request filterRequest(Request request) { requireNonNull(request, "request is null"); TraceToken token = getCurrentTraceToken(); if (token == null) { return request; } String tokenString; if (token.size() == 1) { tokenString = token.toString(); } else { tokenString = TRACE_TOKEN_JSON_CODEC.toJson(token); } return fromRequest(request) .addHeader(TRACETOKEN_HEADER, tokenString) .build(); }
TraceTokenRequestFilter implements HttpRequestFilter { @Override public Request filterRequest(Request request) { requireNonNull(request, "request is null"); TraceToken token = getCurrentTraceToken(); if (token == null) { return request; } String tokenString; if (token.size() == 1) { tokenString = token.toString(); } else { tokenString = TRACE_TOKEN_JSON_CODEC.toJson(token); } return fromRequest(request) .addHeader(TRACETOKEN_HEADER, tokenString) .build(); } }
TraceTokenRequestFilter implements HttpRequestFilter { @Override public Request filterRequest(Request request) { requireNonNull(request, "request is null"); TraceToken token = getCurrentTraceToken(); if (token == null) { return request; } String tokenString; if (token.size() == 1) { tokenString = token.toString(); } else { tokenString = TRACE_TOKEN_JSON_CODEC.toJson(token); } return fromRequest(request) .addHeader(TRACETOKEN_HEADER, tokenString) .build(); }  }
TraceTokenRequestFilter implements HttpRequestFilter { @Override public Request filterRequest(Request request) { requireNonNull(request, "request is null"); TraceToken token = getCurrentTraceToken(); if (token == null) { return request; } String tokenString; if (token.size() == 1) { tokenString = token.toString(); } else { tokenString = TRACE_TOKEN_JSON_CODEC.toJson(token); } return fromRequest(request) .addHeader(TRACETOKEN_HEADER, tokenString) .build(); }  @Override Request filterRequest(Request request); @Override boolean equals(Object obj); @Override int hashCode(); }
TraceTokenRequestFilter implements HttpRequestFilter { @Override public Request filterRequest(Request request) { requireNonNull(request, "request is null"); TraceToken token = getCurrentTraceToken(); if (token == null) { return request; } String tokenString; if (token.size() == 1) { tokenString = token.toString(); } else { tokenString = TRACE_TOKEN_JSON_CODEC.toJson(token); } return fromRequest(request) .addHeader(TRACETOKEN_HEADER, tokenString) .build(); }  @Override Request filterRequest(Request request); @Override boolean equals(Object obj); @Override int hashCode(); static final String TRACETOKEN_HEADER; }