Skip to content

Commit 2597d3b

Browse files
author
adriancole
committed
Moved SaxDecoder into feign-sax dependency.
1 parent 7487f80 commit 2597d3b

9 files changed

Lines changed: 77 additions & 17 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
### Version 5.0
22
* Remove support for Observable methods.
3-
* SaxDecoder now decodes multiple types.
4-
* Remove pattern decoders in favor of SaxDecoder.
53
* Use single non-generic Decoder/Encoder instead of sets of type-specific Decoders/Encoders.
64
* Decoders/Encoders are now more flexible, having access to the Response/RequestTemplate respectively.
5+
* Moved SaxDecoder into `feign-sax` dependency.
6+
* SaxDecoder now decodes multiple types.
7+
* Remove pattern decoders in favor of SaxDecoder.
78
* Added Feign.Builder to simplify client customizations without using Dagger.
89
* Gson type adapters can be registered as Dagger set bindings.
910
* `Feign.create(...)` now requires specifying an encoder and decoder.

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,24 @@ For example, the following pattern might decorate each request with the current
7878
CloudDNS cloudDNS = Feign.builder().target(new CloudIdentityTarget<CloudDNS>(user, apiKey));
7979
```
8080

81-
You can find [several examples](https://github.com/Netflix/feign/tree/master/feign-core/src/test/java/feign/examples) in the test tree. Do take time to look at them, as seeing is believing!
81+
You can find [several examples](https://github.com/Netflix/feign/tree/master/core/src/test/java/feign/examples) in the test tree. Do take time to look at them, as seeing is believing!
8282

8383
### Integrations
8484
Feign intends to work well within Netflix and other Open Source communities. Modules are welcome to integrate with your favorite projects!
85+
8586
### Gson
86-
[GsonModule](https://github.com/Netflix/feign/tree/master/feign-gson) adds default encoders and decoders so you get get started with a JSON api.
87+
[GsonModule](https://github.com/Netflix/feign/tree/master/gson) adds default encoders and decoders so you get get started with a JSON api.
8788

8889
Integration requires you pass `new GsonModule()` to `Feign.create()`, or add it to your graph with Dagger:
8990
```java
9091
GitHub github = Feign.create(GitHub.class, "https://api.github.com", new GsonModule());
9192
```
9293

94+
### Sax
95+
[SaxDecoder](https://github.com/Netflix/feign/tree/master/sax) allows you to decode XML in a way that is compatible with normal JVM and also Android environments.
96+
9397
### JAX-RS
94-
[JAXRSModule](https://github.com/Netflix/feign/tree/master/feign-jaxrs) overrides annotation processing to instead use standard ones supplied by the JAX-RS specification. This is currently targeted at the 1.1 spec.
98+
[JAXRSModule](https://github.com/Netflix/feign/tree/master/jaxrs) overrides annotation processing to instead use standard ones supplied by the JAX-RS specification. This is currently targeted at the 1.1 spec.
9599

96100
Here's the example above re-written to use JAX-RS:
97101
```java
@@ -101,7 +105,7 @@ interface GitHub {
101105
}
102106
```
103107
### Ribbon
104-
[RibbonModule](https://github.com/Netflix/feign/tree/master/feign-ribbon) overrides URL resolution of Feign's client, adding smart routing and resiliency capabilities provided by [Ribbon](https://github.com/Netflix/ribbon).
108+
[RibbonModule](https://github.com/Netflix/feign/tree/master/ribbon) overrides URL resolution of Feign's client, adding smart routing and resiliency capabilities provided by [Ribbon](https://github.com/Netflix/ribbon).
105109

106110
Integration requires you to pass your ribbon client name as the host part of the url, for example `myAppProd`.
107111
```java

build.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ project(':feign-core') {
4545
}
4646
}
4747

