From 42e1032d4203e0e8d92355962cb52f058a08daef Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 10:09:48 -0500 Subject: [PATCH 1/4] [DEVEDSB-98] Add custom error view and dotenv configuration --- .env.example | 6 +++--- pom.xml | 5 +++++ .../verify_quickstart/services/TwilioVerification.java | 10 ++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 005eff8..5251402 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ # Twilio API credentials # (find here https://www.twilio.com/console) -export TWILIO_ACCOUNT_SID= -export TWILIO_AUTH_TOKEN= +TWILIO_ACCOUNT_SID= +TWILIO_AUTH_TOKEN= # Verification Service SID # (create one here https://www.twilio.com/console/verify/services) -export VERIFICATION_SID= +VERIFICATION_SID= diff --git a/pom.xml b/pom.xml index 852de7d..6a4959a 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ 2.0.0-beta test + + io.github.cdimascio + dotenv-java + 2.2.0 + diff --git a/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java b/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java index fcab0be..98d1fbf 100644 --- a/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java +++ b/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java @@ -4,12 +4,14 @@ import com.twilio.exception.ApiException; import com.twilio.rest.verify.v2.service.Verification; import com.twilio.rest.verify.v2.service.VerificationCheck; +import io.github.cdimascio.dotenv.Dotenv; -public class TwilioVerification implements VerificationService { - private static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); - private static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN"); - private static final String VERIFICATION_SID = System.getenv("VERIFICATION_SID"); +public class TwilioVerification implements VerificationService { + private static Dotenv env = Dotenv.configure().ignoreIfMissing().load(); + private static final String ACCOUNT_SID = env.get("TWILIO_ACCOUNT_SID"); + private static final String AUTH_TOKEN = env.get("TWILIO_AUTH_TOKEN"); + private static final String VERIFICATION_SID = env.get("VERIFICATION_SID"); public TwilioVerification() { Twilio.init(ACCOUNT_SID, AUTH_TOKEN); From f1ff8c77052b8b00b6670d7f4e61dcae4e1423b6 Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:06:40 -0500 Subject: [PATCH 2/4] [DEVEDSB-98] Add custom error view and dotenv configuration --- .../servlets/ErrorHandler.java | 21 +++++++++++++++++ src/main/webapp/WEB-INF/web.xml | 23 +++++++++++++++++++ src/main/webapp/error.html | 9 ++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/error.html diff --git a/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java b/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java new file mode 100644 index 0000000..3c45cf9 --- /dev/null +++ b/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java @@ -0,0 +1,21 @@ +// Import required java libraries +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import java.util.*; + +// Extend HttpServlet class +public class ErrorHandler extends HttpServlet { + + // Method to handle GET method request. + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + request.getRequestDispatcher("/error.html").forward(request, response); + } + + // Method to handle POST method request. + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..93494a6 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + ErrorHandler + ErrorHandler + + + + + ErrorHandler + /ErrorHandler + + + + 404 + /ErrorHandler + + + + java.lang.Throwable + /ErrorHandler + + \ No newline at end of file diff --git a/src/main/webapp/error.html b/src/main/webapp/error.html new file mode 100644 index 0000000..8999c95 --- /dev/null +++ b/src/main/webapp/error.html @@ -0,0 +1,9 @@ + + + + +

Something went wrong!

+

Our Engineers are on it

+ Go Home + + From 3754f7d61173c9bf12c10ba07b9a66707863e08a Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:07:59 -0500 Subject: [PATCH 3/4] [DEVEDSB-98] Add custom error view and dotenv configuration --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 1e316ef..25f85c3 100644 --- a/README.md +++ b/README.md @@ -62,14 +62,6 @@ After the above requirements have been met: ``` See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables. - If you are using a UNIX operating system, load the environment variables before the application starts. - - ```bash - source .env - ``` - - _If you are using a different operating system, make sure that all the variables from the `.env` file are loaded into your environment._ - 3. Build the project ```bash From cde6f5c51c13d446ac3711a0ee2c27b09fd6847a Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:08:34 -0500 Subject: [PATCH 4/4] [DEVEDSB-98] Add custom error view and dotenv configuration --- src/main/webapp/WEB-INF/web.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 93494a6..f870121 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -20,4 +20,4 @@ java.lang.Throwable /ErrorHandler - \ No newline at end of file +