Browse Source
* FIXED unsupported jaxrs-2.1 annotations should not break entire interface, resolving #669 * UPDATED jaxrs: more defensive jaxrs2 support * ADDED jsr311-api dependency to httpclient (as jsr311 is `provided` in feign-jaxrs now) * UPDATED httpclient `jsr311-api` scope to test UPDATED jaxrs readmepull/695/head
masc
7 years ago
committed by
Marvin Froeder
7 changed files with 180 additions and 23 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
# Feign JAXRS 2 |
||||
This module overrides annotation processing to instead use standard ones supplied by the JAX-RS specification. This is currently targeted at the 1.1 spec. |
||||
|
||||
## Limitations |
||||
While it may appear possible to reuse the same interface across client and server, bear in mind that JAX-RS resource |
||||
annotations were not designed to be processed by clients. Moreover, JAX-RS 2.0 has a different package hierarchy for |
||||
client invocation. Finally, JAX-RS is a large spec and attempts to implement it completely would be a project larger |
||||
than feign itself. In other words, this implementation is *best efforts* and concedes far from 100% compatibility with |
||||
server interface behavior. |
||||
|
||||
## Currently Supported Annotation Processing |
||||
Feign only supports processing java interfaces (not abstract or concrete classes). |
||||
|
||||
ISE is raised when any annotation's value is empty or null. Ex. `Path("")` raises an ISE. |
||||
|
||||
Here are a list of behaviors currently supported. |
||||
### Type Annotations |
||||
#### `@Path` |
||||
Appends the value to `Target.url()`. Can have tokens corresponding to `@PathParam` annotations. |
||||
### Method Annotations |
||||
#### `@HttpMethod` meta-annotation (present on `@GET`, `@POST`, etc.) |
||||
Sets the request method. |
||||
#### `@Path` |
||||
Appends the value to `Target.url()`. Can have tokens corresponding to `@PathParam` annotations. |
||||
#### `@Produces` |
||||
Adds the first value as the `Accept` header. |
||||
#### `@Consumes` |
||||
Adds the first value as the `Content-Type` header. |
||||
### Parameter Annotations |
||||
#### `@PathParam` |
||||
Links the value of the corresponding parameter to a template variable declared in the path. |
||||
#### `@QueryParam` |
||||
Links the value of the corresponding parameter to a query parameter. When invoked, null will skip the query param. |
||||
#### `@HeaderParam` |
||||
Links the value of the corresponding parameter to a header. |
||||
#### `@FormParam` |
||||
Links the value of the corresponding parameter to a key passed to `Encoder.Text<Map<String, Object>>.encode()`. |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
<!-- |
||||
|
||||
Copyright 2012-2018 The Feign Authors |
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
||||
in compliance with the License. You may obtain a copy of the License at |
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
Unless required by applicable law or agreed to in writing, software distributed under the License |
||||
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
||||
or implied. See the License for the specific language governing permissions and limitations under |
||||
the License. |
||||
|
||||
--> |
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
<modelVersion>4.0.0</modelVersion> |
||||
|
||||
<parent> |
||||
<groupId>io.github.openfeign</groupId> |
||||
<artifactId>parent</artifactId> |
||||
<version>9.7.0-SNAPSHOT</version> |
||||
</parent> |
||||
|
||||
<artifactId>feign-jaxrs2</artifactId> |
||||
<name>Feign JAX-RS 2</name> |
||||
<description>Feign JAX-RS 2</description> |
||||
|
||||
<properties> |
||||
<main.basedir>${project.basedir}/..</main.basedir> |
||||
</properties> |
||||
|
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>${project.groupId}</groupId> |
||||
<artifactId>feign-core</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>${project.groupId}</groupId> |
||||
<artifactId>feign-jaxrs</artifactId> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>javax.ws.rs</groupId> |
||||
<artifactId>javax.ws.rs-api</artifactId> |
||||
<version>2.1</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
|
||||
<!-- for example --> |
||||
<dependency> |
||||
<groupId>${project.groupId}</groupId> |
||||
<artifactId>feign-gson</artifactId> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
|
||||
<dependency> |
||||
<groupId>${project.groupId}</groupId> |
||||
<artifactId>feign-core</artifactId> |
||||
<type>test-jar</type> |
||||
<scope>test</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/** |
||||
* Copyright 2012-2018 The Feign Authors |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
||||
* in compliance with the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License |
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
||||
* or implied. See the License for the specific language governing permissions and limitations under |
||||
* the License. |
||||
*/ |
||||
package feign.jaxrs; |
||||
|
||||
import javax.ws.rs.container.Suspended; |
||||
import javax.ws.rs.core.Context; |
||||
import java.lang.annotation.Annotation; |
||||
|
||||
/** |
||||
* Please refer to the <a href="https://github.com/Netflix/feign/tree/master/feign-jaxrs2">Feign |
||||
* JAX-RS 2 README</a>. |
||||
*/ |
||||
public final class JAXRS2Contract extends JAXRSContract { |
||||
@Override |
||||
protected boolean isUnsupportedHttpParameterAnnotation(Annotation parameterAnnotation) { |
||||
Class<? extends Annotation> annotationType = parameterAnnotation.annotationType(); |
||||
|
||||
// masc20180327. parameter with unsupported jax-rs annotations should not be passed as body params.
|
||||
// this will prevent interfaces from becoming unusable entirely due to single (unsupported) endpoints.
|
||||
// https://github.com/OpenFeign/feign/issues/669
|
||||
return (annotationType == Suspended.class || |
||||
annotationType == Context.class); |
||||
} |
||||
} |
Loading…
Reference in new issue