当前位置: 首页>>代码示例>>Java>>正文


Java GenericHttpMessageConverter.canRead方法代码示例

本文整理汇总了Java中org.springframework.http.converter.GenericHttpMessageConverter.canRead方法的典型用法代码示例。如果您正苦于以下问题:Java GenericHttpMessageConverter.canRead方法的具体用法?Java GenericHttpMessageConverter.canRead怎么用?Java GenericHttpMessageConverter.canRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.http.converter.GenericHttpMessageConverter的用法示例。


在下文中一共展示了GenericHttpMessageConverter.canRead方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractData

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@Override
public T extractData(ResponseEntity<HttpInputMessage> responseEntity) throws IOException {
    MediaType contentType = getContentType(responseEntity);
    for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
        if (messageConverter instanceof GenericHttpMessageConverter) {
            GenericHttpMessageConverter<?> genericMessageConverter =
                    (GenericHttpMessageConverter<?>) messageConverter;
            if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
                return (T) genericMessageConverter.read(this.responseType, null, responseEntity.getBody());
            }
        }
        if (this.responseClass != null) {
            if (messageConverter.canRead(this.responseClass, contentType)) {
                return (T) messageConverter.read((Class) this.responseClass, responseEntity.getBody());
            }
        }
    }

    throw new WxApiResponseException("不能转换相应数据为类型:" + this.responseType, responseEntity);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:21,代码来源:WxApiMessageConverterExtractor.java

