当前位置: 首页>>代码示例>>Java>>正文


Java ErrorDecoder类代码示例

本文整理汇总了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);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:23,代码来源:FeignDepot.java

示例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;
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:20,代码来源:SynchronousMethodHandler.java

示例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());
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:25,代码来源:FeignTest.java

示例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);
		}
	};
}
 
开发者ID:zhaoqilong3031,项目名称:spring-cloud-samples,代码行数:20,代码来源:DefaultFeignClientConfiguration.java

示例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);
    };
}
 
开发者ID:richterplus,项目名称:spring-cloud-sample,代码行数:25,代码来源:FeignConfig.java

示例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));
}
 
开发者ID:client-side,项目名称:completable-feign,代码行数:20,代码来源:CompletableFeignBuilderTest.java

示例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);
}
 
开发者ID:OpenFeign,项目名称:feign-vertx,代码行数:22,代码来源:AsynchronousMethodHandler.java

示例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;
}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:23,代码来源:CompensableFeignErrorDecoder.java

示例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;
}
 
开发者ID:liuyangming,项目名称:ByteJTA,代码行数:23,代码来源:TransactionFeignErrorDecoder.java

示例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);
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:8,代码来源:SynchronousMethodHandler.java

示例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");
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:10,代码来源:ReflectiveFeign.java

示例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;
}
 
开发者ID:retz,项目名称:retz,代码行数:9,代码来源:ErrorResponseDecoder.java

示例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;
}
 
开发者ID:OpenFeign,项目名称:feign-vertx,代码行数:36,代码来源:AsynchronousMethodHandler.java

示例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");
}
 
开发者ID:OpenFeign,项目名称:feign-vertx,代码行数:15,代码来源:VertxFeign.java


注:本文中的feign.codec.ErrorDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。