-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EWT-192] Add support for a limited set of custom HTTP headers (#204)
- Loading branch information
Showing
51 changed files
with
1,156 additions
and
221 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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/truelayer/java/commonapi/CommonHandler.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,29 @@ | ||
package com.truelayer.java.commonapi; | ||
|
||
import static com.truelayer.java.http.mappers.HeadersMapper.toMap; | ||
import static java.util.Collections.emptyMap; | ||
|
||
import com.truelayer.java.commonapi.entities.SubmitPaymentReturnParametersRequest; | ||
import com.truelayer.java.commonapi.entities.SubmitPaymentReturnParametersResponse; | ||
import com.truelayer.java.http.entities.ApiResponse; | ||
import com.truelayer.java.http.entities.Headers; | ||
import java.util.concurrent.CompletableFuture; | ||
import lombok.Value; | ||
|
||
@Value | ||
public class CommonHandler implements ICommonHandler { | ||
|
||
ICommonApi commonApi; | ||
|
||
@Override | ||
public CompletableFuture<ApiResponse<SubmitPaymentReturnParametersResponse>> submitPaymentReturnParameters( | ||
SubmitPaymentReturnParametersRequest request) { | ||
return commonApi.submitPaymentReturnParameters(emptyMap(), request); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ApiResponse<SubmitPaymentReturnParametersResponse>> submitPaymentReturnParameters( | ||
Headers headers, SubmitPaymentReturnParametersRequest request) { | ||
return commonApi.submitPaymentReturnParameters(toMap(headers), request); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/truelayer/java/commonapi/ICommonHandler.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,16 @@ | ||
package com.truelayer.java.commonapi; | ||
|
||
import com.truelayer.java.commonapi.entities.SubmitPaymentReturnParametersRequest; | ||
import com.truelayer.java.commonapi.entities.SubmitPaymentReturnParametersResponse; | ||
import com.truelayer.java.http.entities.ApiResponse; | ||
import com.truelayer.java.http.entities.Headers; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface ICommonHandler { | ||
|
||
CompletableFuture<ApiResponse<SubmitPaymentReturnParametersResponse>> submitPaymentReturnParameters( | ||
SubmitPaymentReturnParametersRequest request); | ||
|
||
CompletableFuture<ApiResponse<SubmitPaymentReturnParametersResponse>> submitPaymentReturnParameters( | ||
Headers headers, SubmitPaymentReturnParametersRequest request); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/truelayer/java/entities/EmptyRequestBody.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,6 @@ | ||
package com.truelayer.java.entities; | ||
|
||
import lombok.Value; | ||
|
||
@Value | ||
public class EmptyRequestBody {} |
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
18 changes: 0 additions & 18 deletions
18
src/main/java/com/truelayer/java/http/entities/Header.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/main/java/com/truelayer/java/http/entities/Headers.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,21 @@ | ||
package com.truelayer.java.http.entities; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Class representing custom TL headers that we allow our users to set. | ||
*/ | ||
@Builder | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public class Headers { | ||
private String idempotencyKey; | ||
|
||
private String signature; | ||
|
||
private String xForwardedFor; | ||
} |
13 changes: 12 additions & 1 deletion
13
...terceptors/IdempotencyKeyInterceptor.java → ...s/IdempotencyKeyGeneratorInterceptor.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 |
---|---|---|
@@ -1,20 +1,31 @@ | ||
package com.truelayer.java.http.interceptors; | ||
|
||
import static org.apache.commons.lang3.ObjectUtils.isEmpty; | ||
|
||
import com.truelayer.java.Constants; | ||
import java.io.IOException; | ||
import java.util.UUID; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class IdempotencyKeyInterceptor implements Interceptor { | ||
public class IdempotencyKeyGeneratorInterceptor implements Interceptor { | ||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
|
||
if (!needsIdempotencyGeneration(request)) { | ||
return chain.proceed(request); | ||
} | ||
|
||
Request newRequest = request.newBuilder() | ||
.header(Constants.HeaderNames.IDEMPOTENCY_KEY, UUID.randomUUID().toString()) | ||
.build(); | ||
|
||
return chain.proceed(newRequest); | ||
} | ||
|
||
private boolean needsIdempotencyGeneration(Request request) { | ||
return isEmpty(request.header(Constants.HeaderNames.IDEMPOTENCY_KEY)); | ||
} | ||
} |
Oops, something went wrong.