示例2: doWithRequest

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
	if (responseType != null) {
		Class<?> responseClass = null;
		if (responseType instanceof Class) {
			responseClass = (Class<?>) responseType;
		}

		List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
		for (HttpMessageConverter<?> converter : getMessageConverters()) {
			if (responseClass != null) {
				if (converter.canRead(responseClass, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}
			else if (converter instanceof GenericHttpMessageConverter) {

				GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
				if (genericConverter.canRead(responseType, null, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}

		}
		if (!allSupportedMediaTypes.isEmpty()) {
			MediaType.sortBySpecificity(allSupportedMediaTypes);
			if (logger.isDebugEnabled()) {
				logger.debug("Setting request Accept header to " +
						allSupportedMediaTypes);
			}
			request.getHeaders().setAccept(allSupportedMediaTypes);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:RestTemplate.java

示例3: extractData

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public T extractData(ClientHttpResponse response) throws IOException {
	if (!hasMessageBody(response)) {
		return null;
	}
	MediaType contentType = getContentType(response);

	for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
		if (messageConverter instanceof GenericHttpMessageConverter) {
			GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter;
			if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseType + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) genericMessageConverter.read(this.responseType, null, response);
			}
		}
		if (this.responseClass != null) {
			if (messageConverter.canRead(this.responseClass, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseClass.getName() + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) messageConverter.read((Class) this.responseClass, response);
			}
		}
	}
	throw new RestClientException(
			"Could not extract response: no suitable HttpMessageConverter found for response type [" +
					this.responseType + "] and content type [" + contentType + "]");
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:HttpMessageConverterExtractor.java

示例4: doWithRequest

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@Override
public void doWithRequest(ClientHttpRequest request) throws IOException {
	if (this.responseType != null) {
		Class<?> responseClass = null;
		if (this.responseType instanceof Class) {
			responseClass = (Class<?>) this.responseType;
		}
		List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
		for (HttpMessageConverter<?> converter : getMessageConverters()) {
			if (responseClass != null) {
				if (converter.canRead(responseClass, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}
			else if (converter instanceof GenericHttpMessageConverter) {
				GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
				if (genericConverter.canRead(this.responseType, null, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}
		}
		if (!allSupportedMediaTypes.isEmpty()) {
			MediaType.sortBySpecificity(allSupportedMediaTypes);
			if (logger.isDebugEnabled()) {
				logger.debug("Setting request Accept header to " + allSupportedMediaTypes);
			}
			request.getHeaders().setAccept(allSupportedMediaTypes);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:31,代码来源:RestTemplate.java

示例5: extractData

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public T extractData(ClientHttpResponse response) throws IOException {
	MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
	if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
		return null;
	}
	MediaType contentType = getContentType(responseWrapper);

	for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
		if (messageConverter instanceof GenericHttpMessageConverter) {
			GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter;
			if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseType + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) genericMessageConverter.read(this.responseType, null, responseWrapper);
			}
		}
		if (this.responseClass != null) {
			if (messageConverter.canRead(this.responseClass, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseClass.getName() + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) messageConverter.read((Class) this.responseClass, responseWrapper);
			}
		}
	}

	throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +
			"for response type [" + this.responseType + "] and content type [" + contentType + "]");
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:HttpMessageConverterExtractor.java

示例6: responseBodyConverter

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
	if (type instanceof Class || type instanceof ParameterizedType) {
		//MediaType contentType = getContentType(responseWrapper);
		MediaType contentType = MediaType.APPLICATION_JSON; //TODO: determine dynamically?
		Class<?> responseClass = (type instanceof Class) ? (Class<?>) type : null;


		for (HttpMessageConverter<?> messageConverter : this.messageConverters.getObject().getConverters()) {
			if (messageConverter instanceof GenericHttpMessageConverter) {
				GenericHttpMessageConverter<?> genericMessageConverter = (GenericHttpMessageConverter<?>) messageConverter;
				if (genericMessageConverter.canRead(type, null, contentType)) {
					if (log.isDebugEnabled()) {
						log.debug("Reading [" + type + "] as \"" +
								contentType + "\" using [" + messageConverter + "]");
					}
					return new SpringResponseConverter(genericMessageConverter, type);
				}
			}
			if (responseClass != null) {
				if (messageConverter.canRead(responseClass, contentType)) {
					if (log.isDebugEnabled()) {
						log.debug("Reading [" + responseClass.getName() + "] as \"" +
								contentType + "\" using [" + messageConverter + "]");
					}
					return new SpringResponseConverter(messageConverter, responseClass);
				}
			}
		}
	}
	return null;
}
 
开发者ID:spring-cloud-incubator,项目名称:spring-cloud-square,代码行数:34,代码来源:SpringConverterFactory.java

示例7: doWithRequest

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void doWithRequest(ClientHttpRequest request) throws IOException {
	if (responseType != null) {
		Class<?> responseClass = null;
		if (responseType instanceof Class) {
			responseClass = (Class<?>) responseType;
		}

		List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
		for (HttpMessageConverter<?> converter : getMessageConverters()) {
			if (responseClass != null) {
				if (converter.canRead(responseClass, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}
			else if (converter instanceof GenericHttpMessageConverter) {

				GenericHttpMessageConverter<?> genericConverter = (GenericHttpMessageConverter<?>) converter;
				if (genericConverter.canRead(responseType, null, null)) {
					allSupportedMediaTypes.addAll(getSupportedMediaTypes(converter));
				}
			}

		}
		if (!allSupportedMediaTypes.isEmpty()) {
			MediaType.sortBySpecificity(allSupportedMediaTypes);
			if (logger.isDebugEnabled()) {
				logger.debug("Setting request Accept header to " +
						allSupportedMediaTypes);
			}
			request.getHeaders().setAccept(allSupportedMediaTypes);
		}
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:35,代码来源:RestTemplate.java

示例8: extractData

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public T extractData(ClientHttpResponse response) throws IOException {
	if (!hasMessageBody(response)) {
		return null;
	}
	MediaType contentType = getContentType(response);

	for (HttpMessageConverter messageConverter : this.messageConverters) {
		if (messageConverter instanceof GenericHttpMessageConverter) {
			GenericHttpMessageConverter genericMessageConverter = (GenericHttpMessageConverter) messageConverter;
			if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseType + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) genericMessageConverter.read(this.responseType, null, response);
			}
		}
		if (this.responseClass != null) {
			if (messageConverter.canRead(this.responseClass, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + this.responseClass.getName() + "] as \"" +
							contentType + "\" using [" + messageConverter + "]");
				}
				return (T) messageConverter.read(this.responseClass, response);
			}
		}
	}
	throw new RestClientException(
			"Could not extract response: no suitable HttpMessageConverter found for response type [" +
					this.responseType + "] and content type [" + contentType + "]");
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:33,代码来源:HttpMessageConverterExtractor.java

示例9: readWithMessageConverters

import org.springframework.http.converter.GenericHttpMessageConverter; //导入方法依赖的package包/类
/**
 * Creates the method argument value of the expected parameter type by reading
 * from the given HttpInputMessage.
 *
 * @param <T> the expected type of the argument value to be created
 * @param inputMessage the HTTP input message representing the current request
 * @param methodParam the method argument
 * @param targetType the type of object to create, not necessarily the same as
 * the method parameter type (e.g. for {@code HttpEntity<String>} method
 * parameter the target type is String)
 * @return the created method argument value
 * @throws IOException if the reading from the request fails
 * @throws HttpMediaTypeNotSupportedException if no suitable message converter is found
 */
@SuppressWarnings("unchecked")
protected <T> Object readWithMessageConverters(HttpInputMessage inputMessage,
		MethodParameter methodParam, Type targetType) throws IOException, HttpMediaTypeNotSupportedException {

	MediaType contentType;
	try {
		contentType = inputMessage.getHeaders().getContentType();
	}
	catch (InvalidMediaTypeException ex) {
		throw new HttpMediaTypeNotSupportedException(ex.getMessage());
	}

	if (contentType == null) {
		contentType = MediaType.APPLICATION_OCTET_STREAM;
	}

			Class<?> contextClass = methodParam.getDeclaringClass();
			Map<TypeVariable, Type> map = GenericTypeResolver.getTypeVariableMap(contextClass);
			Class<T> targetClass = (Class<T>) GenericTypeResolver.resolveType(targetType, map);

			for (HttpMessageConverter<?> converter : this.messageConverters) {
				if (converter instanceof GenericHttpMessageConverter) {
					GenericHttpMessageConverter genericConverter = (GenericHttpMessageConverter) converter;
					if (genericConverter.canRead(targetType, contextClass, contentType)) {
						if (logger.isDebugEnabled()) {
							logger.debug("Reading [" + targetType + "] as \"" +
									contentType + "\" using [" + converter + "]");
						}
						return genericConverter.read(targetType, contextClass, inputMessage);
					}
				}
				if (targetClass != null) {
					if (converter.canRead(targetClass, contentType)) {
						if (logger.isDebugEnabled()) {
							logger.debug("Reading [" + targetClass.getName() + "] as \"" +
									contentType + "\" using [" + converter + "]");
						}
						return ((HttpMessageConverter<T>) converter).read(targetClass, inputMessage);
					}
				}
			}

			throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
		}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:59,代码来源:AbstractMessageConverterMethodArgumentResolver.java


注:本文中的org.springframework.http.converter.GenericHttpMessageConverter.canRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。