本文整理汇总了Java中feign.codec.ErrorDecoder类的典型用法代码示例。如果您正苦于以下问题:Java ErrorDecoder类的具体用法?Java ErrorDecoder怎么用?Java ErrorDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorDecoder类属于feign.codec包,在下文中一共展示了ErrorDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import feign.codec.ErrorDecoder; //导入依赖的package包/类
/**
* Build client for key
*
* @param clazz
* @param <T>
* @return
*/
public <T> T build(final Class<T> clazz, final ErrorDecoder decoder) {
final Feign.Builder builder = Feign.builder();
if (null != this.options) {
builder.options(this.options);
}
if (null != this.defaults) {
builder.retryer(this.defaults);
}
builder.encoder(new JsonObjectEncoder());
builder.decoder(new JsonObjectDecoder());
if (null != decoder) {
builder.errorDecoder(decoder);
}
return builder.target(clazz, this.endpoint);
}
示例2: delegatesToDefaultErrorDecoder
import feign.codec.ErrorDecoder; //导入依赖的package包/类
@Test
public void delegatesToDefaultErrorDecoder() throws Exception {
ErrorDecoder defaultErrorDecoder = new ErrorDecoder() {
@Override
public Exception decode(String methodKey, Response response) {
return new DefaultErrorDecoderException();
}
};
AnnotationErrorDecoder decoder = AnnotationErrorDecoder.builderFor( TestClientInterfaceWithNoAnnotations.class )
.withDefaultDecoder(defaultErrorDecoder)
.build();
assertThat(decoder.decode(feignConfigKey( "method1Test"), testResponse(502)).getClass())
.isEqualTo(DefaultErrorDecoderException.class);
}
开发者ID:OpenFeign,项目名称:feign-annotation-error-decoder,代码行数:18,代码来源:AnnotationErrorDecoderNoAnnotationTest.java
示例3: SynchronousMethodHandler
import feign.codec.ErrorDecoder; //导入依赖的package包/类
private SynchronousMethodHandler(Target<?> target, Client client, Retryer retryer,
List<RequestInterceptor> requestInterceptors, Logger logger,
Logger.Level logLevel, MethodMetadata metadata,
RequestTemplate.Factory buildTemplateFromArgs, Options options,
Decoder decoder, ErrorDecoder errorDecoder, boolean decode404) {
this.target = checkNotNull(target, "target");
this.client = checkNotNull(client, "client for %s", target);
this.retryer = checkNotNull(retryer, "retryer for %s", target);
this.requestInterceptors =
checkNotNull(requestInterceptors, "requestInterceptors for %s", target);
this.logger = checkNotNull(logger, "logger for %s", target);
this.logLevel = checkNotNull(logLevel, "logLevel for %s", target);
this.metadata = checkNotNull(metadata, "metadata for %s", target);
this.buildTemplateFromArgs = checkNotNull(buildTemplateFromArgs, "metadata for %s", target);
this.options = checkNotNull(options, "options for %s", target);
this.errorDecoder = checkNotNull(errorDecoder, "errorDecoder for %s", target);
this.decoder = checkNotNull(decoder, "decoder for %s", target);
this.decode404 = decode404;
}
示例4: ensureRetryerClonesItself
import feign.codec.ErrorDecoder; //导入依赖的package包/类
@Test
public void ensureRetryerClonesItself() {
server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 1"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 2"));
server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 3"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 4"));
MockRetryer retryer = new MockRetryer();
TestInterface api = Feign.builder()
.retryer(retryer)
.errorDecoder(new ErrorDecoder()
{
@Override
public Exception decode(String methodKey, Response response)
{
return new RetryableException("play it again sam!", null);
}
}).target(TestInterface.class, "http://localhost:" + server.getPort());
api.post();
api.post(); // if retryer instance was reused, this statement will throw an exception
assertEquals(4, server.getRequestCount());
}
示例5: buildErrorDecoder
import feign.codec.ErrorDecoder; //导入依赖的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);
}
};
}
示例6: errorDecoder
import feign.codec.ErrorDecoder; //导入依赖的package包/类
@Bean
public ErrorDecoder errorDecoder() {
return (String s, Response response) -> {
if (response.status() == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
Collection<String> contentTypes = response.headers().get("Content-Type");
if (contentTypes != null
&& contentTypes.stream().anyMatch(contentType -> contentType.contains("application/json"))) {
try {
JSONObject responseJson = JSON.parseObject(IOUtils.toString(response.body().asInputStream(), "UTF-8"));
String exceptionClass = responseJson.getString("exceptionClass");
if (exceptionClass != null && exceptionClass.length() > 0) {
if (UserApiException.class.getName().equals(exceptionClass)) {
UserExceptionInfo userExceptionInfo = JSON.parseObject(responseJson.toJSONString(), UserExceptionInfo.class);
return new UserApiException(userExceptionInfo.getUserExceptionData().getCode(), userExceptionInfo.getUserExceptionData().getMessage());
}
}
} catch (IOException e) {
return e;
}
}
}
return defaultErrorDecoder.decode(s, response);
};
}
示例7: testDelegates
import feign.codec.ErrorDecoder; //导入依赖的package包/类
@Test
public void testDelegates() throws Exception {
final TestInterface api = CompletableFeign.builder()
.logLevel(Logger.Level.BASIC)
.logger(new Logger.ErrorLogger())
.client(new Client.Default(null, null))
.retryer(new Retryer.Default())
.encoder(new Encoder.Default())
.decoder(new Decoder.Default())
.decode404()
.errorDecoder(new ErrorDecoder.Default())
.options(new Request.Options())
.requestInterceptor(new BasicAuthRequestInterceptor("user", "pass"))
.requestInterceptors(Collections.emptyList())
.target(TestInterface.class, url);
final Response response = api.post("request data");
assertEquals("response data", Util.toString(response.body().asReader()));
assertEquals("request data", server.takeRequest().getBody().readString(UTF_8));
}
示例8: create
import feign.codec.ErrorDecoder; //导入依赖的package包/类
MethodHandler create(
final Target<?> target,
final MethodMetadata metadata,
final RequestTemplate.Factory buildTemplateFromArgs,
final HttpClientOptions options,
final Decoder decoder,
final ErrorDecoder errorDecoder) {
return new AsynchronousMethodHandler(
target,
client,
retryer,
requestInterceptors,
logger,
logLevel,
metadata,
buildTemplateFromArgs,
options,
decoder,
errorDecoder,
decode404);
}
示例9: invokeAfterPropertiesSet
import feign.codec.ErrorDecoder; //导入依赖的package包/类
public void invokeAfterPropertiesSet() throws Exception {
feign.codec.ErrorDecoder errorDecoder = null;
String[] beanNameArray = this.applicationContext.getBeanNamesForType(feign.codec.ErrorDecoder.class);
for (int i = 0; beanNameArray != null && i < beanNameArray.length; i++) {
String beanName = beanNameArray[i];
Object beanInst = this.applicationContext.getBean(beanName);
if (CompensableFeignErrorDecoder.class.isInstance(beanInst)) {
continue;
} else if (errorDecoder != null) {
throw new RuntimeException("There are more than one feign.codec.ErrorDecoder exists!");
} else {
errorDecoder = (feign.codec.ErrorDecoder) beanInst;
}
}
if (errorDecoder == null) {
errorDecoder = new ErrorDecoder.Default();
} // end-if (errorDecoder == null)
this.delegate = errorDecoder;
}
示例10: invokeAfterPropertiesSet
import feign.codec.ErrorDecoder; //导入依赖的package包/类
public void invokeAfterPropertiesSet() throws Exception {
feign.codec.ErrorDecoder errorDecoder = null;
String[] beanNameArray = this.applicationContext.getBeanNamesForType(feign.codec.ErrorDecoder.class);
for (int i = 0; beanNameArray != null && i < beanNameArray.length; i++) {
String beanName = beanNameArray[i];
Object beanInst = this.applicationContext.getBean(beanName);
if (TransactionFeignErrorDecoder.class.isInstance(beanInst)) {
continue;
} else if (errorDecoder != null) {
throw new RuntimeException("There are more than one feign.codec.ErrorDecoder exists!");
} else {
errorDecoder = (feign.codec.ErrorDecoder) beanInst;
}
}
if (errorDecoder == null) {
errorDecoder = new ErrorDecoder.Default();
} // end-if (errorDecoder == null)
this.delegate = errorDecoder;
}
示例11: create
import feign.codec.ErrorDecoder; //导入依赖的package包/类
public MethodHandler create(Target<?> target, MethodMetadata md,
RequestTemplate.Factory buildTemplateFromArgs,
Options options, Decoder decoder, ErrorDecoder errorDecoder) {
return new SynchronousMethodHandler(target, client, retryer, requestInterceptors, logger,
logLevel, md, buildTemplateFromArgs, options, decoder,
errorDecoder, decode404);
}
示例12: ParseHandlersByName
import feign.codec.ErrorDecoder; //导入依赖的package包/类
ParseHandlersByName(Contract contract, Options options, Encoder encoder, Decoder decoder,
ErrorDecoder errorDecoder, SynchronousMethodHandler.Factory factory) {
this.contract = contract;
this.options = options;
this.factory = factory;
this.errorDecoder = errorDecoder;
this.encoder = checkNotNull(encoder, "encoder");
this.decoder = checkNotNull(decoder, "decoder");
}
示例13: ErrorResponseDecoder
import feign.codec.ErrorDecoder; //导入依赖的package包/类
public ErrorResponseDecoder(
ObjectMapper mapper,
ErrorDecoder delegate,
Function<String, Optional<String>> extractor) {
this.mapper = mapper;
this.delegate = delegate;
this.extractor = extractor;
}
示例14: AsynchronousMethodHandler
import feign.codec.ErrorDecoder; //导入依赖的package包/类
private AsynchronousMethodHandler(
Target<?> target,
VertxHttpClient client,
Retryer retryer,
List<RequestInterceptor> requestInterceptors,
Logger logger,
Logger.Level logLevel,
MethodMetadata metadata,
RequestTemplate.Factory buildTemplateFromArgs,
HttpClientOptions options,
Decoder decoder,
ErrorDecoder errorDecoder,
boolean decode404) {
this.target = checkNotNull(target, "target must be not null");
this.client = checkNotNull(client, "client must be not null");
this.retryer = checkNotNull(retryer,
"retryer for %s must be not null", target);
this.requestInterceptors = checkNotNull(requestInterceptors,
"requestInterceptors for %s must be not null", target);
this.logger = checkNotNull(logger,
"logger for %s must be not null", target);
this.logLevel = checkNotNull(logLevel,
"logLevel for %s must be not null", target);
this.metadata = checkNotNull(metadata,
"metadata for %s must be not null", target);
this.buildTemplateFromArgs = checkNotNull(buildTemplateFromArgs,
"metadata for %s must be not null", target);
this.options = checkNotNull(options,
"options for %s must be not null", target);
this.errorDecoder = checkNotNull(errorDecoder,
"errorDecoder for %s must be not null", target);
this.decoder = checkNotNull(decoder,
"decoder for %s must be not null", target);
this.decode404 = decode404;
}
示例15: ParseHandlersByName
import feign.codec.ErrorDecoder; //导入依赖的package包/类
ParseHandlersByName(
final Contract contract,
final HttpClientOptions options,
final Encoder encoder,
final Decoder decoder,
final ErrorDecoder errorDecoder,
final AsynchronousMethodHandler.Factory factory) {
this.contract = contract;
this.options = options;
this.factory = factory;
this.errorDecoder = errorDecoder;
this.encoder = checkNotNull(encoder, "encoder must not be null");
this.decoder = checkNotNull(decoder, "decoder must not be null");
}