-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
990 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>com.playtika.reactivefeign</groupId> | ||
<artifactId>feign-reactor</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>feign-reactor-jetty</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.playtika.reactivefeign</groupId> | ||
<artifactId>feign-reactor-core</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-reactive-httpclient</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jsr310</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.kptfh.reactivejson</groupId> | ||
<artifactId>json-reactor</artifactId> | ||
</dependency> | ||
|
||
<!-- Tests --> | ||
<dependency> | ||
<groupId>com.playtika.reactivefeign</groupId> | ||
<artifactId>feign-reactor-core</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.projectreactor</groupId> | ||
<artifactId>reactor-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.tomakehurst</groupId> | ||
<artifactId>wiremock</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.logging.log4j</groupId> | ||
<artifactId>log4j-slf4j-impl</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.awaitility</groupId> | ||
<artifactId>awaitility</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>spring-boot-starter-logging</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
</exclusion> | ||
</exclusions> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
86 changes: 86 additions & 0 deletions
86
feign-reactor-jetty/src/main/java/reactivefeign/jetty/JettyReactiveFeign.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright 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 reactivefeign.jetty; | ||
|
||
import com.fasterxml.jackson.core.async_.JsonFactory; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import org.eclipse.jetty.client.HttpClient; | ||
import reactivefeign.ReactiveFeign; | ||
import reactivefeign.ReactiveOptions; | ||
import reactivefeign.jetty.client.JettyReactiveHttpClient; | ||
|
||
/** | ||
* Reactive Jetty client based implementation of reactive Feign | ||
* | ||
* @author Sergii Karpenko | ||
*/ | ||
public class JettyReactiveFeign { | ||
|
||
public static <T> Builder<T> builder() { | ||
try { | ||
HttpClient httpClient = new HttpClient(); | ||
httpClient.start(); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
objectMapper.registerModule(new JavaTimeModule()); | ||
return new Builder<>(httpClient, new JsonFactory(), objectMapper); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
} | ||
|
||
public static <T> Builder<T> builder(HttpClient httpClient, JsonFactory jsonFactory, ObjectMapper objectMapper) { | ||
return new Builder<>(httpClient, jsonFactory, objectMapper); | ||
} | ||
|
||
public static class Builder<T> extends ReactiveFeign.Builder<T> { | ||
|
||
protected HttpClient httpClient; | ||
protected JsonFactory jsonFactory; | ||
private ObjectMapper objectMapper; | ||
protected ReactiveOptions options; | ||
|
||
protected Builder(HttpClient httpClient, JsonFactory jsonFactory, ObjectMapper objectMapper) { | ||
setHttpClient(httpClient, jsonFactory, objectMapper); | ||
this.jsonFactory = jsonFactory; | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Override | ||
public Builder<T> options(ReactiveOptions options) { | ||
if (options.getConnectTimeoutMillis() != null) { | ||
httpClient.setConnectTimeout(options.getConnectTimeoutMillis()); | ||
} | ||
if (options.getReadTimeoutMillis() != null) { | ||
setHttpClient(httpClient, jsonFactory, objectMapper); | ||
} | ||
this.options = options; | ||
return this; | ||
} | ||
|
||
protected void setHttpClient(HttpClient httpClient, JsonFactory jsonFactory, ObjectMapper objectMapper){ | ||
this.httpClient = httpClient; | ||
clientFactory(methodMetadata -> { | ||
JettyReactiveHttpClient jettyClient = JettyReactiveHttpClient.jettyClient(methodMetadata, httpClient, jsonFactory, objectMapper); | ||
if (options != null && options.getReadTimeoutMillis() != null) { | ||
jettyClient.setRequestTimeout(options.getReadTimeoutMillis()); | ||
} | ||
return jettyClient; | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.