Search in sources :

Example 11 with RequestCallback

use of org.springframework.web.client.RequestCallback in project incubator-servicecomb-java-chassis by apache.

the class CseRestTemplate method httpEntityCallback.

@Override
protected <T> RequestCallback httpEntityCallback(Object requestBody) {
    RequestCallback callback = super.httpEntityCallback(requestBody);
    CseRequestCallback cseCallback = new CseRequestCallback(requestBody, callback);
    return cseCallback;
}
Also used : RequestCallback(org.springframework.web.client.RequestCallback)

Example 12 with RequestCallback

use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.

the class TestRestTemplateWrapper method executeWithUnderlyingRestTemplate.

@Test
public void executeWithUnderlyingRestTemplate() {
    RequestCallback requestCallback = clientHttpRequest -> {
    };
    ResponseExtractor<ResponseEntity<String>> responseExtractor = clientHttpResponse -> responseEntity;
    ResponseEntity<String> actual;
    for (HttpMethod method : httpMethods) {
        when(underlying.execute(url, method, requestCallback, responseExtractor, param1, param2)).thenReturn(responseEntity);
        actual = wrapper.execute(url, method, requestCallback, responseExtractor, param1, param2);
        assertThat(actual, is(responseEntity));
        verify(underlying).execute(url, method, requestCallback, responseExtractor, param1, param2);
        when(underlying.execute(url, method, requestCallback, responseExtractor, paramsMap)).thenReturn(responseEntity);
        actual = wrapper.execute(url, method, requestCallback, responseExtractor, paramsMap);
        assertThat(actual, is(responseEntity));
        verify(underlying).execute(url, method, requestCallback, responseExtractor, paramsMap);
        when(underlying.execute(uri, method, requestCallback, responseExtractor)).thenReturn(responseEntity);
        actual = wrapper.execute(uri, method, requestCallback, responseExtractor);
        assertThat(actual, is(responseEntity));
        verify(underlying).execute(uri, method, requestCallback, responseExtractor);
    }
}
Also used : IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) GET(org.springframework.http.HttpMethod.GET) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) HashMap(java.util.HashMap) PATCH(org.springframework.http.HttpMethod.PATCH) DELETE(org.springframework.http.HttpMethod.DELETE) Collections.singletonList(java.util.Collections.singletonList) Assert.assertThat(org.junit.Assert.assertThat) HashSet(java.util.HashSet) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) HEAD(org.springframework.http.HttpMethod.HEAD) DefaultUriBuilderFactory(org.springframework.web.util.DefaultUriBuilderFactory) UriTemplateHandler(org.springframework.web.util.UriTemplateHandler) URI(java.net.URI) OPTIONS(org.springframework.http.HttpMethod.OPTIONS) PUT(org.springframework.http.HttpMethod.PUT) RestTemplate(org.springframework.web.client.RestTemplate) Before(org.junit.Before) RequestEntity(org.springframework.http.RequestEntity) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) POST(org.springframework.http.HttpMethod.POST) ResponseExtractor(org.springframework.web.client.ResponseExtractor) HttpHeaders(org.springframework.http.HttpHeaders) HttpMethod(org.springframework.http.HttpMethod) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) RequestCallback(org.springframework.web.client.RequestCallback) Randomness.uniquify(com.seanyinx.github.unit.scaffolding.Randomness.uniquify) Mockito.never(org.mockito.Mockito.never) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) TRACE(org.springframework.http.HttpMethod.TRACE) ResponseEntity(org.springframework.http.ResponseEntity) OK(org.springframework.http.HttpStatus.OK) Mockito.reset(org.mockito.Mockito.reset) Mockito.mock(org.mockito.Mockito.mock) ResponseEntity(org.springframework.http.ResponseEntity) RequestCallback(org.springframework.web.client.RequestCallback) HttpMethod(org.springframework.http.HttpMethod) Test(org.junit.Test)

Example 13 with RequestCallback

use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.

the class CseRestTemplate method getForObject.

@Override
@Nullable
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
    RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
    CseHttpMessageConverterExtractor<T> responseExtractor = new CseHttpMessageConverterExtractor<>();
    return execute(url, HttpMethod.GET, requestCallback, responseExtractor, uriVariables);
}
Also used : RequestCallback(org.springframework.web.client.RequestCallback) Nullable(org.springframework.lang.Nullable)

Example 14 with RequestCallback

use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.

the class CseRestTemplate method httpEntityCallback.

@Override
public <T> RequestCallback httpEntityCallback(Object requestBody) {
    RequestCallback callback = super.httpEntityCallback(requestBody);
    CseRequestCallback cseCallback = new CseRequestCallback(requestBody, callback, null);
    return cseCallback;
}
Also used : RequestCallback(org.springframework.web.client.RequestCallback)

Example 15 with RequestCallback

use of org.springframework.web.client.RequestCallback in project java-chassis by ServiceComb.

the class CseRestTemplate method postForObject.

// HEAD
// no override
// POST
@Override
@Nullable
public <T> T postForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) throws RestClientException {
    RequestCallback requestCallback = httpEntityCallback(request, responseType);
    CseHttpMessageConverterExtractor<T> responseExtractor = new CseHttpMessageConverterExtractor<>();
    return execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables);
}
Also used : RequestCallback(org.springframework.web.client.RequestCallback) Nullable(org.springframework.lang.Nullable)

Aggregations

RequestCallback (org.springframework.web.client.RequestCallback)24 Nullable (org.springframework.lang.Nullable)9 HttpHeaders (org.springframework.http.HttpHeaders)7 RestTemplate (org.springframework.web.client.RestTemplate)7 IOException (java.io.IOException)6 ResponseEntity (org.springframework.http.ResponseEntity)5 URI (java.net.URI)4 Date (java.util.Date)4 List (java.util.List)4 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)4 Map (java.util.Map)3 Set (java.util.Set)3 Test (org.junit.Test)3 MediaType (org.springframework.http.MediaType)3 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)3 ResponseExtractor (org.springframework.web.client.ResponseExtractor)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 Randomness.uniquify (com.seanyinx.github.unit.scaffolding.Randomness.uniquify)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2