mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-03 21:49:03 +00:00
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -234,7 +234,7 @@ public class ContentNegotiationManagerFactoryBean
|
||||
strategies.add(new HeaderContentNegotiationStrategy());
|
||||
}
|
||||
|
||||
if(this.defaultNegotiationStrategy != null) {
|
||||
if (this.defaultNegotiationStrategy != null) {
|
||||
strategies.add(defaultNegotiationStrategy);
|
||||
}
|
||||
|
||||
|
||||
+16
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,6 @@ import java.util.List;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.http.converter.GenericHttpMessageConverter;
|
||||
@@ -31,12 +30,12 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Response extractor that uses the given {@linkplain HttpMessageConverter entity
|
||||
* converters} to convert the response into a type {@code T}.
|
||||
* Response extractor that uses the given {@linkplain HttpMessageConverter entity converters}
|
||||
* to convert the response into a type {@code T}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @see RestTemplate
|
||||
* @since 3.0
|
||||
* @see RestTemplate
|
||||
*/
|
||||
public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
|
||||
@@ -48,19 +47,18 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
|
||||
private final Log logger;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
|
||||
* response type and message converters. The given converters must support the response
|
||||
* type.
|
||||
* Create a new instance of the {@code HttpMessageConverterExtractor} with the given response
|
||||
* type and message converters. The given converters must support the response type.
|
||||
*/
|
||||
public HttpMessageConverterExtractor(Class<T> responseType, List<HttpMessageConverter<?>> messageConverters) {
|
||||
this((Type) responseType, messageConverters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
|
||||
* response type and message converters. The given converters must support the response
|
||||
* type.
|
||||
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given response
|
||||
* type and message converters. The given converters must support the response type.
|
||||
*/
|
||||
public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters) {
|
||||
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
|
||||
@@ -76,12 +74,12 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public T extractData(ClientHttpResponse response) throws IOException {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public T extractData(ClientHttpResponse response) throws IOException {
|
||||
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
|
||||
if(!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
|
||||
if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
|
||||
return null;
|
||||
}
|
||||
MediaType contentType = getContentType(responseWrapper);
|
||||
@@ -107,9 +105,9 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RestClientException(
|
||||
"Could not extract response: no suitable HttpMessageConverter found for response type [" +
|
||||
this.responseType + "] and content type [" + contentType + "]");
|
||||
|
||||
throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +
|
||||
"for response type [" + this.responseType + "] and content type [" + contentType + "]");
|
||||
}
|
||||
|
||||
private MediaType getContentType(ClientHttpResponse response) {
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ class MessageBodyClientHttpResponseWrapper implements ClientHttpResponse {
|
||||
responseStatus == HttpStatus.NOT_MODIFIED) {
|
||||
return false;
|
||||
}
|
||||
else if(this.getHeaders().getContentLength() == 0) {
|
||||
else if (this.getHeaders().getContentLength() == 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user