當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMessageConverter.read方法代碼示例

本文整理匯總了Java中org.springframework.http.converter.HttpMessageConverter.read方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpMessageConverter.read方法的具體用法?Java HttpMessageConverter.read怎麽用?Java HttpMessageConverter.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.converter.HttpMessageConverter的用法示例。


在下文中一共展示了HttpMessageConverter.read方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractData

import org.springframework.http.converter.HttpMessageConverter; //導入方法依賴的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: extractData

import org.springframework.http.converter.HttpMessageConverter; //導入方法依賴的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

示例3: readWithMessageConverters

import org.springframework.http.converter.HttpMessageConverter; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object readWithMessageConverters(MethodParameter methodParam, HttpInputMessage inputMessage, Class<?> paramType)
		throws Exception {

	MediaType contentType = inputMessage.getHeaders().getContentType();
	if (contentType == null) {
		StringBuilder builder = new StringBuilder(ClassUtils.getShortName(methodParam.getParameterType()));
		String paramName = methodParam.getParameterName();
		if (paramName != null) {
			builder.append(' ');
			builder.append(paramName);
		}
		throw new HttpMediaTypeNotSupportedException(
				"Cannot extract parameter (" + builder.toString() + "): no Content-Type found");
	}

	List<MediaType> allSupportedMediaTypes = new ArrayList<MediaType>();
	if (this.messageConverters != null) {
		for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
			allSupportedMediaTypes.addAll(messageConverter.getSupportedMediaTypes());
			if (messageConverter.canRead(paramType, contentType)) {
				if (logger.isDebugEnabled()) {
					logger.debug("Reading [" + paramType.getName() + "] as \"" + contentType
							+"\" using [" + messageConverter + "]");
				}
				return messageConverter.read((Class) paramType, inputMessage);
			}
		}
	}
	throw new HttpMediaTypeNotSupportedException(contentType, allSupportedMediaTypes);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:HandlerMethodInvoker.java


注:本文中的org.springframework.http.converter.HttpMessageConverter.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。