org.springframework.web.client.HttpMessageConverterExtractor Java Examples
The following examples show how to use
org.springframework.web.client.HttpMessageConverterExtractor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResultErrorDecoder.java From onetwo with Apache License 2.0 | 6 votes |
@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("method[{}], error code: {}, result: {}", methodKey, response.status(), result); //防止普通异常也被熔断,如果不转为 HystrixBadRequestException 并且 fallback 也抛了异常, 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; }
Example #2
Source File: SpringDecoder.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
@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(response.status(), "type is not an instance of Class or ParameterizedType: " + type, response.request()); }
Example #3
Source File: MyController.java From Hands-On-Reactive-Programming-in-Spring-5 with MIT License | 5 votes |
@RequestMapping(produces = MediaType.TEXT_PLAIN_VALUE) public ListenableFuture<?> requestData() { AsyncRestTemplate httpClient = new AsyncRestTemplate(); AsyncDatabaseClient databaseClient = new FakeAsyncDatabaseClient(); CompletionStage<String> completionStage = AsyncAdapters.toCompletion(httpClient.execute( "http://localhost:8080/hello", HttpMethod.GET, null, new HttpMessageConverterExtractor<>(String.class, messageConverters) )); return AsyncAdapters.toListenable(databaseClient.store(completionStage)); }
Example #4
Source File: ExtResponseEntityDecoder.java From onetwo with Apache License 2.0 | 5 votes |
@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; }
Example #5
Source File: VndErrorResponseErrorHandler.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
public VndErrorResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) { errorExtractor = new HttpMessageConverterExtractor<VndErrors>(VndErrors.class, messageConverters); }
Example #6
Source File: VndErrorResponseErrorHandler.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
public VndErrorResponseErrorHandler(List<HttpMessageConverter<?>> messageConverters) { vndErrorsExtractor = new HttpMessageConverterExtractor<VndErrors>(VndErrors.class, messageConverters); vndErrorExtractor = new HttpMessageConverterExtractor<VndError>(VndError.class, messageConverters); }