本文整理汇总了Java中com.netflix.hystrix.exception.HystrixBadRequestException类的典型用法代码示例。如果您正苦于以下问题:Java HystrixBadRequestException类的具体用法?Java HystrixBadRequestException怎么用?Java HystrixBadRequestException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HystrixBadRequestException类属于com.netflix.hystrix.exception包,在下文中一共展示了HystrixBadRequestException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected RestResponsePage<Approval> run() throws Exception {
try {
ParameterizedTypeReference<RestResponsePage<Approval>>
responsetype =
new ParameterizedTypeReference<RestResponsePage<Approval>>() {
};
ResponseEntity<RestResponsePage<Approval>>
result =
restTemplate
.exchange(uriBuilder.build().encode().toUri(), HttpMethod.POST,
new HttpEntity<>(approvalFilters), responsetype);
return result.getBody();
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例2: handleBadRequest
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@ExceptionHandler({HystrixBadRequestException.class})
protected ResponseEntity<Object> handleBadRequest(HystrixBadRequestException e, WebRequest request) {
logWarning(request, e);
String message = e.getMessage();
String code = "[Bad Request]";
int statusCode = 400;
if(e.getCause() instanceof LogiException){
message = e.getCause().getMessage();
code = ((LogiException) e.getCause()).getCode();
statusCode = ((LogiException) e.getCause()).getStatusCode();
//409 is used in Logi to reload when domain Id changes, hence changing it.
if (statusCode == 409 || statusCode == 0) {
statusCode = 400;
}
}
ErrorResource
error =
new ErrorResource(code, message);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return handleExceptionInternal(e, error, headers, HttpStatus.valueOf(statusCode), request);
}
示例3: buildErrorDecoder
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Bean
public ErrorDecoder buildErrorDecoder() {
return new ErrorDecoder() {
@Override
public Exception decode(String methodKey, Response response) {
logger.error("feign失败 方法 :{},原因:{}", methodKey, response);
try {
if (response.body() != null) {
CustomException exception = HttpErrorDecoder.decode(HttpStatus.valueOf(response.status()),
Util.toString(response.body().asReader()));
return new HystrixBadRequestException(exception.getMessage(), exception);
}
} catch (IOException e) {
}
return errorStatus(methodKey, response);
}
};
}
示例4: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected Integer run() throws Exception {
try {
Thread.sleep(executionLatency);
switch (executionResult) {
case SUCCESS:
return 1;
case FAILURE:
throw new IntendedException("induced failure");
case BAD_REQUEST:
throw new HystrixBadRequestException("induced bad request");
default:
throw new IllegalStateException("unhandled HystrixEventType : " + executionResult);
}
} catch (InterruptedException ex) {
System.out.println("Received InterruptedException : " + ex);
throw ex;
}
}
示例5: getAllApplicationPermissions
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
public List<Application> getAllApplicationPermissions() {
return new SimpleJava8HystrixCommand<>(
GROUP_KEY,
"getAllApplicationPermissions",
() -> {
applicationCache.set(front50Api.getAllApplicationPermissions());
healthTracker.success();
return applicationCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to application cache. Cause: " + cause.getMessage());
List<Application> applications = applicationCache.get();
if (applications == null) {
throw new HystrixBadRequestException("Front50 is unavailable", cause);
}
return applications;
}).execute();
}
示例6: getAllServiceAccounts
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
public List<ServiceAccount> getAllServiceAccounts() {
return new SimpleJava8HystrixCommand<>(
GROUP_KEY,
"getAccounts",
() -> {
serviceAccountCache.set(front50Api.getAllServiceAccounts());
healthTracker.success();
return serviceAccountCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to service account cache. Cause: " + cause.getMessage());
List<ServiceAccount> serviceAccounts = serviceAccountCache.get();
if (serviceAccounts == null) {
throw new HystrixBadRequestException("Front50 is unavailable", cause);
}
return serviceAccounts;
}).execute();
}
示例7: getAccounts
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
public List<Account> getAccounts() {
return new SimpleJava8HystrixCommand<>(
GROUP_KEY,
"getAccounts",
() -> {
accountCache.set(clouddriverApi.getAccounts());
healthTracker.success();
return accountCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to account cache. Cause: " + cause.getMessage());
List<Account> accounts = accountCache.get();
if (accounts == null) {
throw new HystrixBadRequestException("Clouddriver is unavailable", cause);
}
return accounts;
}).execute();
}
示例8: getApplications
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
public List<Application> getApplications() {
return new SimpleJava8HystrixCommand<>(
GROUP_KEY,
"getApplications",
() -> {
applicationCache.set(clouddriverApi.getApplications());
healthTracker.success();
return applicationCache.get();
},
(Throwable cause) -> {
log.warn("Falling back to application cache. Cause: " + cause.getMessage());
List<Application> applications = applicationCache.get();
if (applications == null) {
throw new HystrixBadRequestException("Clouddriver is unavailable", cause);
}
return applications;
})
.execute();
}
示例9: decode
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的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;
}
示例10: decode
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
protected Object decode(FeignResponseAdapter response, Type type) throws IOException, FeignException {
Object res = null;
try {
res = decodeByType(response, type);
} catch (HttpMessageNotReadableException e) {
//正常解码失败后尝试用SimpleDataResult解码
response.getBody().reset();
SimpleDataResult dr = decodeByType(response, SimpleDataResult.class);
if(dr.isError()){
// throw new ServiceException(dr.getMessage(), dr.getCode());
throw new HystrixBadRequestException(dr.getMessage(), new ServiceException(dr.getMessage(), dr.getCode()));
}
res = dr.getData();
}
return res;
}
示例11: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected LocationResponseModel run() throws Exception {
URI url = JerseyUriBuilder.fromUri(LocationConstants.URL).build();
HttpEntity<LocationRequestModel> request = new HttpEntity<LocationRequestModel>(model, headers);
try {
ResponseEntity<LocationResponseModel>
entity =
restClient.postForEntity(url, request, LocationResponseModel.class);
return entity.getBody();
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例12: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected CreateApprovalResponse run() throws Exception {
URI link = JerseyUriBuilder.fromUri(url).build();
try {
ResponseEntity<CreateApprovalResponse>
entity =
restTemplate.postForEntity(link, request, CreateApprovalResponse.class);
return entity.getBody();
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例13: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected CreateApprovalResponse run() throws Exception {
try {
return restTemplate.getForEntity(path, CreateApprovalResponse.class, approvalId).getBody();
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例14: run
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
@Override
protected String run() throws Exception {
try {
restTemplate.put(path, request, approvalId);
return approvalId;
} catch (HttpClientErrorException exception) {
throw new HystrixBadRequestException(exception.getMessage(),
new HttpBadRequestException(ErrorResponse.getErrorResponse(exception), exception));
}
}
示例15: handleException
import com.netflix.hystrix.exception.HystrixBadRequestException; //导入依赖的package包/类
/**
* 处理未知异常
*
* @param throwable
* @param request
* @return
*/
@ExceptionHandler(value = {Exception.class})
ResponseEntity<ErrorResult> handleException(Throwable throwable, HttpServletRequest request) {
logger.warn("异常处理");
if (throwable instanceof HystrixBadRequestException && throwable.getCause() instanceof CustomException) {
return handleException((CustomException) throwable.getCause(), request);
} else {
return handleException(new CustomException("未知错误", throwable), request);
}
}