Java Code Examples for org.springframework.web.client.ResponseExtractor

Following code examples demonstrate how to use org.springframework.web.client.ResponseExtractorfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.client.ResponseExtractorand various code implementation of this class.

    @Override
    public <T> T execute(String url, HttpMethod method,
            RequestCallback requestCallback,
            ResponseExtractor<T> responseExtractor, Object... urlVariables) {

        return super.execute(urlBuilder.build(url), method,
                new UserAgentAwareRequestCallback(requestCallback),
                responseExtractor, urlVariables);
    } 


    @Override
    public <T> T execute(String url, HttpMethod method,
            RequestCallback requestCallback,
            ResponseExtractor<T> responseExtractor, Map<String, ?> urlVariables) {

        return super.execute(urlBuilder.build(url), method,
                new UserAgentAwareRequestCallback(requestCallback),
                responseExtractor, urlVariables);
    } 

    @Override
    protected <T> T doExecute(URI url, HttpMethod method, RequestCallback requestCallback, final ResponseExtractor<T> responseExtractor)
            throws RestClientException {

        return super.doExecute(url, method, requestCallback, new ResponseExtractor<T>() {
            public T extractData(ClientHttpResponse response) throws IOException {
                    response.getHeaders().setContentType(MediaType.TEXT_XML);

                return responseExtractor.extractData(response);
            }
        });
    } 

    protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
        super.getResponseExtractor();
        return new YammerOAuth2AccessTokenExtractor();
    } 

Advertisement
Javadoc
Generic callback interface used by RestTemplate's retrieval methods Implementations of this interfac

e perform the actual work of extracting data from a ClientHttpResponse, but don't need to worry about exception handling or closing resources.

Used internally by the RestTemplate, but also useful for application code. There is one available factory method, see RestTemplate#responseEntityExtractor(Type). @author Arjen Poutsma @since 3.0 @param the data type @see RestTemplate#execute

Read More
Advertisement