org.springframework.http.HttpMessage Java Examples

The following examples show how to use org.springframework.http.HttpMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpHeadersForPropagationTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #2
Source File: HttpHeadersForPropagationTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example #3
Source File: WingtipsSpringUtilTest.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    resetTracing();

    httpMessageMock = mock(HttpMessage.class);
    headersMock = mock(HttpHeaders.class);
    doReturn(headersMock).when(httpMessageMock).getHeaders();

    successCallbackMock = mock(SuccessCallback.class);
    failureCallbackMock = mock(FailureCallback.class);
    listenableFutureCallbackMock = mock(ListenableFutureCallback.class);

    tagStrategyMock = mock(HttpTagAndSpanNamingStrategy.class);
    tagAdapterMock = mock(HttpTagAndSpanNamingAdapter.class);
}
 
Example #4
Source File: LoggingInterceptor.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
private void log(HttpMessage message) throws IOException {
  if(message instanceof HttpRequest) {
    HttpRequest request = (HttpRequest) message;
    log.info("URI: {}", request.getURI());
    log.info("Method: {}", request.getMethod());
  } else if(message instanceof ClientHttpResponse) {
    ClientHttpResponse response = (ClientHttpResponse) message;
    log.info("Status code: {}", response.getStatusCode());
  } else {
    return;
  }
  log.info("Headers:");
  message.getHeaders().forEach((k, v) -> log.info("    " + k + ": " + v));
  log.info("----------------------------------------------------------------------------");
}
 
Example #5
Source File: SerializableObjectHttpMessageConverter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void setContentLength(final HttpMessage message, final byte[] messageBody) {
  message.getHeaders().setContentLength(messageBody.length);
}
 
Example #6
Source File: HttpHeadersForPropagation.java    From wingtips with Apache License 2.0 4 votes vote down vote up
public HttpHeadersForPropagation(HttpMessage httpMessage) {
    this(extractHttpHeaders(httpMessage));
}
 
Example #7
Source File: HttpHeadersForPropagation.java    From wingtips with Apache License 2.0 4 votes vote down vote up
protected static HttpHeaders extractHttpHeaders(HttpMessage httpMessage) {
    if (httpMessage == null) {
        throw new IllegalArgumentException("httpMessage cannot be null");
    }
    return httpMessage.getHeaders();
}
 
Example #8
Source File: SerializableObjectHttpMessageConverter.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
protected void setContentLength(final HttpMessage message, final byte[] messageBody) {
  message.getHeaders().setContentLength(messageBody.length);
}
 
Example #9
Source File: WingtipsSpringUtil.java    From wingtips with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example #10
Source File: DecoderHttpMessageReader.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine the Content-Type of the HTTP message based on the
 * "Content-Type" header or otherwise default to
 * {@link MediaType#APPLICATION_OCTET_STREAM}.
 * @param inputMessage the HTTP message
 * @return the MediaType, possibly {@code null}.
 */
@Nullable
protected MediaType getContentType(HttpMessage inputMessage) {
	MediaType contentType = inputMessage.getHeaders().getContentType();
	return (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
}
 
Example #11
Source File: DecoderHttpMessageReader.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine the Content-Type of the HTTP message based on the
 * "Content-Type" header or otherwise default to
 * {@link MediaType#APPLICATION_OCTET_STREAM}.
 * @param inputMessage the HTTP message
 * @return the MediaType, possibly {@code null}.
 */
@Nullable
protected MediaType getContentType(HttpMessage inputMessage) {
	MediaType contentType = inputMessage.getHeaders().getContentType();
	return (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
}