48+
project(':feign-sax') {
49+
apply plugin: 'java'
50+
51+
test {
52+
useTestNG()
53+
}
54+
55+
dependencies {
56+
compile project(':feign-core')
57+
testCompile 'com.google.guava:guava:14.0.1'
58+
testCompile 'org.testng:testng:6.8.5'
59+
}
60+
}
61+
4862
project(':feign-gson') {
4963
apply plugin: 'java'
5064

sax/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Sax Decoder
2+
===================
3+
4+
This module adds support for decoding xml via SAX.
5+
6+
Add this to your object graph like so:
7+
8+
```java
9+
IAM iam = Feign.create(IAM.class, "https://iam.amazonaws.com", new DecodeWithSax());
10+
11+
--snip--
12+
@Module(addsTo = Feign.Defaults.class)
13+
static class DecodeWithSax {
14+
@Provides Decoder saxDecoder(Provider<UserIdHandler> userIdHandler) {
15+
return SAXDecoder.builder() //
16+
.addContentHandler(userIdHandler) //
17+
.build();
18+
}
19+
20+
@Provides Encoder defaultEncoder() {
21+
return new Encoder.Default();
22+
}
23+
}
24+
```

core/src/main/java/feign/codec/SAXDecoder.java renamed to sax/src/main/java/feign/sax/SAXDecoder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package feign.codec;
16+
package feign.sax;
1717

1818
import feign.Response;
19+
import feign.codec.Decoder;
20+
import feign.codec.DecodeException;
1921
import org.xml.sax.ContentHandler;
2022
import org.xml.sax.InputSource;
2123
import org.xml.sax.SAXException;
@@ -90,7 +92,7 @@ private SAXDecoder(Map<Type, Provider<? extends ContentHandlerWithResult<?>>> ha
9092

9193
@Override
9294
public Object decode(Response response, Type type) throws IOException, DecodeException {
93-
if (response.body() == null) {
95+
if (void.class.equals(type) || response.body() == null) {
9496
return null;
9597
}
9698
Provider<? extends ContentHandlerWithResult<?>> handlerProvider = handlerProviders.get(type);

core/src/test/java/feign/codec/SAXDecoderTest.java renamed to sax/src/test/java/feign/sax/SAXDecoderTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package feign.codec;
16+
package feign.sax;
1717

1818
import dagger.ObjectGraph;
1919
import dagger.Provides;
20+
import feign.codec.Decoder;
21+
import feign.codec.DecodeException;
2022
import feign.Response;
2123
import org.testng.annotations.BeforeClass;
2224
import org.testng.annotations.Test;
@@ -135,4 +137,14 @@ public void characters(char ch[], int start, int length) {
135137
currentText.append(ch, start, length);
136138
}
137139
}
140+
141+
@Test public void voidDecodesToNull() throws Exception {
142+
Response response = Response.create(200, "OK", Collections.<String, Collection<String>>emptyMap(), statusFailed);
143+
assertEquals(decoder.decode(response, void.class), null);
144+
}
145+
146+
@Test public void nullBodyDecodesToNull() throws Exception {
147+
Response response = Response.create(204, "OK", Collections.<String, Collection<String>>emptyMap(), null);
148+
assertEquals(decoder.decode(response, String.class), null);
149+
}
138150
}

core/src/test/java/feign/examples/AWSSignatureVersion4.java renamed to sax/src/test/java/feign/sax/examples/AWSSignatureVersion4.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package feign.examples;
16+
package feign.sax.examples;
1717

1818
import com.google.common.base.Function;
1919
import com.google.common.base.Joiner;

core/src/test/java/feign/examples/IAMExample.java renamed to sax/src/test/java/feign/sax/examples/IAMExample.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package feign.examples;
16+
package feign.sax.examples;
1717

1818
import dagger.Module;
1919
import dagger.Provides;
@@ -23,14 +23,13 @@
2323
import feign.RequestTemplate;
2424
import feign.Target;
2525
import feign.codec.Decoder;
26-
import feign.codec.SAXDecoder;
26+
import feign.codec.Encoder;
27+
import feign.sax.SAXDecoder;
2728
import org.xml.sax.helpers.DefaultHandler;
2829

2930
import javax.inject.Inject;
3031
import javax.inject.Provider;
3132

32-
import static dagger.Provides.Type.SET;
33-
3433
public class IAMExample {
3534

3635
interface IAM {
@@ -66,13 +65,17 @@ private IAMTarget(String accessKey, String secretKey) {
6665
}
6766
}
6867

69-
@Module(library = true)
68+
@Module(addsTo = Feign.Defaults.class)
7069
static class DecodeWithSax {
71-
@Provides(type = SET) Decoder saxDecoder(Provider<UserIdHandler> userIdHandler) {
70+
@Provides Decoder saxDecoder(Provider<UserIdHandler> userIdHandler) {
7271
return SAXDecoder.builder() //
7372
.addContentHandler(userIdHandler) //
7473
.build();
7574
}
75+
76+
@Provides Encoder defaultEncoder() {
77+
return new Encoder.Default();
78+
}
7679
}
7780

7881
static class UserIdHandler extends DefaultHandler implements

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
rootProject.name='feign'
2-
include 'core', 'gson', 'jaxrs', 'ribbon', 'example-github', 'example-wikipedia'
2+
include 'core', 'sax', 'gson', 'jaxrs', 'ribbon', 'example-github', 'example-wikipedia'
33

44
rootProject.children.each { childProject ->
55
childProject.name = 'feign-' + childProject.name

0 commit comments

Comments
 (0)