本文整理汇总了Java中feign.codec.Decoder类的典型用法代码示例。如果您正苦于以下问题:Java Decoder类的具体用法?Java Decoder怎么用?Java Decoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Decoder类属于feign.codec包,在下文中一共展示了Decoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readAnnotation
import feign.codec.Decoder; //导入依赖的package包/类
static ErrorHandlingDefinition readAnnotation(ErrorHandling errorHandling, Decoder responseBodyDecoder) {
ExceptionGenerator defaultException = new ExceptionGenerator.Builder()
.withResponseBodyDecoder(responseBodyDecoder)
.withExceptionType(errorHandling.defaultException())
.build();
Map<Integer, ExceptionGenerator> statusCodesDefinition = new HashMap<Integer, ExceptionGenerator>();
for(ErrorCodes statusCodeDefinition : errorHandling.codeSpecific()) {
for(int statusCode : statusCodeDefinition.codes()) {
if(statusCodesDefinition.containsKey(statusCode)) {
throw new IllegalStateException(
"Status Code [" + statusCode + "] " +
"has already been declared to throw [" + statusCodesDefinition.get(statusCode).getExceptionType().getName() + "] " +
"and [" + statusCodeDefinition.generate() + "] - dupe definition");
}
statusCodesDefinition.put(statusCode,
new ExceptionGenerator.Builder()
.withResponseBodyDecoder(responseBodyDecoder)
.withExceptionType(statusCodeDefinition.generate())
.build());
}
}
return new ErrorHandlingDefinition(defaultException, statusCodesDefinition);
}
示例2: SynchronousMethodHandler
import feign.codec.Decoder; //导入依赖的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;
}
示例3: testOverrideDecoder
import feign.codec.Decoder; //导入依赖的package包/类
@Test
public void testOverrideDecoder() throws Exception {
server.enqueue(new MockResponse().setBody("success!"));
String url = "http://localhost:" + server.getPort();
Decoder decoder = new Decoder() {
@Override
public Object decode(Response response, Type type) {
return "fail";
}
};
TestInterface api = Feign.builder().decoder(decoder).target(TestInterface.class, url);
assertEquals("fail", api.decodedPost());
assertEquals(1, server.getRequestCount());
}
示例4: resolvesParameterizedResult
import feign.codec.Decoder; //导入依赖的package包/类
@Test
public void resolvesParameterizedResult() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder()
.decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type)
.isEqualTo(new TypeToken<Entity<String, Long>>() {
}.getType());
return null;
}
})
.target(MyApi.class, baseUrl).get("foo");
assertThat(server.takeRequest()).hasPath("/default/api/foo");
}
示例5: resolvesBodyParameter
import feign.codec.Decoder; //导入依赖的package包/类
@Test
public void resolvesBodyParameter() throws InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
String baseUrl = server.url("/default").toString();
Feign.builder()
.encoder(new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
assertThat(bodyType)
.isEqualTo(new TypeToken<Keys<String>>() {
}.getType());
}
})
.decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) {
assertThat(type)
.isEqualTo(new TypeToken<Entities<String, Long>>() {
}.getType());
return null;
}
})
.target(MyApi.class, baseUrl).getAll(new Keys<String>());
}
示例6: doesntRetryAfterResponseIsSent
import feign.codec.Decoder; //导入依赖的package包/类
@Test
public void doesntRetryAfterResponseIsSent() throws Exception {
server.enqueue(new MockResponse().setBody("success!"));
thrown.expect(FeignException.class);
thrown.expectMessage("timeout reading POST http://");
TestInterface api = new TestInterfaceBuilder()
.decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) throws IOException {
throw new IOException("timeout");
}
}).target("http://localhost:" + server.getPort());
api.post();
}
示例7: decodingExceptionGetWrappedInDecode404Mode
import feign.codec.Decoder; //导入依赖的package包/类
@Test
public void decodingExceptionGetWrappedInDecode404Mode() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404));
thrown.expect(DecodeException.class);
thrown.expectCause(isA(NoSuchElementException.class));;
TestInterface api = new TestInterfaceBuilder()
.decode404()
.decoder(new Decoder() {
@Override
public Object decode(Response response, Type type) throws IOException {
assertEquals(404, response.status());
throw new NoSuchElementException();
}
}).target("http://localhost:" + server.getPort());
api.post();
}
示例8: testDelegates
import feign.codec.Decoder; //导入依赖的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));
}
示例9: feignDecoder
import feign.codec.Decoder; //导入依赖的package包/类
@Bean
public Decoder feignDecoder () {
val springConverters = messageConverters.getObject().getConverters();
val decoderConverters = new ArrayList<HttpMessageConverter<?>>(springConverters.size() + 1);
decoderConverters.addAll(springConverters);
decoderConverters.add(new SpringManyMultipartFilesReader(4096));
val httpMessageConverters = new HttpMessageConverters(decoderConverters);
return new SpringDecoder(new ObjectFactory<HttpMessageConverters>() {
@Override
public HttpMessageConverters getObject () {
return httpMessageConverters;
}
});
}
示例10: create
import feign.codec.Decoder; //导入依赖的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);
}
示例11: feignDecoder
import feign.codec.Decoder; //导入依赖的package包/类
@Bean
@Primary
Decoder feignDecoder(BeanFactory beanFactory) {
return new TraceFeignDecoder(beanFactory,
new ResponseEntityDecoder(new SpringDecoder(this.messageConverters)) {
@Override
public Object decode(Response response, Type type)
throws IOException, FeignException {
FeignRequestContext feignRequestContext = FeignRequestContext
.getInstance();
FeignResponseHeadersHolder feignResponseHeadersHolder = new FeignResponseHeadersHolder(
response.headers());
feignResponseHeadersInjector().inject(
feignRequestContext.getCurrentSpan(),
feignResponseHeadersHolder);
return super.decode(
Response.create(response.status(), response.reason(),
feignResponseHeadersHolder.responseHeaders,
response.body()),
type);
}
});
}
示例12: feign
import feign.codec.Decoder; //导入依赖的package包/类
protected Feign.Builder feign(FeignContext context) {
FeignLoggerFactory loggerFactory = get(context, FeignLoggerFactory.class);
Logger logger = loggerFactory.create(this.type);
// @formatter:off
Feign.Builder builder = get(context, Feign.Builder.class)
// required values
.logger(logger)
.encoder(get(context, Encoder.class))
.decoder(get(context, Decoder.class))
.contract(get(context, Contract.class));
// @formatter:on
configureFeign(context, builder);
return builder;
}
示例13: progressDecoder
import feign.codec.Decoder; //导入依赖的package包/类
@Provides(type = SET)
Decoder progressDecoder() {
return new UpdateableDecoder<Progress>() {
@Override
protected Progress build(JsonReader reader) throws IOException {
Progress.Builder builder = Progress.builder();
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("id")) {
builder.id(reader.nextString());
} else if (key.equals("status")) {
builder.status(reader.nextString());
} else if (key.equals("progress")) {
builder.progress(reader.nextString());
} else if (key.equals("error")) {
builder.error(reader.nextString());
} else {
reader.skipValue();
}
}
return builder.build();
}
};
}
示例14: feign
import feign.codec.Decoder; //导入依赖的package包/类
@Provides
@Singleton
Feign feign(Logger logger, Logger.Level logLevel) {
/**
* {@link UltraDNS#updateDirectionalPoolRecord(DirectionalRecord, DirectionalGroup)} and {@link
* UltraDNS#addDirectionalPoolRecord(DirectionalRecord, DirectionalGroup, String)} can take up
* to 10 minutes to complete.
*/
Options options = new Options(10 * 1000, 10 * 60 * 1000);
Decoder decoder = decoder();
return Feign.builder()
.logger(logger)
.logLevel(logLevel)
.options(options)
.encoder(new UltraDNSFormEncoder())
.decoder(decoder)
.errorDecoder(new UltraDNSErrorDecoder(decoder))
.build();
}
示例15: ExceptionGenerator
import feign.codec.Decoder; //导入依赖的package包/类
ExceptionGenerator(Integer bodyIndex, Integer headerMapIndex, Integer numOfParams, Class bodyType, Class<? extends Exception> exceptionType, Decoder bodyDecoder) {
this.bodyIndex = bodyIndex;
this.headerMapIndex = headerMapIndex;
this.numOfParams = numOfParams;
this.bodyType = bodyType;
this.exceptionType = exceptionType;
this.bodyDecoder = bodyDecoder;
}