Skip to content

Commit

Permalink
Removing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed Nov 4, 2022
2 parents ba413e8 + 45cff06 commit 734272c
Show file tree
Hide file tree
Showing 81 changed files with 2,012 additions and 739 deletions.
11 changes: 7 additions & 4 deletions README.md
@@ -1,4 +1,4 @@
# Feign makes writing java http clients easier
# Feign makes writing Java http clients easier

[![Join the chat at https://gitter.im/OpenFeign/feign](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OpenFeign/feign?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![CircleCI](https://circleci.com/gh/OpenFeign/feign/tree/master.svg?style=svg)](https://circleci.com/gh/OpenFeign/feign/tree/master)
Expand All @@ -9,7 +9,7 @@ Feign is a Java to HTTP client binder inspired by [Retrofit](https://github.com/
---
### Why Feign and not X?

Feign uses tools like Jersey and CXF to write java clients for ReST or SOAP services. Furthermore, Feign allows you to write your own code on top of http libraries such as Apache HC. Feign connects your code to http APIs with minimal overhead and code via customizable decoders and error handling, which can be written to any text-based http API.
Feign uses tools like Jersey and CXF to write Java clients for ReST or SOAP services. Furthermore, Feign allows you to write your own code on top of http libraries such as Apache HC. Feign connects your code to http APIs with minimal overhead and code via customizable decoders and error handling, which can be written to any text-based http API.

### How does Feign work?

Expand Down Expand Up @@ -897,16 +897,19 @@ public interface Api {
}
```

When used in this manner, without specifying a custom `QueryMapEncoder`, the query map will be generated using member variable names as query parameter names. The following POJO will generate query params of "/find?name={name}&number={number}" (order of included query parameters not guaranteed, and as usual, if any value is null, it will be left out).
When used in this manner, without specifying a custom `QueryMapEncoder`, the query map will be generated using member variable names as query parameter names. You can annotate a specific field of `CustomPojo` with the `@Param` annotation to specify a different name to the query parameter. The following POJO will generate query params of "/find?name={name}&number={number}&region_id={regionId}" (order of included query parameters not guaranteed, and as usual, if any value is null, it will be left out).

```java
public class CustomPojo {
private final String name;
private final int number;
@Param("region_id")
private final String regionId;

public CustomPojo (String name, int number) {
public CustomPojo (String name, int number, String regionId) {
this.name = name;
this.number = number;
this.regionId = regionId;
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion annotation-error-decoder/pom.xml
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>parent</artifactId>
<version>12.0-SNAPSHOT</version>
<version>12.1-SNAPSHOT</version>
</parent>

<artifactId>feign-annotation-error-decoder</artifactId>
Expand Down
6 changes: 3 additions & 3 deletions apt-test-generator/pom.xml
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>parent</artifactId>
<version>12.0-SNAPSHOT</version>
<version>12.1-SNAPSHOT</version>
</parent>

<groupId>io.github.openfeign.experimental</groupId>
Expand All @@ -36,7 +36,7 @@
<dependency>
<groupId>com.github.jknack</groupId>
<artifactId>handlebars</artifactId>
<version>4.3.0</version>
<version>4.3.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -95,7 +95,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
6 changes: 3 additions & 3 deletions benchmark/pom.xml
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>parent</artifactId>
<version>12.0-SNAPSHOT</version>
<version>12.1-SNAPSHOT</version>
</parent>

<artifactId>feign-benchmark</artifactId>
Expand All @@ -30,7 +30,7 @@
<jmh.version>1.35</jmh.version>
<rx.netty.version>0.5.3</rx.netty.version>
<rx.java.version>1.3.8</rx.java.version>
<netty.version>4.1.82.Final</netty.version>
<netty.version>4.1.84.Final</netty.version>
<main.basedir>${project.basedir}/..</main.basedir>
</properties>

Expand Down Expand Up @@ -134,7 +134,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>io.github.openfeign</groupId>
<artifactId>parent</artifactId>
<version>12.0-SNAPSHOT</version>
<version>12.1-SNAPSHOT</version>
</parent>

<artifactId>feign-core</artifactId>
Expand Down
121 changes: 18 additions & 103 deletions core/src/main/java/feign/AsyncFeign.java
Expand Up @@ -13,20 +13,17 @@
*/
package feign;

import feign.InvocationHandlerFactory.MethodHandler;
import feign.ReflectiveFeign.ParseHandlersByName;
import feign.Logger.Level;
import feign.Request.Options;
import feign.Target.HardCodedTarget;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.codec.ErrorDecoder;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

/**
Expand All @@ -45,7 +42,7 @@
* be done (for example, creating and submitting a task to an {@link ExecutorService}).
*/
@Experimental
public abstract class AsyncFeign<C> {
public final class AsyncFeign<C> {
public static <C> AsyncBuilder<C> builder() {
return new AsyncBuilder<>();
}
Expand Down Expand Up @@ -196,7 +193,6 @@ public AsyncBuilder<C> invocationHandlerFactory(InvocationHandlerFactory invocat

public AsyncFeign<C> build() {
super.enrich();
ThreadLocal<AsyncInvocation<C>> activeContextHolder = new ThreadLocal<>();

AsyncResponseHandler responseHandler =
(AsyncResponseHandler) Capability.enrich(
Expand All @@ -210,113 +206,32 @@ public AsyncFeign<C> build() {
AsyncResponseHandler.class,
capabilities);

final SynchronousMethodHandler.Factory synchronousMethodHandlerFactory =
new SynchronousMethodHandler.Factory(stageExecution(activeContextHolder, client), retryer,
requestInterceptors, this.clientInterceptors,
responseInterceptor, logger, logLevel, dismiss404, closeAfterDecode,
propagationPolicy, true);
final ParseHandlersByName handlersByName =
new ParseHandlersByName(contract, options, encoder,
stageDecode(activeContextHolder, logger, logLevel, responseHandler), queryMapEncoder,
errorDecoder, synchronousMethodHandlerFactory);
final ReflectiveFeign feign =
new ReflectiveFeign(handlersByName, invocationHandlerFactory, queryMapEncoder);
return new ReflectiveAsyncFeign<>(feign, defaultContextSupplier, activeContextHolder,
methodInfoResolver);
}

private Client stageExecution(
ThreadLocal<AsyncInvocation<C>> activeContext,
AsyncClient<C> client) {
return (request, options) -> {
final Response result = Response.builder().status(200).request(request).build();

final AsyncInvocation<C> invocationContext = activeContext.get();

invocationContext.setResponseFuture(
client.execute(request, options, Optional.ofNullable(invocationContext.context())));

return result;
};
}

// from SynchronousMethodHandler
long elapsedTime(long start) {
return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
}

private Decoder stageDecode(
ThreadLocal<AsyncInvocation<C>> activeContext,
Logger logger,
Level logLevel,
AsyncResponseHandler responseHandler) {
return (response, type) -> {
final AsyncInvocation<C> invocationContext = activeContext.get();

final CompletableFuture<Object> result = new CompletableFuture<>();

invocationContext
.responseFuture()
.whenComplete(
(r, t) -> {
final long elapsedTime = elapsedTime(invocationContext.startNanos());

if (t != null) {
if (logLevel != Logger.Level.NONE && t instanceof IOException) {
final IOException e = (IOException) t;
logger.logIOException(invocationContext.configKey(), logLevel, e,
elapsedTime);
}
result.completeExceptionally(t);
} else {
responseHandler.handleResponse(
result,
invocationContext.configKey(),
r,
invocationContext.underlyingType(),
elapsedTime);
}
});

result.whenComplete(
(r, t) -> {
if (result.isCancelled()) {
invocationContext.responseFuture().cancel(true);
}
});

if (invocationContext.isAsyncReturnType()) {
return result;
}
try {
return result.join();
} catch (final CompletionException e) {
final Response r = invocationContext.responseFuture().join();
Throwable cause = e.getCause();
if (cause == null) {
cause = e;
}
throw new AsyncJoinException(r.status(), cause.getMessage(), r.request(), cause);
}
};
final MethodHandler.Factory<C> methodHandlerFactory =
new AsynchronousMethodHandler.Factory<>(
client, retryer, requestInterceptors,
clientInterceptors, responseHandler, logger, logLevel,
propagationPolicy, methodInfoResolver);
final ParseHandlersByName<C> handlersByName =
new ParseHandlersByName<>(contract, options, encoder,
decoder, queryMapEncoder,
errorDecoder, methodHandlerFactory);
final ReflectiveFeign<C> feign =
new ReflectiveFeign<>(handlersByName, invocationHandlerFactory, defaultContextSupplier);
return new AsyncFeign<>(feign);
}
}

private final Feign feign;
private AsyncContextSupplier<C> defaultContextSupplier;
private final ReflectiveFeign<C> feign;

protected AsyncFeign(Feign feign, AsyncContextSupplier<C> defaultContextSupplier) {
private AsyncFeign(ReflectiveFeign<C> feign) {
this.feign = feign;
this.defaultContextSupplier = defaultContextSupplier;
}

public <T> T newInstance(Target<T> target) {
return newInstance(target, defaultContextSupplier.newContext());
return feign.newInstance(target);
}

public <T> T newInstance(Target<T> target, C context) {
return wrap(target.type(), feign.newInstance(target), context);
return feign.newInstance(target, context);
}

protected abstract <T> T wrap(Class<T> type, T instance, C context);
}
64 changes: 0 additions & 64 deletions core/src/main/java/feign/AsyncInvocation.java

This file was deleted.

35 changes: 0 additions & 35 deletions core/src/main/java/feign/AsyncJoinException.java

This file was deleted.

0 comments on commit 734272c

Please sign in to comment.