@Before
 public void setup() throws Exception {
   mockClientTracer = mock(ClientTracer.class);
   mockExecutionContext = mock(ClientExecutionContext.class);
   mockClientRequest = buildClientRequest();
   when(mockExecutionContext.getRequest()).thenReturn(mockClientRequest);
   mockClientResponse = buildClientResponse();
   when(mockExecutionContext.proceed()).thenReturn(mockClientResponse);
   interceptor = new BraveClientExecutionInterceptor(mockClientTracer);
 }
  @Override
  public ClientResponse execute(ClientExecutionContext context) throws Exception {
    if (context.getRequest().getBody() != null) {
      return context.proceed(); // let the MBW handle this
    }

    MultivaluedMap<String, Object> headers = context.getRequest().getHeadersAsObjects();
    List<DKIMSignature> list = getHeaders(headers);

    for (DKIMSignature dosetaSignature : list) {
      KeyRepository repository =
          (KeyRepository) context.getRequest().getAttributes().get(KeyRepository.class.getName());
      sign(repository, headers, null, dosetaSignature);
    }

    return context.proceed();
  }
 protected ClientResponse handleExpired(
     ClientExecutionContext ctx, ClientRequest request, BrowserCache.Entry entry)
     throws Exception {
   ClientResponse response = ctx.proceed();
   if (response.getStatus() == Response.Status.NOT_MODIFIED.getStatusCode()) {
     return updateOnNotModified(request, entry, (BaseClientResponse) response);
   }
   return cache(request, response);
 }
  public ClientResponse execute(ClientExecutionContext ctx) throws Exception {
    ClientRequest request = ctx.getRequest();
    if (!request.getHttpMethod().equals("GET")) {
      return ctx.proceed();
    }

    BrowserCache.Entry entry = getEntry(request);
    if (entry == null) {
      return cache(request, ctx.proceed());
    }

    if (entry.expired()) {
      cache.remove(request.getUri(), entry.getMediaType());
      BrowserCache.Header[] headers = entry.getValidationHeaders();
      for (BrowserCache.Header header : headers) {
        request.header(header.getName(), header.getValue());
      }
      return handleExpired(ctx, request, entry);
    }

    return createClientResponse(request, entry);
  }
  @Test
  public void testExecuteProceedThrowsException() throws Exception {

    final SpanId mockSpanId = mock(SpanId.class);
    when(mockSpanId.getTraceId()).thenReturn(TRACE_ID);
    when(mockSpanId.getSpanId()).thenReturn(SPAN_ID);
    when(mockSpanId.getParentSpanId()).thenReturn(PARENT_SPAN_ID);

    when(mockClientTracer.startNewSpan(PATH)).thenReturn(mockSpanId);
    final IllegalStateException exception = new IllegalStateException("Test exception");
    when(mockExecutionContext.proceed()).thenThrow(exception);

    try {
      interceptor.execute(mockExecutionContext);
      fail("Expected exception.");
    } catch (final IllegalStateException e) {
      assertSame(exception, e);
    }

    final InOrder inOrder = inOrder(mockClientTracer, mockClientRequest, mockExecutionContext);

    inOrder.verify(mockClientTracer).startNewSpan(PATH);
    inOrder.verify(mockClientRequest).header(BraveHttpHeaders.Sampled.getName(), "true");
    inOrder.verify(mockClientRequest).header(BraveHttpHeaders.TraceId.getName(), TRACE_ID_HEX);
    inOrder.verify(mockClientRequest).header(BraveHttpHeaders.SpanId.getName(), SPAN_ID_HEX);
    inOrder
        .verify(mockClientRequest)
        .header(BraveHttpHeaders.ParentSpanId.getName(), Long.toHexString(PARENT_SPAN_ID));
    inOrder.verify(mockClientTracer).setCurrentClientServiceName(CONTEXT_PATH);
    inOrder
        .verify(mockClientTracer)
        .submitBinaryAnnotation(REQUEST_ANNOTATION, HTTP_METHOD + " " + URI);
    inOrder.verify(mockClientTracer).setClientSent();
    inOrder.verify(mockExecutionContext).proceed();
    inOrder.verify(mockClientTracer).submitBinaryAnnotation(HTTP_RESPONSE_CODE_ANNOTATION, 0);
    inOrder.verify(mockClientTracer).submitAnnotation("failure");
    inOrder.verify(mockClientTracer).setClientReceived();
    verifyNoMoreInteractions(mockClientTracer);
  }