Before this change, apis that follow patterns across a service could
only be modeled by copy/paste/find/replace. Especially with a large
count, this is monotonous and error prone.
This change introduces support for base apis via single-inheritance
interfaces. Users ensure their target interface bind any type variables
and as a result have little effort to create boilerplate apis.
Ex.
```java
@Headers("Accept: application/json")
interface BaseApi<V> {
@RequestLine("GET /api/{key}")
V get(@Param("key") String);
@RequestLine("GET /api")
List<V> list();
@Headers("Content-Type: application/json")
@RequestLine("PUT /api/{key}")
void put(@Param("key") String, V value);
}
interface FooApi extends BaseApi<Foo> { }
interface BarApi extends BaseApi<Bar> { }
```
closes#133
While encoding or decoding, an exception without a message can occur.
Before this change, a NPE would return as the codec exceptions null
checked the message from the cause.
Files had various formatting differences, as did pull requests. Rather than
create our own style, this inherits and requires the well documented Google
Java Style.
Parameters annotated with `Param` expand based on their `toString`. By
specifying a custom `Param.Expander`, users can control this behavior,
for example formatting dates.
```java
@RequestLine("GET /?since={date}") Result list(@Param(value = "date", expander = DateToMillis.class) Date date);
```
Closes#122
Feign 8.x will no longer support Dagger, nor interfaces annotated with `javax.inject.@Named`. Users must migrate from `javax.inject.@Named` to `feign.@Param` via Feign v7.1+ before attempting to update to Feign 8.0.
For example, the following uses `@Param` as opposed to `@Named` to annotate template parameters.
```java
interface GitHub {
@RequestLine("GET /repos/{owner}/{repo}/contributors")
List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}
```
AssertJ has more powerful test assertions and does not run the risk of
interfering with the classpath of main code, such as guava does. This
removes guava from test and example code and adjusts using AssertJ in
some cases.
JUnit Rules, such as MockWebServerRule, reduce boilerplate setup present
in our tests. By migrating off TestNG, and onto rules, our tests become
more maintainable as JUnit is well understood.
Adds a new "slf4j" module. A few methods in Logger are now protected rather
than package protected to allow access by Logger subclasses that aren't
inner classes of Logger.
Request/Response/RequestTemplate are now fundamentally based on a byte[] body field.
For Request/RequestTemplate, if a charset is provided, it can be treated as text.
For many users of the library, the change should barely be noticeable, as the methods that
were changed were mostly used internally.
There were some non-backwards-compatible signature changes that require a
major version bump, however.
commit 34eb5751c760cf1f11cdbab920d6a3a1c6f06640
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 15 15:54:20 2013 -0400
Remove unnecessary defensive close of Reader
commit 38e51606750517d4a52571c408190e614a4a4834
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:59:35 2013 -0400
Replace wildcard import with individual imports
commit cc845814ea677ba5920caf5a7a914010623caf1e
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:55:37 2013 -0400
Revert GitHub example to use JacksonDecoder rather than JacksonModule now that JacksonDecoder behaves sensibly with its default ObjectMapper
commit 8b9638261afe2549c3a43238ee1b66d044f969f4
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:52:45 2013 -0400
Configure default ObjectMapper used by JacksonEncoder and JacksonDecoder with sensible overrides of default behaviors
commit 0f275bf7574b66c20a0e6aefe0140f599638992f
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:18:26 2013 -0400
Unwrap RuntimeJsonMappingExceptions caught in JacksonDecoder, since they are only ever used to wrap JsonMappingExceptions, which are IOExceptions.
commit 1b6995260a5727796e388bbb0b6c88b65e182415
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:09:44 2013 -0400
Update Jackson integration README
commit add4007a59559e7b4e2accfa0b0a0215bab62cef
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 13:07:35 2013 -0400
Update CHANGES and README to reflect addition of Jackson integration
commit 86c0fcfc704b1b8d03e5eaf69c608fc2761d617b
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 12:11:56 2013 -0400
Update Jackson GitHub example to make use of JacksonModule, and to avoid the need for Jackson annotations
commit 1552b3f8239636da0f27ace3c7b42038536e5caf
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 12:05:56 2013 -0400
Replace wildcard import with individual imports
commit 0b7cfd08516dfbf66f1a69263ed456f2c0671c76
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 11:01:11 2013 -0400
Initial implementation of Jackson codec
This new codec may be used as an alternative to Gson.
commit 94027ec3319f5145c0e18ef472d8e928e97a9527
Author: Matt Hurne <matt@thehurnes.com>
Date: Tue Oct 8 08:31:14 2013 -0400
Improve EncodeException and DecodeException Javadoc comments
This changeset adds a simple request interceptor that performs HTTP basic authentication.
The HTTP spec isn't very clear on the use of character encodings within this header.
The most common interpretation in servers appears to be to expect ISO-8859-1, so I've
used that as a default, as well as allowing the encoding to be specified.
At @adriancole's suggestion, sun.misc.BASE64Encoder is used for the base64 encoding
rather than pulling an implementation into the Util class. If we ever run into a JRE that
doesn't provide compatibility with that class, we can eliminate that dependency.
Previously, the default decoder had logic relating to responses that made it distinct from StringDecoder.
Now that that's handled elsewhere, the body of the decode methods had less meaningful differences.
I opted to maintain Decoder.Default for consistency with other default implementations. StringDecoder
is maintained as a separate class for backwards compatibility, and because it may be useful in the
future for clients to use a plain String decoder even if the default decoder starts having additional
capabilities.
For those who do not use Dagger, or do not wish to, this provides an alternate method of defining dependencies.
This includes logging config, decoders, etc. It still uses Dagger under the scenes, but doesn't require the user
to deal with the module system.
Decoder.Default's decoding to Response didn't actually work; the reader would always
be closed when used from Feign, as it depended on the url connection, which would
have been closed by the time the Response object was returned to the client.
This wasn't noticed because the default decoder tests don't use the mock web server.
There will be test coverage added for this shortly as part of the enhancements to
support a Builder.
This is intended as a step towards simplifying Feign.
This changeset removes the generics from both interfaces, and changes their
Dagger bindings from SET to UNIQUE.
Additionally, in changing the signatures for Encoder/Decoder, it focuses on use
of the RequestTemplate and Response objects, allowing us to extend them
in the future to support binary data without needing to change the
Encoder/Decoder signatures again.
They look something like this:
java.lang.NullPointerException
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:88)
at feign.$Proxy16.equals(Unknown Source)
In my particular instance, I had a proxy created by Feign registered in a Spring application context,
and it resulted in a NullPointerException on application shutdown.
Enhances the default client to GZIP-encode request bodies when the appropriate
content-encoding header is set in the interface's method definition.
https://github.com/Netflix/feign/issues/52
Sometimes, it's useful to override the hostname verifier for SSL connections.
One example, would be when you're developing against a test server managed by
another company that's using a self-signed certificate with a mis-matched
hostname. This patch enables that usage by overriding the default
HostnameVerifier in a Dagger module.
Adding test coverage required switching the TrustingSSLSocketFactory from
using an anonymous cipher suite to one that authenticates. A test keystore is
used for this purpose. It contains two self-signed certificates, one
each with alias (and CN) "localhost" and "bad.example.com". The
TrustingSSLSocketFactory is no longer a singleton; it now
optionally takes a key alias as an argument.