public HttpHeadersForPropagation(HttpMessage httpMessage) { this(extractHttpHeaders(httpMessage)); }
/** * Sets the tracing headers on the given {@link HttpMessage#getHeaders()} with values from the given {@link Span}. * Does nothing if any of the given arguments are null (i.e. it is safe to pass null, but nothing will happen). * Usually you'd want to use one of the interceptors to handle tracing propagation for you * ({@link WingtipsClientHttpRequestInterceptor} or {@link WingtipsAsyncClientHttpRequestInterceptor}), however * you can call this method to do manual propagation if needed. * * <p>This method conforms to the <a href="https://github.com/openzipkin/b3-propagation">B3 propagation spec</a>. * * @param httpMessage The {@link HttpMessage} to set tracing headers on. Can be null - if this is null then this * method will do nothing. * @param span The {@link Span} to get the tracing info from to set on the headers. Can be null - if this is null * then this method will do nothing. */ public static void propagateTracingHeaders(HttpMessage httpMessage, Span span) { HttpHeadersForPropagation headersForPropagation = (httpMessage == null) ? null : new HttpHeadersForPropagation(httpMessage); HttpRequestTracingUtils.propagateTracingHeaders(headersForPropagation, span); }
@Test public void setHeader_passes_through_to_httpHeaders() { // given HttpHeaders headersMock = mock(HttpHeaders.class); HttpHeadersForPropagation impl = new HttpHeadersForPropagation(headersMock); String headerKey = UUID.randomUUID().toString(); String headerValue = UUID.randomUUID().toString(); // when impl.setHeader(headerKey, headerValue); // then verify(headersMock).set(headerKey, headerValue); }
/** * Sets the tracing headers on the given {@link HttpMessage#getHeaders()} with values from the given {@link Span}. * Does nothing if any of the given arguments are null (i.e. it is safe to pass null, but nothing will happen). * Usually you'd want to use one of the interceptors to handle tracing propagation for you * ({@link WingtipsClientHttpRequestInterceptor} or {@link WingtipsAsyncClientHttpRequestInterceptor}), however * you can call this method to do manual propagation if needed. * * <p>This method conforms to the <a href="https://github.com/openzipkin/b3-propagation">B3 propagation spec</a>. * * @param httpMessage The {@link HttpMessage} to set tracing headers on. Can be null - if this is null then this * method will do nothing. * @param span The {@link Span} to get the tracing info from to set on the headers. Can be null - if this is null * then this method will do nothing. */ public static void propagateTracingHeaders(HttpMessage httpMessage, Span span) { HttpHeadersForPropagation headersForPropagation = (httpMessage == null) ? null : new HttpHeadersForPropagation(httpMessage); HttpRequestTracingUtils.propagateTracingHeaders(headersForPropagation, span); }
@Test public void constructor_with_HttpHeaders_arg_throws_IllegalArgumentException_when_passed_null() { // when Throwable ex = catchThrowable(() -> new HttpHeadersForPropagation((HttpHeaders)null)); // then assertThat(ex) .isInstanceOf(IllegalArgumentException.class) .hasMessage("httpHeaders cannot be null"); }
public HttpHeadersForPropagation(HttpMessage httpMessage) { this(extractHttpHeaders(httpMessage)); }
@Test public void constructor_with_HttpMessage_arg_throws_IllegalArgumentException_when_passed_null() { // when Throwable ex = catchThrowable(() -> new HttpHeadersForPropagation((HttpMessage)null)); // then assertThat(ex) .isInstanceOf(IllegalArgumentException.class) .hasMessage("httpMessage cannot be null"); }
@Test public void constructor_with_HttpHeaders_arg_sets_fields_as_expected() { // given HttpHeaders headersMock = mock(HttpHeaders.class); // when HttpHeadersForPropagation impl = new HttpHeadersForPropagation(headersMock); // then assertThat(impl.httpHeaders).isSameAs(headersMock); }
@Test public void constructor_with_HttpMessage_arg_sets_fields_as_expected() { // given HttpHeaders headersMock = mock(HttpHeaders.class); HttpMessage messageMock = mock(HttpMessage.class); doReturn(headersMock).when(messageMock).getHeaders(); // when HttpHeadersForPropagation impl = new HttpHeadersForPropagation(messageMock); // then assertThat(impl.httpHeaders).isSameAs(headersMock); }