From abd470c4d3e2110e9340f444c039872dc1bff2bc Mon Sep 17 00:00:00 2001 From: Ahmed Hosny Date: Sun, 25 Sep 2022 16:59:57 +0100 Subject: [PATCH 1/2] Adding Logging Interceptor. --- pom.xml | 7 ++++++- src/main/java/co/dapi/DapiRequest.java | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index bc49155..5db2835 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ co.dapi dapi-java - 1.4.3 + 0.1.${BUILD_NUMBER} jar ${project.groupId}:${project.artifactId} @@ -122,6 +122,11 @@ okhttp 4.9.1 + + com.squareup.okhttp3 + logging-interceptor + 4.9.1 + diff --git a/src/main/java/co/dapi/DapiRequest.java b/src/main/java/co/dapi/DapiRequest.java index c03d8aa..829424d 100644 --- a/src/main/java/co/dapi/DapiRequest.java +++ b/src/main/java/co/dapi/DapiRequest.java @@ -3,6 +3,7 @@ import co.dapi.types.UserInput; import com.google.gson.*; import okhttp3.*; +import okhttp3.logging.HttpLoggingInterceptor; import java.io.IOException; import java.lang.reflect.Type; @@ -21,10 +22,19 @@ public class DapiRequest { .registerTypeAdapter(HashMap.class, new SDKRequestSerializer()) .create(); - private final static OkHttpClient httpClient = new OkHttpClient().newBuilder() - .readTimeout(2, TimeUnit.MINUTES) - .build(); + private static OkHttpClient httpClient = null; + private static OkHttpClient getHttpClient(){ + if(httpClient == null){ + HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); + logger.setLevel(HttpLoggingInterceptor.Level.BODY); + httpClient = new OkHttpClient().newBuilder() + .addInterceptor(logger) + .readTimeout(2, TimeUnit.MINUTES) + .build(); + } + return httpClient; + } public static Response HandleSDK(String bodyJson, HashMap headersMap) throws IOException { headersMap.put("host", "dd.dapi.com"); @@ -68,7 +78,7 @@ private static Response doRequest(String bodyJson, String url, HashMap Date: Mon, 26 Sep 2022 22:06:30 +0100 Subject: [PATCH 2/2] Update the UserInput object to have default constructor and setters. --- src/main/java/co/dapi/types/UserInput.java | 43 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/dapi/types/UserInput.java b/src/main/java/co/dapi/types/UserInput.java index abc3de0..ef52347 100644 --- a/src/main/java/co/dapi/types/UserInput.java +++ b/src/main/java/co/dapi/types/UserInput.java @@ -3,10 +3,17 @@ import java.util.Optional; public class UserInput { - private final UserInputID id; - private final int index; - private final String query; - private final String answer; + private UserInputID id; + private int index; + private String query; + private String answer; + + /** + * Creates an empty UserInput object. + * + */ + public UserInput() { + } /** * Creates a UserInput object with all of its info. @@ -50,6 +57,13 @@ public UserInputID getId() { return id; } + /** + * Sets the id field. + */ + public void setId(UserInputID id) { + this.id = id; + } + /** * returns the index of this UserInput, starting from 0. * will always be 0 if only one input is requested. @@ -58,6 +72,13 @@ public int getIndex() { return index; } + /** + * Sets the index. + */ + public void setIndex(int index) { + this.index = index; + } + /** * returns the textual description of what is required from the user side by this UserInput. */ @@ -65,6 +86,13 @@ public Optional getQuery() { return Optional.ofNullable(query); } + /** + * Sets the query. + */ + public void setQuery(String query) { + this.query = query; + } + /** * returns the UserInput that must be submitted. * in the response it will always be empty. @@ -73,6 +101,13 @@ public Optional getAnswer() { return Optional.ofNullable(answer); } + /** + * Sets the answer. + */ + public void setAnswer(String answer) { + this.answer = answer; + } + public enum UserInputID { otp, secret_question,