diff --git a/pom.xml b/pom.xml index 95e3096..2af0b5a 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,11 @@ okhttp 4.9.3 + + 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 79b1f06..51ed71b 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; @@ -24,10 +25,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"); @@ -73,7 +83,7 @@ private static Response doRequest(String bodyJson, String url, HashMap 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,