本文整理汇总了Java中org.springframework.web.client.HttpMessageConverterExtractor类的典型用法代码示例。如果您正苦于以下问题:Java HttpMessageConverterExtractor类的具体用法?Java HttpMessageConverterExtractor怎么用?Java HttpMessageConverterExtractor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpMessageConverterExtractor类属于org.springframework.web.client包,在下文中一共展示了HttpMessageConverterExtractor类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: readResponse
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <E> Optional<E> readResponse(ResponseType<E> type) {
final Type responseType = type.getType();
try {
// check InputStream
if (InputStream.class == responseType) {
return (Optional<E>) Optional.ofNullable(response.getBody().getInputStream());
}
if (Void.class != responseType) {
ResponseExtractor<E> extractor = new HttpMessageConverterExtractor<>(responseType,
getMessageConverters());
return Optional.ofNullable(extractor.extractData(httpResponse));
}
} catch (Exception e) {
throw new HttpEntityProcessingException("Failed to read HTTP entity as [" + type + "]", e);
}
return Optional.empty();
}
开发者ID:holon-platform,项目名称:holon-core,代码行数:20,代码来源:SpringResponseEntity.java
示例2: decode
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
@Override
public Exception decode(String methodKey, Response response) {
if((response.status() >= 200 && response.status() < 300) ||
response.status()==HttpStatus.BAD_REQUEST.value() ||
response.status()==HttpStatus.INTERNAL_SERVER_ERROR.value() ){
try {
HttpMessageConverterExtractor<SimpleDataResult<Object>> extractor = new HttpMessageConverterExtractor<SimpleDataResult<Object>>(SimpleDataResult.class, this.httpMessageConverters.getConverters());
SimpleDataResult<Object> result = extractor.extractData(new FeignResponseAdapter(response));
log.error("error code: {}, result: {}", response.status(), result);
//防止普通异常也被熔断,if not convert as HystrixBadRequestException and fallback also throws error, it will be enabled short-circuited get "Hystrix circuit short-circuited and is OPEN" when client frequently invoke
if(result!=null){
return new HystrixBadRequestException(result.getMessage(), new ServiceException(result.getMessage(), result.getCode()));
}
} catch (IOException e) {
throw new BaseException("error feign response : " + e.getMessage(), e);
}
}
Exception exception = defaultDecoder.decode(methodKey, response);
return exception;
}
开发者ID:wayshall,项目名称:onetwo,代码行数:22,代码来源:ResultErrorDecoder.java
示例3: getJson
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
private static String getJson(RestTemplate restTemplate, String urlString) {
ClientHttpResponse response = null;
HttpMethod method = null;
try {
method = HttpMethod.GET;
URI url = new UriTemplate(urlString).expand();
ClientHttpRequest request = restTemplate.getRequestFactory().createRequest(url, method);
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_JSON);
request.getHeaders().setAccept(acceptableMediaTypes );
//if (requestCallback != null) {
// requestCallback.doWithRequest(request);
//}
response = request.execute();
if (response.getBody() != null) {
HttpMessageConverterExtractor<String> extractor = new HttpMessageConverterExtractor<String>(String.class, restTemplate.getMessageConverters());
String data = extractor.extractData(response);
return data;
};
}
catch (IOException ex) {
throw new ResourceAccessException("I/O error on " + method.name() +
" request for \"" + urlString + "\":" + ex.getMessage(), ex);
}
finally {
if (response != null) {
response.close();
}
}
return null;
}
开发者ID:eclipse,项目名称:cft,代码行数:34,代码来源:CloudFoundryClientFactory.java
示例4: decodeByType
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <T> T decodeByType(FeignResponseAdapter response, Type type) throws IOException, FeignException {
HttpMessageConverterExtractor<SimpleDataResult> extractor = new HttpMessageConverterExtractor(
type, this.messageConverters.getObject().getConverters());
T dr = (T)extractor.extractData(response);
return dr;
}
开发者ID:wayshall,项目名称:onetwo,代码行数:8,代码来源:ExtResponseEntityDecoder.java
示例5: decode
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
@Override
public Object decode(final Response response, Type type)
throws IOException, FeignException {
if (type instanceof Class || type instanceof ParameterizedType
|| type instanceof WildcardType) {
@SuppressWarnings({ "unchecked", "rawtypes" })
HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor(
type, this.messageConverters.getObject().getConverters());
return extractor.extractData(new FeignResponseAdapter(response));
}
throw new DecodeException(
"type is not an instance of Class or ParameterizedType: " + type);
}
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:15,代码来源:SpringDecoder.java
示例6: extractData
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
protected final <T> T extractData(ClientHttpResponse response, Class<T> cls) throws IOException {
notNull(response, "response");
notNull(cls, "cls");
if (Void.class.isAssignableFrom(cls)) {
return null;
}
return new HttpMessageConverterExtractor<>(cls, restTemplate.getMessageConverters()).extractData(response);
}
开发者ID:gooddata,项目名称:gooddata-java,代码行数:9,代码来源:AbstractService.java
示例7: VndErrorResponseErrorHandler
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
public VndErrorResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) {
errorExtractor = new HttpMessageConverterExtractor<VndErrors>(VndErrors.class, messageConverters);
}
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:4,代码来源:VndErrorResponseErrorHandler.java
示例8: VndErrorResponseErrorHandler
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
public VndErrorResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) {
vndErrorsExtractor = new HttpMessageConverterExtractor<VndErrors>(VndErrors.class, messageConverters);
vndErrorExtractor = new HttpMessageConverterExtractor<VndError>(VndError.class, messageConverters);
}
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:5,代码来源:VndErrorResponseErrorHandler.java
示例9: readBody
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
private <I> I readBody(final Type type, final ClientHttpResponse response) throws IOException {
final ResponseExtractor<I> extractor = new HttpMessageConverterExtractor<>(type, converters);
return extractor.extractData(response);
}
开发者ID:zalando,项目名称:riptide,代码行数:5,代码来源:MessageWorker.java
示例10: execute
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
protected <T> T execute(String url, final Object data, HttpMethod method, Class<T> responseType, Map<String, ?> urlParams) {
return template.execute(url, method, new HttpEntityRequestCallback(data), new HttpMessageConverterExtractor<T>(responseType, template.getMessageConverters()), urlParams);
}
开发者ID:makeandbuild,项目名称:vessl,代码行数:4,代码来源:CouchDBBaseImpl.java
示例11: ResponseErrorHandler
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
public ResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) {
gdcErrorExtractor = new HttpMessageConverterExtractor<>(ErrorStructure.class,
noNullElements(messageConverters, "messageConverters"));
}
开发者ID:gooddata,项目名称:gooddata-java,代码行数:5,代码来源:ResponseErrorHandler.java
示例12: getResponseExtractor
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {
getRestTemplate(); // force initialization
return new HttpMessageConverterExtractor<OAuth2AccessToken>(OAuth2AccessToken.class, this.messageConverters);
}
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:5,代码来源:OAuth2AccessTokenSupport.java
示例13: handleError
import org.springframework.web.client.HttpMessageConverterExtractor; //导入依赖的package包/类
public void handleError(final ClientHttpResponse response) throws IOException {
if (! HttpStatus.Series.CLIENT_ERROR.equals(response.getStatusCode().series())) {
// We should only care about 400 level errors. Ex: A 500 server error shouldn't
// be an oauth related error.
errorHandler.handleError(response);
} else {
// Need to use buffered response because input stream may need to be consumed multiple times.
ClientHttpResponse bufferedResponse = new ClientHttpResponse() {
private byte[] lazyBody;
public HttpStatus getStatusCode() throws IOException {
return response.getStatusCode();
}
public synchronized InputStream getBody() throws IOException {
if (lazyBody == null) {
InputStream bodyStream = response.getBody();
if (bodyStream != null) {
lazyBody = FileCopyUtils.copyToByteArray(bodyStream);
}
}
return new ByteArrayInputStream(lazyBody);
}
public HttpHeaders getHeaders() {
return response.getHeaders();
}
public String getStatusText() throws IOException {
return response.getStatusText();
}
public void close() {
response.close();
}
public int getRawStatusCode() throws IOException {
return response.getRawStatusCode();
}
};
try {
HttpMessageConverterExtractor<OAuth2Exception> extractor = new HttpMessageConverterExtractor<OAuth2Exception>(
OAuth2Exception.class, messageConverters);
try {
OAuth2Exception body = extractor.extractData(bufferedResponse);
if (body != null) {
// If we can get an OAuth2Exception already from the body, it is likely to have more information than
// the header does, so just re-throw it here.
throw body;
}
}
catch (RestClientException e) {
// ignore
}
// first try: www-authenticate error
List<String> authenticateHeaders = bufferedResponse.getHeaders().get("WWW-Authenticate");
if (authenticateHeaders != null) {
for (String authenticateHeader : authenticateHeaders) {
maybeThrowExceptionFromHeader(authenticateHeader, OAuth2AccessToken.BEARER_TYPE);
maybeThrowExceptionFromHeader(authenticateHeader, OAuth2AccessToken.OAUTH2_TYPE);
}
}
// then delegate to the custom handler
errorHandler.handleError(bufferedResponse);
}
catch (OAuth2Exception ex) {
if (bufferedResponse.getRawStatusCode() == 401 || ! ex.getClass().equals(OAuth2Exception.class)) {
// Status code 401 should always mean that we need a legitimate token.
// Caught a specific, derived class so this is not just some generic error
throw ex;
} else {
// This is not an exception that is really understood, so allow our delegate
// to handle it in a non-oauth way
errorHandler.handleError(bufferedResponse);
}
}
}
}
开发者ID:jungyang,项目名称:oauth-client-master,代码行数:82,代码来源:OAuth2ErrorHandler.java
注:本文中的org.springframework.web.client.HttpMessageConverterExtractor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论