本文整理汇总了Java中feign.codec.Encoder类的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Encoder类属于feign.codec包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodesXmlWithCustomJAXBEncoding
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void encodesXmlWithCustomJAXBEncoding() throws Exception {
JAXBContextFactory jaxbContextFactory =
new JAXBContextFactory.Builder().withMarshallerJAXBEncoding("UTF-16").build();
Encoder encoder = new JAXBEncoder(jaxbContextFactory);
MockObject mock = new MockObject();
mock.value = "Test";
RequestTemplate template = new RequestTemplate();
encoder.encode(mock, MockObject.class, template);
assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-16\" "
+ "standalone=\"yes\"?><mockObject><value>Test</value></mockObject>");
}
示例2: encodesXmlWithCustomJAXBSchemaLocation
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void encodesXmlWithCustomJAXBSchemaLocation() throws Exception {
JAXBContextFactory jaxbContextFactory =
new JAXBContextFactory.Builder()
.withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd")
.build();
Encoder encoder = new JAXBEncoder(jaxbContextFactory);
MockObject mock = new MockObject();
mock.value = "Test";
RequestTemplate template = new RequestTemplate();
encoder.encode(mock, MockObject.class, template);
assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-8\" " +
"standalone=\"yes\"?><mockObject xsi:schemaLocation=\"http://apihost "
+
"http://apihost/schema.xsd\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+
"<value>Test</value></mockObject>");
}
示例3: encodesXmlWithCustomJAXBNoNamespaceSchemaLocation
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void encodesXmlWithCustomJAXBNoNamespaceSchemaLocation() throws Exception {
JAXBContextFactory jaxbContextFactory =
new JAXBContextFactory.Builder()
.withMarshallerNoNamespaceSchemaLocation("http://apihost/schema.xsd").build();
Encoder encoder = new JAXBEncoder(jaxbContextFactory);
MockObject mock = new MockObject();
mock.value = "Test";
RequestTemplate template = new RequestTemplate();
encoder.encode(mock, MockObject.class, template);
assertThat(template).hasBody("<?xml version=\"1.0\" encoding=\"UTF-8\" " +
"standalone=\"yes\"?><mockObject xsi:noNamespaceSchemaLocation=\"http://apihost/schema.xsd\" "
+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<value>Test</value></mockObject>");
}
示例4: encodesXmlWithCustomJAXBFormattedOutput
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void encodesXmlWithCustomJAXBFormattedOutput() {
JAXBContextFactory jaxbContextFactory =
new JAXBContextFactory.Builder().withMarshallerFormattedOutput(true).build();
Encoder encoder = new JAXBEncoder(jaxbContextFactory);
MockObject mock = new MockObject();
mock.value = "Test";
RequestTemplate template = new RequestTemplate();
encoder.encode(mock, MockObject.class, template);
String NEWLINE = System.getProperty("line.separator");
assertThat(template).hasBody(
new StringBuilder().append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
.append(NEWLINE)
.append("<mockObject>")
.append(NEWLINE)
.append(" <value>Test</value>")
.append(NEWLINE)
.append("</mockObject>")
.append(NEWLINE)
.toString());
}
示例5: testOverrideEncoder
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void testOverrideEncoder() throws Exception {
server.enqueue(new MockResponse().setBody("response data"));
String url = "http://localhost:" + server.getPort();
Encoder encoder = new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
template.body(object.toString());
}
};
TestInterface api = Feign.builder().encoder(encoder).target(TestInterface.class, url);
api.encodedPost(Arrays.asList("This", "is", "my", "request"));
assertThat(server.takeRequest())
.hasBody("[This, is, my, request]");
}
示例6: resolvesBodyParameter
import feign.codec.Encoder; //导入依赖的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>());
}
示例7: bodyTypeCorrespondsWithParameterType
import feign.codec.Encoder; //导入依赖的package包/类
/**
* The type of a parameter value may not be the desired type to encode as. Prefer the interface
* type.
*/
@Test
public void bodyTypeCorrespondsWithParameterType() throws Exception {
server.enqueue(new MockResponse().setBody("foo"));
final AtomicReference<Type> encodedType = new AtomicReference<Type>();
TestInterface api = new TestInterfaceBuilder()
.encoder(new Encoder.Default() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
encodedType.set(bodyType);
}
})
.target("http://localhost:" + server.getPort());
api.body(Arrays.asList("netflix", "denominator", "password"));
server.takeRequest();
assertThat(encodedType.get()).isEqualTo(new TypeToken<List<String>>() {
}.getType());
}
示例8: testDelegates
import feign.codec.Encoder; //导入依赖的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: feign
import feign.codec.Encoder; //导入依赖的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;
}
示例10: ParseHandlersByName
import feign.codec.Encoder; //导入依赖的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");
}
示例11: okIfEncodeRootCauseHasNoMessage
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void okIfEncodeRootCauseHasNoMessage() throws Exception {
server.enqueue(new MockResponse().setBody("success!"));
thrown.expect(EncodeException.class);
TestInterface api = new TestInterfaceBuilder()
.encoder(new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
throw new RuntimeException();
}
}).target("http://localhost:" + server.getPort());
api.body(Arrays.asList("foo"));
}
示例12: MovieController
import feign.codec.Encoder; //导入依赖的package包/类
@Autowired
public MovieController(Decoder decoder, Encoder encoder, Client client, Contract contract) {
// 这边的decoder、encoder、client、contract,可以debug看看是什么实例。
this.userUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
.requestInterceptor(new BasicAuthRequestInterceptor("user", "password1")).target(UserFeignClient.class, "http://microservice-provider-user/");
this.adminUserFeignClient = Feign.builder().client(client).encoder(encoder).decoder(decoder).contract(contract)
.requestInterceptor(new BasicAuthRequestInterceptor("admin", "password2"))
.target(UserFeignClient.class, "http://microservice-provider-user/");
}
示例13: testLoadDeEncoder
import feign.codec.Encoder; //导入依赖的package包/类
@Test
public void testLoadDeEncoder() throws Exception {
final TestInterface api = CompletableFeign.builder()
.decoder(Decoder.class)
.encoder(Encoder.class)
.target(TestInterface.class, url);
final CompletableFuture<Response> response = api.get();
assertEquals("response data", Util.toString(response.join().body().asReader()));
}
示例14: SpringFormEncoder
import feign.codec.Encoder; //导入依赖的package包/类
/**
* Constructor with specified delegate encoder.
*
* @param delegate delegate encoder, if this encoder couldn't encode object.
*/
public SpringFormEncoder (Encoder delegate) {
super(delegate);
val processor = (MultipartFormContentProcessor) getContentProcessor(MULTIPART);
processor.addWriter(new SpringSingleMultipartFileWriter());
processor.addWriter(new SpringManyMultipartFilesWriter());
}
示例15: FormEncoder
import feign.codec.Encoder; //导入依赖的package包/类
/**
* Constructor with specified delegate encoder.
*
* @param delegate delegate encoder, if this encoder couldn't encode object.
*/
public FormEncoder (Encoder delegate) {
this.delegate = delegate;
val list = asList(new MultipartFormContentProcessor(delegate),
new UrlencodedFormContentProcessor());
processors = new HashMap<ContentType, ContentProcessor>(list.size(), 1.F);
for (ContentProcessor processor : list) {
processors.put(processor.getSupportedContentType(), processor);
}
}